configure([ 'preferences' => [ DynamicCollector::class => DynamicCollectorMock::class ] ]); $this->layout = Bootstrap::getObjectManager()->get(LayoutInterface::class); $this->dynamicCollected = Bootstrap::getObjectManager()->get(DynamicCollector::class); $this->random = Bootstrap::getObjectManager()->get(Random::class); } /** * Validate policies preserved when reading block from cache. * * @return void * * @magentoAppArea frontend * @magentoCache block_html enabled */ public function testCachedPolicies(): void { /** @var Template $block */ $block = $this->layout->createBlock( Template::class, 'test-block', ['data' => ['cache_lifetime' => 3600, 'cache_key' => $this->random->getRandomString(32)]] ); $block->setTemplate('Magento_TestModuleCspUtil::secure.phtml'); //Clearing previously added just in case. $this->dynamicCollected->consumeAdded(); $block->toHtml(); $dynamic = $this->dynamicCollected->consumeAdded(); $this->assertNotEmpty($dynamic); //From cache $block->toHtml(); $cached = $this->dynamicCollected->consumeAdded(); $this->assertEquals($dynamic, $cached); } }