‪TYPO3CMS  9.5
VariableFrontendTest.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
17 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
18 
22 class ‪VariableFrontendTest extends UnitTestCase
23 {
28  {
29  $this->expectException(\InvalidArgumentException::class);
30  $this->expectExceptionCode(1233058264);
31 
32  $cache = $this->getMockBuilder(\‪TYPO3\CMS\Core\Cache\Frontend\VariableFrontend::class)
33  ->setMethods(['isValidEntryIdentifier'])
34  ->disableOriginalConstructor()
35  ->getMock();
36  $cache->expects($this->once())->method('isValidEntryIdentifier')->with('foo')->will($this->returnValue(false));
37  $cache->set('foo', 'bar');
38  }
39 
44  {
45  $theString = 'Just some value';
46  $backend = $this->getMockBuilder(\‪TYPO3\CMS\Core\Cache\Backend\AbstractBackend::class)
47  ->setMethods(['get', 'set', 'has', 'remove', 'findIdentifiersByTag', 'flush', 'flushByTag', 'collectGarbage'])
48  ->disableOriginalConstructor()
49  ->getMock();
50  $backend->expects($this->once())->method('set')->with($this->equalTo('VariableCacheTest'), $this->equalTo(serialize($theString)));
51 
52  $cache = new \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend('VariableFrontend', $backend);
53  $cache->set('VariableCacheTest', $theString);
54  }
55 
60  {
61  $theArray = ['Just some value', 'and another one.'];
62  $backend = $this->getMockBuilder(\‪TYPO3\CMS\Core\Cache\Backend\AbstractBackend::class)
63  ->setMethods(['get', 'set', 'has', 'remove', 'findIdentifiersByTag', 'flush', 'flushByTag', 'collectGarbage'])
64  ->disableOriginalConstructor()
65  ->getMock();
66  $backend->expects($this->once())->method('set')->with($this->equalTo('VariableCacheTest'), $this->equalTo(serialize($theArray)));
67 
68  $cache = new \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend('VariableFrontend', $backend);
69  $cache->set('VariableCacheTest', $theArray);
70  }
71 
76  {
77  $theString = 'Just some value';
78  $theLifetime = 1234;
79  $backend = $this->getMockBuilder(\‪TYPO3\CMS\Core\Cache\Backend\AbstractBackend::class)
80  ->setMethods(['get', 'set', 'has', 'remove', 'findIdentifiersByTag', 'flush', 'flushByTag', 'collectGarbage'])
81  ->disableOriginalConstructor()
82  ->getMock();
83  $backend->expects($this->once())->method('set')->with($this->equalTo('VariableCacheTest'), $this->equalTo(serialize($theString)), $this->equalTo([]), $this->equalTo($theLifetime));
84 
85  $cache = new \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend('VariableFrontend', $backend);
86  $cache->set('VariableCacheTest', $theString, [], $theLifetime);
87  }
88 
93  {
94  $backend = $this->getMockBuilder(\‪TYPO3\CMS\Core\Cache\Backend\AbstractBackend::class)
95  ->setMethods(['get', 'set', 'has', 'remove', 'findIdentifiersByTag', 'flush', 'flushByTag', 'collectGarbage'])
96  ->disableOriginalConstructor()
97  ->getMock();
98  $backend->expects($this->once())->method('get')->will($this->returnValue(serialize('Just some value')));
99 
100  $cache = new \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend('VariableFrontend', $backend);
101  $this->assertEquals('Just some value', $cache->get('VariableCacheTest'), 'The returned value was not the expected string.');
102  }
103 
108  {
109  $theArray = ['Just some value', 'and another one.'];
110  $backend = $this->getMockBuilder(\‪TYPO3\CMS\Core\Cache\Backend\AbstractBackend::class)
111  ->setMethods(['get', 'set', 'has', 'remove', 'findIdentifiersByTag', 'flush', 'flushByTag', 'collectGarbage'])
112  ->disableOriginalConstructor()
113  ->getMock();
114  $backend->expects($this->once())->method('get')->will($this->returnValue(serialize($theArray)));
115 
116  $cache = new \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend('VariableFrontend', $backend);
117  $this->assertEquals($theArray, $cache->get('VariableCacheTest'), 'The returned value was not the expected unserialized array.');
118  }
119 
124  {
125  $backend = $this->getMockBuilder(\‪TYPO3\CMS\Core\Cache\Backend\AbstractBackend::class)
126  ->setMethods(['get', 'set', 'has', 'remove', 'findIdentifiersByTag', 'flush', 'flushByTag', 'collectGarbage'])
127  ->disableOriginalConstructor()
128  ->getMock();
129  $backend->expects($this->once())->method('get')->will($this->returnValue(serialize(false)));
130 
131  $cache = new \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend('VariableFrontend', $backend);
132  $this->assertFalse($cache->get('VariableCacheTest'), 'The returned value was not the FALSE.');
133  }
134 
139  {
140  $backend = $this->getMockBuilder(\‪TYPO3\CMS\Core\Cache\Backend\AbstractBackend::class)
141  ->setMethods(['get', 'set', 'has', 'remove', 'findIdentifiersByTag', 'flush', 'flushByTag', 'collectGarbage'])
142  ->disableOriginalConstructor()
143  ->getMock();
144  $backend->expects($this->once())->method('has')->with($this->equalTo('VariableCacheTest'))->will($this->returnValue(true));
145 
146  $cache = new \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend('VariableFrontend', $backend);
147  $this->assertTrue($cache->has('VariableCacheTest'), 'has() did not return TRUE.');
148  }
149 
153  public function ‪removeCallsBackend()
154  {
155  $cacheIdentifier = 'someCacheIdentifier';
156  $backend = $this->getMockBuilder(\‪TYPO3\CMS\Core\Cache\Backend\AbstractBackend::class)
157  ->setMethods(['get', 'set', 'has', 'remove', 'findIdentifiersByTag', 'flush', 'flushByTag', 'collectGarbage'])
158  ->disableOriginalConstructor()
159  ->getMock();
160 
161  $backend->expects($this->once())->method('remove')->with($this->equalTo($cacheIdentifier))->will($this->returnValue(true));
162 
163  $cache = new \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend('VariableFrontend', $backend);
164  $this->assertTrue($cache->remove($cacheIdentifier), 'remove() did not return TRUE');
165  }
166 }
‪TYPO3\CMS\Core\Tests\Unit\Cache\Frontend\VariableFrontendTest\getFetchesArrayValueFromBackend
‪getFetchesArrayValueFromBackend()
Definition: VariableFrontendTest.php:107
‪TYPO3
‪TYPO3\CMS\Core\Tests\Unit\Cache\Frontend\VariableFrontendTest\setPassesSerializedStringToBackend
‪setPassesSerializedStringToBackend()
Definition: VariableFrontendTest.php:43
‪TYPO3\CMS\Core\Tests\Unit\Cache\Frontend
Definition: AbstractFrontendTest.php:2
‪TYPO3\CMS\Core\Tests\Unit\Cache\Frontend\VariableFrontendTest\getFetchesFalseBooleanValueFromBackend
‪getFetchesFalseBooleanValueFromBackend()
Definition: VariableFrontendTest.php:123
‪TYPO3\CMS\Core\Tests\Unit\Cache\Frontend\VariableFrontendTest\removeCallsBackend
‪removeCallsBackend()
Definition: VariableFrontendTest.php:153
‪TYPO3\CMS\Core\Tests\Unit\Cache\Frontend\VariableFrontendTest\getFetchesStringValueFromBackend
‪getFetchesStringValueFromBackend()
Definition: VariableFrontendTest.php:92
‪TYPO3\CMS\Core\Tests\Unit\Cache\Frontend\VariableFrontendTest\setPassesSerializedArrayToBackend
‪setPassesSerializedArrayToBackend()
Definition: VariableFrontendTest.php:59
‪TYPO3\CMS\Core\Tests\Unit\Cache\Frontend\VariableFrontendTest\setChecksIfTheIdentifierIsValid
‪setChecksIfTheIdentifierIsValid()
Definition: VariableFrontendTest.php:27
‪TYPO3\CMS\Core\Tests\Unit\Cache\Frontend\VariableFrontendTest\hasReturnsResultFromBackend
‪hasReturnsResultFromBackend()
Definition: VariableFrontendTest.php:138
‪TYPO3\CMS\Core\Tests\Unit\Cache\Frontend\VariableFrontendTest\setPassesLifetimeToBackend
‪setPassesLifetimeToBackend()
Definition: VariableFrontendTest.php:75
‪TYPO3\CMS\Core\Tests\Unit\Cache\Frontend\VariableFrontendTest
Definition: VariableFrontendTest.php:23