‪TYPO3CMS  9.5
StringFrontendTest.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  */
17 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
18 
22 class ‪StringFrontendTest extends UnitTestCase
23 {
28  {
29  $this->expectException(\InvalidArgumentException::class);
30  $this->expectExceptionCode(1233057566);
31 
32  $cache = $this->getMockBuilder(\‪TYPO3\CMS\Core\Cache\Frontend\StringFrontend::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 
43  public function ‪setPassesStringToBackend()
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('StringCacheTest'), $this->equalTo($theString));
51  $cache = new \TYPO3\CMS\Core\Cache\Frontend\StringFrontend('StringFrontend', $backend);
52  $cache->set('StringCacheTest', $theString);
53  }
54 
59  {
60  $theString = 'Just some value';
61  $theLifetime = 1234;
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('StringCacheTest'), $this->equalTo($theString), $this->equalTo([]), $this->equalTo($theLifetime));
67  $cache = new \TYPO3\CMS\Core\Cache\Frontend\StringFrontend('StringFrontend', $backend);
68  $cache->set('StringCacheTest', $theString, [], $theLifetime);
69  }
70 
75  {
76  $this->expectException(InvalidDataException::class);
77  $this->expectExceptionCode(1222808333);
78 
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  $cache = new \TYPO3\CMS\Core\Cache\Frontend\StringFrontend('StringFrontend', $backend);
84  $cache->set('StringCacheTest', []);
85  }
86 
91  {
92  $backend = $this->getMockBuilder(\‪TYPO3\CMS\Core\Cache\Backend\AbstractBackend::class)
93  ->setMethods(['get', 'set', 'has', 'remove', 'findIdentifiersByTag', 'flush', 'flushByTag', 'collectGarbage'])
94  ->disableOriginalConstructor()
95  ->getMock();
96  $backend->expects($this->once())->method('get')->will($this->returnValue('Just some value'));
97  $cache = new \TYPO3\CMS\Core\Cache\Frontend\StringFrontend('StringFrontend', $backend);
98  $this->assertEquals('Just some value', $cache->get('StringCacheTest'), 'The returned value was not the expected string.');
99  }
100 
105  {
106  $backend = $this->getMockBuilder(\‪TYPO3\CMS\Core\Cache\Backend\AbstractBackend::class)
107  ->setMethods(['get', 'set', 'has', 'remove', 'findIdentifiersByTag', 'flush', 'flushByTag', 'collectGarbage'])
108  ->disableOriginalConstructor()
109  ->getMock();
110  $backend->expects($this->once())->method('has')->with($this->equalTo('StringCacheTest'))->will($this->returnValue(true));
111  $cache = new \TYPO3\CMS\Core\Cache\Frontend\StringFrontend('StringFrontend', $backend);
112  $this->assertTrue($cache->has('StringCacheTest'), 'has() did not return TRUE.');
113  }
114 
118  public function ‪removeCallsBackend()
119  {
120  $cacheIdentifier = 'someCacheIdentifier';
121  $backend = $this->getMockBuilder(\‪TYPO3\CMS\Core\Cache\Backend\AbstractBackend::class)
122  ->setMethods(['get', 'set', 'has', 'remove', 'findIdentifiersByTag', 'flush', 'flushByTag', 'collectGarbage'])
123  ->disableOriginalConstructor()
124  ->getMock();
125  $backend->expects($this->once())->method('remove')->with($this->equalTo($cacheIdentifier))->will($this->returnValue(true));
126  $cache = new \TYPO3\CMS\Core\Cache\Frontend\StringFrontend('StringFrontend', $backend);
127  $this->assertTrue($cache->remove($cacheIdentifier), 'remove() did not return TRUE');
128  }
129 }
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Cache\Frontend\StringFrontendTest\hasReturnsResultFromBackend
‪hasReturnsResultFromBackend()
Definition: StringFrontendTest.php:104
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Cache\Frontend\StringFrontendTest
Definition: StringFrontendTest.php:23
‪TYPO3
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Cache\Frontend\StringFrontendTest\setChecksIfTheIdentifierIsValid
‪setChecksIfTheIdentifierIsValid()
Definition: StringFrontendTest.php:27
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Cache\Frontend\StringFrontendTest\setThrowsInvalidDataExceptionOnNonStringValues
‪setThrowsInvalidDataExceptionOnNonStringValues()
Definition: StringFrontendTest.php:74
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Cache\Frontend\StringFrontendTest\setPassesStringToBackend
‪setPassesStringToBackend()
Definition: StringFrontendTest.php:43
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Cache\Frontend\StringFrontendTest\setPassesLifetimeToBackend
‪setPassesLifetimeToBackend()
Definition: StringFrontendTest.php:58
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Cache\Frontend
Definition: StringFrontendTest.php:2
‪TYPO3\CMS\Core\Cache\Exception\InvalidDataException
Definition: InvalidDataException.php:21
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Cache\Frontend\StringFrontendTest\getFetchesStringValueFromBackend
‪getFetchesStringValueFromBackend()
Definition: StringFrontendTest.php:90
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Cache\Frontend\StringFrontendTest\removeCallsBackend
‪removeCallsBackend()
Definition: StringFrontendTest.php:118