TYPO3 CMS  TYPO3_6-2
Typo3DatabaseBackendTest.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 
21 
26 {
27 
31  public function getReturnsPreviouslySetEntry()
32  {
33  $frontendProphecy = $this->prophesize('TYPO3\\CMS\\Core\\Cache\\Frontend\FrontendInterface');
34  $frontendProphecy->getIdentifier()->willReturn('cache_pages');
35 
36  $subject = new Typo3DatabaseBackend('Testing');
37  $subject->setCache($frontendProphecy->reveal());
38 
39  $subject->set('myIdentifier', 'myData');
40  $this->assertSame('myData', $subject->get('myIdentifier'));
41  }
42 
47  {
48  $frontendProphecy = $this->prophesize('TYPO3\\CMS\\Core\\Cache\\Frontend\FrontendInterface');
49  $frontendProphecy->getIdentifier()->willReturn('cache_pages');
50 
51  $subject = new Typo3DatabaseBackend('Testing');
52  $subject->setCache($frontendProphecy->reveal());
53 
54  $subject->set('myIdentifier', 'myData');
55  $subject->set('myIdentifier', 'myNewData');
56  $this->assertSame('myNewData', $subject->get('myIdentifier'));
57  }
58 
63  {
64  $frontendProphecy = $this->prophesize('TYPO3\\CMS\\Core\\Cache\\Frontend\FrontendInterface');
65  $frontendProphecy->getIdentifier()->willReturn('cache_pages');
66 
67  $subject = new Typo3DatabaseBackend('Testing');
68  $subject->setCache($frontendProphecy->reveal());
69 
70  $subject->set('myIdentifier', 'myData', array('aTag', 'anotherTag'));
71 
72  $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', 'cf_cache_pages', 'identifier="myIdentifier"');
73  $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', 'cf_cache_pages_tags', 'identifier="myIdentifier" AND tag="aTag"');
74  $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', 'cf_cache_pages_tags', 'identifier="myIdentifier" AND tag="anotherTag"');
75  }
76 
80  public function setStoresCompressedContent()
81  {
82  $frontendProphecy = $this->prophesize('TYPO3\\CMS\\Core\\Cache\\Frontend\FrontendInterface');
83  $frontendProphecy->getIdentifier()->willReturn('cache_pages');
84 
85  // Have backend with compression enabled
86  $subject = new Typo3DatabaseBackend('Testing', array('compression' => true));
87  $subject->setCache($frontendProphecy->reveal());
88 
89  $subject->set('myIdentifier', 'myCachedContent');
90 
91  $row = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow(
92  'content',
93  'cf_cache_pages',
94  'identifier="myIdentifier"'
95  );
96 
97  // Content comes back uncompressed
98  $this->assertSame('myCachedContent', gzuncompress($row['content']));
99  }
100 
105  {
106  $frontendProphecy = $this->prophesize('TYPO3\\CMS\\Core\\Cache\\Frontend\FrontendInterface');
107  $frontendProphecy->getIdentifier()->willReturn('cache_pages');
108 
109  $subject = new Typo3DatabaseBackend('Testing');
110  $subject->setCache($frontendProphecy->reveal());
111 
112  $this->assertFalse($subject->get('myIdentifier'));
113  }
114 
119  {
120  $frontendProphecy = $this->prophesize('TYPO3\\CMS\\Core\\Cache\\Frontend\FrontendInterface');
121  $frontendProphecy->getIdentifier()->willReturn('cache_pages');
122 
123  // Push an expired row into db
124  $GLOBALS['TYPO3_DB']->exec_INSERTquery(
125  'cf_cache_pages',
126  array(
127  'identifier' => 'myIdentifier',
128  'expires' => $GLOBALS['EXEC_TIME'] - 60,
129  'content' => 'myCachedContent',
130  )
131  );
132 
133  $subject = new Typo3DatabaseBackend('Testing');
134  $subject->setCache($frontendProphecy->reveal());
135 
136  $this->assertFalse($subject->get('myIdentifier'));
137  }
138 
143  {
144  $frontendProphecy = $this->prophesize('TYPO3\\CMS\\Core\\Cache\\Frontend\FrontendInterface');
145  $frontendProphecy->getIdentifier()->willReturn('cache_pages');
146 
147  // Push a row into db
148  $GLOBALS['TYPO3_DB']->exec_INSERTquery(
149  'cf_cache_pages',
150  array(
151  'identifier' => 'myIdentifier',
152  'expires' => $GLOBALS['EXEC_TIME'] + 60,
153  'content' => 'myCachedContent',
154  )
155  );
156 
157  $subject = new Typo3DatabaseBackend('Testing');
158  $subject->setCache($frontendProphecy->reveal());
159 
160  $this->assertSame('myCachedContent', $subject->get('myIdentifier'));
161  }
162 
167  {
168  $frontendProphecy = $this->prophesize('TYPO3\\CMS\\Core\\Cache\\Frontend\FrontendInterface');
169  $frontendProphecy->getIdentifier()->willReturn('cache_pages');
170 
171  // Push a compressed row into db
172  $GLOBALS['TYPO3_DB']->exec_INSERTquery(
173  'cf_cache_pages',
174  array(
175  'identifier' => 'myIdentifier',
176  'expires' => $GLOBALS['EXEC_TIME'] + 60,
177  'content' => gzcompress('myCachedContent'),
178  )
179  );
180 
181 
182 
183  // Have backend with compression enabled
184  $subject = new Typo3DatabaseBackend('Testing', array('compression' => true));
185  $subject->setCache($frontendProphecy->reveal());
186 
187  // Content comes back uncompressed
188  $this->assertSame('myCachedContent', $subject->get('myIdentifier'));
189  }
190 
195  {
196  $frontendProphecy = $this->prophesize('TYPO3\\CMS\\Core\\Cache\\Frontend\FrontendInterface');
197  $frontendProphecy->getIdentifier()->willReturn('cache_pages');
198 
199  // Push a compressed row into db
200  $GLOBALS['TYPO3_DB']->exec_INSERTquery(
201  'cf_cache_pages',
202  array(
203  'identifier' => 'myIdentifier',
204  'expires' => $GLOBALS['EXEC_TIME'] + 60,
205  'content' => gzcompress(''),
206  )
207  );
208 
209  // Have backend with compression enabled
210  $subject = new Typo3DatabaseBackend('Testing', array('compression' => true));
211  $subject->setCache($frontendProphecy->reveal());
212 
213  // Content comes back uncompressed
214  $this->assertSame('', $subject->get('myIdentifier'));
215  }
216 
221  {
222  $frontendProphecy = $this->prophesize('TYPO3\\CMS\\Core\\Cache\\Frontend\FrontendInterface');
223  $frontendProphecy->getIdentifier()->willReturn('cache_pages');
224 
225  $subject = new Typo3DatabaseBackend('Testing');
226  $subject->setCache($frontendProphecy->reveal());
227 
228  $this->assertFalse($subject->has('myIdentifier'));
229  }
230 
235  {
236  $frontendProphecy = $this->prophesize('TYPO3\\CMS\\Core\\Cache\\Frontend\FrontendInterface');
237  $frontendProphecy->getIdentifier()->willReturn('cache_pages');
238 
239  // Push an expired row into db
240  $GLOBALS['TYPO3_DB']->exec_INSERTquery(
241  'cf_cache_pages',
242  array(
243  'identifier' => 'myIdentifier',
244  'expires' => $GLOBALS['EXEC_TIME'] - 60,
245  'content' => 'myCachedContent',
246  )
247  );
248 
249  $subject = new Typo3DatabaseBackend('Testing');
250  $subject->setCache($frontendProphecy->reveal());
251 
252  $this->assertFalse($subject->has('myIdentifier'));
253  }
254 
259  {
260  $frontendProphecy = $this->prophesize('TYPO3\\CMS\\Core\\Cache\\Frontend\FrontendInterface');
261  $frontendProphecy->getIdentifier()->willReturn('cache_pages');
262 
263  // Push a row into db
264  $GLOBALS['TYPO3_DB']->exec_INSERTquery(
265  'cf_cache_pages',
266  array(
267  'identifier' => 'myIdentifier',
268  'expires' => $GLOBALS['EXEC_TIME'] + 60,
269  'content' => 'myCachedContent',
270  )
271  );
272 
273  $subject = new Typo3DatabaseBackend('Testing');
274  $subject->setCache($frontendProphecy->reveal());
275 
276  $this->assertTrue($subject->has('myIdentifier'));
277  }
278 
283  {
284  $frontendProphecy = $this->prophesize('TYPO3\\CMS\\Core\\Cache\\Frontend\FrontendInterface');
285  $frontendProphecy->getIdentifier()->willReturn('cache_pages');
286 
287  $subject = new Typo3DatabaseBackend('Testing');
288  $subject->setCache($frontendProphecy->reveal());
289 
290  $this->assertFalse($subject->remove('myIdentifier'));
291  }
292 
297  {
298  $frontendProphecy = $this->prophesize('TYPO3\\CMS\\Core\\Cache\\Frontend\FrontendInterface');
299  $frontendProphecy->getIdentifier()->willReturn('cache_pages');
300 
301  // Push a row into db
302  $GLOBALS['TYPO3_DB']->exec_INSERTquery(
303  'cf_cache_pages',
304  array(
305  'identifier' => 'myIdentifier',
306  'expires' => $GLOBALS['EXEC_TIME'] + 60,
307  'content' => 'myCachedContent',
308  )
309  );
310  $subject = new Typo3DatabaseBackend('Testing');
311  $subject->setCache($frontendProphecy->reveal());
312  $this->assertTrue($subject->remove('myIdentifier'));
313  }
314 
319  {
320  $frontendProphecy = $this->prophesize('TYPO3\\CMS\\Core\\Cache\\Frontend\FrontendInterface');
321  $frontendProphecy->getIdentifier()->willReturn('cache_pages');
322 
323  // Add one cache row to remove and another one that shouldn't be removed
324  $GLOBALS['TYPO3_DB']->INSERTmultipleRows(
325  'cf_cache_pages',
326  array('identifier', 'expires', 'content'),
327  array(
328  array('myIdentifier', $GLOBALS['EXEC_TIME'] + 60, 'myCachedContent'),
329  array('otherIdentifier', $GLOBALS['EXEC_TIME'] + 60, 'otherCachedContent'),
330  )
331  );
332 
333  $subject = new Typo3DatabaseBackend('Testing');
334  $subject->setCache($frontendProphecy->reveal());
335 
336  // Add a couple of tags
337  $GLOBALS['TYPO3_DB']->INSERTmultipleRows(
338  'cf_cache_pages',
339  array('identifier', 'tag'),
340  array(
341  array('myIdentifier', 'aTag'),
342  array('myIdentifier', 'otherTag'),
343  array('otherIdentifier', 'aTag'),
344  array('otherIdentifier', 'otherTag'),
345  )
346  );
347 
348  $subject->remove('myIdentifier');
349 
350  // cache row with removed identifier has been removed, other one exists
351  $this->assertSame(0, $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', 'cf_cache_pages', 'identifier="myIdentifier"'));
352  $this->assertSame(0, $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', 'cf_cache_pages', 'identifier="otherIdentifier"'));
353 
354  // tags of myIdentifier should have been removed, others exist
355  $this->assertSame(0, $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', 'cf_cache_pages_tags', 'identifier="myIdentifier"'));
356  $this->assertSame(0, $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', 'cf_cache_pages_tags', 'identifier="otherIdentifier"'));
357  }
358 
363  {
364  $frontendProphecy = $this->prophesize('TYPO3\\CMS\\Core\\Cache\\Frontend\FrontendInterface');
365  $frontendProphecy->getIdentifier()->willReturn('cache_pages');
366 
367  $subject = new Typo3DatabaseBackend('Testing');
368  $subject->setCache($frontendProphecy->reveal());
369 
370  $subject->set('idA', 'dataA', array('tagA', 'tagB'));
371  $subject->set('idB', 'dataB', array('tagB', 'tagC'));
372 
373  $this->assertSame(array('idA' => 'idA'), $subject->findIdentifiersByTag('tagA'));
374  $this->assertSame(array('idA' => 'idA', 'idB' => 'idB'), $subject->findIdentifiersByTag('tagB'));
375  $this->assertSame(array('idB' => 'idB'), $subject->findIdentifiersByTag('tagC'));
376  }
377 
382  {
383  $frontendProphecy = $this->prophesize('TYPO3\\CMS\\Core\\Cache\\Frontend\FrontendInterface');
384  $frontendProphecy->getIdentifier()->willReturn('cache_pages');
385 
386  // Must be mocked here to test for "mysql" version implementation
387  $subject = $this->getMockBuilder('TYPO3\\CMS\\Core\\Cache\\Backend\\Typo3DatabaseBackend')
388  ->setMethods(array('isConnectionMysql'))
389  ->setConstructorArgs(array('Testing'))
390  ->getMock();
391  $subject->expects($this->once())->method('isConnectionMysql')->willReturn(true);
392  $subject->setCache($frontendProphecy->reveal());
393 
394  $subject->flushByTag('tagB');
395  }
396 
401  {
402  $frontendProphecy = $this->prophesize('TYPO3\\CMS\\Core\\Cache\\Frontend\FrontendInterface');
403  $frontendProphecy->getIdentifier()->willReturn('cache_pages');
404 
405  // Must be mocked here to test for "mysql" version implementation
406  $subject = $this->getMockBuilder('TYPO3\\CMS\\Core\\Cache\\Backend\\Typo3DatabaseBackend')
407  ->setMethods(array('isConnectionMysql'))
408  ->setConstructorArgs(array('Testing'))
409  ->getMock();
410  $subject->expects($this->once())->method('isConnectionMysql')->willReturn(true);
411  $subject->setCache($frontendProphecy->reveal());
412 
413  $subject->set('idA', 'dataA', array('tagA', 'tagB'));
414  $subject->set('idB', 'dataB', array('tagB', 'tagC'));
415  $subject->set('idC', 'dataC', array('tagC', 'tagD'));
416  $subject->flushByTag('tagB');
417 
418  $this->assertSame(0, $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', 'cf_cache_pages', 'identifier="idA"'));
419  $this->assertSame(0, $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', 'cf_cache_pages', 'identifier="idB"'));
420  $this->assertSame(1, $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', 'cf_cache_pages', 'identifier="idC"'));
421  $this->assertSame(0, $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', 'cf_cache_pages_tags', 'identifier="idA"'));
422  $this->assertSame(0, $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', 'cf_cache_pages_tags', 'identifier="idB"'));
423  $this->assertSame(2, $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', 'cf_cache_pages_tags', 'identifier="idC"'));
424  }
425 
430  {
431  $frontendProphecy = $this->prophesize('TYPO3\\CMS\\Core\\Cache\\Frontend\FrontendInterface');
432  $frontendProphecy->getIdentifier()->willReturn('cache_pages');
433 
434  // Must be mocked here to test for "mysql" version implementation
435  $subject = $this->getMockBuilder('TYPO3\\CMS\\Core\\Cache\\Backend\\Typo3DatabaseBackend')
436  ->setMethods(array('isConnectionMysql'))
437  ->setConstructorArgs(array('Testing'))
438  ->getMock();
439  $subject->expects($this->once())->method('isConnectionMysql')->willReturn(false);
440  $subject->setCache($frontendProphecy->reveal());
441 
442  $subject->flushByTag('tagB');
443  }
444 
449  {
450  $frontendProphecy = $this->prophesize('TYPO3\\CMS\\Core\\Cache\\Frontend\FrontendInterface');
451  $frontendProphecy->getIdentifier()->willReturn('cache_pages');
452 
453  // Must be mocked here to test for "mysql" version implementation
454  $subject = $this->getMockBuilder('TYPO3\\CMS\\Core\\Cache\\Backend\\Typo3DatabaseBackend')
455  ->setMethods(array('isConnectionMysql'))
456  ->setConstructorArgs(array('Testing'))
457  ->getMock();
458  $subject->expects($this->once())->method('isConnectionMysql')->willReturn(false);
459  $subject->setCache($frontendProphecy->reveal());
460 
461  $subject->set('idA', 'dataA', array('tagA', 'tagB'));
462  $subject->set('idB', 'dataB', array('tagB', 'tagC'));
463  $subject->set('idC', 'dataC', array('tagC', 'tagD'));
464  $subject->flushByTag('tagB');
465 
466  $this->assertSame(0, $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', 'cf_cache_pages', 'identifier="idA"'));
467  $this->assertSame(0, $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', 'cf_cache_pages', 'identifier="idB"'));
468  $this->assertSame(1, $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', 'cf_cache_pages', 'identifier="idC"'));
469  $this->assertSame(0, $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', 'cf_cache_pages_tags', 'identifier="idA"'));
470  $this->assertSame(0, $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', 'cf_cache_pages_tags', 'identifier="idB"'));
471  $this->assertSame(2, $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', 'cf_cache_pages_tags', 'identifier="idC"'));
472  }
473 
478  {
479  $frontendProphecy = $this->prophesize('TYPO3\\CMS\\Core\\Cache\\Frontend\FrontendInterface');
480  $frontendProphecy->getIdentifier()->willReturn('cache_pages');
481 
482  // Must be mocked here to test for "mysql" version implementation
483  $subject = $this->getMockBuilder('TYPO3\\CMS\\Core\\Cache\\Backend\\Typo3DatabaseBackend')
484  ->setMethods(array('isConnectionMysql'))
485  ->setConstructorArgs(array('Testing'))
486  ->getMock();
487  $subject->expects($this->once())->method('isConnectionMysql')->willReturn(true);
488  $subject->setCache($frontendProphecy->reveal());
489 
490  $subject->collectGarbage();
491  }
492 
497  {
498  $frontendProphecy = $this->prophesize('TYPO3\\CMS\\Core\\Cache\\Frontend\FrontendInterface');
499  $frontendProphecy->getIdentifier()->willReturn('cache_pages');
500 
501  // Must be mocked here to test for "mysql" version implementation
502  $subject = $this->getMockBuilder('TYPO3\\CMS\\Core\\Cache\\Backend\\Typo3DatabaseBackend')
503  ->setMethods(array('isConnectionMysql'))
504  ->setConstructorArgs(array('Testing'))
505  ->getMock();
506  $subject->expects($this->once())->method('isConnectionMysql')->willReturn(true);
507  $subject->setCache($frontendProphecy->reveal());
508 
509  // idA should be expired after EXEC_TIME manipulation, idB should stay
510  $subject->set('idA', 'dataA', array(), 60);
511  $subject->set('idB', 'dataB', array(), 240);
512 
513  $GLOBALS['EXEC_TIME'] = $GLOBALS['EXEC_TIME'] + 120;
514 
515  $subject->collectGarbage();
516 
517  $this->assertSame(0, $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', 'cf_cache_pages', 'identifier="idA"'));
518  $this->assertSame(1, $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', 'cf_cache_pages', 'identifier="idB"'));
519  }
520 
525  {
526  $frontendProphecy = $this->prophesize('TYPO3\\CMS\\Core\\Cache\\Frontend\FrontendInterface');
527  $frontendProphecy->getIdentifier()->willReturn('cache_pages');
528 
529  // Must be mocked here to test for "mysql" version implementation
530  $subject = $this->getMockBuilder('TYPO3\\CMS\\Core\\Cache\\Backend\\Typo3DatabaseBackend')
531  ->setMethods(array('isConnectionMysql'))
532  ->setConstructorArgs(array('Testing'))
533  ->getMock();
534  $subject->expects($this->once())->method('isConnectionMysql')->willReturn(true);
535  $subject->setCache($frontendProphecy->reveal());
536 
537  // tag rows tagA and tagB should be removed by garbage collector after EXEC_TIME manipulation
538  $subject->set('idA', 'dataA', array('tagA', 'tagB'), 60);
539  $subject->set('idB', 'dataB', array('tagB', 'tagC'), 240);
540 
541  $GLOBALS['EXEC_TIME'] = $GLOBALS['EXEC_TIME'] + 120;
542 
543  $subject->collectGarbage();
544 
545  $this->assertSame(0, $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', 'cf_cache_pages_tags', 'identifier="idA"'));
546  $this->assertSame(2, $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', 'cf_cache_pages_tags', 'identifier="idB"'));
547  }
548 
553  {
554  $frontendProphecy = $this->prophesize('TYPO3\\CMS\\Core\\Cache\\Frontend\FrontendInterface');
555  $frontendProphecy->getIdentifier()->willReturn('cache_pages');
556 
557  // Must be mocked here to test for "mysql" version implementation
558  $subject = $this->getMockBuilder('TYPO3\\CMS\\Core\\Cache\\Backend\\Typo3DatabaseBackend')
559  ->setMethods(array('isConnectionMysql'))
560  ->setConstructorArgs(array('Testing'))
561  ->getMock();
562  $subject->expects($this->once())->method('isConnectionMysql')->willReturn(true);
563  $subject->setCache($frontendProphecy->reveal());
564 
565  // tag rows tagA and tagB should be removed by garbage collector after EXEC_TIME manipulation
566  $subject->set('idA', 'dataA', array('tagA', 'tagB'), 60);
567  $subject->set('idB', 'dataB', array('tagB', 'tagC'), 240);
568 
569  // Push two orphaned tag row into db - tags that have no related cache record anymore for whatever reason
570  $GLOBALS['TYPO3_DB']->exec_INSERTquery(
571  'cf_cache_pages_tags',
572  array(
573  'identifier' => 'idC',
574  'tag' => 'tagC'
575  )
576  );
577  $GLOBALS['TYPO3_DB']->exec_INSERTquery(
578  'cf_cache_pages_tags',
579  array(
580  'identifier' => 'idC',
581  'tag' => 'tagD'
582  )
583  );
584 
585  $GLOBALS['EXEC_TIME'] = $GLOBALS['EXEC_TIME'] + 120;
586 
587  $subject->collectGarbage();
588 
589  $this->assertSame(0, $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', 'cf_cache_pages_tags', 'identifier="idA"'));
590  $this->assertSame(2, $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', 'cf_cache_pages_tags', 'identifier="idB"'));
591  $this->assertSame(0, $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', 'cf_cache_pages_tags', 'identifier="idC"'));
592  }
593 
598  {
599  $frontendProphecy = $this->prophesize('TYPO3\\CMS\\Core\\Cache\\Frontend\FrontendInterface');
600  $frontendProphecy->getIdentifier()->willReturn('cache_pages');
601 
602  // Must be mocked here to test for "mysql" version implementation
603  $subject = $this->getMockBuilder('TYPO3\\CMS\\Core\\Cache\\Backend\\Typo3DatabaseBackend')
604  ->setMethods(array('isConnectionMysql'))
605  ->setConstructorArgs(array('Testing'))
606  ->getMock();
607  $subject->expects($this->once())->method('isConnectionMysql')->willReturn(false);
608  $subject->setCache($frontendProphecy->reveal());
609 
610  $subject->collectGarbage();
611  }
612 
617  {
618  $frontendProphecy = $this->prophesize('TYPO3\\CMS\\Core\\Cache\\Frontend\FrontendInterface');
619  $frontendProphecy->getIdentifier()->willReturn('cache_pages');
620 
621  // Must be mocked here to test for "mysql" version implementation
622  $subject = $this->getMockBuilder('TYPO3\\CMS\\Core\\Cache\\Backend\\Typo3DatabaseBackend')
623  ->setMethods(array('isConnectionMysql'))
624  ->setConstructorArgs(array('Testing'))
625  ->getMock();
626  $subject->expects($this->once())->method('isConnectionMysql')->willReturn(false);
627  $subject->setCache($frontendProphecy->reveal());
628 
629  // idA should be expired after EXEC_TIME manipulation, idB should stay
630  $subject->set('idA', 'dataA', array(), 60);
631  $subject->set('idB', 'dataB', array(), 240);
632 
633  $GLOBALS['EXEC_TIME'] = $GLOBALS['EXEC_TIME'] + 120;
634 
635  $subject->collectGarbage();
636 
637  $this->assertSame(0, $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', 'cf_cache_pages', 'identifier="idA"'));
638  $this->assertSame(1, $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', 'cf_cache_pages', 'identifier="idB"'));
639  }
640 
645  {
646  $frontendProphecy = $this->prophesize('TYPO3\\CMS\\Core\\Cache\\Frontend\FrontendInterface');
647  $frontendProphecy->getIdentifier()->willReturn('cache_pages');
648 
649  // Must be mocked here to test for "mysql" version implementation
650  $subject = $this->getMockBuilder('TYPO3\\CMS\\Core\\Cache\\Backend\\Typo3DatabaseBackend')
651  ->setMethods(array('isConnectionMysql'))
652  ->setConstructorArgs(array('Testing'))
653  ->getMock();
654  $subject->expects($this->once())->method('isConnectionMysql')->willReturn(false);
655  $subject->setCache($frontendProphecy->reveal());
656 
657  // tag rows tagA and tagB should be removed by garbage collector after EXEC_TIME manipulation
658  $subject->set('idA', 'dataA', array('tagA', 'tagB'), 60);
659  $subject->set('idB', 'dataB', array('tagB', 'tagC'), 240);
660 
661  $GLOBALS['EXEC_TIME'] = $GLOBALS['EXEC_TIME'] + 120;
662 
663  $subject->collectGarbage();
664 
665  $this->assertSame(0, $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', 'cf_cache_pages_tags', 'identifier="idA"'));
666  $this->assertSame(2, $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', 'cf_cache_pages_tags', 'identifier="idB"'));
667  }
668 
673  {
674  $frontendProphecy = $this->prophesize('TYPO3\\CMS\\Core\\Cache\\Frontend\FrontendInterface');
675  $frontendProphecy->getIdentifier()->willReturn('cache_pages');
676 
677  // Must be mocked here to test for "mysql" version implementation
678  $subject = $this->getMockBuilder('TYPO3\\CMS\\Core\\Cache\\Backend\\Typo3DatabaseBackend')
679  ->setMethods(array('isConnectionMysql'))
680  ->setConstructorArgs(array('Testing'))
681  ->getMock();
682  $subject->expects($this->once())->method('isConnectionMysql')->willReturn(false);
683  $subject->setCache($frontendProphecy->reveal());
684 
685  // tag rows tagA and tagB should be removed by garbage collector after EXEC_TIME manipulation
686  $subject->set('idA', 'dataA', array('tagA', 'tagB'), 60);
687  $subject->set('idB', 'dataB', array('tagB', 'tagC'), 240);
688 
689  // Push two orphaned tag row into db - tags that have no related cache record anymore for whatever reason
690  $GLOBALS['TYPO3_DB']->exec_INSERTquery(
691  'cf_cache_pages_tags',
692  array(
693  'identifier' => 'idC',
694  'tag' => 'tagC'
695  )
696  );
697  $GLOBALS['TYPO3_DB']->exec_INSERTquery(
698  'cf_cache_pages_tags',
699  array(
700  'identifier' => 'idC',
701  'tag' => 'tagD'
702  )
703  );
704 
705  $GLOBALS['EXEC_TIME'] = $GLOBALS['EXEC_TIME'] + 120;
706 
707  $subject->collectGarbage();
708 
709  $this->assertSame(0, $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', 'cf_cache_pages_tags', 'identifier="idA"'));
710  $this->assertSame(2, $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', 'cf_cache_pages_tags', 'identifier="idB"'));
711  $this->assertSame(0, $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', 'cf_cache_pages_tags', 'identifier="idC"'));
712  }
713 
718  {
719  $frontendProphecy = $this->prophesize('TYPO3\\CMS\\Core\\Cache\\Frontend\FrontendInterface');
720  $frontendProphecy->getIdentifier()->willReturn('cache_pages');
721 
722  $subject = new Typo3DatabaseBackend('Testing');
723  $subject->setCache($frontendProphecy->reveal());
724 
725  $subject->set('idA', 'dataA', array('tagA', 'tagB'));
726 
727  $subject->flush();
728 
729  $this->assertSame(0, $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', 'cf_cache_pages'));
730  $this->assertSame(0, $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', 'cf_cache_pages_tags'));
731  }
732 }
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]