‪TYPO3CMS  10.4
Typo3DatabaseBackendTest.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 
22 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
23 
27 class ‪Typo3DatabaseBackendTest extends FunctionalTestCase
28 {
29 
34  {
35  $frontendProphecy = $this->prophesize(FrontendInterface::class);
36  $frontendProphecy->getIdentifier()->willReturn('pages');
37 
38  $subject = new ‪Typo3DatabaseBackend('Testing');
39  $subject->setCache($frontendProphecy->reveal());
40 
41  $subject->set('myIdentifier', 'myData');
42  self::assertSame('myData', $subject->get('myIdentifier'));
43  }
44 
49  {
50  $frontendProphecy = $this->prophesize(FrontendInterface::class);
51  $frontendProphecy->getIdentifier()->willReturn('pages');
52 
53  $subject = new ‪Typo3DatabaseBackend('Testing');
54  $subject->setCache($frontendProphecy->reveal());
55 
56  $subject->set('myIdentifier', 'myData');
57  $subject->set('myIdentifier', 'myNewData');
58  self::assertSame('myNewData', $subject->get('myIdentifier'));
59  }
60 
65  {
66  $frontendProphecy = $this->prophesize(FrontendInterface::class);
67  $frontendProphecy->getIdentifier()->willReturn('pages');
68 
69  $subject = new ‪Typo3DatabaseBackend('Testing');
70  $subject->setCache($frontendProphecy->reveal());
71 
72  $subject->set('myIdentifier', 'myData', ['aTag', 'anotherTag']);
73 
74  $cacheTableConnection = (new ‪ConnectionPool())->getConnectionForTable('cache_pages');
75  $tagsTableConnection = (new ‪ConnectionPool())->getConnectionForTable('cache_pages_tags');
76  self::assertSame(1, $cacheTableConnection->count('*', 'cache_pages', ['identifier' => 'myIdentifier']));
77  self::assertSame(1, $tagsTableConnection->count('*', 'cache_pages_tags', ['identifier' => 'myIdentifier', 'tag' => 'aTag']));
78  self::assertSame(1, $tagsTableConnection->count('*', 'cache_pages_tags', ['identifier' => 'myIdentifier', 'tag' => 'anotherTag']));
79  }
80 
85  {
86  $frontendProphecy = $this->prophesize(FrontendInterface::class);
87  $frontendProphecy->getIdentifier()->willReturn('pages');
88 
89  // Have backend with compression enabled
90  $subject = new ‪Typo3DatabaseBackend('Testing', ['compression' => true]);
91  $subject->setCache($frontendProphecy->reveal());
92 
93  $subject->set('myIdentifier', 'myCachedContent');
94 
95  $row = (new ‪ConnectionPool())
96  ->getConnectionForTable('cache_pages')
97  ->select(
98  ['content'],
99  'cache_pages',
100  ['identifier' => 'myIdentifier']
101  )
102  ->fetch();
103 
104  // Content comes back uncompressed
105  self::assertSame('myCachedContent', gzuncompress($row['content']));
106  }
107 
112  {
113  $frontendProphecy = $this->prophesize(FrontendInterface::class);
114  $frontendProphecy->getIdentifier()->willReturn('pages');
115 
116  $subject = new ‪Typo3DatabaseBackend('Testing');
117  $subject->setCache($frontendProphecy->reveal());
118 
119  self::assertFalse($subject->get('myIdentifier'));
120  }
121 
126  {
127  $frontendProphecy = $this->prophesize(FrontendInterface::class);
128  $frontendProphecy->getIdentifier()->willReturn('pages');
129 
130  // Push an expired row into db
131  (new ‪ConnectionPool())->getConnectionForTable('cache_pages')->insert(
132  'cache_pages',
133  [
134  'identifier' => 'myIdentifier',
135  'expires' => ‪$GLOBALS['EXEC_TIME'] - 60,
136  'content' => 'myCachedContent',
137  ],
138  [
139  'content' => ‪Connection::PARAM_LOB
140  ]
141  );
142 
143  $subject = new ‪Typo3DatabaseBackend('Testing');
144  $subject->setCache($frontendProphecy->reveal());
145 
146  self::assertFalse($subject->get('myIdentifier'));
147  }
148 
153  {
154  $frontendProphecy = $this->prophesize(FrontendInterface::class);
155  $frontendProphecy->getIdentifier()->willReturn('pages');
156 
157  // Push a row into db
158  (new ‪ConnectionPool())->getConnectionForTable('cache_pages')->insert(
159  'cache_pages',
160  [
161  'identifier' => 'myIdentifier',
162  'expires' => ‪$GLOBALS['EXEC_TIME'] + 60,
163  'content' => 'myCachedContent',
164  ],
165  [
166  'content' => ‪Connection::PARAM_LOB
167  ]
168  );
169 
170  $subject = new ‪Typo3DatabaseBackend('Testing');
171  $subject->setCache($frontendProphecy->reveal());
172 
173  self::assertSame('myCachedContent', $subject->get('myIdentifier'));
174  }
175 
180  {
181  $frontendProphecy = $this->prophesize(FrontendInterface::class);
182  $frontendProphecy->getIdentifier()->willReturn('pages');
183 
184  // Push a compressed row into db
185  (new ‪ConnectionPool())->getConnectionForTable('cache_pages')->insert(
186  'cache_pages',
187  [
188  'identifier' => 'myIdentifier',
189  'expires' => ‪$GLOBALS['EXEC_TIME'] + 60,
190  'content' => gzcompress('myCachedContent'),
191  ],
192  [
193  'content' => ‪Connection::PARAM_LOB
194  ]
195  );
196 
197  // Have backend with compression enabled
198  $subject = new ‪Typo3DatabaseBackend('Testing', ['compression' => true]);
199  $subject->setCache($frontendProphecy->reveal());
200 
201  // Content comes back uncompressed
202  self::assertSame('myCachedContent', $subject->get('myIdentifier'));
203  }
204 
209  {
210  $frontendProphecy = $this->prophesize(FrontendInterface::class);
211  $frontendProphecy->getIdentifier()->willReturn('pages');
212 
213  // Push a compressed row into db
214  (new ‪ConnectionPool())->getConnectionForTable('cache_pages')->insert(
215  'cache_pages',
216  [
217  'identifier' => 'myIdentifier',
218  'expires' => ‪$GLOBALS['EXEC_TIME'] + 60,
219  'content' => gzcompress(''),
220  ],
221  [
222  'content' => ‪Connection::PARAM_LOB
223  ]
224  );
225 
226  // Have backend with compression enabled
227  $subject = new ‪Typo3DatabaseBackend('Testing', ['compression' => true]);
228  $subject->setCache($frontendProphecy->reveal());
229 
230  // Content comes back uncompressed
231  self::assertSame('', $subject->get('myIdentifier'));
232  }
233 
238  {
239  $frontendProphecy = $this->prophesize(FrontendInterface::class);
240  $frontendProphecy->getIdentifier()->willReturn('pages');
241 
242  $subject = new ‪Typo3DatabaseBackend('Testing');
243  $subject->setCache($frontendProphecy->reveal());
244 
245  self::assertFalse($subject->has('myIdentifier'));
246  }
247 
252  {
253  $frontendProphecy = $this->prophesize(FrontendInterface::class);
254  $frontendProphecy->getIdentifier()->willReturn('pages');
255 
256  // Push an expired row into db
257  (new ‪ConnectionPool())->getConnectionForTable('cache_pages')->insert(
258  'cache_pages',
259  [
260  'identifier' => 'myIdentifier',
261  'expires' => ‪$GLOBALS['EXEC_TIME'] - 60,
262  'content' => 'myCachedContent',
263  ],
264  [
265  'content' => ‪Connection::PARAM_LOB
266  ]
267  );
268 
269  $subject = new ‪Typo3DatabaseBackend('Testing');
270  $subject->setCache($frontendProphecy->reveal());
271 
272  self::assertFalse($subject->has('myIdentifier'));
273  }
274 
279  {
280  $frontendProphecy = $this->prophesize(FrontendInterface::class);
281  $frontendProphecy->getIdentifier()->willReturn('pages');
282 
283  // Push a row into db
284  (new ‪ConnectionPool())->getConnectionForTable('cache_pages')->insert(
285  'cache_pages',
286  [
287  'identifier' => 'myIdentifier',
288  'expires' => ‪$GLOBALS['EXEC_TIME'] + 60,
289  'content' => 'myCachedContent',
290  ],
291  [
292  'content' => ‪Connection::PARAM_LOB
293  ]
294  );
295 
296  $subject = new ‪Typo3DatabaseBackend('Testing');
297  $subject->setCache($frontendProphecy->reveal());
298 
299  self::assertTrue($subject->has('myIdentifier'));
300  }
301 
306  {
307  $frontendProphecy = $this->prophesize(FrontendInterface::class);
308  $frontendProphecy->getIdentifier()->willReturn('pages');
309 
310  $subject = new ‪Typo3DatabaseBackend('Testing');
311  $subject->setCache($frontendProphecy->reveal());
312 
313  self::assertFalse($subject->remove('myIdentifier'));
314  }
315 
320  {
321  $frontendProphecy = $this->prophesize(FrontendInterface::class);
322  $frontendProphecy->getIdentifier()->willReturn('pages');
323 
324  // Push a row into db
325  (new ‪ConnectionPool())->getConnectionForTable('cache_pages')->insert(
326  'cache_pages',
327  [
328  'identifier' => 'myIdentifier',
329  'expires' => ‪$GLOBALS['EXEC_TIME'] + 60,
330  'content' => 'myCachedContent',
331  ],
332  [
333  'content' => ‪Connection::PARAM_LOB
334  ]
335  );
336 
337  $subject = new ‪Typo3DatabaseBackend('Testing');
338  $subject->setCache($frontendProphecy->reveal());
339 
340  self::assertTrue($subject->remove('myIdentifier'));
341  }
342 
347  {
348  $frontendProphecy = $this->prophesize(FrontendInterface::class);
349  $frontendProphecy->getIdentifier()->willReturn('pages');
350 
351  // Add one cache row to remove and another one that shouldn't be removed
352  $cacheTableConnection = (new ‪ConnectionPool())->getConnectionForTable('cache_pages');
353  $cacheTableConnection->bulkInsert(
354  'cache_pages',
355  [
356  ['myIdentifier', ‪$GLOBALS['EXEC_TIME'] + 60, 'myCachedContent'],
357  ['otherIdentifier', ‪$GLOBALS['EXEC_TIME'] + 60, 'otherCachedContent'],
358  ],
359  ['identifier', 'expires', 'content'],
360  [
361  'content' => ‪Connection::PARAM_LOB
362  ]
363  );
364  $subject = new ‪Typo3DatabaseBackend('Testing');
365  $subject->setCache($frontendProphecy->reveal());
366 
367  // Add a couple of tags
368  $tagsTableConnection = (new ‪ConnectionPool())->getConnectionForTable('cache_pages_tags');
369  $tagsTableConnection->bulkInsert(
370  'cache_pages_tags',
371  [
372  ['myIdentifier', 'aTag'],
373  ['myIdentifier', 'otherTag'],
374  ['otherIdentifier', 'aTag'],
375  ['otherIdentifier', 'otherTag'],
376  ],
377  ['identifier', 'tag']
378  );
379 
380  $subject->remove('myIdentifier');
381 
382  // cache row with removed identifier has been removed, other one exists
383  self::assertSame(0, $cacheTableConnection->count('*', 'cache_pages', ['identifier' => 'myIdentifier']));
384  self::assertSame(1, $cacheTableConnection->count('*', 'cache_pages', ['identifier' => 'otherIdentifier']));
385 
386  // tags of myIdentifier should have been removed, others exist
387  self::assertSame(0, $tagsTableConnection->count('*', 'cache_pages_tags', ['identifier' => 'myIdentifier']));
388  self::assertSame(2, $tagsTableConnection->count('*', 'cache_pages_tags', ['identifier' => 'otherIdentifier']));
389  }
390 
395  {
396  $subject = $this->‪getSubjectObject();
397 
398  self::assertEquals(['idA' => 'idA'], $subject->findIdentifiersByTag('tagA'));
399  self::assertEquals(['idA' => 'idA', 'idB' => 'idB'], $subject->findIdentifiersByTag('tagB'));
400  self::assertEquals(['idB' => 'idB', 'idC' => 'idC'], $subject->findIdentifiersByTag('tagC'));
401  }
402 
411  {
412  $subject = $this->‪getSubjectObject(true);
413  $subject->flushByTag('tagB');
414  }
415 
424  {
425  $subject = $this->‪getSubjectObject(true);
426  $subject->flushByTags(['tagB']);
427  }
428 
437  {
438  $subject = $this->‪getSubjectObject(true);
439  $subject->flushByTag('tagB');
440 
441  $cacheTableConnection = (new ‪ConnectionPool())->getConnectionForTable('cache_pages');
442  self::assertSame(0, $cacheTableConnection->count('*', 'cache_pages', ['identifier' => 'idA']));
443  self::assertSame(0, $cacheTableConnection->count('*', 'cache_pages', ['identifier' => 'idB']));
444  self::assertSame(1, $cacheTableConnection->count('*', 'cache_pages', ['identifier' => 'idC']));
445  $tagsTableConnection = (new ‪ConnectionPool())->getConnectionForTable('cache_pages_tags');
446  self::assertSame(0, $tagsTableConnection->count('*', 'cache_pages_tags', ['identifier' => 'idA']));
447  self::assertSame(0, $tagsTableConnection->count('*', 'cache_pages_tags', ['identifier' => 'idB']));
448  self::assertSame(2, $tagsTableConnection->count('*', 'cache_pages_tags', ['identifier' => 'idC']));
449  }
450 
459  {
460  $subject = $this->‪getSubjectObject(true);
461  $subject->flushByTags(['tagC', 'tagD']);
462 
463  $cacheTableConnection = (new ‪ConnectionPool())->getConnectionForTable('cache_pages');
464  self::assertSame(1, $cacheTableConnection->count('*', 'cache_pages', ['identifier' => 'idA']));
465  self::assertSame(0, $cacheTableConnection->count('*', 'cache_pages', ['identifier' => 'idB']));
466  self::assertSame(0, $cacheTableConnection->count('*', 'cache_pages', ['identifier' => 'idC']));
467  $tagsTableConnection = (new ‪ConnectionPool())->getConnectionForTable('cache_pages_tags');
468  self::assertSame(2, $tagsTableConnection->count('*', 'cache_pages_tags', ['identifier' => 'idA']));
469  self::assertSame(0, $tagsTableConnection->count('*', 'cache_pages_tags', ['identifier' => 'idB']));
470  self::assertSame(0, $tagsTableConnection->count('*', 'cache_pages_tags', ['identifier' => 'idC']));
471  }
472 
477  {
478  $subject = $this->‪getSubjectObject(true, false);
479  $subject->flushByTag('tagB');
480  }
481 
486  {
487  $subject = $this->‪getSubjectObject(true, false);
488  $subject->flushByTags(['tagB', 'tagC']);
489  }
490 
495  {
496  $subject = $this->‪getSubjectObject(true, false);
497  $subject->flushByTag('tagB');
498 
499  $cacheTableConnection = (new ‪ConnectionPool())->getConnectionForTable('cache_pages');
500  self::assertSame(0, $cacheTableConnection->count('*', 'cache_pages', ['identifier' => 'idA']));
501  self::assertSame(0, $cacheTableConnection->count('*', 'cache_pages', ['identifier' => 'idB']));
502  self::assertSame(1, $cacheTableConnection->count('*', 'cache_pages', ['identifier' => 'idC']));
503  $tagsTableConnection = (new ‪ConnectionPool())->getConnectionForTable('cache_pages_tags');
504  self::assertSame(0, $tagsTableConnection->count('*', 'cache_pages_tags', ['identifier' => 'idA']));
505  self::assertSame(0, $tagsTableConnection->count('*', 'cache_pages_tags', ['identifier' => 'idB']));
506  self::assertSame(2, $tagsTableConnection->count('*', 'cache_pages_tags', ['identifier' => 'idC']));
507  }
508 
513  {
514  $subject = $this->‪getSubjectObject(true, false);
515  $subject->flushByTags(['tagC', 'tagD']);
516 
517  $cacheTableConnection = (new ‪ConnectionPool())->getConnectionForTable('cache_pages');
518  self::assertSame(1, $cacheTableConnection->count('*', 'cache_pages', ['identifier' => 'idA']));
519  self::assertSame(0, $cacheTableConnection->count('*', 'cache_pages', ['identifier' => 'idB']));
520  self::assertSame(0, $cacheTableConnection->count('*', 'cache_pages', ['identifier' => 'idC']));
521  $tagsTableConnection = (new ‪ConnectionPool())->getConnectionForTable('cache_pages_tags');
522  self::assertSame(2, $tagsTableConnection->count('*', 'cache_pages_tags', ['identifier' => 'idA']));
523  self::assertSame(0, $tagsTableConnection->count('*', 'cache_pages_tags', ['identifier' => 'idB']));
524  self::assertSame(0, $tagsTableConnection->count('*', 'cache_pages_tags', ['identifier' => 'idC']));
525  }
526 
535  {
536  $subject = $this->‪getSubjectObject(true);
537  $subject->collectGarbage();
538  }
539 
548  {
549  $frontendProphecy = $this->prophesize(FrontendInterface::class);
550  $frontendProphecy->getIdentifier()->willReturn('pages');
551 
552  // Must be mocked here to test for "mysql" version implementation
553  $subject = $this->getMockBuilder(Typo3DatabaseBackend::class)
554  ->setMethods(['isConnectionMysql'])
555  ->setConstructorArgs(['Testing'])
556  ->getMock();
557  $subject->expects(self::once())->method('isConnectionMysql')->willReturn(true);
558  $subject->setCache($frontendProphecy->reveal());
559 
560  // idA should be expired after EXEC_TIME manipulation, idB should stay
561  $subject->set('idA', 'dataA', [], 60);
562  $subject->set('idB', 'dataB', [], 240);
563 
564  ‪$GLOBALS['EXEC_TIME'] = ‪$GLOBALS['EXEC_TIME'] + 120;
565 
566  $subject->collectGarbage();
567 
568  $cacheTableConnection = (new ‪ConnectionPool())->getConnectionForTable('cache_pages');
569  self::assertSame(0, $cacheTableConnection->count('*', 'cache_pages', ['identifier' => 'idA']));
570  self::assertSame(1, $cacheTableConnection->count('*', 'cache_pages', ['identifier' => 'idB']));
571  }
572 
581  {
582  $frontendProphecy = $this->prophesize(FrontendInterface::class);
583  $frontendProphecy->getIdentifier()->willReturn('pages');
584 
585  // Must be mocked here to test for "mysql" version implementation
586  $subject = $this->getMockBuilder(Typo3DatabaseBackend::class)
587  ->setMethods(['isConnectionMysql'])
588  ->setConstructorArgs(['Testing'])
589  ->getMock();
590  $subject->expects(self::once())->method('isConnectionMysql')->willReturn(true);
591  $subject->setCache($frontendProphecy->reveal());
592 
593  // tag rows tagA and tagB should be removed by garbage collector after EXEC_TIME manipulation
594  $subject->set('idA', 'dataA', ['tagA', 'tagB'], 60);
595  $subject->set('idB', 'dataB', ['tagB', 'tagC'], 240);
596 
597  ‪$GLOBALS['EXEC_TIME'] = ‪$GLOBALS['EXEC_TIME'] + 120;
598 
599  $subject->collectGarbage();
600 
601  $tagsTableConnection = (new ‪ConnectionPool())->getConnectionForTable('cache_pages_tags');
602  self::assertSame(0, $tagsTableConnection->count('*', 'cache_pages_tags', ['identifier' => 'idA']));
603  self::assertSame(2, $tagsTableConnection->count('*', 'cache_pages_tags', ['identifier' => 'idB']));
604  }
605 
614  {
615  $frontendProphecy = $this->prophesize(FrontendInterface::class);
616  $frontendProphecy->getIdentifier()->willReturn('pages');
617 
618  // Must be mocked here to test for "mysql" version implementation
619  $subject = $this->getMockBuilder(Typo3DatabaseBackend::class)
620  ->setMethods(['isConnectionMysql'])
621  ->setConstructorArgs(['Testing'])
622  ->getMock();
623  $subject->expects(self::once())->method('isConnectionMysql')->willReturn(true);
624  $subject->setCache($frontendProphecy->reveal());
625 
626  // tag rows tagA and tagB should be removed by garbage collector after EXEC_TIME manipulation
627  $subject->set('idA', 'dataA', ['tagA', 'tagB'], 60);
628  $subject->set('idB', 'dataB', ['tagB', 'tagC'], 240);
629 
630  $tagsTableConnection = (new ‪ConnectionPool())->getConnectionForTable('cache_pages_tags');
631 
632  // Push two orphaned tag row into db - tags that have no related cache record anymore for whatever reason
633  $tagsTableConnection->insert(
634  'cache_pages_tags',
635  [
636  'identifier' => 'idC',
637  'tag' => 'tagC'
638  ]
639  );
640  $tagsTableConnection->insert(
641  'cache_pages_tags',
642  [
643  'identifier' => 'idC',
644  'tag' => 'tagD'
645  ]
646  );
647 
648  ‪$GLOBALS['EXEC_TIME'] = ‪$GLOBALS['EXEC_TIME'] + 120;
649 
650  $subject->collectGarbage();
651 
652  self::assertSame(0, $tagsTableConnection->count('*', 'cache_pages_tags', ['identifier' => 'idA']));
653  self::assertSame(2, $tagsTableConnection->count('*', 'cache_pages_tags', ['identifier' => 'idB']));
654  self::assertSame(0, $tagsTableConnection->count('*', 'cache_pages_tags', ['identifier' => 'idC']));
655  }
656 
661  {
662  $frontendProphecy = $this->prophesize(FrontendInterface::class);
663  $frontendProphecy->getIdentifier()->willReturn('pages');
664 
665  // Must be mocked here to test for "mysql" version implementation
666  $subject = $this->getMockBuilder(Typo3DatabaseBackend::class)
667  ->setMethods(['isConnectionMysql'])
668  ->setConstructorArgs(['Testing'])
669  ->getMock();
670  $subject->expects(self::once())->method('isConnectionMysql')->willReturn(false);
671  $subject->setCache($frontendProphecy->reveal());
672 
673  $subject->collectGarbage();
674  }
675 
680  {
681  $frontendProphecy = $this->prophesize(FrontendInterface::class);
682  $frontendProphecy->getIdentifier()->willReturn('pages');
683 
684  // Must be mocked here to test for "mysql" version implementation
685  $subject = $this->getMockBuilder(Typo3DatabaseBackend::class)
686  ->setMethods(['isConnectionMysql'])
687  ->setConstructorArgs(['Testing'])
688  ->getMock();
689  $subject->expects(self::once())->method('isConnectionMysql')->willReturn(false);
690  $subject->setCache($frontendProphecy->reveal());
691 
692  // idA should be expired after EXEC_TIME manipulation, idB should stay
693  $subject->set('idA', 'dataA', [], 60);
694  $subject->set('idB', 'dataB', [], 240);
695 
696  ‪$GLOBALS['EXEC_TIME'] = ‪$GLOBALS['EXEC_TIME'] + 120;
697 
698  $subject->collectGarbage();
699 
700  $cacheTableConnection = (new ‪ConnectionPool())->getConnectionForTable('cache_pages');
701  self::assertSame(0, $cacheTableConnection->count('*', 'cache_pages', ['identifier' => 'idA']));
702  self::assertSame(1, $cacheTableConnection->count('*', 'cache_pages', ['identifier' => 'idB']));
703  }
704 
709  {
710  $frontendProphecy = $this->prophesize(FrontendInterface::class);
711  $frontendProphecy->getIdentifier()->willReturn('pages');
712 
713  // Must be mocked here to test for "mysql" version implementation
714  $subject = $this->getMockBuilder(Typo3DatabaseBackend::class)
715  ->setMethods(['isConnectionMysql'])
716  ->setConstructorArgs(['Testing'])
717  ->getMock();
718  $subject->expects(self::once())->method('isConnectionMysql')->willReturn(false);
719  $subject->setCache($frontendProphecy->reveal());
720 
721  // tag rows tagA and tagB should be removed by garbage collector after EXEC_TIME manipulation
722  $subject->set('idA', 'dataA', ['tagA', 'tagB'], 60);
723  $subject->set('idB', 'dataB', ['tagB', 'tagC'], 240);
724 
725  ‪$GLOBALS['EXEC_TIME'] = ‪$GLOBALS['EXEC_TIME'] + 120;
726 
727  $subject->collectGarbage();
728 
729  $tagsTableConnection = (new ‪ConnectionPool())->getConnectionForTable('cache_pages_tags');
730  self::assertSame(0, $tagsTableConnection->count('*', 'cache_pages_tags', ['identifier' => 'idA']));
731  self::assertSame(2, $tagsTableConnection->count('*', 'cache_pages_tags', ['identifier' => 'idB']));
732  }
733 
738  {
739  $frontendProphecy = $this->prophesize(FrontendInterface::class);
740  $frontendProphecy->getIdentifier()->willReturn('pages');
741 
742  // Must be mocked here to test for "mysql" version implementation
743  $subject = $this->getMockBuilder(Typo3DatabaseBackend::class)
744  ->setMethods(['isConnectionMysql'])
745  ->setConstructorArgs(['Testing'])
746  ->getMock();
747  $subject->expects(self::once())->method('isConnectionMysql')->willReturn(false);
748  $subject->setCache($frontendProphecy->reveal());
749 
750  // tag rows tagA and tagB should be removed by garbage collector after EXEC_TIME manipulation
751  $subject->set('idA', 'dataA', ['tagA', 'tagB'], 60);
752  $subject->set('idB', 'dataB', ['tagB', 'tagC'], 240);
753 
754  $tagsTableConnection = (new ‪ConnectionPool())->getConnectionForTable('cache_pages_tags');
755 
756  // Push two orphaned tag row into db - tags that have no related cache record anymore for whatever reason
757  $tagsTableConnection->insert(
758  'cache_pages_tags',
759  [
760  'identifier' => 'idC',
761  'tag' => 'tagC'
762  ]
763  );
764  $tagsTableConnection->insert(
765  'cache_pages_tags',
766  [
767  'identifier' => 'idC',
768  'tag' => 'tagD'
769  ]
770  );
771 
772  ‪$GLOBALS['EXEC_TIME'] = ‪$GLOBALS['EXEC_TIME'] + 120;
773 
774  $subject->collectGarbage();
775 
776  self::assertSame(0, $tagsTableConnection->count('*', 'cache_pages_tags', ['identifier' => 'idA']));
777  self::assertSame(2, $tagsTableConnection->count('*', 'cache_pages_tags', ['identifier' => 'idB']));
778  self::assertSame(0, $tagsTableConnection->count('*', 'cache_pages_tags', ['identifier' => 'idC']));
779  }
780 
785  {
786  $frontendProphecy = $this->prophesize(FrontendInterface::class);
787  $frontendProphecy->getIdentifier()->willReturn('pages');
788 
789  $subject = new ‪Typo3DatabaseBackend('Testing');
790  $subject->setCache($frontendProphecy->reveal());
791 
792  $subject->set('idA', 'dataA', ['tagA', 'tagB']);
793 
794  $subject->flush();
795 
796  $cacheTableConnection = (new ‪ConnectionPool())->getConnectionForTable('cache_pages');
797  $tagsTableConnection = (new ‪ConnectionPool())->getConnectionForTable('cache_pages_tags');
798  self::assertSame(0, $cacheTableConnection->count('*', 'cache_pages', []));
799  self::assertSame(0, $tagsTableConnection->count('*', 'cache_pages_tags', []));
800  }
801 
808  protected function ‪getSubjectObject($returnMockObject = false, $isConnectionMysql = true)
809  {
810  $frontendProphecy = $this->prophesize(FrontendInterface::class);
811  $frontendProphecy->getIdentifier()->willReturn('pages');
812 
813  if (!$returnMockObject) {
814  $subject = new ‪Typo3DatabaseBackend('Testing');
815  } else {
816  $subject = $this->getMockBuilder(Typo3DatabaseBackend::class)
817  ->setMethods(['isConnectionMysql'])
818  ->setConstructorArgs(['Testing'])
819  ->getMock();
820  $subject->expects(self::once())->method('isConnectionMysql')->willReturn($isConnectionMysql);
821  }
822  $subject->setCache($frontendProphecy->reveal());
823 
824  $subject->set('idA', 'dataA', ['tagA', 'tagB']);
825  $subject->set('idB', 'dataB', ['tagB', 'tagC']);
826  $subject->set('idC', 'dataC', ['tagC', 'tagD']);
827 
828  return $subject;
829  }
830 }
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\Typo3DatabaseBackendTest\getReturnsFalseIfNoCacheEntryExists
‪getReturnsFalseIfNoCacheEntryExists()
Definition: Typo3DatabaseBackendTest.php:111
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\Typo3DatabaseBackendTest\hasReturnsNotExpiredCacheEntry
‪hasReturnsNotExpiredCacheEntry()
Definition: Typo3DatabaseBackendTest.php:278
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\Typo3DatabaseBackendTest\getReturnsNotExpiredCacheEntry
‪getReturnsNotExpiredCacheEntry()
Definition: Typo3DatabaseBackendTest.php:152
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend
Definition: MemcachedBackendTest.php:16
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\Typo3DatabaseBackendTest\removeRemovesCorrectEntriesFromDatabase
‪removeRemovesCorrectEntriesFromDatabase()
Definition: Typo3DatabaseBackendTest.php:346
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\Typo3DatabaseBackendTest\collectGarbageRemovesCacheEntryWithExpiredLifetimeWithNonMysql
‪collectGarbageRemovesCacheEntryWithExpiredLifetimeWithNonMysql()
Definition: Typo3DatabaseBackendTest.php:679
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\Typo3DatabaseBackendTest\findIdentifiersByTagReturnsIdentifierTaggedWithGivenTag
‪findIdentifiersByTagReturnsIdentifierTaggedWithGivenTag()
Definition: Typo3DatabaseBackendTest.php:394
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\Typo3DatabaseBackendTest\getReturnsEmptyStringUnzipped
‪getReturnsEmptyStringUnzipped()
Definition: Typo3DatabaseBackendTest.php:208
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\Typo3DatabaseBackendTest\flushByTagRemovesCorrectRowsFromDatabaseWithMysql
‪flushByTagRemovesCorrectRowsFromDatabaseWithMysql()
Definition: Typo3DatabaseBackendTest.php:436
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\Typo3DatabaseBackendTest\removeReturnsFalseIfNoEntryHasBeenRemoved
‪removeReturnsFalseIfNoEntryHasBeenRemoved()
Definition: Typo3DatabaseBackendTest.php:305
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\Typo3DatabaseBackendTest\getReturnsUnzipsNotExpiredCacheEntry
‪getReturnsUnzipsNotExpiredCacheEntry()
Definition: Typo3DatabaseBackendTest.php:179
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\Typo3DatabaseBackendTest\getReturnsFalseForExpiredCacheEntry
‪getReturnsFalseForExpiredCacheEntry()
Definition: Typo3DatabaseBackendTest.php:125
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\Typo3DatabaseBackendTest\flushByTagWorksWithEmptyCacheTablesWithMysql
‪flushByTagWorksWithEmptyCacheTablesWithMysql()
Definition: Typo3DatabaseBackendTest.php:410
‪TYPO3\CMS\Core\Cache\Backend\Typo3DatabaseBackend
Definition: Typo3DatabaseBackend.php:31
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\Typo3DatabaseBackendTest\hasReturnsFalseForExpiredCacheEntry
‪hasReturnsFalseForExpiredCacheEntry()
Definition: Typo3DatabaseBackendTest.php:251
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\Typo3DatabaseBackendTest\getReturnsPreviouslySetEntryWithNewContentIfSetWasCalledMultipleTimes
‪getReturnsPreviouslySetEntryWithNewContentIfSetWasCalledMultipleTimes()
Definition: Typo3DatabaseBackendTest.php:48
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\Typo3DatabaseBackendTest\flushByTagRemovesCorrectRowsFromDatabaseWithNonMysql
‪flushByTagRemovesCorrectRowsFromDatabaseWithNonMysql()
Definition: Typo3DatabaseBackendTest.php:494
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\Typo3DatabaseBackendTest\collectGarbageRemovesTagEntriesForCacheEntriesWithExpiredLifetimeWithMysql
‪collectGarbageRemovesTagEntriesForCacheEntriesWithExpiredLifetimeWithMysql()
Definition: Typo3DatabaseBackendTest.php:580
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\Typo3DatabaseBackendTest\flushByTagsRemovesCorrectRowsFromDatabaseWithNonMysql
‪flushByTagsRemovesCorrectRowsFromDatabaseWithNonMysql()
Definition: Typo3DatabaseBackendTest.php:512
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\Typo3DatabaseBackendTest\getReturnsPreviouslySetEntry
‪getReturnsPreviouslySetEntry()
Definition: Typo3DatabaseBackendTest.php:33
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\Typo3DatabaseBackendTest\flushLeavesCacheAndTagsTableEmpty
‪flushLeavesCacheAndTagsTableEmpty()
Definition: Typo3DatabaseBackendTest.php:784
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\Typo3DatabaseBackendTest\collectGarbageRemovesCacheEntryWithExpiredLifetimeWithMysql
‪collectGarbageRemovesCacheEntryWithExpiredLifetimeWithMysql()
Definition: Typo3DatabaseBackendTest.php:547
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\Typo3DatabaseBackendTest\flushByTagsRemovesCorrectRowsFromDatabaseWithMysql
‪flushByTagsRemovesCorrectRowsFromDatabaseWithMysql()
Definition: Typo3DatabaseBackendTest.php:458
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\Typo3DatabaseBackendTest\setInsertsDataWithTagsIntoCacheTable
‪setInsertsDataWithTagsIntoCacheTable()
Definition: Typo3DatabaseBackendTest.php:64
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\Typo3DatabaseBackendTest\flushByTagWorksWithEmptyCacheTablesWithNonMysql
‪flushByTagWorksWithEmptyCacheTablesWithNonMysql()
Definition: Typo3DatabaseBackendTest.php:476
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\Typo3DatabaseBackendTest\collectGarbageRemovesOrphanedTagEntriesFromTagsTableWithNonMysql
‪collectGarbageRemovesOrphanedTagEntriesFromTagsTableWithNonMysql()
Definition: Typo3DatabaseBackendTest.php:737
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\Typo3DatabaseBackendTest\collectGarbageRemovesTagEntriesForCacheEntriesWithExpiredLifetimeWithNonMysql
‪collectGarbageRemovesTagEntriesForCacheEntriesWithExpiredLifetimeWithNonMysql()
Definition: Typo3DatabaseBackendTest.php:708
‪TYPO3\CMS\Core\Database\Connection
Definition: Connection.php:36
‪TYPO3\CMS\Core\Cache\Frontend\FrontendInterface
Definition: FrontendInterface.php:22
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\Typo3DatabaseBackendTest\getSubjectObject
‪Typo3DatabaseBackend getSubjectObject($returnMockObject=false, $isConnectionMysql=true)
Definition: Typo3DatabaseBackendTest.php:808
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\Typo3DatabaseBackendTest\collectGarbageWorksWithEmptyTableWithNonMysql
‪collectGarbageWorksWithEmptyTableWithNonMysql()
Definition: Typo3DatabaseBackendTest.php:660
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\Typo3DatabaseBackendTest\flushByTagsWorksWithEmptyCacheTablesWithMysql
‪flushByTagsWorksWithEmptyCacheTablesWithMysql()
Definition: Typo3DatabaseBackendTest.php:423
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\Typo3DatabaseBackendTest\collectGarbageRemovesOrphanedTagEntriesFromTagsTableWithMysql
‪collectGarbageRemovesOrphanedTagEntriesFromTagsTableWithMysql()
Definition: Typo3DatabaseBackendTest.php:613
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\Typo3DatabaseBackendTest\collectGarbageWorksWithEmptyTableWithMysql
‪collectGarbageWorksWithEmptyTableWithMysql()
Definition: Typo3DatabaseBackendTest.php:534
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\Typo3DatabaseBackendTest\setStoresCompressedContent
‪setStoresCompressedContent()
Definition: Typo3DatabaseBackendTest.php:84
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\Typo3DatabaseBackendTest
Definition: Typo3DatabaseBackendTest.php:28
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\Typo3DatabaseBackendTest\flushByTagsWorksWithEmptyCacheTablesWithNonMysql
‪flushByTagsWorksWithEmptyCacheTablesWithNonMysql()
Definition: Typo3DatabaseBackendTest.php:485
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\Typo3DatabaseBackendTest\hasReturnsFalseIfNoCacheEntryExists
‪hasReturnsFalseIfNoCacheEntryExists()
Definition: Typo3DatabaseBackendTest.php:237
‪TYPO3\CMS\Core\Database\Connection\PARAM_LOB
‪const PARAM_LOB
Definition: Connection.php:57
‪TYPO3\CMS\Core\Tests\Functional\Cache\Backend\Typo3DatabaseBackendTest\removeReturnsTrueIfAnEntryHasBeenRemoved
‪removeReturnsTrueIfAnEntryHasBeenRemoved()
Definition: Typo3DatabaseBackendTest.php:319