TYPO3 CMS  TYPO3_6-2
StringFrontendTest.php
Go to the documentation of this file.
1 <?php
3 
25 
30  public function setChecksIfTheIdentifierIsValid() {
31  $cache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\StringFrontend', array('isValidEntryIdentifier'), array(), '', FALSE);
32  $cache->expects($this->once())->method('isValidEntryIdentifier')->with('foo')->will($this->returnValue(FALSE));
33  $cache->set('foo', 'bar');
34  }
35 
39  public function setPassesStringToBackend() {
40  $theString = 'Just some value';
41  $backend = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Backend\\AbstractBackend', array('get', 'set', 'has', 'remove', 'findIdentifiersByTag', 'flush', 'flushByTag', 'collectGarbage'), array(), '', FALSE);
42  $backend->expects($this->once())->method('set')->with($this->equalTo('StringCacheTest'), $this->equalTo($theString));
43  $cache = new \TYPO3\CMS\Core\Cache\Frontend\StringFrontend('StringFrontend', $backend);
44  $cache->set('StringCacheTest', $theString);
45  }
46 
50  public function setPassesLifetimeToBackend() {
51  $theString = 'Just some value';
52  $theLifetime = 1234;
53  $backend = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Backend\\AbstractBackend', array('get', 'set', 'has', 'remove', 'findIdentifiersByTag', 'flush', 'flushByTag', 'collectGarbage'), array(), '', FALSE);
54  $backend->expects($this->once())->method('set')->with($this->equalTo('StringCacheTest'), $this->equalTo($theString), $this->equalTo(array()), $this->equalTo($theLifetime));
55  $cache = new \TYPO3\CMS\Core\Cache\Frontend\StringFrontend('StringFrontend', $backend);
56  $cache->set('StringCacheTest', $theString, array(), $theLifetime);
57  }
58 
64  $backend = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Backend\\AbstractBackend', array('get', 'set', 'has', 'remove', 'findIdentifiersByTag', 'flush', 'flushByTag', 'collectGarbage'), array(), '', FALSE);
65  $cache = new \TYPO3\CMS\Core\Cache\Frontend\StringFrontend('StringFrontend', $backend);
66  $cache->set('StringCacheTest', array());
67  }
68 
73  $backend = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Backend\\AbstractBackend', array('get', 'set', 'has', 'remove', 'findIdentifiersByTag', 'flush', 'flushByTag', 'collectGarbage'), array(), '', FALSE);
74  $backend->expects($this->once())->method('get')->will($this->returnValue('Just some value'));
75  $cache = new \TYPO3\CMS\Core\Cache\Frontend\StringFrontend('StringFrontend', $backend);
76  $this->assertEquals('Just some value', $cache->get('StringCacheTest'), 'The returned value was not the expected string.');
77  }
78 
82  public function hasReturnsResultFromBackend() {
83  $backend = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Backend\\AbstractBackend', array('get', 'set', 'has', 'remove', 'findIdentifiersByTag', 'flush', 'flushByTag', 'collectGarbage'), array(), '', FALSE);
84  $backend->expects($this->once())->method('has')->with($this->equalTo('StringCacheTest'))->will($this->returnValue(TRUE));
85  $cache = new \TYPO3\CMS\Core\Cache\Frontend\StringFrontend('StringFrontend', $backend);
86  $this->assertTrue($cache->has('StringCacheTest'), 'has() did not return TRUE.');
87  }
88 
92  public function removeCallsBackend() {
93  $cacheIdentifier = 'someCacheIdentifier';
94  $backend = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Backend\\AbstractBackend', array('get', 'set', 'has', 'remove', 'findIdentifiersByTag', 'flush', 'flushByTag', 'collectGarbage'), array(), '', FALSE);
95  $backend->expects($this->once())->method('remove')->with($this->equalTo($cacheIdentifier))->will($this->returnValue(TRUE));
96  $cache = new \TYPO3\CMS\Core\Cache\Frontend\StringFrontend('StringFrontend', $backend);
97  $this->assertTrue($cache->remove($cacheIdentifier), 'remove() did not return TRUE');
98  }
99 
104  public function getByTagRejectsInvalidTags() {
105  $backend = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Backend\\BackendInterface', array(), array(), '', FALSE);
106  $backend->expects($this->never())->method('getByTag');
107  $cache = new \TYPO3\CMS\Core\Cache\Frontend\StringFrontend('StringFrontend', $backend);
108  $cache->getByTag('SomeInvalid\\Tag');
109  }
110 
114  public function getByTagCallsBackend() {
115  $tag = 'sometag';
116  $identifiers = array('one', 'two');
117  $entries = array('one value', 'two value');
118  $backend = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Backend\\AbstractBackend', array('get', 'set', 'has', 'remove', 'findIdentifiersByTag', 'flush', 'flushByTag', 'collectGarbage'), array(), '', FALSE);
119  $backend->expects($this->once())->method('findIdentifiersByTag')->with($this->equalTo($tag))->will($this->returnValue($identifiers));
120  $backend->expects($this->exactly(2))->method('get')->will($this->onConsecutiveCalls('one value', 'two value'));
121  $cache = new \TYPO3\CMS\Core\Cache\Frontend\StringFrontend('StringFrontend', $backend);
122  $this->assertEquals($entries, $cache->getByTag($tag), 'Did not receive the expected entries');
123  }
124 
125 }