Feature #23200 » 15141_01.diff
tests/t3lib/cache/backend/t3lib_cache_backend_dbbackendTest.php (working copy) | ||
---|---|---|
protected $testingTagsTable;
|
||
/**
|
||
* Sets up this testcase
|
||
* Sets up the backend used for testing
|
||
*
|
||
* @return void
|
||
* @author Ingo Renner <ingo@typo3.org>
|
||
* @author Christian Kuhn <lolli@schwarzbu.ch>
|
||
*/
|
||
public function setUp() {
|
||
$this->testingCacheTable = 'test_cache_dbbackend';
|
||
$this->testingTagsTable = 'test_cache_dbbackend_tags';
|
||
public function setUpBackend(array $backendOptions = array()) {
|
||
$defaultTestingCacheTable = 'test_cache_dbbackend';
|
||
$defaultTestingTagsTable = 'test_cache_dbbackend_tags';
|
||
$backendOptions = array_merge(
|
||
array(
|
||
'cacheTable' => $defaultTestingCacheTable,
|
||
'tagsTable' => $defaultTestingTagsTable,
|
||
),
|
||
$backendOptions
|
||
);
|
||
$this->testingCacheTable = $backendOptions['cacheTable'];
|
||
$this->testingTagsTable = $backendOptions['tagsTable'];
|
||
$GLOBALS['TYPO3_DB']->sql_query('CREATE TABLE ' . $this->testingCacheTable . ' (
|
||
id int(11) unsigned NOT NULL auto_increment,
|
||
identifier varchar(128) DEFAULT \'\' NOT NULL,
|
||
crdate int(11) unsigned DEFAULT \'0\' NOT NULL,
|
||
content mediumtext,
|
||
content mediumblob,
|
||
lifetime int(11) unsigned DEFAULT \'0\' NOT NULL,
|
||
PRIMARY KEY (id),
|
||
KEY cache_id (identifier)
|
||
... | ... | |
$this->backend = t3lib_div::makeInstance(
|
||
't3lib_cache_backend_DbBackend',
|
||
array(
|
||
'cacheTable' => $this->testingCacheTable,
|
||
'tagsTable' => $this->testingTagsTable,
|
||
)
|
||
$backendOptions
|
||
);
|
||
}
|
||
/**
|
||
* @author Ingo Renner <ingo@typo3.org>
|
||
*/
|
||
public function tearDown() {
|
||
$GLOBALS['TYPO3_DB']->sql_query(
|
||
'DROP TABLE ' . $this->testingCacheTable . ';'
|
||
);
|
||
$GLOBALS['TYPO3_DB']->sql_query(
|
||
'DROP TABLE ' . $this->testingTagsTable . ';'
|
||
);
|
||
}
|
||
/**
|
||
* @test
|
||
* @expectedException t3lib_cache_Exception
|
||
* @author Ingo Renner <ingo@typo3.org>
|
||
... | ... | |
* @author Ingo Renner <ingo@typo3.org>
|
||
*/
|
||
public function getCacheTableReturnsThePreviouslySetTable() {
|
||
$this->setUpBackend();
|
||
$this->backend->setCacheTable($this->testingCacheTable);
|
||
$this->assertEquals($this->testingCacheTable, $this->backend->getCacheTable(), 'getCacheTable() did not return the expected value.');
|
||
}
|
||
... | ... | |
* @author Ingo Renner <ingo@typo3.org>
|
||
*/
|
||
public function setThrowsExceptionIfDataIsNotAString() {
|
||
$this->setUpBackend();
|
||
$cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend',
|
||
array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'),
|
||
array(),
|
||
... | ... | |
* @author Ingo Renner <ingo@typo3.org>
|
||
*/
|
||
public function setReallySavesToTheSpecifiedTable() {
|
||
$this->setUpBackend();
|
||
$cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend',
|
||
array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'),
|
||
array(),
|
||
... | ... | |
* @author Ingo Renner <ingo@typo3.org>
|
||
*/
|
||
public function setRemovesAnAlreadyExistingCacheEntryForTheSameIdentifier() {
|
||
$this->setUpBackend();
|
||
$cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend',
|
||
array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'),
|
||
array(),
|
||
... | ... | |
* @author Ingo Renner <ingo@typo3.org>
|
||
*/
|
||
public function setReallySavesSpecifiedTags() {
|
||
$this->setUpBackend();
|
||
$cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend',
|
||
array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'),
|
||
array(),
|
||
... | ... | |
/**
|
||
* @test
|
||
* @author Christian Kuhn <lolli@schwarzbu.ch>
|
||
*/
|
||
public function setSavesCompressedDataWithEnabledCompression() {
|
||
$mockCache = $this->getMock('t3lib_cache_frontend_AbstractFrontend', array(), array(), '', FALSE);
|
||
$mockCache->expects($this->any())->method('getIdentifier')->will($this->returnValue('UnitTestCache'));
|
||
$this->setUpBackend(
|
||
array(
|
||
'compression' => TRUE,
|
||
)
|
||
);
|
||
$this->backend->setCache($mockCache);
|
||
$data = 'some data ' . microtime();
|
||
$entryIdentifier = 'BackendDbTest';
|
||
$this->backend->set($entryIdentifier, $data);
|
||
$entry = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
|
||
'content',
|
||
$this->testingCacheTable,
|
||
'identifier = \'' . $entryIdentifier . '\''
|
||
);
|
||
$this->assertEquals($data, @gzuncompress($entry[0]['content']), 'Original and compressed data don\'t match');
|
||
}
|
||
/**
|
||
* @test
|
||
* @author Christian Kuhn <lolli@schwarzbu.ch>
|
||
*/
|
||
public function setSavesPlaintextDataWithEnabledCompressionAndCompressionLevel0() {
|
||
$mockCache = $this->getMock('t3lib_cache_frontend_AbstractFrontend', array(), array(), '', FALSE);
|
||
$mockCache->expects($this->any())->method('getIdentifier')->will($this->returnValue('UnitTestCache'));
|
||
$this->setUpBackend(
|
||
array(
|
||
'compression' => TRUE,
|
||
'compressionLevel' => 0,
|
||
)
|
||
);
|
||
$this->backend->setCache($mockCache);
|
||
$data = 'some data ' . microtime();
|
||
$entryIdentifier = 'BackendDbTest';
|
||
$this->backend->set($entryIdentifier, $data);
|
||
$entry = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
|
||
'content',
|
||
$this->testingCacheTable,
|
||
'identifier = \'' . $entryIdentifier . '\''
|
||
);
|
||
$this->assertGreaterThan(0, substr_count($entry[0]['content'], $data), 'Plaintext data not found');
|
||
}
|
||
/**
|
||
* @test
|
||
* @author Ingo Renner <ingo@typo3.org>
|
||
*/
|
||
public function getReturnsContentOfTheCorrectCacheEntry() {
|
||
$this->setUpBackend();
|
||
$cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend',
|
||
array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'),
|
||
array(),
|
||
... | ... | |
* @author Ingo Renner <ingo@typo3.org>
|
||
*/
|
||
public function hasReturnsTheCorrectResult() {
|
||
$this->setUpBackend();
|
||
$cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend',
|
||
array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'),
|
||
array(),
|
||
... | ... | |
* @author Ingo Renner <ingo@typo3.org>
|
||
*/
|
||
public function removeReallyRemovesACacheEntry() {
|
||
$this->setUpBackend();
|
||
$cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend',
|
||
array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'),
|
||
array(),
|
||
... | ... | |
* @author Ingo Renner <ingo@typo3.org>
|
||
*/
|
||
public function collectGarbageReallyRemovesAnExpiredCacheEntry() {
|
||
$this->setUpBackend();
|
||
$cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend',
|
||
array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'),
|
||
array(),
|
||
... | ... | |
* @author Ingo Renner <ingo@typo3.org>
|
||
*/
|
||
public function collectGarbageReallyRemovesAllExpiredCacheEntries() {
|
||
$this->setUpBackend();
|
||
$cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend',
|
||
array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'),
|
||
array(),
|
||
... | ... | |
* @author Ingo Renner <ingo@typo3.org>
|
||
*/
|
||
public function findIdentifiersByTagFindsCacheEntriesWithSpecifiedTag() {
|
||
$this->setUpBackend();
|
||
$cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend',
|
||
array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'),
|
||
array(),
|
||
... | ... | |
* @author Ingo Renner <ingo@typo3.org>
|
||
*/
|
||
public function flushRemovesAllCacheEntries() {
|
||
$this->setUpBackend();
|
||
$cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend',
|
||
array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'),
|
||
array(),
|
||
... | ... | |
* @author Ingo Renner <ingo@typo3.org>
|
||
*/
|
||
public function flushByTagRemovesCacheEntriesWithSpecifiedTag() {
|
||
$this->setUpBackend();
|
||
$cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend',
|
||
array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'),
|
||
array(),
|
||
... | ... | |
* @author Ingo Renner <ingo@typo3.org>
|
||
*/
|
||
public function hasReturnsTheCorrectResultForEntryWithExceededLifetime() {
|
||
$this->setUpBackend();
|
||
$cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend',
|
||
array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'),
|
||
array(),
|
||
... | ... | |
* @author Ingo Renner <ingo@typo3.org>
|
||
*/
|
||
public function getReturnsFalseForEntryWithExceededLifetime() {
|
||
$this->setUpBackend();
|
||
$cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend',
|
||
array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'),
|
||
array(),
|
||
... | ... | |
* @author Ingo Renner <ingo@typo3.org>
|
||
*/
|
||
public function findIdentifiersByTagReturnsEmptyArrayForEntryWithExceededLifetime() {
|
||
$this->setUpBackend();
|
||
$cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend',
|
||
array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'),
|
||
array(),
|
||
... | ... | |
* @author Ingo Renner <ingo@typo3.org>
|
||
*/
|
||
public function setWithUnlimitedLifetimeWritesCorrectEntry() {
|
||
$this->setUpBackend();
|
||
$cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend',
|
||
array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'),
|
||
array(),
|
||
... | ... | |
$retrievedData = $entriesFound[0]['content'];
|
||
$this->assertEquals($data, $retrievedData, 'The original and the retrieved data don\'t match.');
|
||
}
|
||
/**
|
||
* @author Ingo Renner <ingo@typo3.org>
|
||
*/
|
||
public function tearDown() {
|
||
$GLOBALS['TYPO3_DB']->sql_query(
|
||
'DROP TABLE ' . $this->testingCacheTable . ';'
|
||
);
|
||
$GLOBALS['TYPO3_DB']->sql_query(
|
||
'DROP TABLE ' . $this->testingTagsTable . ';'
|
||
);
|
||
}
|
||
}
|
||
?>
|
t3lib/stddb/tables.sql (working copy) | ||
---|---|---|
id int(11) unsigned NOT NULL auto_increment,
|
||
identifier varchar(128) DEFAULT '' NOT NULL,
|
||
crdate int(11) unsigned DEFAULT '0' NOT NULL,
|
||
content mediumtext,
|
||
content mediumblob,
|
||
lifetime int(11) unsigned DEFAULT '0' NOT NULL,
|
||
PRIMARY KEY (id),
|
||
KEY cache_id (identifier)
|
t3lib/cache/backend/class.t3lib_cache_backend_dbbackend.php (working copy) | ||
---|---|---|
protected $cacheTable;
|
||
protected $tagsTable;
|
||
/**
|
||
* @var boolean Indicates wether data is compressed or not (requires php zlib)
|
||
*/
|
||
protected $compression = FALSE;
|
||
/**
|
||
* @var integer -1 to 9, indicates zlib compression level: -1 = default level 6, 0 = no compression, 9 maximum compression
|
||
*/
|
||
protected $compressionLevel = -1;
|
||
protected $identifierField;
|
||
protected $creationField;
|
||
protected $lifetimeField;
|
||
... | ... | |
$this->remove($entryIdentifier);
|
||
if ($this->compression) {
|
||
$data = gzcompress($data, $this->compressionLevel);
|
||
}
|
||
$GLOBALS['TYPO3_DB']->exec_INSERTquery(
|
||
$this->cacheTable,
|
||
array(
|
||
... | ... | |
$cacheEntry = $cacheEntries[0]['content'];
|
||
}
|
||
if ($this->compression && strlen($cacheEntry)) {
|
||
$cacheEntry = gzuncompress($cacheEntry);
|
||
}
|
||
return $cacheEntry;
|
||
}
|
||
... | ... | |
}
|
||
/**
|
||
* Enable data compression
|
||
*
|
||
* @param boolean TRUE to enable compression
|
||
*/
|
||
public function setCompression($compression) {
|
||
$this->compression = $compression;
|
||
}
|
||
/**
|
||
* Set data compression level.
|
||
* If compression is enabled and this is not set,
|
||
* gzcompress default level will be used
|
||
*
|
||
* @param integer -1 to 9: Compression level
|
||
*/
|
||
public function setCompressionLevel($compressionLevel) {
|
||
if ($compressionLevel >= -1 && $compressionLevel <= 9) {
|
||
$this->compressionLevel = $compressionLevel;
|
||
}
|
||
}
|
||
/**
|
||
* Gets the query to be used for selecting entries by a tag. The asterisk ("*")
|
||
* is allowed as a wildcard at the beginning and the end of a tag.
|
||
*
|
typo3/sysext/cms/ext_tables.sql (working copy) | ||
---|---|---|
id int(11) unsigned NOT NULL auto_increment,
|
||
identifier varchar(128) DEFAULT '' NOT NULL,
|
||
crdate int(11) unsigned DEFAULT '0' NOT NULL,
|
||
content mediumtext,
|
||
content mediumblob,
|
||
lifetime int(11) unsigned DEFAULT '0' NOT NULL,
|
||
PRIMARY KEY (id),
|
||
KEY cache_id (identifier)
|
||
... | ... | |
id int(11) unsigned NOT NULL auto_increment,
|
||
identifier varchar(128) DEFAULT '' NOT NULL,
|
||
crdate int(11) unsigned DEFAULT '0' NOT NULL,
|
||
content mediumtext,
|
||
content mediumblob,
|
||
lifetime int(11) unsigned DEFAULT '0' NOT NULL,
|
||
PRIMARY KEY (id),
|
||
KEY cache_id (identifier)
|