59558f4887f9a2cf446accc898596ef706803d56
[Packages/TYPO3.CMS.git] / tests / t3lib / cache / backend / class.t3lib_cache_backend_dbbackendTest.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009-2011 Ingo Renner <ingo@typo3.org>
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24
25 /**
26 * Testcase for the DB cache backend
27 *
28 * @author Ingo Renner <ingo@typo3.org>
29 * @package TYPO3
30 * @subpackage tests
31 */
32 class t3lib_cache_backend_DbBackendTest extends tx_phpunit_testcase {
33
34 /**
35 * Enable backup of global and system variables
36 *
37 * @var boolean
38 */
39 protected $backupGlobals = TRUE;
40
41 /**
42 * Exclude TYPO3_DB from backup/ restore of $GLOBALS
43 * because resource types cannot be handled during serializing
44 *
45 * @var array
46 */
47 protected $backupGlobalsBlacklist = array('TYPO3_DB');
48
49 /**
50 * @var t3lib_DB Backup of original TYPO3_DB instance
51 */
52 protected $typo3DbBackup;
53
54 /**
55 * @var string Name of the testing data table
56 */
57 protected $testingCacheTable = 'cachingframework_Testing';
58
59 /**
60 * @var string Name of the testing tags table
61 */
62 protected $testingTagsTable = 'cachingframework_Testing_tags';
63
64 /**
65 * Set up testcases
66 */
67 public function setUp() {
68 $this->typo3DbBackup = $GLOBALS['TYPO3_DB'];
69 }
70
71 /**
72 * Sets up the backend used for testing
73 *
74 * @return void
75 * @author Ingo Renner <ingo@typo3.org>
76 * @author Christian Kuhn <lolli@schwarzbu.ch>
77 */
78 protected function setUpBackend(array $backendOptions = array()) {
79 $GLOBALS['TYPO3_DB']->sql_query('CREATE TABLE ' . $this->testingCacheTable . ' (
80 id int(11) unsigned NOT NULL auto_increment,
81 identifier varchar(250) DEFAULT \'\' NOT NULL,
82 crdate int(11) unsigned DEFAULT \'0\' NOT NULL,
83 content mediumblob,
84 lifetime int(11) unsigned DEFAULT \'0\' NOT NULL,
85 PRIMARY KEY (id),
86 KEY cache_id (identifier)
87 ) ENGINE=InnoDB;
88 ');
89
90 $GLOBALS['TYPO3_DB']->sql_query('CREATE TABLE ' . $this->testingTagsTable . ' (
91 id int(11) unsigned NOT NULL auto_increment,
92 identifier varchar(250) DEFAULT \'\' NOT NULL,
93 tag varchar(250) DEFAULT \'\' NOT NULL,
94 PRIMARY KEY (id),
95 KEY cache_id (identifier),
96 KEY cache_tag (tag)
97 ) ENGINE=InnoDB;
98 ');
99
100 $backend = t3lib_div::makeInstance(
101 't3lib_cache_backend_DbBackend',
102 'Testing',
103 $backendOptions
104 );
105
106 return $backend;
107 }
108
109 /**
110 * Helper method to inject a mock frontend to backend instance
111 *
112 * @param t3lib_cache_backend_DbBackend $backend Current backend instance
113 * @return void
114 */
115 protected function setUpMockFrontendOfBackend(t3lib_cache_backend_DbBackend $backend) {
116 $mockCache = $this->getMock('t3lib_cache_frontend_AbstractFrontend', array(), array(), '', FALSE);
117 $mockCache->expects($this->any())->method('getIdentifier')->will($this->returnValue('Testing'));
118 $backend->setCache($mockCache);
119 }
120
121 /**
122 * @author Ingo Renner <ingo@typo3.org>
123 */
124 public function tearDown() {
125 $GLOBALS['TYPO3_DB']->sql_query(
126 'DROP TABLE IF EXISTS ' . $this->testingCacheTable . ';'
127 );
128
129 $GLOBALS['TYPO3_DB']->sql_query(
130 'DROP TABLE IF EXISTS ' . $this->testingTagsTable . ';'
131 );
132
133 $GLOBALS['TYPO3_DB'] = $this->typo3DbBackup;
134 }
135
136 /**
137 * @test
138 * @author Ingo Renner <ingo@typo3.org>
139 */
140 public function setCacheCalculatesCacheTableName() {
141 $backend = $this->setUpBackend();
142 $this->setUpMockFrontendOfBackend($backend);
143 $this->assertEquals($this->testingCacheTable, $backend->getCacheTable());
144 }
145
146 /**
147 * @test
148 */
149 public function setCacheCalculatesTagsTableName() {
150 $backend = $this->setUpBackend();
151 $this->setUpMockFrontendOfBackend($backend);
152
153 $this->assertEquals($this->testingTagsTable, $backend->getTagsTable());
154 }
155
156 /**
157 * @test
158 * @expectedException t3lib_cache_Exception
159 */
160 public function setThrowsExceptionIfFrontendWasNotSet() {
161 $backend = $this->setUpBackend();
162 $backend->set('identifier', 'data');
163 }
164
165 /**
166 * @test
167 * @expectedException t3lib_cache_exception_InvalidData
168 * @author Ingo Renner <ingo@typo3.org>
169 */
170 public function setThrowsExceptionIfDataIsNotAString() {
171 $backend = $this->setUpBackend();
172 $this->setUpMockFrontendOfBackend($backend);
173
174 $data = array('Some data');
175 $entryIdentifier = 'BackendDbTest';
176
177 $backend->set($entryIdentifier, $data);
178 }
179
180 /**
181 * @test
182 * @author Ingo Renner <ingo@typo3.org>
183 */
184 public function setInsertsEntryInTable() {
185 $backend = $this->setUpBackend();
186 $this->setUpMockFrontendOfBackend($backend);
187
188 $data = 'some data' . microtime();
189 $entryIdentifier = 'BackendDbTest';
190
191 $backend->set($entryIdentifier, $data);
192
193 $entryFound = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow(
194 '*',
195 $this->testingCacheTable,
196 'identifier = \'' . $entryIdentifier . '\''
197 );
198
199 $this->assertEquals($data, $entryFound['content']);
200 }
201
202 /**
203 * @test
204 * @author Ingo Renner <ingo@typo3.org>
205 */
206 public function setRemovesAnAlreadyExistingCacheEntryForTheSameIdentifier() {
207 $backend = $this->setUpBackend();
208 $this->setUpMockFrontendOfBackend($backend);
209
210 $data1 = 'some data' . microtime();
211 $data2 = $data1 . '_different';
212 $entryIdentifier = 'BackendDbRemoveBeforeSetTest';
213
214 $backend->set($entryIdentifier, $data1, array(), 500);
215 $backend->set($entryIdentifier, $data2, array(), 200);
216
217 $entriesFound = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
218 '*',
219 $this->testingCacheTable,
220 'identifier = \'' . $entryIdentifier . '\''
221 );
222
223 $this->assertEquals(1, count($entriesFound));
224 }
225
226 /**
227 * @test
228 * @author Ingo Renner <ingo@typo3.org>
229 */
230 public function setReallySavesSpecifiedTags() {
231 $backend = $this->setUpBackend();
232 $this->setUpMockFrontendOfBackend($backend);
233
234 $data = 'some data' . microtime();
235 $entryIdentifier = 'BackendDbTest';
236
237 $backend->set($entryIdentifier, $data, array('UnitTestTag%tag1', 'UnitTestTag%tag2'));
238
239 $entriesFound = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
240 '*',
241 $this->testingTagsTable,
242 'identifier = \'' . $entryIdentifier . '\''
243 );
244
245 $tags = array();
246
247 foreach ($entriesFound as $entry) {
248 $tags[] = $entry['tag'];
249 }
250
251 $this->assertTrue(count($tags) > 0);
252 $this->assertTrue(in_array('UnitTestTag%tag1', $tags));
253 $this->assertTrue(in_array('UnitTestTag%tag2', $tags));
254 }
255
256 /**
257 * @test
258 * @author Christian Kuhn <lolli@schwarzbu.ch>
259 */
260 public function setSavesCompressedDataWithEnabledCompression() {
261 $backend = $this->setUpBackend(
262 array(
263 'compression' => TRUE,
264 )
265 );
266 $this->setUpMockFrontendOfBackend($backend);
267
268 $data = 'some data ' . microtime();
269 $entryIdentifier = 'BackendDbTest';
270
271 $backend->set($entryIdentifier, $data);
272
273 $entry = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow(
274 'content',
275 $this->testingCacheTable,
276 'identifier = \'' . $entryIdentifier . '\''
277 );
278
279 $this->assertEquals($data, @gzuncompress($entry['content']));
280 }
281
282 /**
283 * @test
284 * @author Christian Kuhn <lolli@schwarzbu.ch>
285 */
286 public function setSavesPlaintextDataWithEnabledCompressionAndCompressionLevel0() {
287 $backend = $this->setUpBackend(
288 array(
289 'compression' => TRUE,
290 'compressionLevel' => 0,
291 )
292 );
293 $this->setUpMockFrontendOfBackend($backend);
294
295 $data = 'some data ' . microtime();
296 $entryIdentifier = 'BackendDbTest';
297
298 $backend->set($entryIdentifier, $data);
299
300 $entry = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow(
301 'content',
302 $this->testingCacheTable,
303 'identifier = \'' . $entryIdentifier . '\''
304 );
305
306 $this->assertGreaterThan(0, substr_count($entry['content'], $data));
307 }
308
309 /**
310 * @test
311 * @expectedException t3lib_cache_Exception
312 */
313 public function getThrowsExceptionIfFrontendWasNotSet() {
314 $backend = $this->setUpBackend();
315 $backend->get('identifier');
316 }
317
318 /**
319 * @test
320 * @author Ingo Renner <ingo@typo3.org>
321 */
322 public function getReturnsContentOfTheCorrectCacheEntry() {
323 $backend = $this->setUpBackend();
324 $this->setUpMockFrontendOfBackend($backend);
325
326 $data = 'some data' . microtime();
327 $entryIdentifier = 'BackendDbTest';
328
329 $backend->set($entryIdentifier, $data, array(), 500);
330
331 $data = 'some other data' . microtime();
332 $backend->set($entryIdentifier, $data, array(), 100);
333
334 $loadedData = $backend->get($entryIdentifier);
335
336 $this->assertEquals($data, $loadedData);
337 }
338
339 /**
340 * @test
341 * @expectedException t3lib_cache_Exception
342 */
343 public function hasThrowsExceptionIfFrontendWasNotSet() {
344 $backend = $this->setUpBackend();
345 $backend->has('identifier');
346 }
347
348 /**
349 * @test
350 * @author Ingo Renner <ingo@typo3.org>
351 */
352 public function hasReturnsTheCorrectResult() {
353 $backend = $this->setUpBackend();
354 $this->setUpMockFrontendOfBackend($backend);
355
356 $data = 'some data' . microtime();
357 $entryIdentifier = 'BackendDbTest';
358
359 $backend->set($entryIdentifier, $data);
360
361 $this->assertTrue($backend->has($entryIdentifier));
362 $this->assertFalse($backend->has($entryIdentifier . 'Not'));
363 }
364
365 /**
366 * @test
367 * @expectedException t3lib_cache_Exception
368 */
369 public function removeThrowsExceptionIfFrontendWasNotSet() {
370 $backend = $this->setUpBackend();
371 $backend->remove('identifier');
372 }
373
374 /**
375 * @test
376 * @author Ingo Renner <ingo@typo3.org>
377 */
378 public function removeReallyRemovesACacheEntry() {
379 $backend = $this->setUpBackend();
380 $this->setUpMockFrontendOfBackend($backend);
381
382 $data = 'some data' . microtime();
383 $entryIdentifier = 'BackendDbRemovalTest';
384
385 $backend->set($entryIdentifier, $data);
386
387 $backend->remove($entryIdentifier);
388
389 $entriesFound = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
390 '*',
391 $this->testingCacheTable,
392 'identifier = \'' . $entryIdentifier . '\''
393 );
394
395 $this->assertTrue(count($entriesFound) == 0);
396 }
397
398 /**
399 * @test
400 * @expectedException t3lib_cache_Exception
401 */
402 public function collectGarbageThrowsExceptionIfFrontendWasNotSet() {
403 $backend = $this->setUpBackend();
404 $backend->collectGarbage();
405 }
406
407 /**
408 * @test
409 * @author Ingo Renner <ingo@typo3.org>
410 */
411 public function collectGarbageReallyRemovesAnExpiredCacheEntry() {
412 $backend = $this->setUpBackend();
413 $this->setUpMockFrontendOfBackend($backend);
414
415 $data = 'some data' . microtime();
416 $entryIdentifier = 'BackendDbRemovalTest';
417
418 $backend->set($entryIdentifier, $data, array(), 1);
419
420 $GLOBALS['EXEC_TIME'] += 2;
421 $backend->collectGarbage();
422
423 $entriesFound = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
424 '*',
425 $this->testingCacheTable,
426 'identifier = \'' . $entryIdentifier . '\''
427 );
428
429 $this->assertTrue(count($entriesFound) == 0);
430 }
431
432 /**
433 * @test
434 * @author Ingo Renner <ingo@typo3.org>
435 */
436 public function collectGarbageReallyRemovesAllExpiredCacheEntries() {
437 $backend = $this->setUpBackend();
438 $this->setUpMockFrontendOfBackend($backend);
439
440 $data = 'some data' . microtime();
441 $entryIdentifier = 'BackendDbRemovalTest';
442
443 $backend->set($entryIdentifier . 'A', $data, array(), 1);
444 $backend->set($entryIdentifier . 'B', $data, array(), 1);
445 $backend->set($entryIdentifier . 'C', $data, array(), 1);
446
447 $GLOBALS['EXEC_TIME'] += 2;
448 $backend->collectGarbage();
449
450 $entriesFound = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
451 '*',
452 $this->testingCacheTable,
453 ''
454 );
455
456 $this->assertTrue(count($entriesFound) == 0);
457 }
458
459 /**
460 * @test
461 * @author Ingo Renner <ingo@typo3.org>
462 */
463 public function findIdentifiersByTagFindsCacheEntriesWithSpecifiedTag() {
464 $backend = $this->setUpBackend();
465 $this->setUpMockFrontendOfBackend($backend);
466
467 $data = 'some data' . microtime();
468 $backend->set('BackendDbTest1', $data, array('UnitTestTag%test', 'UnitTestTag%boring'));
469 $backend->set('BackendDbTest2', $data, array('UnitTestTag%test', 'UnitTestTag%special'));
470 $backend->set('BackendDbTest3', $data, array('UnitTestTag%test'));
471
472 $expectedEntry = 'BackendDbTest2';
473
474 $actualEntries = $backend->findIdentifiersByTag('UnitTestTag%special');
475 $this->assertTrue(is_array($actualEntries));
476 $this->assertEquals($expectedEntry, array_pop($actualEntries));
477 }
478
479 /**
480 * @test
481 * @expectedException t3lib_cache_Exception
482 */
483 public function flushThrowsExceptionIfFrontendWasNotSet() {
484 $backend = $this->setUpBackend();
485 $backend->flush();
486 }
487
488 /**
489 * @test
490 * @author Ingo Renner <ingo@typo3.org>
491 */
492 public function flushRemovesAllCacheEntries() {
493 $backend = $this->setUpBackend();
494 $this->setUpMockFrontendOfBackend($backend);
495
496 $data = 'some data' . microtime();
497 $backend->set('BackendDbTest1', $data, array('UnitTestTag%test'));
498 $backend->set('BackendDbTest2', $data, array('UnitTestTag%test', 'UnitTestTag%special'));
499 $backend->set('BackendDbTest3', $data, array('UnitTestTag%test'));
500
501 $backend->flush();
502
503 $entriesFound = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
504 '*',
505 $this->testingCacheTable,
506 ''
507 );
508
509 $this->assertTrue(count($entriesFound) == 0);
510 }
511
512 /**
513 * @test
514 */
515 public function flushDropsDataTable() {
516 $backend = $this->setUpBackend();
517 $this->setUpMockFrontendOfBackend($backend);
518
519 $GLOBALS['TYPO3_DB'] = $this->getMock('t3lib_DB', array('admin_query'));
520 $GLOBALS['TYPO3_DB']->expects($this->at(0))
521 ->method('admin_query')
522 ->with('DROP TABLE IF EXISTS cachingframework_Testing');
523
524 $backend->flush();
525 }
526
527 /**
528 * @test
529 */
530 public function flushDropsTagsTable() {
531 $backend = $this->setUpBackend();
532 $this->setUpMockFrontendOfBackend($backend);
533
534 $GLOBALS['TYPO3_DB'] = $this->getMock('t3lib_DB', array('admin_query'));
535 $GLOBALS['TYPO3_DB']->expects($this->at(1))
536 ->method('admin_query')
537 ->with('DROP TABLE IF EXISTS cachingframework_Testing_tags');
538
539 $backend->flush();
540 }
541
542 /**
543 * @test
544 */
545 public function flushCreatesDataTable() {
546 $backend = $this->setUpBackend();
547 $this->setUpMockFrontendOfBackend($backend);
548
549 $GLOBALS['TYPO3_DB'] = $this->getMock('t3lib_DB', array('admin_query'));
550 $GLOBALS['TYPO3_DB']->expects($this->at(2))
551 ->method('admin_query')
552 ->will($this->returnCallback(array($this, flushCreatesDataTableCallback)));
553
554 $backend->flush();
555 }
556
557 /**
558 * Callback of flushCreatesDataTable to check if data table is created
559 *
560 * @param string $sql SQL of admin_query
561 * @return void
562 */
563 public function flushCreatesDataTableCallback($sql) {
564 $startOfStatement = 'CREATE TABLE cachingframework_Testing (';
565 $this->assertEquals($startOfStatement, substr($sql, 0, strlen($startOfStatement)));
566 }
567
568 /**
569 * @test
570 */
571 public function flushCreatesTagsTable() {
572 $backend = $this->setUpBackend();
573 $this->setUpMockFrontendOfBackend($backend);
574
575 $GLOBALS['TYPO3_DB'] = $this->getMock('t3lib_DB', array('admin_query'));
576 $GLOBALS['TYPO3_DB']->expects($this->at(3))
577 ->method('admin_query')
578 ->will($this->returnCallback(array($this, flushCreatesTagsTableCallback)));
579
580 $backend->flush();
581 }
582
583 /**
584 * Callback of flushCreatesTagsTable to check if tags table is created
585 *
586 * @param string $sql SQL of admin_query
587 * @return void
588 */
589 public function flushCreatesTagsTableCallback($sql) {
590 $startOfStatement = 'CREATE TABLE cachingframework_Testing_tags (';
591 $this->assertEquals($startOfStatement, substr($sql, 0, strlen($startOfStatement)));
592 }
593
594 /**
595 * @test
596 * @expectedException t3lib_cache_Exception
597 */
598 public function flushByTagThrowsExceptionIfFrontendWasNotSet() {
599 $backend = $this->setUpBackend();
600 $backend->flushByTag(array());
601 }
602
603 /**
604 * @test
605 * @author Ingo Renner <ingo@typo3.org>
606 */
607 public function flushByTagRemovesCacheEntriesWithSpecifiedTag() {
608 $backend = $this->setUpBackend();
609 $this->setUpMockFrontendOfBackend($backend);
610
611 $data = 'some data' . microtime();
612 $backend->set('BackendDbTest1', $data, array('UnitTestTag%test', 'UnitTestTag%boring'));
613 $backend->set('BackendDbTest2', $data, array('UnitTestTag%test', 'UnitTestTag%special'));
614 $backend->set('BackendDbTest3', $data, array('UnitTestTag%test'));
615
616 $backend->flushByTag('UnitTestTag%special');
617
618 $this->assertTrue($backend->has('BackendDbTest1'), 'BackendDbTest1 does not exist anymore.');
619 $this->assertFalse($backend->has('BackendDbTest2'), 'BackendDbTest2 still exists.');
620 $this->assertTrue($backend->has('BackendDbTest3'), 'BackendDbTest3 does not exist anymore.');
621
622 $tagEntriesFound = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
623 '*',
624 $this->testingTagsTable,
625 'tag = ' . $GLOBALS['TYPO3_DB']->fullQuoteStr('UnitTestTag%special', $this->testingTagsTable)
626 );
627 $this->assertEquals(0, count($tagEntriesFound));
628 }
629
630
631 /**
632 * @test
633 * @author Ingo Renner <ingo@typo3.org>
634 */
635 public function hasReturnsTheCorrectResultForEntryWithExceededLifetime() {
636 $backend = $this->setUpBackend();
637 $this->setUpMockFrontendOfBackend($backend);
638
639 $data = 'some data' . microtime();
640 $entryIdentifier = 'BackendDbTest';
641
642 $backend->set($entryIdentifier, $data);
643
644 $expiredEntryIdentifier = 'ExpiredBackendDbTest';
645 $expiredData = 'some old data' . microtime();
646 $backend->set($expiredEntryIdentifier, $expiredData, array(), 1);
647
648 $GLOBALS['EXEC_TIME'] += 2;
649
650 $this->assertFalse($backend->has($expiredEntryIdentifier));
651 }
652
653 /**
654 * @test
655 * @author Christian Kuhn <lolli@schwarzbu.ch>
656 */
657 public function hasReturnsTrueForEntryWithUnlimitedLifetime() {
658 $backend = $this->setUpBackend();
659 $this->setUpMockFrontendOfBackend($backend);
660
661 $entryIdentifier = 'BackendDbTest';
662
663 $backend->set($entryIdentifier, 'data', array(), 0);
664
665 $GLOBALS['EXEC_TIME'] += 1;
666 $this->assertTrue($backend->has($entryIdentifier));
667 }
668
669 /**
670 * @test
671 * @author Ingo Renner <ingo@typo3.org>
672 */
673 public function getReturnsFalseForEntryWithExceededLifetime() {
674 $backend = $this->setUpBackend();
675 $this->setUpMockFrontendOfBackend($backend);
676
677 $data = 'some data' . microtime();
678 $entryIdentifier = 'BackendDbTest';
679
680 $backend->set($entryIdentifier, $data);
681
682 $expiredEntryIdentifier = 'ExpiredBackendDbTest';
683 $expiredData = 'some old data' . microtime();
684 $backend->set($expiredEntryIdentifier, $expiredData, array(), 1);
685
686 $GLOBALS['EXEC_TIME'] += 2;
687
688 $this->assertEquals($data, $backend->get($entryIdentifier));
689 $this->assertFalse($backend->get($expiredEntryIdentifier));
690 }
691
692 /**
693 * @test
694 * @expectedException t3lib_cache_Exception
695 */
696 public function findIdentifiersByTagThrowsExceptionIfFrontendWasNotSet() {
697 $backend = $this->setUpBackend();
698 $backend->findIdentifiersByTag('identifier');
699 }
700
701 /**
702 * @test
703 * @author Ingo Renner <ingo@typo3.org>
704 */
705 public function findIdentifiersByTagReturnsEmptyArrayForEntryWithExceededLifetime() {
706 $backend = $this->setUpBackend();
707 $mockCache = $this->getMock('t3lib_cache_frontend_AbstractFrontend', array(), array(), '', FALSE);
708 $mockCache->expects($this->any())->method('getIdentifier')->will($this->returnValue('Testing'));
709 $backend->setCache($mockCache);
710
711 $backend->set('BackendDbTest', 'some data', array('UnitTestTag%special'), 1);
712
713 $GLOBALS['EXEC_TIME'] += 2;
714 // Not required, but used to update the pre-calculated queries:
715 $backend->setCache($mockCache);
716
717 $this->assertEquals(array(), $backend->findIdentifiersByTag('UnitTestTag%special'));
718 }
719
720 /**
721 * @test
722 * @author Ingo Renner <ingo@typo3.org>
723 */
724 public function setWithUnlimitedLifetimeWritesCorrectEntry() {
725 $backend = $this->setUpBackend();
726 $this->setUpMockFrontendOfBackend($backend);
727
728 $data = 'some data' . microtime();
729 $entryIdentifier = 'BackendFileTest';
730
731 $backend->set($entryIdentifier, $data, array(), 0);
732
733 $entryFound = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow(
734 '*',
735 $this->testingCacheTable,
736 ''
737 );
738
739 $this->assertTrue(is_array($entryFound));
740
741 $retrievedData = $entryFound['content'];
742 $this->assertEquals($data, $retrievedData);
743 }
744 }
745
746 ?>