/**
  * @test
  */
 public function flushRemovesAllCacheEntries()
 {
     $cache = $this->getMock('TYPO3\\Flow\\Cache\\Frontend\\FrontendInterface', array(), array(), '', FALSE);
     $backend = new \TYPO3\Flow\Cache\Backend\TransientMemoryBackend(new ApplicationContext('Testing'));
     $backend->setCache($cache);
     $data = 'some data' . microtime();
     $backend->set('TransientMemoryBackendTest1', $data);
     $backend->set('TransientMemoryBackendTest2', $data);
     $backend->set('TransientMemoryBackendTest3', $data);
     $backend->flush();
     $this->assertFalse($backend->has('TransientMemoryBackendTest1'), 'TransientMemoryBackendTest1');
     $this->assertFalse($backend->has('TransientMemoryBackendTest2'), 'TransientMemoryBackendTest2');
     $this->assertFalse($backend->has('TransientMemoryBackendTest3'), 'TransientMemoryBackendTest3');
 }
 /**
  * @test
  */
 public function getCachedSegmentWithExistingCacheEntryReplacesNestedCachedSegments()
 {
     $contentCache = new ContentCache();
     $mockSecurityContext = $this->createMock('TYPO3\\Flow\\Security\\Context');
     $this->inject($contentCache, 'securityContext', $mockSecurityContext);
     $mockPropertyMapper = $this->createMock('TYPO3\\Flow\\Property\\PropertyMapper');
     $mockPropertyMapper->expects($this->any())->method('convert')->will($this->returnArgument(0));
     $this->inject($contentCache, 'propertyMapper', $mockPropertyMapper);
     $this->inject($contentCache, 'parser', new CacheSegmentParser());
     $mockContext = $this->getMockBuilder('TYPO3\\Flow\\Core\\ApplicationContext')->disableOriginalConstructor()->getMock();
     $cacheBackend = new \TYPO3\Flow\Cache\Backend\TransientMemoryBackend($mockContext);
     $cacheFrontend = new \TYPO3\Flow\Cache\Frontend\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);
 }