Fixed bug #16445: Performance Tuning: Replace exec_SELECTgetRows with exec_SELECTgetS...
[Packages/TYPO3.CMS.git] / tests / t3lib / cache / backend / t3lib_cache_backend_dbbackendTest.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009-2010 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 * @version $Id$
32 */
33 class t3lib_cache_backend_DbBackendTest extends tx_phpunit_testcase {
34
35 /**
36 * If set, the tearDown() method will clean up the cache table used by this unit test.
37 *
38 * @var t3lib_cache_backend_DbBackend
39 */
40 protected $backend;
41
42 protected $testingCacheTable;
43 protected $testingTagsTable;
44
45 /**
46 * Sets up the backend used for testing
47 *
48 * @return void
49 * @author Ingo Renner <ingo@typo3.org>
50 * @author Christian Kuhn <lolli@schwarzbu.ch>
51 */
52 public function setUpBackend(array $backendOptions = array()) {
53 $defaultTestingCacheTable = 'test_cache_dbbackend';
54 $defaultTestingTagsTable = 'test_cache_dbbackend_tags';
55
56 $backendOptions = array_merge(
57 array(
58 'cacheTable' => $defaultTestingCacheTable,
59 'tagsTable' => $defaultTestingTagsTable,
60 ),
61 $backendOptions
62 );
63
64 $this->testingCacheTable = $backendOptions['cacheTable'];
65 $this->testingTagsTable = $backendOptions['tagsTable'];
66
67 $GLOBALS['TYPO3_DB']->sql_query('CREATE TABLE ' . $this->testingCacheTable . ' (
68 id int(11) unsigned NOT NULL auto_increment,
69 identifier varchar(128) DEFAULT \'\' NOT NULL,
70 crdate int(11) unsigned DEFAULT \'0\' NOT NULL,
71 content mediumblob,
72 lifetime int(11) unsigned DEFAULT \'0\' NOT NULL,
73 PRIMARY KEY (id),
74 KEY cache_id (identifier)
75 ) ENGINE=InnoDB;
76 ');
77
78 $GLOBALS['TYPO3_DB']->sql_query('CREATE TABLE ' . $this->testingTagsTable . ' (
79 id int(11) unsigned NOT NULL auto_increment,
80 identifier varchar(128) DEFAULT \'\' NOT NULL,
81 tag varchar(128) DEFAULT \'\' NOT NULL,
82 PRIMARY KEY (id),
83 KEY cache_id (identifier),
84 KEY cache_tag (tag)
85 ) ENGINE=InnoDB;
86 ');
87
88 $this->backend = t3lib_div::makeInstance(
89 't3lib_cache_backend_DbBackend',
90 $backendOptions
91 );
92 }
93
94 /**
95 * @author Ingo Renner <ingo@typo3.org>
96 */
97 public function tearDown() {
98 $GLOBALS['TYPO3_DB']->sql_query(
99 'DROP TABLE ' . $this->testingCacheTable . ';'
100 );
101
102 $GLOBALS['TYPO3_DB']->sql_query(
103 'DROP TABLE ' . $this->testingTagsTable . ';'
104 );
105 }
106
107 /**
108 * @test
109 * @expectedException t3lib_cache_Exception
110 * @author Ingo Renner <ingo@typo3.org>
111 */
112 # deactivated as the according check in the DB backend causes trouble during TYPO3's initialization
113 # public function setCacheTableThrowsExceptionOnNonExistentTable() {
114 # $this->backend->setCacheTable('test_cache_non_existent_table');
115 # }
116
117 /**
118 * @test
119 * @author Ingo Renner <ingo@typo3.org>
120 */
121 public function getCacheTableReturnsThePreviouslySetTable() {
122 $this->setUpBackend();
123 $this->backend->setCacheTable($this->testingCacheTable);
124 $this->assertEquals($this->testingCacheTable, $this->backend->getCacheTable(), 'getCacheTable() did not return the expected value.');
125 }
126
127 /**
128 * @test
129 * @expectedException t3lib_cache_exception_InvalidData
130 * @author Ingo Renner <ingo@typo3.org>
131 */
132 public function setThrowsExceptionIfDataIsNotAString() {
133 $this->setUpBackend();
134 $cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend',
135 array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'),
136 array(),
137 '',
138 FALSE
139 );
140
141 $data = array('Some data');
142 $entryIdentifier = 'BackendDbTest';
143
144 $this->backend->setCache($cache);
145
146 $this->backend->set($entryIdentifier, $data);
147 }
148
149 /**
150 * @test
151 * @author Ingo Renner <ingo@typo3.org>
152 */
153 public function setReallySavesToTheSpecifiedTable() {
154 $this->setUpBackend();
155 $cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend',
156 array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'),
157 array(),
158 '',
159 FALSE
160 );
161
162 $data = 'some data' . microtime();
163 $entryIdentifier = 'BackendDbTest';
164
165 $this->backend->setCache($cache);
166 $this->backend->set($entryIdentifier, $data);
167
168 $entryFound = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow(
169 '*',
170 $this->testingCacheTable,
171 'identifier = \'' . $entryIdentifier . '\''
172 );
173
174 $this->assertEquals(
175 $data,
176 $entryFound['content'],
177 'The original and the retrieved data don\'t match.'
178 );
179 }
180
181 /**
182 * @test
183 * @author Ingo Renner <ingo@typo3.org>
184 */
185 public function setRemovesAnAlreadyExistingCacheEntryForTheSameIdentifier() {
186 $this->setUpBackend();
187 $cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend',
188 array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'),
189 array(),
190 '',
191 FALSE
192 );
193
194 $data1 = 'some data' . microtime();
195 $data2 = 'some data' . microtime();
196 $entryIdentifier = 'BackendDbRemoveBeforeSetTest';
197
198 $this->backend->setCache($cache);
199 $this->backend->set($entryIdentifier, $data1, array(), 500);
200 // setting a second entry with the same identifier, but different
201 // data, this should _replace_ the existing one we set before
202 $this->backend->set($entryIdentifier, $data2, array(), 200);
203
204 $entriesFound = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
205 '*',
206 $this->testingCacheTable,
207 'identifier = \'' . $entryIdentifier . '\''
208 );
209
210 $this->assertEquals(1, count($entriesFound), 'There was not exactly one cache entry.');
211 }
212
213 /**
214 * @test
215 * @author Ingo Renner <ingo@typo3.org>
216 */
217 public function setReallySavesSpecifiedTags() {
218 $this->setUpBackend();
219 $cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend',
220 array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'),
221 array(),
222 '',
223 FALSE
224 );
225
226 $data = 'some data' . microtime();
227 $entryIdentifier = 'BackendDbTest';
228
229 $this->backend->setCache($cache);
230 $this->backend->set($entryIdentifier, $data, array('UnitTestTag%tag1', 'UnitTestTag%tag2'));
231
232 $entriesFound = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
233 '*',
234 $this->testingTagsTable,
235 'identifier = \'' . $entryIdentifier . '\''
236 );
237
238 $tags = array();
239
240 foreach ($entriesFound as $entry) {
241 $tags[] = $entry['tag'];
242 }
243
244 $this->assertTrue(count($tags) > 0, 'The tags do not exist.');
245 $this->assertTrue(in_array('UnitTestTag%tag1', $tags), 'Tag UnitTestTag%tag1 does not exist.');
246 $this->assertTrue(in_array('UnitTestTag%tag2', $tags), 'Tag UnitTestTag%tag2 does not exist.');
247 }
248
249 /**
250 * @test
251 * @author Christian Kuhn <lolli@schwarzbu.ch>
252 */
253 public function setSavesCompressedDataWithEnabledCompression() {
254 $mockCache = $this->getMock('t3lib_cache_frontend_AbstractFrontend', array(), array(), '', FALSE);
255 $mockCache->expects($this->any())->method('getIdentifier')->will($this->returnValue('UnitTestCache'));
256 $this->setUpBackend(
257 array(
258 'compression' => TRUE,
259 )
260 );
261 $this->backend->setCache($mockCache);
262
263 $data = 'some data ' . microtime();
264
265 $entryIdentifier = 'BackendDbTest';
266
267 $this->backend->set($entryIdentifier, $data);
268
269 $entry = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow(
270 'content',
271 $this->testingCacheTable,
272 'identifier = \'' . $entryIdentifier . '\''
273 );
274
275 $this->assertEquals($data, @gzuncompress($entry['content']), 'Original and compressed data don\'t match');
276 }
277
278 /**
279 * @test
280 * @author Christian Kuhn <lolli@schwarzbu.ch>
281 */
282 public function setSavesPlaintextDataWithEnabledCompressionAndCompressionLevel0() {
283 $mockCache = $this->getMock('t3lib_cache_frontend_AbstractFrontend', array(), array(), '', FALSE);
284 $mockCache->expects($this->any())->method('getIdentifier')->will($this->returnValue('UnitTestCache'));
285 $this->setUpBackend(
286 array(
287 'compression' => TRUE,
288 'compressionLevel' => 0,
289 )
290 );
291 $this->backend->setCache($mockCache);
292
293 $data = 'some data ' . microtime();
294
295 $entryIdentifier = 'BackendDbTest';
296
297 $this->backend->set($entryIdentifier, $data);
298
299 $entry = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow(
300 'content',
301 $this->testingCacheTable,
302 'identifier = \'' . $entryIdentifier . '\''
303 );
304
305 $this->assertGreaterThan(0, substr_count($entry['content'], $data), 'Plaintext data not found');
306 }
307
308 /**
309 * @test
310 * @author Ingo Renner <ingo@typo3.org>
311 */
312 public function getReturnsContentOfTheCorrectCacheEntry() {
313 $this->setUpBackend();
314 $cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend',
315 array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'),
316 array(),
317 '',
318 FALSE
319 );
320
321 $data = 'some data' . microtime();
322 $entryIdentifier = 'BackendDbTest';
323
324 $this->backend->setCache($cache);
325 $this->backend->set($entryIdentifier, $data, array(), 500);
326
327 $data = 'some other data' . microtime();
328 $this->backend->set($entryIdentifier, $data, array(), 100);
329
330 $loadedData = $this->backend->get($entryIdentifier);
331
332 $this->assertEquals($data, $loadedData, 'The original and the retrieved data don\'t match.');
333 }
334
335 /**
336 * @test
337 * @author Ingo Renner <ingo@typo3.org>
338 */
339 public function hasReturnsTheCorrectResult() {
340 $this->setUpBackend();
341 $cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend',
342 array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'),
343 array(),
344 '',
345 FALSE
346 );
347
348 $data = 'some data' . microtime();
349 $entryIdentifier = 'BackendDbTest';
350
351 $this->backend->setCache($cache);
352 $this->backend->set($entryIdentifier, $data);
353
354 $this->assertTrue($this->backend->has($entryIdentifier), 'has() did not return TRUE.');
355 $this->assertFalse($this->backend->has($entryIdentifier . 'Not'), 'has() did not return FALSE.');
356 }
357
358 /**
359 * @test
360 * @author Ingo Renner <ingo@typo3.org>
361 */
362 public function removeReallyRemovesACacheEntry() {
363 $this->setUpBackend();
364 $cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend',
365 array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'),
366 array(),
367 '',
368 FALSE
369 );
370
371 $data = 'some data' . microtime();
372 $entryIdentifier = 'BackendDbRemovalTest';
373
374 $this->backend->setCache($cache);
375 $this->backend->set($entryIdentifier, $data);
376
377 $entriesFound = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
378 '*',
379 $this->testingCacheTable,
380 'identifier = \'' . $entryIdentifier . '\''
381 );
382
383 $this->assertTrue(is_array($entriesFound) && count($entriesFound) > 0, 'The cache entry does not exist.');
384
385 $this->backend->remove($entryIdentifier);
386
387 $entriesFound = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
388 '*',
389 $this->testingCacheTable,
390 'identifier = \'' . $entryIdentifier . '\''
391 );
392
393 $this->assertTrue(count($entriesFound) == 0, 'The cache entry still exists.');
394 }
395
396 /**
397 * @test
398 * @author Ingo Renner <ingo@typo3.org>
399 */
400 public function collectGarbageReallyRemovesAnExpiredCacheEntry() {
401 $this->setUpBackend();
402 $cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend',
403 array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'),
404 array(),
405 '',
406 FALSE
407 );
408
409 $data = 'some data' . microtime();
410 $entryIdentifier = 'BackendDbRemovalTest';
411
412 $this->backend->setCache($cache);
413 $this->backend->set($entryIdentifier, $data, array(), 1);
414
415 $entriesFound = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
416 '*',
417 $this->testingCacheTable,
418 'identifier = \'' . $entryIdentifier . '\''
419 );
420
421 $this->assertTrue(is_array($entriesFound) && count($entriesFound) > 0, 'The cache entry does not exist.');
422
423 sleep(2);
424 $GLOBALS['EXEC_TIME'] += 2;
425 $this->backend->collectGarbage();
426
427 $entriesFound = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
428 '*',
429 $this->testingCacheTable,
430 'identifier = \'' . $entryIdentifier . '\''
431 );
432
433 $this->assertTrue(count($entriesFound) == 0, 'The cache entry still exists.');
434 }
435
436 /**
437 * @test
438 * @author Ingo Renner <ingo@typo3.org>
439 */
440 public function collectGarbageReallyRemovesAllExpiredCacheEntries() {
441 $this->setUpBackend();
442 $cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend',
443 array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'),
444 array(),
445 '',
446 FALSE
447 );
448
449 $data = 'some data' . microtime();
450 $entryIdentifier = 'BackendDbRemovalTest';
451
452 $this->backend->setCache($cache);
453
454 $this->backend->set($entryIdentifier . 'A', $data, array(), 1);
455 $this->backend->set($entryIdentifier . 'B', $data, array(), 1);
456 $this->backend->set($entryIdentifier . 'C', $data, array(), 1);
457
458 $entriesFound = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
459 '*',
460 $this->testingCacheTable,
461 ''
462 );
463
464 $this->assertTrue(is_array($entriesFound) && count($entriesFound) > 0, 'The cache entries do not exist.');
465
466 sleep(2);
467 $GLOBALS['EXEC_TIME'] += 2;
468 $this->backend->collectGarbage();
469
470 $entriesFound = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
471 '*',
472 $this->testingCacheTable,
473 ''
474 );
475
476 $this->assertTrue(count($entriesFound) == 0, 'The cache entries still exist.');
477 }
478
479 /**
480 * @test
481 * @author Ingo Renner <ingo@typo3.org>
482 */
483 public function findIdentifiersByTagFindsCacheEntriesWithSpecifiedTag() {
484 $this->setUpBackend();
485 $cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend',
486 array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'),
487 array(),
488 '',
489 FALSE
490 );
491
492 $this->backend->setCache($cache);
493
494 $data = 'some data' . microtime();
495 $this->backend->set('BackendDbTest1', $data, array('UnitTestTag%test', 'UnitTestTag%boring'));
496 $this->backend->set('BackendDbTest2', $data, array('UnitTestTag%test', 'UnitTestTag%special'));
497 $this->backend->set('BackendDbTest3', $data, array('UnitTestTag%test'));
498
499 $expectedEntry = 'BackendDbTest2';
500
501 $actualEntries = $this->backend->findIdentifiersByTag('UnitTestTag%special');
502 $this->assertTrue(is_array($actualEntries), 'actualEntries is not an array.');
503
504 $this->assertEquals($expectedEntry, array_pop($actualEntries));
505 }
506
507 /**
508 * @test
509 * @author Ingo Renner <ingo@typo3.org>
510 */
511 public function flushRemovesAllCacheEntries() {
512 $this->setUpBackend();
513 $cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend',
514 array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'),
515 array(),
516 '',
517 FALSE
518 );
519
520 $this->backend->setCache($cache);
521
522 $data = 'some data' . microtime();
523 $this->backend->set('BackendDbTest1', $data, array('UnitTestTag%test'));
524 $this->backend->set('BackendDbTest2', $data, array('UnitTestTag%test', 'UnitTestTag%special'));
525 $this->backend->set('BackendDbTest3', $data, array('UnitTestTag%test'));
526
527 $this->backend->flush();
528
529 $entriesFound = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
530 '*',
531 $this->testingCacheTable,
532 ''
533 );
534
535 $this->assertTrue(count($entriesFound) == 0, 'Still entries in the cache table');
536 }
537
538 /**
539 * @test
540 * @author Ingo Renner <ingo@typo3.org>
541 */
542 public function flushByTagRemovesCacheEntriesWithSpecifiedTag() {
543 $this->setUpBackend();
544 $cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend',
545 array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'),
546 array(),
547 '',
548 FALSE
549 );
550
551 $this->backend->setCache($cache);
552
553 $data = 'some data' . microtime();
554 $this->backend->set('BackendDbTest1', $data, array('UnitTestTag%test', 'UnitTestTag%boring'));
555 $this->backend->set('BackendDbTest2', $data, array('UnitTestTag%test', 'UnitTestTag%special'));
556 $this->backend->set('BackendDbTest3', $data, array('UnitTestTag%test'));
557
558 $this->backend->flushByTag('UnitTestTag%special');
559
560 $this->assertTrue($this->backend->has('BackendDbTest1'), 'BackendDbTest1 does not exist anymore.');
561 $this->assertFalse($this->backend->has('BackendDbTest2'), 'BackendDbTest2 still exists.');
562 $this->assertTrue($this->backend->has('BackendDbTest3'), 'BackendDbTest3 does not exist anymore.');
563
564 $tagEntriesFound = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
565 '*',
566 $this->testingTagsTable,
567 'tag = ' . $GLOBALS['TYPO3_DB']->fullQuoteStr('UnitTestTag%special', $this->testingTagsTable)
568 );
569 $this->assertEquals(0, count($tagEntriesFound), 'UnitTestTag%special still exists in tags table');
570 }
571
572
573 /**
574 * @test
575 * @author Ingo Renner <ingo@typo3.org>
576 */
577 public function hasReturnsTheCorrectResultForEntryWithExceededLifetime() {
578 $this->setUpBackend();
579 $cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend',
580 array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'),
581 array(),
582 '',
583 FALSE
584 );
585
586 $data = 'some data' . microtime();
587 $entryIdentifier = 'BackendDbTest';
588
589 $this->backend->setCache($cache);
590 $this->backend->set($entryIdentifier, $data);
591
592 $expiredEntryIdentifier = 'ExpiredBackendDbTest';
593 $expiredData = 'some old data' . microtime();
594 $this->backend->set($expiredEntryIdentifier, $expiredData, array(), 1);
595
596 sleep(2);
597 $GLOBALS['EXEC_TIME'] += 2;
598
599 $this->assertFalse($this->backend->has($expiredEntryIdentifier), 'has() did not return FALSE.');
600 }
601
602 /**
603 * @test
604 * @author Christian Kuhn <lolli@schwarzbu.ch>
605 */
606 public function hasReturnsTrueForEntryWithUnlimitedLifetime() {
607 $this->setUpBackend();
608 $mockCache = $this->getMock('t3lib_cache_frontend_AbstractFrontend', array(), array(), '', FALSE);
609 $mockCache->expects($this->any())->method('getIdentifier')->will($this->returnValue('UnitTestCache'));
610
611 $entryIdentifier = 'BackendDbTest';
612
613 $this->backend->setCache($mockCache);
614 $this->backend->set($entryIdentifier, 'data', array(), 0);
615
616 $GLOBALS['EXEC_TIME'] += 1;
617 $this->assertTrue($this->backend->has($entryIdentifier));
618 }
619
620 /**
621 * @test
622 * @author Ingo Renner <ingo@typo3.org>
623 */
624 public function getReturnsFalseForEntryWithExceededLifetime() {
625 $this->setUpBackend();
626 $cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend',
627 array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'),
628 array(),
629 '',
630 FALSE
631 );
632
633 $data = 'some data' . microtime();
634 $entryIdentifier = 'BackendDbTest';
635
636 $this->backend->setCache($cache);
637 $this->backend->set($entryIdentifier, $data);
638
639 $expiredEntryIdentifier = 'ExpiredBackendDbTest';
640 $expiredData = 'some old data' . microtime();
641 $this->backend->set($expiredEntryIdentifier, $expiredData, array(), 1);
642
643 sleep(2);
644 $GLOBALS['EXEC_TIME'] += 2;
645
646 $this->assertEquals($data, $this->backend->get($entryIdentifier), 'The original and the retrieved data don\'t match.');
647 $this->assertFalse($this->backend->get($expiredEntryIdentifier), 'The expired entry could be loaded.');
648 }
649
650 /**
651 * @test
652 * @author Ingo Renner <ingo@typo3.org>
653 */
654 public function findIdentifiersByTagReturnsEmptyArrayForEntryWithExceededLifetime() {
655 $this->setUpBackend();
656 $cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend',
657 array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'),
658 array(),
659 '',
660 FALSE
661 );
662
663 $this->backend->setCache($cache);
664 $this->backend->set('BackendDbTest', 'some data', array('UnitTestTag%special'), 1);
665
666 sleep(2);
667 $GLOBALS['EXEC_TIME'] += 2;
668 // Not required, but used to update the pre-calculated queries:
669 $this->backend->setTagsTable($this->testingTagsTable);
670
671 $this->assertEquals(array(), $this->backend->findIdentifiersByTag('UnitTestTag%special'));
672 }
673
674 /**
675 * @test
676 * @author Ingo Renner <ingo@typo3.org>
677 */
678 public function setWithUnlimitedLifetimeWritesCorrectEntry() {
679 $this->setUpBackend();
680 $cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend',
681 array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'),
682 array(),
683 '',
684 FALSE
685 );
686
687 $data = 'some data' . microtime();
688 $entryIdentifier = 'BackendFileTest';
689
690 $this->backend->setCache($cache);
691 $this->backend->set($entryIdentifier, $data, array(), 0);
692
693 $entryFound = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow(
694 '*',
695 $this->testingCacheTable,
696 ''
697 );
698
699 $this->assertTrue(is_array($entryFound), 'entriesFound is not an array.');
700
701 $retrievedData = $entryFound['content'];
702 $this->assertEquals($data, $retrievedData, 'The original and the retrieved data don\'t match.');
703 }
704 }
705
706 ?>