‪TYPO3CMS  10.4
AbstractFrontendTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
21 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
22 
26 class ‪AbstractFrontendTest extends UnitTestCase
27 {
32  {
33  $mockBackend = $this->getMockBuilder(AbstractBackend::class)
34  ->setMethods(['get', 'set', 'has', 'remove', 'findIdentifiersByTag', 'flush', 'flushByTag', 'collectGarbage'])
35  ->disableOriginalConstructor()
36  ->getMock();
37  foreach (['x', 'someValue', '123fivesixseveneight', 'some&', 'ab_cd%', rawurlencode('resource://some/äöü$&% sadf'), str_repeat('x', 250)] as $identifier) {
38  $this->getMockBuilder(VariableFrontend::class)
39  ->setMethods(['__construct', 'get', 'set', 'has', 'remove', 'flush', 'flushByTag', 'collectGarbage'])
40  ->setConstructorArgs([$identifier, $mockBackend])
41  ->getMock();
42  }
43  }
44 
49  {
50  $mockBackend = $this->getMockBuilder(AbstractBackend::class)
51  ->setMethods(['get', 'set', 'has', 'remove', 'findIdentifiersByTag', 'flush', 'flushByTag', 'collectGarbage'])
52  ->disableOriginalConstructor()
53  ->getMock();
54  foreach (['', 'abc def', 'foo!', 'bar:', 'some/', 'bla*', 'one+', 'äöü', str_repeat('x', 251), 'x$', '\\a', 'b#'] as $identifier) {
55  try {
56  $this->getMockBuilder(VariableFrontend::class)
57  ->setMethods(['__construct', 'get', 'set', 'has', 'remove', 'flush', 'flushByTag', 'collectGarbage'])
58  ->setConstructorArgs([$identifier, $mockBackend])
59  ->getMock();
60  self::fail('Identifier "' . $identifier . '" was not rejected.');
61  } catch (\InvalidArgumentException $exception) {
62  }
63  }
64  }
65 
69  public function ‪flushCallsBackend()
70  {
71  $identifier = 'someCacheIdentifier';
72  $backend = $this->getMockBuilder(AbstractBackend::class)
73  ->setMethods(['get', 'set', 'has', 'remove', 'findIdentifiersByTag', 'flush', 'flushByTag', 'collectGarbage'])
74  ->disableOriginalConstructor()
75  ->getMock();
76  $backend->expects(self::once())->method('flush');
77  $cache = $this->getMockBuilder(VariableFrontend::class)
78  ->setMethods(['__construct', 'get', 'set', 'has', 'remove'])
79  ->setConstructorArgs([$identifier, $backend])
80  ->getMock();
81  $cache->flush();
82  }
83 
88  {
89  $this->expectException(\InvalidArgumentException::class);
90  $this->expectExceptionCode(1233057359);
91 
92  $identifier = 'someCacheIdentifier';
93  $backend = $this->createMock(TaggableBackendInterface::class);
94  $backend->expects(self::never())->method('flushByTag');
95  $cache = $this->getMockBuilder(VariableFrontend::class)
96  ->setMethods(['__construct', 'get', 'set', 'has', 'remove'])
97  ->setConstructorArgs([$identifier, $backend])
98  ->getMock();
99  $cache->flushByTag('SomeInvalid\\Tag');
100  }
101 
106  {
107  $tag = 'sometag';
108  $identifier = 'someCacheIdentifier';
109  $backend = $this->getMockBuilder(TaggableBackendInterface::class)
110  ->setMethods(['setCache', 'get', 'set', 'has', 'remove', 'findIdentifiersByTag', 'flush', 'flushByTag', 'flushByTags', 'collectGarbage'])
111  ->disableOriginalConstructor()
112  ->getMock();
113  $backend->expects(self::once())->method('flushByTag')->with($tag);
114  $cache = $this->getMockBuilder(VariableFrontend::class)
115  ->setMethods(['__construct', 'get', 'set', 'has', 'remove'])
116  ->setConstructorArgs([$identifier, $backend])
117  ->getMock();
118  $cache->flushByTag($tag);
119  }
120 
125  {
126  $tag = 'sometag';
127  $identifier = 'someCacheIdentifier';
128  $backend = $this->getMockBuilder(TaggableBackendInterface::class)
129  ->setMethods(['setCache', 'get', 'set', 'has', 'remove', 'findIdentifiersByTag', 'flush', 'flushByTag', 'flushByTags', 'collectGarbage'])
130  ->disableOriginalConstructor()
131  ->getMock();
132  $backend->expects(self::once())->method('flushByTags')->with([$tag]);
133  $cache = $this->getMockBuilder(VariableFrontend::class)
134  ->setMethods(['__construct', 'get', 'set', 'has', 'remove'])
135  ->setConstructorArgs([$identifier, $backend])
136  ->getMock();
137  $cache->flushByTags([$tag]);
138  }
139 
144  {
145  $identifier = 'someCacheIdentifier';
146  $backend = $this->getMockBuilder(AbstractBackend::class)
147  ->setMethods(['get', 'set', 'has', 'remove', 'findIdentifiersByTag', 'flush', 'flushByTag', 'collectGarbage'])
148  ->disableOriginalConstructor()
149  ->getMock();
150  $backend->expects(self::once())->method('collectGarbage');
151  $cache = $this->getMockBuilder(VariableFrontend::class)
152  ->setMethods(['__construct', 'get', 'set', 'has', 'remove'])
153  ->setConstructorArgs([$identifier, $backend])
154  ->getMock();
155  $cache->collectGarbage();
156  }
157 
162  {
163  $identifier = 'someCacheIdentifier';
164  $backend = $this->createMock(AbstractBackend::class);
165  $cache = $this->getMockBuilder(VariableFrontend::class)
166  ->setMethods(['__construct', 'get', 'set', 'has', 'remove'])
167  ->setConstructorArgs([$identifier, $backend])
168  ->getMock();
169  foreach (['', 'abc def', 'foo!', 'bar:', 'some/', 'bla*', 'one+', 'äöü', str_repeat('x', 251), 'x$', '\\a', 'b#'] as $entryIdentifier) {
170  self::assertFalse($cache->isValidEntryIdentifier($entryIdentifier), 'Invalid identifier "' . $entryIdentifier . '" was not rejected.');
171  }
172  }
173 
178  {
179  $identifier = 'someCacheIdentifier';
180  $backend = $this->createMock(AbstractBackend::class);
181  $cache = $this->getMockBuilder(VariableFrontend::class)
182  ->setMethods(['__construct', 'get', 'set', 'has', 'remove'])
183  ->setConstructorArgs([$identifier, $backend])
184  ->getMock();
185  foreach (['_', 'abcdef', 'foo', 'bar123', '3some', '_bl_a', 'some&', 'one%TWO', str_repeat('x', 250)] as $entryIdentifier) {
186  self::assertTrue($cache->isValidEntryIdentifier($entryIdentifier), 'Valid identifier "' . $entryIdentifier . '" was not accepted.');
187  }
188  }
189 
194  {
195  $identifier = 'someCacheIdentifier';
196  $backend = $this->createMock(AbstractBackend::class);
197  $cache = $this->getMockBuilder(VariableFrontend::class)
198  ->setMethods(['__construct', 'get', 'set', 'has', 'remove'])
199  ->setConstructorArgs([$identifier, $backend])
200  ->getMock();
201  foreach (['', 'abc def', 'foo!', 'bar:', 'some/', 'bla*', 'one+', 'äöü', str_repeat('x', 251), 'x$', '\\a', 'b#'] as $tag) {
202  self::assertFalse($cache->isValidTag($tag), 'Invalid tag "' . $tag . '" was not rejected.');
203  }
204  }
205 
210  {
211  $identifier = 'someCacheIdentifier';
212  $backend = $this->createMock(AbstractBackend::class);
213  $cache = $this->getMockBuilder(VariableFrontend::class)
214  ->setMethods(['__construct', 'get', 'set', 'has', 'remove'])
215  ->setConstructorArgs([$identifier, $backend])
216  ->getMock();
217  foreach (['abcdef', 'foo-bar', 'foo_baar', 'bar123', '3some', 'file%Thing', 'some&', '%x%', str_repeat('x', 250)] as $tag) {
218  self::assertTrue($cache->isValidTag($tag), 'Valid tag "' . $tag . '" was not accepted.');
219  }
220  }
221 }
‪TYPO3\CMS\Core\Tests\Unit\Cache\Frontend\AbstractFrontendTest\flushCallsBackend
‪flushCallsBackend()
Definition: AbstractFrontendTest.php:69
‪TYPO3\CMS\Core\Tests\Unit\Cache\Frontend\AbstractFrontendTest\theConstructorRejectsInvalidIdentifiers
‪theConstructorRejectsInvalidIdentifiers()
Definition: AbstractFrontendTest.php:48
‪TYPO3\CMS\Core\Cache\Backend\TaggableBackendInterface
Definition: TaggableBackendInterface.php:22
‪TYPO3\CMS\Core\Tests\Unit\Cache\Frontend
Definition: AbstractFrontendTest.php:16
‪TYPO3\CMS\Core\Tests\Unit\Cache\Frontend\AbstractFrontendTest\flushByTagCallsBackendIfItIsATaggableBackend
‪flushByTagCallsBackendIfItIsATaggableBackend()
Definition: AbstractFrontendTest.php:105
‪TYPO3\CMS\Core\Tests\Unit\Cache\Frontend\AbstractFrontendTest\theConstructorAcceptsValidIdentifiers
‪theConstructorAcceptsValidIdentifiers()
Definition: AbstractFrontendTest.php:31
‪TYPO3\CMS\Core\Tests\Unit\Cache\Frontend\AbstractFrontendTest
Definition: AbstractFrontendTest.php:27
‪TYPO3\CMS\Core\Tests\Unit\Cache\Frontend\AbstractFrontendTest\flushByTagsCallsBackendIfItIsATaggableBackend
‪flushByTagsCallsBackendIfItIsATaggableBackend()
Definition: AbstractFrontendTest.php:124
‪TYPO3\CMS\Core\Tests\Unit\Cache\Frontend\AbstractFrontendTest\collectGarbageCallsBackend
‪collectGarbageCallsBackend()
Definition: AbstractFrontendTest.php:143
‪TYPO3\CMS\Core\Cache\Frontend\VariableFrontend
Definition: VariableFrontend.php:25
‪TYPO3\CMS\Core\Tests\Unit\Cache\Frontend\AbstractFrontendTest\validTagsAreRecognizedAsValid
‪validTagsAreRecognizedAsValid()
Definition: AbstractFrontendTest.php:209
‪TYPO3\CMS\Core\Tests\Unit\Cache\Frontend\AbstractFrontendTest\validEntryIdentifiersAreRecognizedAsValid
‪validEntryIdentifiersAreRecognizedAsValid()
Definition: AbstractFrontendTest.php:177
‪TYPO3\CMS\Core\Cache\Backend\AbstractBackend
Definition: AbstractBackend.php:28
‪TYPO3\CMS\Core\Tests\Unit\Cache\Frontend\AbstractFrontendTest\flushByTagRejectsInvalidTags
‪flushByTagRejectsInvalidTags()
Definition: AbstractFrontendTest.php:87
‪TYPO3\CMS\Core\Tests\Unit\Cache\Frontend\AbstractFrontendTest\invalidTagsAreRecognizedAsInvalid
‪invalidTagsAreRecognizedAsInvalid()
Definition: AbstractFrontendTest.php:193
‪TYPO3\CMS\Core\Tests\Unit\Cache\Frontend\AbstractFrontendTest\invalidEntryIdentifiersAreRecognizedAsInvalid
‪invalidEntryIdentifiersAreRecognizedAsInvalid()
Definition: AbstractFrontendTest.php:161