TYPO3 CMS  TYPO3_6-2
PdoBackendTest.php
Go to the documentation of this file.
1 <?php
3 
23 
27  public function setUp() {
28  if (!extension_loaded('pdo_sqlite')) {
29  $this->markTestSkipped('pdo_sqlite extension was not available');
30  }
31  }
32 
38  $backend = new \TYPO3\CMS\Core\Cache\Backend\PdoBackend('Testing');
39  $data = 'Some data';
40  $identifier = 'MyIdentifier';
41  $backend->set($identifier, $data);
42  }
43 
48  $backend = $this->setUpBackend();
49  $data = 'Some data';
50  $identifier = 'MyIdentifier';
51  $backend->set($identifier, $data);
52  $this->assertTrue($backend->has($identifier));
53  }
54 
58  public function itIsPossibleToSetAndGetEntry() {
59  $backend = $this->setUpBackend();
60  $data = 'Some data';
61  $identifier = 'MyIdentifier';
62  $backend->set($identifier, $data);
63  $fetchedData = $backend->get($identifier);
64  $this->assertEquals($data, $fetchedData);
65  }
66 
71  $backend = $this->setUpBackend();
72  $data = 'Some data';
73  $identifier = 'MyIdentifier';
74  $backend->set($identifier, $data);
75  $backend->remove($identifier);
76  $this->assertFalse($backend->has($identifier));
77  }
78 
83  $backend = $this->setUpBackend();
84  $data = 'Some data';
85  $identifier = 'MyIdentifier';
86  $backend->set($identifier, $data);
87  $otherData = 'some other data';
88  $backend->set($identifier, $otherData);
89  $fetchedData = $backend->get($identifier);
90  $this->assertEquals($otherData, $fetchedData);
91  }
92 
97  $backend = $this->setUpBackend();
98  $data = 'Some data';
99  $entryIdentifier = 'MyIdentifier';
100  $backend->set($entryIdentifier, $data, array('UnitTestTag%tag1', 'UnitTestTag%tag2'));
101  $retrieved = $backend->findIdentifiersByTag('UnitTestTag%tag1');
102  $this->assertEquals($entryIdentifier, $retrieved[0]);
103  $retrieved = $backend->findIdentifiersByTag('UnitTestTag%tag2');
104  $this->assertEquals($entryIdentifier, $retrieved[0]);
105  }
106 
110  public function setRemovesTagsFromPreviousSet() {
111  $backend = $this->setUpBackend();
112  $data = 'Some data';
113  $entryIdentifier = 'MyIdentifier';
114  $backend->set($entryIdentifier, $data, array('UnitTestTag%tag1', 'UnitTestTag%tag2'));
115  $backend->set($entryIdentifier, $data, array('UnitTestTag%tag3'));
116  $retrieved = $backend->findIdentifiersByTag('UnitTestTag%tag2');
117  $this->assertEquals(array(), $retrieved);
118  }
119 
124  $backend = $this->setUpBackend();
125  $data1 = 'data1';
126  $entryIdentifier = $this->getUniqueId('test');
127  $backend->set($entryIdentifier, $data1, array(), 1);
128  $data2 = 'data2';
129  $GLOBALS['EXEC_TIME'] += 2;
130  $backend->set($entryIdentifier, $data2, array(), 10);
131  $this->assertEquals($data2, $backend->get($entryIdentifier));
132  }
133 
138  $backend = $this->setUpBackend();
139  $identifier = 'NonExistingIdentifier';
140  $this->assertFalse($backend->has($identifier));
141  }
142 
147  $backend = $this->setUpBackend();
148  $identifier = 'NonExistingIdentifier';
149  $this->assertFalse($backend->remove($identifier));
150  }
151 
156  $backend = $this->setUpBackend();
157  $data = 'some data' . microtime();
158  $backend->set('PdoBackendTest1', $data, array('UnitTestTag%test', 'UnitTestTag%boring'));
159  $backend->set('PdoBackendTest2', $data, array('UnitTestTag%test', 'UnitTestTag%special'));
160  $backend->set('PdoBackendTest3', $data, array('UnitTestTag%test'));
161  $backend->flushByTag('UnitTestTag%special');
162  $this->assertTrue($backend->has('PdoBackendTest1'), 'PdoBackendTest1');
163  $this->assertFalse($backend->has('PdoBackendTest2'), 'PdoBackendTest2');
164  $this->assertTrue($backend->has('PdoBackendTest3'), 'PdoBackendTest3');
165  }
166 
170  public function flushRemovesAllCacheEntries() {
171  $backend = $this->setUpBackend();
172  $data = 'some data' . microtime();
173  $backend->set('PdoBackendTest1', $data);
174  $backend->set('PdoBackendTest2', $data);
175  $backend->set('PdoBackendTest3', $data);
176  $backend->flush();
177  $this->assertFalse($backend->has('PdoBackendTest1'), 'PdoBackendTest1');
178  $this->assertFalse($backend->has('PdoBackendTest2'), 'PdoBackendTest2');
179  $this->assertFalse($backend->has('PdoBackendTest3'), 'PdoBackendTest3');
180  }
181 
185  public function flushRemovesOnlyOwnEntries() {
186  $thisCache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\FrontendInterface', array(), array(), '', FALSE);
187  $thisCache->expects($this->any())->method('getIdentifier')->will($this->returnValue('thisCache'));
188  $thisBackend = $this->setUpBackend();
189  $thisBackend->setCache($thisCache);
190  $thatCache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\FrontendInterface', array(), array(), '', FALSE);
191  $thatCache->expects($this->any())->method('getIdentifier')->will($this->returnValue('thatCache'));
192  $thatBackend = $this->setUpBackend();
193  $thatBackend->setCache($thatCache);
194  $thisBackend->set('thisEntry', 'Hello');
195  $thatBackend->set('thatEntry', 'World!');
196  $thatBackend->flush();
197  $this->assertEquals('Hello', $thisBackend->get('thisEntry'));
198  $this->assertFalse($thatBackend->has('thatEntry'));
199  }
200 
205  $backend = $this->setUpBackend();
206  $data = 'some data' . microtime();
207  $entryIdentifier = 'BackendPDORemovalTest';
208  $backend->set($entryIdentifier, $data, array(), 1);
209  $this->assertTrue($backend->has($entryIdentifier));
210  $GLOBALS['EXEC_TIME'] += 2;
211  $backend->collectGarbage();
212  $this->assertFalse($backend->has($entryIdentifier));
213  }
214 
219  $backend = $this->setUpBackend();
220  $data = 'some data' . microtime();
221  $entryIdentifier = 'BackendPDORemovalTest';
222  $backend->set($entryIdentifier . 'A', $data, array(), NULL);
223  $backend->set($entryIdentifier . 'B', $data, array(), 10);
224  $backend->set($entryIdentifier . 'C', $data, array(), 1);
225  $backend->set($entryIdentifier . 'D', $data, array(), 1);
226  $this->assertTrue($backend->has($entryIdentifier . 'A'));
227  $this->assertTrue($backend->has($entryIdentifier . 'B'));
228  $this->assertTrue($backend->has($entryIdentifier . 'C'));
229  $this->assertTrue($backend->has($entryIdentifier . 'D'));
230  $GLOBALS['EXEC_TIME'] += 2;
231  $backend->collectGarbage();
232  $this->assertTrue($backend->has($entryIdentifier . 'A'));
233  $this->assertTrue($backend->has($entryIdentifier . 'B'));
234  $this->assertFalse($backend->has($entryIdentifier . 'C'));
235  $this->assertFalse($backend->has($entryIdentifier . 'D'));
236  }
237 
243  protected function setUpBackend() {
244  $mockCache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\FrontendInterface', array(), array(), '', FALSE);
245  $mockCache->expects($this->any())->method('getIdentifier')->will($this->returnValue('TestCache'));
246  $backend = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\Backend\\PdoBackend', 'Testing');
247  $backend->setCache($mockCache);
248  $backend->setDataSourceName('sqlite::memory:');
249  $backend->initializeObject();
250  return $backend;
251  }
252 
253 }
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]