Neos\Fusion\Tests\Unit\Core\Cache\ContentCacheTest::getCachedSegmentWithExistingCacheEntryReplacesNestedCachedSegments PHP Метод

getCachedSegmentWithExistingCacheEntryReplacesNestedCachedSegments() публичный Метод

    public function getCachedSegmentWithExistingCacheEntryReplacesNestedCachedSegments()
    {
        $contentCache = new ContentCache();
        $mockSecurityContext = $this->createMock(Context::class);
        $this->inject($contentCache, 'securityContext', $mockSecurityContext);
        $mockPropertyMapper = $this->createMock(PropertyMapper::class);
        $mockPropertyMapper->expects($this->any())->method('convert')->will($this->returnArgument(0));
        $this->inject($contentCache, 'propertyMapper', $mockPropertyMapper);
        $this->inject($contentCache, 'parser', new CacheSegmentParser());
        $mockContext = $this->getMockBuilder(ApplicationContext::class)->disableOriginalConstructor()->getMock();
        $cacheBackend = new TransientMemoryBackend($mockContext);
        $cacheFrontend = new StringFrontend('foo', $cacheBackend);
        $cacheBackend->setCache($cacheFrontend);
        $this->inject($contentCache, 'cache', $cacheFrontend);
        $invalidContent = 'You should probably not use ' . ContentCache::CACHE_SEGMENT_START_TOKEN . ', ' . ContentCache::CACHE_SEGMENT_SEPARATOR_TOKEN . ' or ' . ContentCache::CACHE_SEGMENT_END_TOKEN . ' inside your content.';
        $innerCachedContent = $contentCache->createCacheSegment($invalidContent, 'some.typoscripth.path.innerCached', array('node' => 'foo'), array('mytag1', 'mytag2'));
        $uncachedCommandOutput = 'This content is highly dynamic with ' . ContentCache::CACHE_SEGMENT_SEPARATOR_TOKEN . ' and ' . ContentCache::CACHE_SEGMENT_END_TOKEN;
        $innerUncachedContent = $contentCache->createUncachedSegment($uncachedCommandOutput, 'some.typoscripth.path.innerUncached', array('node' => 'A node identifier'));
        $outerContentStart = 'You can nest cached segments like <';
        $outerContentMiddle = '> or uncached segments like <';
        $outerContentEnd = '> inside other segments.';
        $outerContent = $outerContentStart . $innerCachedContent . $outerContentMiddle . $innerUncachedContent . $outerContentEnd;
        $content = $contentCache->createCacheSegment($outerContent, 'some.typoscripth.path', array('node' => 'bar'), array('mytag2'), 86400);
        $output = $contentCache->processCacheSegments($content);
        $expectedOutput = $outerContentStart . $invalidContent . $outerContentMiddle . $uncachedCommandOutput . $outerContentEnd;
        $this->assertSame($expectedOutput, $output);
        $cachedContent = $contentCache->getCachedSegment(function ($command) use($uncachedCommandOutput) {
            if ($command === 'eval=some.typoscripth.path.innerUncached') {
                return $uncachedCommandOutput;
            } else {
                $this->fail('Unexpected command: ' . $command);
            }
        }, 'some.typoscripth.path', array('node' => 'bar'));
        $this->assertSame($expectedOutput, $cachedContent);
    }