‪TYPO3CMS  9.5
AbstractFrontendTest.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 ‪AbstractFrontendTest extends UnitTestCase
23 {
28  {
29  $mockBackend = $this->getMockBuilder(\‪TYPO3\CMS\Core\Cache\Backend\AbstractBackend::class)
30  ->setMethods(['get', 'set', 'has', 'remove', 'findIdentifiersByTag', 'flush', 'flushByTag', 'collectGarbage'])
31  ->disableOriginalConstructor()
32  ->getMock();
33  foreach (['x', 'someValue', '123fivesixseveneight', 'some&', 'ab_cd%', rawurlencode('resource://some/äöü$&% sadf'), str_repeat('x', 250)] as $identifier) {
34  $this->getMockBuilder(\‪TYPO3\CMS\Core\Cache\Frontend\VariableFrontend::class)
35  ->setMethods(['__construct', 'get', 'set', 'has', 'remove', 'getByTag', 'flush', 'flushByTag', 'collectGarbage'])
36  ->setConstructorArgs([$identifier, $mockBackend])
37  ->getMock();
38  }
39  }
40 
45  {
46  $mockBackend = $this->getMockBuilder(\‪TYPO3\CMS\Core\Cache\Backend\AbstractBackend::class)
47  ->setMethods(['get', 'set', 'has', 'remove', 'findIdentifiersByTag', 'flush', 'flushByTag', 'collectGarbage'])
48  ->disableOriginalConstructor()
49  ->getMock();
50  foreach (['', 'abc def', 'foo!', 'bar:', 'some/', 'bla*', 'one+', 'äöü', str_repeat('x', 251), 'x$', '\\a', 'b#'] as $identifier) {
51  try {
52  $this->getMockBuilder(\‪TYPO3\CMS\Core\Cache\Frontend\VariableFrontend::class)
53  ->setMethods(['__construct', 'get', 'set', 'has', 'remove', 'getByTag', 'flush', 'flushByTag', 'collectGarbage'])
54  ->setConstructorArgs([$identifier, $mockBackend])
55  ->getMock();
56  $this->fail('Identifier "' . $identifier . '" was not rejected.');
57  } catch (\InvalidArgumentException $exception) {
58  }
59  }
60  }
61 
65  public function ‪flushCallsBackend()
66  {
67  $identifier = 'someCacheIdentifier';
68  $backend = $this->getMockBuilder(\‪TYPO3\CMS\Core\Cache\Backend\AbstractBackend::class)
69  ->setMethods(['get', 'set', 'has', 'remove', 'findIdentifiersByTag', 'flush', 'flushByTag', 'collectGarbage'])
70  ->disableOriginalConstructor()
71  ->getMock();
72  $backend->expects($this->once())->method('flush');
73  $cache = $this->getMockBuilder(\‪TYPO3\CMS\Core\Cache\Frontend\VariableFrontend::class)
74  ->setMethods(['__construct', 'get', 'set', 'has', 'remove', 'getByTag'])
75  ->setConstructorArgs([$identifier, $backend])
76  ->getMock();
77  $cache->flush();
78  }
79 
84  {
85  $this->expectException(\InvalidArgumentException::class);
86  $this->expectExceptionCode(1233057359);
87 
88  $identifier = 'someCacheIdentifier';
89  $backend = $this->createMock(\‪TYPO3\CMS\Core\Cache\Backend\TaggableBackendInterface::class);
90  $backend->expects($this->never())->method('flushByTag');
91  $cache = $this->getMockBuilder(\‪TYPO3\CMS\Core\Cache\Frontend\VariableFrontend::class)
92  ->setMethods(['__construct', 'get', 'set', 'has', 'remove', 'getByTag'])
93  ->setConstructorArgs([$identifier, $backend])
94  ->getMock();
95  $cache->flushByTag('SomeInvalid\\Tag');
96  }
97 
102  {
103  $tag = 'sometag';
104  $identifier = 'someCacheIdentifier';
105  $backend = $this->getMockBuilder(\‪TYPO3\CMS\Core\Cache\Backend\TaggableBackendInterface::class)
106  ->setMethods(['setCache', 'get', 'set', 'has', 'remove', 'findIdentifiersByTag', 'flush', 'flushByTag', 'flushByTags', 'collectGarbage'])
107  ->disableOriginalConstructor()
108  ->getMock();
109  $backend->expects($this->once())->method('flushByTag')->with($tag);
110  $cache = $this->getMockBuilder(\‪TYPO3\CMS\Core\Cache\Frontend\VariableFrontend::class)
111  ->setMethods(['__construct', 'get', 'set', 'has', 'remove', 'getByTag'])
112  ->setConstructorArgs([$identifier, $backend])
113  ->getMock();
114  $cache->flushByTag($tag);
115  }
116 
121  {
122  $tag = 'sometag';
123  $identifier = 'someCacheIdentifier';
124  $backend = $this->getMockBuilder(\‪TYPO3\CMS\Core\Cache\Backend\TaggableBackendInterface::class)
125  ->setMethods(['setCache', 'get', 'set', 'has', 'remove', 'findIdentifiersByTag', 'flush', 'flushByTag', 'flushByTags', 'collectGarbage'])
126  ->disableOriginalConstructor()
127  ->getMock();
128  $backend->expects($this->once())->method('flushByTags')->with([$tag]);
129  $cache = $this->getMockBuilder(\‪TYPO3\CMS\Core\Cache\Frontend\VariableFrontend::class)
130  ->setMethods(['__construct', 'get', 'set', 'has', 'remove', 'getByTag'])
131  ->setConstructorArgs([$identifier, $backend])
132  ->getMock();
133  $cache->flushByTags([$tag]);
134  }
135 
140  {
141  $identifier = 'someCacheIdentifier';
142  $backend = $this->getMockBuilder(\‪TYPO3\CMS\Core\Cache\Backend\AbstractBackend::class)
143  ->setMethods(['get', 'set', 'has', 'remove', 'findIdentifiersByTag', 'flush', 'flushByTag', 'collectGarbage'])
144  ->disableOriginalConstructor()
145  ->getMock();
146  $backend->expects($this->once())->method('collectGarbage');
147  $cache = $this->getMockBuilder(\‪TYPO3\CMS\Core\Cache\Frontend\VariableFrontend::class)
148  ->setMethods(['__construct', 'get', 'set', 'has', 'remove', 'getByTag'])
149  ->setConstructorArgs([$identifier, $backend])
150  ->getMock();
151  $cache->collectGarbage();
152  }
153 
158  {
159  $identifier = 'someCacheIdentifier';
160  $backend = $this->createMock(\‪TYPO3\CMS\Core\Cache\Backend\AbstractBackend::class);
161  $cache = $this->getMockBuilder(\‪TYPO3\CMS\Core\Cache\Frontend\VariableFrontend::class)
162  ->setMethods(['__construct', 'get', 'set', 'has', 'remove', 'getByTag'])
163  ->setConstructorArgs([$identifier, $backend])
164  ->getMock();
165  foreach (['', 'abc def', 'foo!', 'bar:', 'some/', 'bla*', 'one+', 'äöü', str_repeat('x', 251), 'x$', '\\a', 'b#'] as $entryIdentifier) {
166  $this->assertFalse($cache->isValidEntryIdentifier($entryIdentifier), 'Invalid identifier "' . $entryIdentifier . '" was not rejected.');
167  }
168  }
169 
174  {
175  $identifier = 'someCacheIdentifier';
176  $backend = $this->createMock(\‪TYPO3\CMS\Core\Cache\Backend\AbstractBackend::class);
177  $cache = $this->getMockBuilder(\‪TYPO3\CMS\Core\Cache\Frontend\VariableFrontend::class)
178  ->setMethods(['__construct', 'get', 'set', 'has', 'remove', 'getByTag'])
179  ->setConstructorArgs([$identifier, $backend])
180  ->getMock();
181  foreach (['_', 'abcdef', 'foo', 'bar123', '3some', '_bl_a', 'some&', 'one%TWO', str_repeat('x', 250)] as $entryIdentifier) {
182  $this->assertTrue($cache->isValidEntryIdentifier($entryIdentifier), 'Valid identifier "' . $entryIdentifier . '" was not accepted.');
183  }
184  }
185 
190  {
191  $identifier = 'someCacheIdentifier';
192  $backend = $this->createMock(\‪TYPO3\CMS\Core\Cache\Backend\AbstractBackend::class);
193  $cache = $this->getMockBuilder(\‪TYPO3\CMS\Core\Cache\Frontend\VariableFrontend::class)
194  ->setMethods(['__construct', 'get', 'set', 'has', 'remove', 'getByTag'])
195  ->setConstructorArgs([$identifier, $backend])
196  ->getMock();
197  foreach (['', 'abc def', 'foo!', 'bar:', 'some/', 'bla*', 'one+', 'äöü', str_repeat('x', 251), 'x$', '\\a', 'b#'] as $tag) {
198  $this->assertFalse($cache->isValidTag($tag), 'Invalid tag "' . $tag . '" was not rejected.');
199  }
200  }
201 
206  {
207  $identifier = 'someCacheIdentifier';
208  $backend = $this->createMock(\‪TYPO3\CMS\Core\Cache\Backend\AbstractBackend::class);
209  $cache = $this->getMockBuilder(\‪TYPO3\CMS\Core\Cache\Frontend\VariableFrontend::class)
210  ->setMethods(['__construct', 'get', 'set', 'has', 'remove', 'getByTag'])
211  ->setConstructorArgs([$identifier, $backend])
212  ->getMock();
213  foreach (['abcdef', 'foo-bar', 'foo_baar', 'bar123', '3some', 'file%Thing', 'some&', '%x%', str_repeat('x', 250)] as $tag) {
214  $this->assertTrue($cache->isValidTag($tag), 'Valid tag "' . $tag . '" was not accepted.');
215  }
216  }
217 }
‪TYPO3\CMS\Core\Tests\Unit\Cache\Frontend\AbstractFrontendTest\flushCallsBackend
‪flushCallsBackend()
Definition: AbstractFrontendTest.php:65
‪TYPO3\CMS\Core\Tests\Unit\Cache\Frontend\AbstractFrontendTest\theConstructorRejectsInvalidIdentifiers
‪theConstructorRejectsInvalidIdentifiers()
Definition: AbstractFrontendTest.php:44
‪TYPO3
‪TYPO3\CMS\Core\Tests\Unit\Cache\Frontend
Definition: AbstractFrontendTest.php:2
‪TYPO3\CMS\Core\Tests\Unit\Cache\Frontend\AbstractFrontendTest\flushByTagCallsBackendIfItIsATaggableBackend
‪flushByTagCallsBackendIfItIsATaggableBackend()
Definition: AbstractFrontendTest.php:101
‪TYPO3\CMS\Core\Tests\Unit\Cache\Frontend\AbstractFrontendTest\theConstructorAcceptsValidIdentifiers
‪theConstructorAcceptsValidIdentifiers()
Definition: AbstractFrontendTest.php:27
‪TYPO3\CMS\Core\Tests\Unit\Cache\Frontend\AbstractFrontendTest
Definition: AbstractFrontendTest.php:23
‪TYPO3\CMS\Core\Tests\Unit\Cache\Frontend\AbstractFrontendTest\flushByTagsCallsBackendIfItIsATaggableBackend
‪flushByTagsCallsBackendIfItIsATaggableBackend()
Definition: AbstractFrontendTest.php:120
‪TYPO3\CMS\Core\Tests\Unit\Cache\Frontend\AbstractFrontendTest\collectGarbageCallsBackend
‪collectGarbageCallsBackend()
Definition: AbstractFrontendTest.php:139
‪TYPO3\CMS\Core\Tests\Unit\Cache\Frontend\AbstractFrontendTest\validTagsAreRecognizedAsValid
‪validTagsAreRecognizedAsValid()
Definition: AbstractFrontendTest.php:205
‪TYPO3\CMS\Core\Tests\Unit\Cache\Frontend\AbstractFrontendTest\validEntryIdentifiersAreRecognizedAsValid
‪validEntryIdentifiersAreRecognizedAsValid()
Definition: AbstractFrontendTest.php:173
‪TYPO3\CMS\Core\Tests\Unit\Cache\Frontend\AbstractFrontendTest\flushByTagRejectsInvalidTags
‪flushByTagRejectsInvalidTags()
Definition: AbstractFrontendTest.php:83
‪TYPO3\CMS\Core\Tests\Unit\Cache\Frontend\AbstractFrontendTest\invalidTagsAreRecognizedAsInvalid
‪invalidTagsAreRecognizedAsInvalid()
Definition: AbstractFrontendTest.php:189
‪TYPO3\CMS\Core\Tests\Unit\Cache\Frontend\AbstractFrontendTest\invalidEntryIdentifiersAreRecognizedAsInvalid
‪invalidEntryIdentifiersAreRecognizedAsInvalid()
Definition: AbstractFrontendTest.php:157