Index: tests/contrib/removexssTest.php =================================================================== --- tests/contrib/removexssTest.php (Revision 7835) +++ tests/contrib/removexssTest.php (Arbeitskopie) @@ -33,7 +33,7 @@ * @ see http://ha.ckers.org/xss.html * @ examples from http://ha.ckers.org/xssAttacks.xml */ -class RemoveXSS_testcase extends tx_phpunit_testcase { +class RemoveXSSTest extends tx_phpunit_testcase { /** * @test Index: tests/contrib/removexss_testcase.php =================================================================== --- tests/contrib/removexss_testcase.php (Revision 7835) +++ tests/contrib/removexss_testcase.php (Arbeitskopie) @@ -1,372 +0,0 @@ - -* All rights reserved -* -* This script is part of the TYPO3 project. The TYPO3 project is -* free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* The GNU General Public License can be found at -* http://www.gnu.org/copyleft/gpl.html. -* -* This script is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* This copyright notice MUST APPEAR in all copies of the script! -***************************************************************/ - -require_once(PATH_typo3 . 'contrib/RemoveXSS/RemoveXSS.php'); - -/** - * Testcase for class RemoveXSS - * - * @author Steffen Kamper - * @package TYPO3 - * @subpackage contrib - * @ see http://ha.ckers.org/xss.html - * @ examples from http://ha.ckers.org/xssAttacks.xml - */ -class RemoveXSS_testcase extends tx_phpunit_testcase { - - /** - * @test - */ - public function checkAttackScriptAlert() { - $testString = ""; - $expectedString = "ript>alert('XSS')"; - $actualString = RemoveXSS::process($testString); - - $this->assertEquals($expectedString, $actualString); - } - /** - * @test - */ - public function checkAttackScriptSrcJs() { - $testString = ''; - $expectedString = "ript SRC=http://ha.ckers.org/xss.js>"; - $actualString = RemoveXSS::process($testString); - - $this->assertEquals($expectedString, $actualString); - } - /** - * @test - */ - public function checkAttackScriptAlertFromCharCode() { - $testString = ''; - $expectedString = 'ript>alert(String.fromCharCode(88,83,83))'; - $actualString = RemoveXSS::process($testString); - - $this->assertEquals($expectedString, $actualString); - } - /** - * @test - */ - public function checkAttackBaseHref() { - $testString = ""; - $expectedString = "se HREF=\"javascript:alert('XSS');//\">"; - $actualString = RemoveXSS::process($testString); - - $this->assertEquals($expectedString, $actualString); - } - /** - * @test - */ - public function checkAttackBgsound() { - $testString = ""; - $expectedString = "sound SRC=\"javascript:alert('XSS');\">"; - $actualString = RemoveXSS::process($testString); - - $this->assertEquals($expectedString, $actualString); - } - /** - * @test - */ - public function checkAttackBodyBackground() { - $testString = ""; - $expectedString = "vascript:alert('XSS');\">"; - $actualString = RemoveXSS::process($testString); - - $this->assertEquals($expectedString, $actualString); - } - /** - * @test - */ - public function checkAttackBodyOnLoad() { - $testString = ""; - $expectedString = "load=alert('XSS')>"; - $actualString = RemoveXSS::process($testString); - - $this->assertEquals($expectedString, $actualString); - } - /** - * @test - */ - public function checkAttackStyleUrl() { - $testString = "
"; - $expectedString = "
yle=\"background-image: url(javascript:alert('XSS'))\">"; - $actualString = RemoveXSS::process($testString); - - $this->assertEquals($expectedString, $actualString); - } - /** - * @test - */ - public function checkAttackStyleWidth() { - $testString = "
"; - $expectedString = "
yle=\"width: expression(alert('XSS'));\">"; - $actualString = RemoveXSS::process($testString); - - $this->assertEquals($expectedString, $actualString); - } - /** - * @test - */ - public function checkAttackFrameset() { - $testString = ""; - $expectedString = "ameset>ame SRC=\"javascript:alert('XSS');\">"; - $actualString = RemoveXSS::process($testString); - - $this->assertEquals($expectedString, $actualString); - } - /** - * @test - */ - public function checkAttackIframe() { - $testString = ""; - $expectedString = "rame SRC=\"javascript:alert('XSS');\">"; - $actualString = RemoveXSS::process($testString); - - $this->assertEquals($expectedString, $actualString); - } - /** - * @test - */ - public function checkAttackInputImage() { - $testString = ""; - $expectedString = "vascript:alert('XSS');\">"; - $actualString = RemoveXSS::process($testString); - - $this->assertEquals($expectedString, $actualString); - } - /** - * @test - */ - public function checkAttackImageSrc() { - $testString = ""; - $expectedString = "vascript:alert('XSS');\">"; - $actualString = RemoveXSS::process($testString); - - $this->assertEquals($expectedString, $actualString); - } - /** - * @test - */ - public function checkAttackImageSrcNoQuotesNoSemicolon() { - $testString = ""; - $expectedString = "vascript:alert('XSS')>"; - $actualString = RemoveXSS::process($testString); - - $this->assertEquals($expectedString, $actualString); - } - /** - * @test - */ - public function checkAttackImageDynsrc() { - $testString = ""; - $expectedString = "vascript:alert('XSS');\">"; - $actualString = RemoveXSS::process($testString); - - $this->assertEquals($expectedString, $actualString); - } - /** - * @test - */ - public function checkAttackImageLowsrc() { - $testString = ""; - $expectedString = "vascript:alert('XSS');\">"; - $actualString = RemoveXSS::process($testString); - - $this->assertEquals($expectedString, $actualString); - } - /** - * @test - */ - public function checkAttackStyle() { - $testString = ""; - $expectedString = "yle>li {list-style-image: url(\"javascript:alert('XSS')\");}"; - $actualString = RemoveXSS::process($testString); - - $this->assertEquals($expectedString, $actualString); - } - /** - * @test - */ - public function checkAttackImageVbscript() { - $testString = ""; - $expectedString = ""; - $actualString = RemoveXSS::process($testString); - - $this->assertEquals($expectedString, $actualString); - } - /** - * @test - */ - public function checkAttackLayer() { - $testString = ""; - $expectedString = "yer SRC=\"http://ha.ckers.org/scriptlet.html\">"; - $actualString = RemoveXSS::process($testString); - - $this->assertEquals($expectedString, $actualString); - } - /** - * @test - */ - public function checkAttackMeta() { - $testString = ''; - $expectedString = 'ta HTTP-EQUIV="refresh" CONTENT="0;url=javascript:alert(\'XSS\');">'; - $actualString = RemoveXSS::process($testString); - - $this->assertEquals($expectedString, $actualString); - } - /** - * @test - */ - public function checkAttackMetaWithUrl() { - $testString = ''; - $expectedString = 'ta HTTP-EQUIV="refresh" CONTENT="0;url=data:text/html;base64,PHNjcmlwdD5hbGVydCgnWFNTJyk8L3NjcmlwdD4K">'; - $actualString = RemoveXSS::process($testString); - - $this->assertEquals($expectedString, $actualString); - } - /** - * @test - */ - public function checkAttackMetaWithUrlExtended() { - $testString = ''; - $expectedString = 'ta HTTP-EQUIV="refresh" CONTENT="0; URL=http://;URL=javascript:alert(\'XSS\');">'; - $actualString = RemoveXSS::process($testString); - - $this->assertEquals($expectedString, $actualString); - } - /** - * @test - */ - public function checkAttackObject() { - $testString = ''; - $expectedString = 'ject TYPE="text/x-scriptlet" DATA="http://ha.ckers.org/scriptlet.html">'; - $actualString = RemoveXSS::process($testString); - - $this->assertEquals($expectedString, $actualString); - } - /** - * @test - */ - public function checkAttackObjectEmbeddedXss() { - $testString = ''; - $expectedString = 'ject classid=clsid:ae24fdae-03c6-11d1-8b76-0080c744f389>vascript:alert(\'XSS\')>'; - $actualString = RemoveXSS::process($testString); - - $this->assertEquals($expectedString, $actualString); - } - /** - * @test - */ - public function checkAttackEmbedFlash() { - $testString = ''; - $expectedString = 'bed SRC="http://ha.ckers.org/xss.swf" AllowScriptAccess="always">'; - $actualString = RemoveXSS::process($testString); - - $this->assertEquals($expectedString, $actualString); - } - /** - * @test - */ - public function checkAttackActionScriptEval() { - $testString = 'a="get";b="URL("";c="javascript:";d="alert(\'XSS\');")";eval(a+b+c+d);";'; - $expectedString = 'a="get";b="URL("";c="javascript:";d="alert(\'XSS\');")";eval(a+b+c+d);";'; - $actualString = RemoveXSS::process($testString); - - $this->assertEquals($expectedString, $actualString); - } - /** - * @test - */ - public function checkAttackImageStyleWithComment() { - $testString = ''; - $expectedString = 'yle="xss:expr/*XSS*/ession(alert(\'XSS\'))">'; - $actualString = RemoveXSS::process($testString); - - $this->assertEquals($expectedString, $actualString); - } - /** - * @test - */ - public function checkAttackStyleInAnonymousHtml() { - $testString = ''; - $expectedString = 'yle="xss:expression(alert(\'XSS\'))">'; - $actualString = RemoveXSS::process($testString); - - $this->assertEquals($expectedString, $actualString); - } - /** - * @test - */ - public function checkAttackStyleWithBackgroundImage() { - $testString = ''; - $expectedString = 'yle>.XSS{background-image:url("javascript:alert(\'XSS\')");}'; - $actualString = RemoveXSS::process($testString); - - $this->assertEquals($expectedString, $actualString); - } - /** - * @test - */ - public function checkAttackStyleWithBackground() { - $testString = ''; - $expectedString = 'yle type="text/css">BODY{background:url("javascript:alert(\'XSS\')")}'; - $actualString = RemoveXSS::process($testString); - - $this->assertEquals($expectedString, $actualString); - } - /** - * @test - */ - public function checkAttackStylesheet() { - $testString = ''; - $expectedString = 'nk REL="stylesheet" HREF="javascript:alert(\'XSS\');">'; - $actualString = RemoveXSS::process($testString); - - $this->assertEquals($expectedString, $actualString); - } - /** - * @test - */ - public function checkAttackRemoteStylesheet() { - $testString = ''; - $expectedString = 'nk REL="stylesheet" HREF="http://ha.ckers.org/xss.css">'; - $actualString = RemoveXSS::process($testString); - - $this->assertEquals($expectedString, $actualString); - } - /** - * @test - */ - public function checkAttackImportRemoteStylesheet() { - $testString = ''; - $expectedString = 'yle>@import\'http://ha.ckers.org/xss.css\';'; - $actualString = RemoveXSS::process($testString); - - $this->assertEquals($expectedString, $actualString); - } - - -} - -?> \ No newline at end of file Index: tests/t3lib/t3lib_extmgm_testcase.php =================================================================== --- tests/t3lib/t3lib_extmgm_testcase.php (Revision 7835) +++ tests/t3lib/t3lib_extmgm_testcase.php (Arbeitskopie) @@ -1,466 +0,0 @@ - -* All rights reserved -* -* This script is part of the TYPO3 project. The TYPO3 project is -* free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* The GNU General Public License can be found at -* http://www.gnu.org/copyleft/gpl.html. -* -* This script is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* This copyright notice MUST APPEAR in all copies of the script! -***************************************************************/ - -/** - * Testcase for class t3lib_extMgm - * - * @author Oliver Hader - * @author Oliver Klee - * - * @package TYPO3 - * @subpackage t3lib - */ -class t3lib_extmgm_testcase extends tx_phpunit_testcase { - /** - * backup of defined GLOBALS - * - * @var array - */ - protected $globals = array(); - - public function setUp() { - $this->globals = array( - 'TYPO3_LOADED_EXT' => serialize($GLOBALS['TYPO3_LOADED_EXT']), - 'TCA' => serialize($GLOBALS['TCA']), - ); - } - - public function tearDown() { - t3lib_extMgm::clearExtensionKeyMap(); - - foreach ($this->globals as $key => $value) { - $GLOBALS[$key] = unserialize($value); - } - } - - - ////////////////////// - // Utility functions - ////////////////////// - - /** - * Generates a basic TCA for a given table. - * - * @param string $table name of the table, must not be empty - * @return array generated TCA for the given table, will not be empty - */ - private function generateTCAForTable($table) { - $tca = array(); - $tca[$table] = array(); - $tca[$table]['columns'] = array( - 'fieldA' => array(), - 'fieldC' => array(), - ); - $tca[$table]['types'] = array( - 'typeA' => array('showitem' => 'fieldA, fieldB, fieldC;labelC;paletteC;specialC, fieldD'), - 'typeB' => array('showitem' => 'fieldA, fieldB, fieldC;labelC;paletteC;specialC, fieldD'), - 'typeC' => array('showitem' => 'fieldC;;paletteD'), - ); - $tca[$table]['palettes'] = array( - 'paletteA' => array('showitem' => 'fieldX, fieldY'), - 'paletteB' => array('showitem' => 'fieldX, fieldY'), - 'paletteC' => array('showitem' => 'fieldX, fieldY'), - 'paletteD' => array('showitem' => 'fieldX, fieldY'), - ); - - return $tca; - } - - - ///////////////////////////////////////////// - // Tests concerning getExtensionKeyByPrefix - ///////////////////////////////////////////// - - /** - * @test - * @see t3lib_extMgm::getExtensionKeyByPrefix - */ - public function getExtensionKeyByPrefixForLoadedExtensionWithUnderscoresReturnsExtensionKey() { - t3lib_extMgm::clearExtensionKeyMap(); - - $uniqueSuffix = uniqid('test'); - $extensionKey = 'tt_news' . $uniqueSuffix; - $extensionPrefix = 'tx_ttnews' . $uniqueSuffix; - - $GLOBALS['TYPO3_LOADED_EXT'][$extensionKey] = array(); - - $this->assertEquals( - $extensionKey, - t3lib_extMgm::getExtensionKeyByPrefix($extensionPrefix) - ); - } - - /** - * @test - * @see t3lib_extMgm::getExtensionKeyByPrefix - */ - public function getExtensionKeyByPrefixForLoadedExtensionWithoutUnderscoresReturnsExtensionKey() { - t3lib_extMgm::clearExtensionKeyMap(); - - $uniqueSuffix = uniqid('test'); - $extensionKey = 'kickstarter' . $uniqueSuffix; - $extensionPrefix = 'tx_kickstarter' . $uniqueSuffix; - - $GLOBALS['TYPO3_LOADED_EXT'][$extensionKey] = array(); - - $this->assertEquals( - $extensionKey, - t3lib_extMgm::getExtensionKeyByPrefix($extensionPrefix) - ); - } - - /** - * @test - * @see t3lib_extMgm::getExtensionKeyByPrefix - */ - public function getExtensionKeyByPrefixForNotLoadedExtensionReturnsFalse(){ - t3lib_extMgm::clearExtensionKeyMap(); - - $uniqueSuffix = uniqid('test'); - $extensionKey = 'unloadedextension' . $uniqueSuffix; - $extensionPrefix = 'tx_unloadedextension' . $uniqueSuffix; - - $this->assertFalse( - t3lib_extMgm::getExtensionKeyByPrefix($extensionPrefix) - ); - } - - - ////////////////////////////////////// - // Tests concerning addToAllTCAtypes - ////////////////////////////////////// - - /** - * Tests whether fields can be add to all TCA types and duplicate fields are considered. - * @test - * @see t3lib_extMgm::addToAllTCAtypes() - */ - public function canAddFieldsToAllTCATypesBeforeExistingOnes() { - $table = uniqid('tx_coretest_table'); - $GLOBALS['TCA'] = $this->generateTCAForTable($table); - - t3lib_extMgm::addToAllTCAtypes($table, 'newA, newA, newB, fieldA', '', 'before:fieldD'); - - // Checking typeA: - $this->assertEquals( - 'fieldA, fieldB, fieldC;labelC;paletteC;specialC, newA, newB, fieldD', - $GLOBALS['TCA'][$table]['types']['typeA']['showitem'] - ); - // Checking typeB: - $this->assertEquals( - 'fieldA, fieldB, fieldC;labelC;paletteC;specialC, newA, newB, fieldD', - $GLOBALS['TCA'][$table]['types']['typeB']['showitem'] - ); - } - - /** - * Tests whether fields can be add to all TCA types and duplicate fields are considered. - * @test - * @see t3lib_extMgm::addToAllTCAtypes() - */ - public function canAddFieldsToAllTCATypesAfterExistingOnes() { - $table = uniqid('tx_coretest_table'); - $GLOBALS['TCA'] = $this->generateTCAForTable($table); - - t3lib_extMgm::addToAllTCAtypes($table, 'newA, newA, newB, fieldA', '', 'after:fieldC'); - - // Checking typeA: - $this->assertEquals( - 'fieldA, fieldB, fieldC;labelC;paletteC;specialC, newA, newB, fieldD', - $GLOBALS['TCA'][$table]['types']['typeA']['showitem'] - ); - // Checking typeB: - $this->assertEquals( - 'fieldA, fieldB, fieldC;labelC;paletteC;specialC, newA, newB, fieldD', - $GLOBALS['TCA'][$table]['types']['typeB']['showitem'] - ); - } - - /** - * Tests whether fields can be add to a TCA type before existing ones - * @test - * @see t3lib_extMgm::addToAllTCAtypes() - */ - public function canAddFieldsToTCATypeBeforeExistingOnes() { - $table = uniqid('tx_coretest_table'); - $GLOBALS['TCA'] = $this->generateTCAForTable($table); - - t3lib_extMgm::addToAllTCAtypes($table, 'newA, newA, newB, fieldA', 'typeA', 'before:fieldD'); - - // Checking typeA: - $this->assertEquals( - 'fieldA, fieldB, fieldC;labelC;paletteC;specialC, newA, newB, fieldD', - $GLOBALS['TCA'][$table]['types']['typeA']['showitem'] - ); - // Checking typeB: - $this->assertEquals( - 'fieldA, fieldB, fieldC;labelC;paletteC;specialC, fieldD', - $GLOBALS['TCA'][$table]['types']['typeB']['showitem'] - ); - } - - /** - * Tests whether fields can be add to a TCA type after existing ones - * @test - * @see t3lib_extMgm::addToAllTCAtypes() - */ - public function canAddFieldsToTCATypeAfterExistingOnes() { - $table = uniqid('tx_coretest_table'); - $GLOBALS['TCA'] = $this->generateTCAForTable($table); - - t3lib_extMgm::addToAllTCAtypes($table, 'newA, newA, newB, fieldA', 'typeA', 'after:fieldC'); - - // Checking typeA: - $this->assertEquals( - 'fieldA, fieldB, fieldC;labelC;paletteC;specialC, newA, newB, fieldD', - $GLOBALS['TCA'][$table]['types']['typeA']['showitem'] - ); - // Checking typeB: - $this->assertEquals( - 'fieldA, fieldB, fieldC;labelC;paletteC;specialC, fieldD', - $GLOBALS['TCA'][$table]['types']['typeB']['showitem'] - ); - } - - - /////////////////////////////////////////////////// - // Tests concerning addFieldsToAllPalettesOfField - /////////////////////////////////////////////////// - - /** - * Tests whether fields can be added to a palette before existing elements. - * @test - * @see t3lib_extMgm::addFieldsToPalette() - */ - public function canAddFieldsToPaletteBeforeExistingOnes() { - $table = uniqid('tx_coretest_table'); - $GLOBALS['TCA'] = $this->generateTCAForTable($table); - - t3lib_extMgm::addFieldsToPalette($table, 'paletteA', 'newA, newA, newB, fieldX', 'before:fieldY'); - - $this->assertEquals( - 'fieldX, newA, newB, fieldY', - $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem'] - ); - } - - /** - * Tests whether fields can be added to a palette after existing elements. - * @test - * @see t3lib_extMgm::addFieldsToPalette() - */ - public function canAddFieldsToPaletteAfterExistingOnes() { - $table = uniqid('tx_coretest_table'); - $GLOBALS['TCA'] = $this->generateTCAForTable($table); - - t3lib_extMgm::addFieldsToPalette($table, 'paletteA', 'newA, newA, newB, fieldX', 'after:fieldX'); - - $this->assertEquals( - 'fieldX, newA, newB, fieldY', - $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem'] - ); - } - - /** - * Tests whether fields can be added to a palette after a not existing elements. - * @test - * @see t3lib_extMgm::addFieldsToPalette() - */ - public function canAddFieldsToPaletteAfterNotExistingOnes() { - $table = uniqid('tx_coretest_table'); - $GLOBALS['TCA'] = $this->generateTCAForTable($table); - - t3lib_extMgm::addFieldsToPalette($table, 'paletteA', 'newA, newA, newB, fieldX', 'after:' . uniqid('notExisting')); - - $this->assertEquals( - 'fieldX, fieldY, newA, newB', - $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem'] - ); - } - - /** - * Tests whether fields can be added to all palettes of a regular field before existing ones. - * @test - * @see t3lib_extMgm::addFieldsToAllPalettesOfField() - */ - public function canAddFieldsToAllPalettesOfFieldBeforeExistingOnes() { - $table = uniqid('tx_coretest_table'); - $GLOBALS['TCA'] = $this->generateTCAForTable($table); - - t3lib_extMgm::addFieldsToAllPalettesOfField($table, 'fieldC', 'newA, newA, newB, fieldX', 'before:fieldY'); - - $this->assertEquals( - 'fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem'] - ); - $this->assertEquals( - 'fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteB']['showitem'] - ); - $this->assertEquals( - 'fieldX, newA, newB, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteC']['showitem'] - ); - $this->assertEquals( - 'fieldX, newA, newB, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteD']['showitem'] - ); - } - - /** - * Tests whether fields can be added to all palettes of a regular field after existing ones. - * @test - * @see t3lib_extMgm::addFieldsToAllPalettesOfField() - */ - public function canAddFieldsToAllPalettesOfFieldAfterExistingOnes() { - $table = uniqid('tx_coretest_table'); - $GLOBALS['TCA'] = $this->generateTCAForTable($table); - - t3lib_extMgm::addFieldsToAllPalettesOfField($table, 'fieldC', 'newA, newA, newB, fieldX', 'after:fieldX'); - - $this->assertEquals( - 'fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem'] - ); - $this->assertEquals( - 'fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteB']['showitem'] - ); - $this->assertEquals( - 'fieldX, newA, newB, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteC']['showitem'] - ); - $this->assertEquals( - 'fieldX, newA, newB, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteD']['showitem'] - ); - } - - /** - * Tests whether fields can be added to all palettes of a regular field after a not existing field. - * @test - * @see t3lib_extMgm::addFieldsToAllPalettesOfField() - */ - public function canAddFieldsToAllPalettesOfFieldAfterNotExistingOnes() { - $table = uniqid('tx_coretest_table'); - $GLOBALS['TCA'] = $this->generateTCAForTable($table); - - t3lib_extMgm::addFieldsToAllPalettesOfField($table, 'fieldC', 'newA, newA, newB, fieldX', 'after:' . uniqid('notExisting')); - - $this->assertEquals( - 'fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem'] - ); - $this->assertEquals( - 'fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteB']['showitem'] - ); - $this->assertEquals( - 'fieldX, fieldY, newA, newB', $GLOBALS['TCA'][$table]['palettes']['paletteC']['showitem'] - ); - $this->assertEquals( - 'fieldX, fieldY, newA, newB', $GLOBALS['TCA'][$table]['palettes']['paletteD']['showitem'] - ); - } - - /** - * Tests whether fields are added to a new palette that did not exist before. - * @test - * @see t3lib_extMgm::addFieldsToAllPalettesOfField() - */ - public function canAddFieldsToAllPalettesOfFieldWithoutPaletteExistingBefore() { - $table = uniqid('tx_coretest_table'); - $GLOBALS['TCA'] = $this->generateTCAForTable($table); - - t3lib_extMgm::addFieldsToAllPalettesOfField($table, 'fieldA', 'newA, newA, newB, fieldX'); - - $this->assertEquals( - 'fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem'] - ); - $this->assertEquals( - 'fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteB']['showitem'] - ); - $this->assertEquals( - 'fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteC']['showitem'] - ); - $this->assertEquals( - 'fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteD']['showitem'] - ); - $this->assertEquals( - 'newA, newB, fieldX', $GLOBALS['TCA'][$table]['palettes']['generatedFor-fieldA']['showitem'] - ); - } - - - ///////////////////////////////////////// - // Tests concerning getExtensionVersion - ///////////////////////////////////////// - - /** - * Data provider for negative getExtensionVersion() tests. - * - * @return array - */ - public function getExtensionVersionFaultyDataProvider() { - return array( - array(''), - array(0), - array(new stdClass()), - array(TRUE), - ); - } - - /** - * @test - * @expectedException InvalidArgumentException - * @dataProvider getExtensionVersionFaultyDataProvider - */ - public function getExtensionVersionForFaultyExtensionKeyThrowsException($key) { - t3lib_extMgm::getExtensionVersion($key); - } - - /** - * @test - */ - public function getExtensionVersionForNotLoadedExtensionReturnsEmptyString() { - t3lib_extMgm::clearExtensionKeyMap(); - - $uniqueSuffix = uniqid('test'); - $extensionKey = 'unloadedextension' . $uniqueSuffix; - - $this->assertEquals( - '', - t3lib_extMgm::getExtensionVersion($extensionKey) - ); - } - - /** - * @test - */ - public function getExtensionVersionForLoadedExtensionReturnsExtensionVersion() { - t3lib_extMgm::clearExtensionKeyMap(); - - $uniqueSuffix = uniqid('test'); - $extensionKey = 'unloadedextension' . $uniqueSuffix; - - $GLOBALS['TYPO3_LOADED_EXT'][$extensionKey] = array( - 'siteRelPath' => 'typo3_src/tests/t3lib/fixtures/', - ); - $this->assertEquals( - '1.2.3', - t3lib_extMgm::getExtensionVersion($extensionKey) - ); - } -} -?> \ No newline at end of file Index: tests/t3lib/t3lib_befunc_testcase.php =================================================================== --- tests/t3lib/t3lib_befunc_testcase.php (Revision 7835) +++ tests/t3lib/t3lib_befunc_testcase.php (Arbeitskopie) @@ -1,68 +0,0 @@ - - */ -class t3lib_befunc_testcase extends tx_phpunit_testcase { - /** - * @var t3lib_BEfunc - */ - private $fixture; - - public function setUp() { - $this->fixture = new t3lib_BEfunc(); - } - - public function tearDown() { - unset($this->fixture); - } - - - /////////////////////////////////////// - // Tests concerning getProcessedValue - /////////////////////////////////////// - - /** - * @test - * - * @see http://bugs.typo3.org/view.php?id=11875 - */ - public function getProcessedValueForZeroStringIsZero() { - $this->assertEquals( - '0', - $this->fixture->getProcessedValue( - 'tt_content', 'header', '0' - ) - ); - } -} -?> Index: tests/t3lib/t3lib_pagerenderer_testcase.php =================================================================== --- tests/t3lib/t3lib_pagerenderer_testcase.php (Revision 7835) +++ tests/t3lib/t3lib_pagerenderer_testcase.php (Arbeitskopie) @@ -1,656 +0,0 @@ -fixture = new t3lib_PageRenderer(); - $this->fixture->setCharSet('utf-8'); - } - - public function tearDown() { - unset( - $this->fixture - ); - } - - - ////////////////////////////////////// - // Tests for the basic functionality - ////////////////////////////////////// - - /** - * @test - */ - public function fixtureCanBeCreated() { - $this->assertTrue( - $this->fixture instanceof t3lib_PageRenderer - ); - } - - ////////////////////// - // test functions - ////////////////////// - - /** - * test set xml prolog and doctype - * - */ - public function testSetXmlPrologAndDocType() { - - $expectedReturnValue = ''; - $this->fixture->setXmlPrologAndDocType(''); - $out = $this->fixture->render(); - - $this->assertContains( - $expectedReturnValue, - $out - ); - } - - /** - * test set title - * - */ - public function testSetTitle() { - - $expectedReturnValue = 'This is the title'; - $this->fixture->setTitle('This is the title'); - $out = $this->fixture->render(); - - $this->assertContains( - $expectedReturnValue, - $out - ); - } - - /** - * test set charset - * - */ - public function testSetCharset() { - - $expectedReturnValue = ''; - $this->fixture->setCharset('utf-8'); - $out = $this->fixture->render(); - - $this->assertContains( - $expectedReturnValue, - $out - ); - } - - /** - * test set favicon - * - */ - public function testSetFavIcon() { - - $expectedReturnValue1 = ''; - $expectedReturnValue2 = ''; - $this->fixture->setFavIcon('http://google.com/favicon.ico'); - $out = $this->fixture->render(); - - $this->assertContains( - $expectedReturnValue1, - $out - ); - $this->assertContains( - $expectedReturnValue2, - $out - ); - - } - - /** - * test set baseUrl - * - */ - public function testSetBaseUrl() { - - $expectedReturnValue = ''; - $this->fixture->setBaseUrl('http://ggogle.com/'); - $out = $this->fixture->render(); - - $this->assertContains( - $expectedReturnValue, - $out - ); - } - - /** - * test add meta tag - * - */ - public function testAddMetaTag() { - - $expectedReturnValue = ''; - $this->fixture->addMetaTag(''); - $out = $this->fixture->render(); - - $this->assertContains( - $expectedReturnValue, - $out - ); - } - - /** - * test add inline comment - * - */ - public function testAddInlineComment() { - - $expectedReturnValue = 'this is an inline comment written by unit test'; - $this->fixture->addInlineComment('this is an inline comment written by unit test'); - $out = $this->fixture->render(); - - $this->assertContains( - $expectedReturnValue, - $out - ); - } - - /** - * test add header data - * - */ - public function testAddHeaderData() { - - $expectedReturnValue = ''; - $this->fixture->addHeaderData(''); - $out = $this->fixture->render(); - - $this->assertContains( - $expectedReturnValue, - $out - ); - } - - /** - * test add footer data - * - */ - public function testAddFooterData() { - - $expectedReturnValue = ''; - $this->fixture->addFooterData(''); - $out = $this->fixture->render(t3lib_PageRenderer::PART_FOOTER); - - $this->assertContains( - $expectedReturnValue, - $out - ); - } - - /** - * test add JS library file - * - */ - public function testAddJsLibrary() { - - $expectedRegExp = '##'; - $this->fixture->addJsLibrary('test', 'fileadmin/test.js'); - $out = $this->fixture->render(); - - $this->assertRegExp( - $expectedRegExp, - $out - ); - } - - - /** - * test add JS footer library file - * - */ - public function testAddJsFooterLibrary() { - - $expectedRegExp = '##'; - $this->fixture->addJsFooterLibrary('test', 'fileadmin/test.js'); - $out = $this->fixture->render(t3lib_PageRenderer::PART_FOOTER); - - $this->assertRegExp( - $expectedRegExp, - $out - ); - } - - /** - * test add JS file - * - */ - public function testAddJsFile() { - - $expectedRegExp = '##'; - $this->fixture->addJsFile('fileadmin/test.js'); - $out = $this->fixture->render(); - - $this->assertRegExp( - $expectedRegExp, - $out - ); - } - - /** - * test add JS file for footer - * - */ - public function testAddJsFooterFile() { - - $expectedRegExp = '##'; - $this->fixture->addJsFooterFile('fileadmin/test.js'); - $out = $this->fixture->render(t3lib_PageRenderer::PART_FOOTER); - - $this->assertRegExp( - $expectedRegExp, - $out - ); - } - - /** - * test add JS inline - * - */ - public function testAddJsInlineCode() { - - $expectedReturnValue = 'var x = "testvar"'; - $this->fixture->addJsInlineCode('test', 'var x = "testvar"'); - $out = $this->fixture->render(); - - $this->assertContains( - $expectedReturnValue, - $out - ); - } - - /** - * test add JS inline for footer - * - */ - public function testAddJsFooterInlineCode() { - - $expectedReturnValue = 'var x = "testvar"'; - $this->fixture->addJsFooterInlineCode('test', 'var x = "testvar"'); - $out = $this->fixture->render(t3lib_PageRenderer::PART_FOOTER); - - $this->assertContains( - $expectedReturnValue, - $out - ); - } - - /** - * test add JS handler - * - */ - public function testAddExtOnReadyCode() { - - $expectedReturnValue1 = 'Ext.onReady(function() {'; - $expectedReturnValue2 = 'var x = "testvar";'; - $this->fixture->loadExtJS(); - $this->fixture->addExtOnReadyCode('var x = "testvar";'); - $out = $this->fixture->render(); - - $this->assertContains( - $expectedReturnValue1, - $out - ); - - $this->assertContains( - $expectedReturnValue2, - $out - ); - - } - - /** - * test add CSS file - * - */ - public function testAddCssFile() { - - $expectedReturnValue = ''; - $this->fixture->addCssFile('fileadmin/test.css'); - $out = $this->fixture->render(); - - $this->assertContains( - $expectedReturnValue, - $out - ); - } - - /** - * test add CSS inline - * - */ - public function testAddCssInlineBlock() { - - $expectedReturnValue = 'body {margin:20px;}'; - $this->fixture->addCssInlineBlock('general', 'body {margin:20px;}'); - $out = $this->fixture->render(); - - $this->assertContains( - $expectedReturnValue, - $out - ); - } - - /** - * test add CSS inline and force on top - * - */ - public function testAddCssInlineBlockForceOnTop() { - - $expectedReturnValue = '/*general1*/' . LF . 'h1 {margin:20px;}' . LF . '/*general*/' . LF . 'body {margin:20px;}'; - $this->fixture->addCssInlineBlock('general', 'body {margin:20px;}'); - $this->fixture->addCssInlineBlock('general1', 'h1 {margin:20px;}', NULL, TRUE); - $out = $this->fixture->render(); - - $this->assertContains( - $expectedReturnValue, - $out - ); - } - - /** - * test load prototype - * - */ - public function testLoadPrototype() { - - $expectedRegExp = '##'; - $this->fixture->loadPrototype(); - $out = $this->fixture->render(); - - $this->assertRegExp( - $expectedRegExp, - $out - ); - } - - /** - * test load Scriptaculous - * - */ - public function testLoadScriptaculous() { - - $expectedRegExp = '##'; - $this->fixture->loadScriptaculous('slider,controls'); - $out = $this->fixture->render(); - - $this->assertRegExp( - $expectedRegExp, - $out - ); - } - - /** - * test load ExtJS - * - */ - public function testLoadExtJS() { - - $expectedRegExp = '#' . LF . '#m'; - $this->fixture->loadExtJS(TRUE, TRUE, 'jquery'); - $out = $this->fixture->render(); - - $this->assertRegExp( - $expectedRegExp, - $out - ); - } - - /** - * test load ExtCore - * - */ - public function testLoadExtCore() { - - $expectedRegExp = '##'; - $this->fixture->loadExtCore(); - $out = $this->fixture->render(); - - $this->assertRegExp( - $expectedRegExp, - $out - ); - } - - /** - * test enable ExtJsDebug - * - */ - public function testEnableExtJsDebug() { - - $expectedRegExp = '##'; - $this->fixture->loadExtJS(TRUE, TRUE, 'jquery'); - $this->fixture->enableExtJsDebug(); - $out = $this->fixture->render(); - - $this->assertRegExp( - $expectedRegExp, - $out - ); - } - - /** - * test enable ExtCoreDebug - * - */ - public function testEnableExtCoreDebug() { - - $expectedRegExp = '##'; - $this->fixture->loadExtCore(); - $this->fixture->enableExtCoreDebug(); - $out = $this->fixture->render(); - - $this->assertRegExp( - $expectedRegExp, - $out - ); - } - - /** - * test inline language label - * - */ - public function testAddInlineLanguageLabel() { - - $expectedReturnValue = 'TYPO3.lang = {"myKey":"myValue"}'; - $this->fixture->loadExtJS(); - $this->fixture->addInlineLanguageLabel('myKey', 'myValue'); - $out = $this->fixture->enableMoveJsFromHeaderToFooter(); - $out = $this->fixture->render(t3lib_PageRenderer::PART_FOOTER); - - $this->assertContains( - $expectedReturnValue, - $out - ); - } - - /** - * test inline language label as array - * - */ - public function testAddInlineLanguageLabelArray() { - - $expectedReturnValue = 'TYPO3.lang = {"myKey1":"myValue1","myKey2":"myValue2"}'; - $this->fixture->loadExtJS(); - $this->fixture->addInlineLanguageLabelArray(array('myKey1' => 'myValue1', 'myKey2' => 'myValue2',)); - $out = $this->fixture->enableMoveJsFromHeaderToFooter(); - $out = $this->fixture->render(t3lib_PageRenderer::PART_FOOTER); - - $this->assertContains( - $expectedReturnValue, - $out - ); - } - - /** - * test inline language label as array get merged - * - */ - public function testAddInlineLanguageLabelArrayMerged() { - - $expectedReturnValue = 'TYPO3.lang = {"myKey1":"myValue1","myKey2":"myValue2"}'; - $this->fixture->loadExtJS(); - $this->fixture->addInlineLanguageLabelArray(array('myKey1' => 'myValue1',)); - $this->fixture->addInlineLanguageLabelArray(array('myKey2' => 'myValue2',)); - $out = $this->fixture->enableMoveJsFromHeaderToFooter(); - $out = $this->fixture->render(t3lib_PageRenderer::PART_FOOTER); - - $this->assertContains( - $expectedReturnValue, - $out - ); - } - - /** - * test inline setting - * - */ - public function testAddInlineSetting() { - - $expectedReturnValue = 'TYPO3.settings = {"myApp":{"myKey":"myValue"}};'; - $this->fixture->loadExtJS(); - $this->fixture->addInlineSetting('myApp', 'myKey', 'myValue'); - $out = $this->fixture->enableMoveJsFromHeaderToFooter(); - $out = $this->fixture->render(t3lib_PageRenderer::PART_FOOTER); - - $this->assertContains( - $expectedReturnValue, - $out - ); - } - - /** - * test inline settings with array - * - */ - public function testAddInlineSettingArray() { - - $expectedReturnValue = 'TYPO3.settings = {"myApp":{"myKey1":"myValue1","myKey2":"myValue2"}};'; - $this->fixture->loadExtJS(); - $this->fixture->addInlineSettingArray('myApp', array('myKey1' => 'myValue1', 'myKey2' => 'myValue2',)); - $out = $this->fixture->enableMoveJsFromHeaderToFooter(); - $out = $this->fixture->render(t3lib_PageRenderer::PART_FOOTER); - - $this->assertContains( - $expectedReturnValue, - $out - ); - } - - /** - * test inline settings with array get merged - * - */ - public function testAddInlineSettingArrayMerged() { - - $expectedReturnValue = 'TYPO3.settings = {"myApp":{"myKey1":"myValue1","myKey2":"myValue2"}};'; - $this->fixture->loadExtJS(); - $this->fixture->addInlineSettingArray('myApp', array('myKey1' => 'myValue1',)); - $this->fixture->addInlineSettingArray('myApp', array('myKey2' => 'myValue2',)); - $out = $this->fixture->enableMoveJsFromHeaderToFooter(); - $out = $this->fixture->render(t3lib_PageRenderer::PART_FOOTER); - - $this->assertContains( - $expectedReturnValue, - $out - ); - } - - /** - * test add body content - * - */ - public function testAddBodyContent() { - $expectedReturnValue = 'ABCDE'; - $this->fixture->addBodyContent('A'); - $this->fixture->addBodyContent('B'); - $this->fixture->addBodyContent('C'); - $this->fixture->addBodyContent('D'); - $this->fixture->addBodyContent('E'); - - $out = $this->fixture->getBodyContent(); - $this->assertEquals( - $expectedReturnValue, - $out - ); - } - - - /** - * test set body content - * - */ - public function testSetBodyContent() { - $expectedReturnValue = 'ABCDE'; - $this->fixture->setBodyContent('ABCDE'); - - $out = $this->fixture->getBodyContent(); - $this->assertEquals( - $expectedReturnValue, - $out - ); - - $out = $this->fixture->render(); - - $this->assertContains( - $expectedReturnValue, - $out - ); - } - - /** - * Tests whether labels are delivered in a non-UTF-8 context. - * (background: json_encode() requires UTF-8 to work properly) - * - * @test - */ - public function isInlineLanguageLabelDeliveredWithNonUTF8() { - $testPrefix = uniqid('test'); - $this->fixture->loadExtCore(); - $this->fixture->setCharSet('iso-8859-1'); - $this->fixture->addInlineLanguageLabel($testPrefix, $testPrefix . "_\xd8"); - - $out = $this->fixture->render(); - - $this->assertContains($testPrefix . '_\\u00d8', $out); - } -} -?> \ No newline at end of file Index: tests/t3lib/t3lib_matchcondition_testcase.php =================================================================== --- tests/t3lib/t3lib_matchcondition_testcase.php (Revision 7835) +++ tests/t3lib/t3lib_matchcondition_testcase.php (Arbeitskopie) @@ -1,631 +0,0 @@ - -* All rights reserved -* -* This script is part of the TYPO3 project. The TYPO3 project is -* free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* The GNU General Public License can be found at -* http://www.gnu.org/copyleft/gpl.html. -* -* This script is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* This copyright notice MUST APPEAR in all copies of the script! -***************************************************************/ - - -/** - * Testcase for class t3lib_matchCondition. - * - * @author Oliver Hader - * @package TYPO3 - * @subpackage t3lib - */ -class t3lib_matchCondition_testcase extends tx_phpunit_testcase { - /** - * @var array - */ - private $backupGlobalVariables; - - /** - * @var array - */ - private $rootline; - - /** - * @var t3lib_matchCondition - */ - private $matchCondition; - - public function setUp() { - $this->backupGlobalVariables = array( - '_ENV' => $_ENV, - '_GET' => $_GET, - '_POST' => $_POST, - '_SERVER' => $_SERVER, - 'TYPO3_CONF_VARS' => $GLOBALS['TYPO3_CONF_VARS'], - 'T3_VAR' => $GLOBALS['T3_VAR'], - ); - - $GLOBALS['TYPO3_CONF_VARS']['SYS']['enableDeprecationLog'] = FALSE; - - $this->testGlobalNamespace = uniqid('TEST'); - $GLOBALS[$this->testGlobalNamespace] = array(); - - $this->setUpTSFE(); - $this->matchCondition = t3lib_div::makeInstance('t3lib_matchCondition'); - } - - public function tearDown() { - foreach ($this->backupGlobalVariables as $key => $data) { - $GLOBALS[$key] = $data; - } - - unset($this->matchCondition); - unset($this->backupGlobalVariables); - unset($GLOBALS[$this->testGlobalNamespace]); - } - - private function setUpTSFE() { - $this->rootline = array( - 2 => array('uid' => 121, 'pid' => 111), - 1 => array('uid' => 111, 'pid' => 101,), - 0 => array('uid' => 101, 'pid' => 0,), - ); - - $GLOBALS['TSFE'] = $this->getMock('tslib_fe', array(), array(), '', FALSE); - $GLOBALS['TSFE']->tmpl = $this->getMock('t3lib_TStemplate'); - } - - /** - * Tests whether a faulty expression fails. - * @test - */ - public function simulateDisabledMatchAllConditionsFailsOnFaultyExpression() { - $this->matchCondition->matchAll = false; - $this->assertFalse($this->matchCondition->match('[nullCondition = This expression would return false in general]')); - } - - /** - * Tests whether simulating positive matches for all conditions succeeds. - * @test - */ - public function simulateEnabledMatchAllConditionsSucceeds() { - $this->matchCondition->matchAll = true; - $this->assertTrue($this->matchCondition->match('[nullCondition = This expression would return false in general]')); - } - - /** - * Tests whether simulating positive matches for specific conditions succeeds. - * @test - */ - public function simulateEnabledMatchSpecificConditionsSucceeds() { - $testCondition = '[' . uniqid('test') . ' = Any condition to simulate a positive match]'; - $this->matchCondition->matchAlternative = array($testCondition); - $this->assertTrue($this->matchCondition->match($testCondition)); - } - - /** - * Tests whether a condition matches Internet Explorer 7 on Windows. - * - * @return void - * @test - */ - public function conditionMatchesInternetExplorer7Windows() { - $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)'; - $result = $this->matchCondition->match('[browser = msie] && [version = 7] && [system = winNT]'); - $this->assertTrue($result); - } - - /** - * Tests whether a condition does not match Internet Explorer 7 on Windows. - * - * @return void - * @test - */ - public function conditionDoesNotMatchInternetExplorer7Windows() { - $_SERVER['HTTP_USER_AGENT'] = 'Opera/9.25 (Windows NT 6.0; U; en)'; - $result = $this->matchCondition->match('[browser = msie] && [version = 7] && [system = winNT]'); - $this->assertFalse($result); - } - - /** - * Tests whether the browserInfo hook is called. - * - * @return void - * @test - */ - public function deprecatedBrowserInfoHookIsCalled() { - $classRef = uniqid('tx_browserInfoHook'); - $browserInfoHookMock = $this->getMock($classRef, array('browserInfo')); - $browserInfoHookMock->expects($this->atLeastOnce())->method('browserInfo'); - - $GLOBALS['T3_VAR']['getUserObj'][$classRef] = $browserInfoHookMock; - $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_matchcondition.php']['matchConditionClass'][$classRef] = $classRef; - - $this->matchCondition->__construct(); - $this->matchCondition->match('[browser = msie] && [version = 7] && [system = winNT]'); - } - - /** - * Tests whether a device type condition matches a crawler. - * @test - */ - public function deviceConditionMatchesRobot() { - $_SERVER['HTTP_USER_AGENT'] = 'Googlebot/2.1 (+http://www.google.com/bot.html)'; - $result = $this->matchCondition->match('[device = robot]'); - $this->assertTrue($result); - } - - /** - * Tests whether a device type condition does not match a crawler. - * @test - */ - public function deviceConditionDoesNotMatchRobot() { - $_SERVER['HTTP_USER_AGENT'] = md5('Some strange user agent'); - $result = $this->matchCondition->match('[device = robot]'); - $this->assertFalse($result); - } - - /** - * Tests whether the whichDevice hook is called. - * - * @return void - * @test - */ - public function deprecatedWhichDeviceHookIsCalled() { - $classRef = uniqid('tx_whichDeviceHook'); - $whichDeviceHookMock = $this->getMock($classRef, array('whichDevice')); - $whichDeviceHookMock->expects($this->atLeastOnce())->method('whichDevice'); - - $GLOBALS['T3_VAR']['getUserObj'][$classRef] = $whichDeviceHookMock; - $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_matchcondition.php']['matchConditionClass'][$classRef] = $classRef; - - $this->matchCondition->__construct(); - $this->matchCondition->match('[device = robot]'); - } - - /** - * Tests whether the language comparison matches. - * @test - */ - public function languageConditionMatchesSingleLanguageExpression() { - $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'de-de,de;q=0.8,en-us;q=0.5,en;q=0.3'; - $this->assertTrue($this->matchCondition->match('[language = *de*]')); - $this->assertTrue($this->matchCondition->match('[language = *de-de*]')); - } - - /** - * Tests whether the language comparison matches. - * @test - */ - public function languageConditionMatchesMultipleLanguagesExpression() { - $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'de-de,de;q=0.8,en-us;q=0.5,en;q=0.3'; - $this->assertTrue($this->matchCondition->match('[language = *en*,*de*]')); - $this->assertTrue($this->matchCondition->match('[language = *en-us*,*de-de*]')); - } - - /** - * Tests whether the language comparison matches. - * @test - */ - public function languageConditionMatchesCompleteLanguagesExpression() { - $this->markTestSkipped('This comparison seems to be incomplete in t3lib_matchCondition.'); - - $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'de-de,de;q=0.8,en-us;q=0.5,en;q=0.3'; - $this->assertTrue($this->matchCondition->match('[language = de-de,de;q=0.8]')); - } - - /** - * Tests whether usergroup comparison matches. - * @test - */ - public function usergroupConditionMatchesSingleGroupId() { - $GLOBALS['TSFE']->gr_list = '13,14,15'; - $this->assertTrue($this->matchCondition->match('[usergroup = 13]')); - } - - /** - * Tests whether usergroup comparison matches. - * @test - */ - public function usergroupConditionMatchesMultipleUserGroupId() { - $GLOBALS['TSFE']->gr_list = '13,14,15'; - $this->assertTrue($this->matchCondition->match('[usergroup = 999,15,14,13]')); - } - - /** - * Tests whether usergroup comparison matches. - * @test - */ - public function usergroupConditionDoesNotMatchDefaulUserGroupIds() { - $GLOBALS['TSFE']->gr_list = '0,-1'; - $this->assertFalse($this->matchCondition->match('[usergroup = 0,-1]')); - } - - /** - * Tests whether user comparison matches. - * @test - */ - public function loginUserConditionMatchesAnyLoggedInUser() { - $GLOBALS['TSFE']->loginUser = TRUE; - $GLOBALS['TSFE']->fe_user->user['uid'] = 13; - $this->assertTrue($this->matchCondition->match('[loginUser = *]')); - } - - /** - * Tests whether user comparison matches. - * @test - */ - public function loginUserConditionMatchesSingleLoggedInUser() { - $GLOBALS['TSFE']->loginUser = TRUE; - $GLOBALS['TSFE']->fe_user->user['uid'] = 13; - $this->assertTrue($this->matchCondition->match('[loginUser = 13]')); - } - - /** - * Tests whether user comparison matches. - * @test - */ - public function loginUserConditionMatchesMultipleLoggedInUsers() { - $GLOBALS['TSFE']->loginUser = TRUE; - $GLOBALS['TSFE']->fe_user->user['uid'] = 13; - $this->assertTrue($this->matchCondition->match('[loginUser = 999,13]')); - } - - /** - * Tests whether user comparison matches. - * @test - */ - public function loginUserConditionDoesNotMatchIfNotUserIsLoggedId() { - $GLOBALS['TSFE']->loginUser = FALSE; - $GLOBALS['TSFE']->fe_user->user['uid'] = 13; - $this->assertFalse($this->matchCondition->match('[loginUser = *]')); - $this->assertFalse($this->matchCondition->match('[loginUser = 13]')); - } - - /** - * Tests whether user is not logged in - * @test - */ - public function loginUserConditionMatchIfUserIsNotLoggedIn() { - $GLOBALS['TSFE']->loginUser = FALSE; - $this->assertTrue($this->matchCondition->match('[loginUser = ]')); - } - - /** - * Tests whether numerical comparison matches. - * @test - */ - public function globalVarConditionMatchesOnEqualExpression() { - $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 = 10]')); - $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 = 10.1]')); - - $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 == 10]')); - $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 == 10.1]')); - } - - /** - * Tests whether numerical comparison matches. - * @test - */ - public function globalVarConditionMatchesOnNotEqualExpression() { - $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 != 20]')); - $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 != 10.2]')); - } - - /** - * Tests whether numerical comparison matches. - * @test - */ - public function globalVarConditionMatchesOnLowerThanExpression() { - $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 < 20]')); - $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 < 10.2]')); - } - - /** - * Tests whether numerical comparison matches. - * @test - */ - public function globalVarConditionMatchesOnLowerThanOrEqualExpression() { - $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 <= 10]')); - $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 <= 20]')); - - $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 <= 10.1]')); - $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 <= 10.2]')); - } - - /** - * Tests whether numerical comparison matches. - * @test - */ - public function globalVarConditionMatchesOnGreaterThanExpression() { - $this->assertTrue($this->matchCondition->match('[globalVar = LIT:20 > 10]')); - $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.2 > 10.1]')); - } - - /** - * Tests whether numerical comparison matches. - * @test - */ - public function globalVarConditionMatchesOnGreaterThanOrEqualExpression() { - $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 >= 10]')); - $this->assertTrue($this->matchCondition->match('[globalVar = LIT:20 >= 10]')); - - $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 >= 10.1]')); - $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.2 >= 10.1]')); - } - - /** - * Tests whether numerical comparison matches. - * @test - */ - public function globalVarConditionMatchesOnEmptyExpressionWithNoValueSet() { - $testKey = uniqid('test'); - $this->assertTrue($this->matchCondition->match('[globalVar = GP:' . $testKey . '=]')); - $this->assertTrue($this->matchCondition->match('[globalVar = GP:' . $testKey . ' = ]')); - } - - /** - * Tests whether numerical comparison matches. - * @test - */ - public function globalVarConditionDoesNotMatchOnEmptyExpressionWithValueSetToZero() { - $testKey = uniqid('test'); - - $_GET = array(); - $_POST = array($testKey => 0); - - $this->assertFalse($this->matchCondition->match('[globalVar = GP:' . $testKey . '=]')); - $this->assertFalse($this->matchCondition->match('[globalVar = GP:' . $testKey . ' = ]')); - } - - /** - * Tests whether string comparison matches. - * @test - */ - public function globalStringConditionMatchesOnEqualExpression() { - $this->assertTrue($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = TYPO3.Test.Condition]')); - $this->assertFalse($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = TYPO3]')); - } - - /** - * Tests whether string comparison matches. - * @test - */ - public function globalStringConditionMatchesWildcardExpression() { - $this->assertTrue($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = TYPO3?Test?Condition]')); - $this->assertTrue($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = TYPO3.T*t.Condition]')); - $this->assertTrue($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = TYPO3?T*t?Condition]')); - } - - /** - * Tests whether string comparison matches. - * @test - */ - public function globalStringConditionMatchesRegularExpression() { - $this->assertTrue($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = /^[A-Za-z3.]+$/]')); - $this->assertTrue($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = /^TYPO3\..+Condition$/]')); - $this->assertFalse($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = /^FALSE/]')); - } - - /** - * Tests whether string comparison matches. - * @test - */ - public function globalStringConditionMatchesEmptyRegularExpression() { - $testKey = uniqid('test'); - $_SERVER[$testKey] = ''; - $this->assertTrue($this->matchCondition->match('[globalString = _SERVER|' . $testKey . ' = /^$/]')); - } - - /** - * Tests whether treeLevel comparison matches. - * @test - */ - public function treeLevelConditionMatchesSingleValue() { - $GLOBALS['TSFE']->tmpl->rootLine = $this->rootline; - $this->assertTrue($this->matchCondition->match('[treeLevel = 2]')); - } - - /** - * Tests whether treeLevel comparison matches. - * @test - */ - public function treeLevelConditionMatchesMultipleValues() { - $GLOBALS['TSFE']->tmpl->rootLine = $this->rootline; - $this->assertTrue($this->matchCondition->match('[treeLevel = 999,998,2]')); - } - - /** - * Tests whether treeLevel comparison matches. - * @test - */ - public function treeLevelConditionDoesNotMatchFaultyValue() { - $GLOBALS['TSFE']->tmpl->rootLine = $this->rootline; - $this->assertFalse($this->matchCondition->match('[treeLevel = 999]')); - } - - /** - * Tests whether a page Id is found in the previous rootline entries. - * @test - */ - public function PIDupinRootlineConditionMatchesSinglePageIdInRootline() { - $GLOBALS['TSFE']->tmpl->rootLine = $this->rootline; - $GLOBALS['TSFE']->id = 121; - $this->assertTrue($this->matchCondition->match('[PIDupinRootline = 111]')); - } - - /** - * Tests whether a page Id is found in the previous rootline entries. - * @test - */ - public function PIDupinRootlineConditionMatchesMultiplePageIdsInRootline() { - $GLOBALS['TSFE']->tmpl->rootLine = $this->rootline; - $GLOBALS['TSFE']->id = 121; - $this->assertTrue($this->matchCondition->match('[PIDupinRootline = 999,111,101]')); - } - - /** - * Tests whether a page Id is found in the previous rootline entries. - * @test - */ - public function PIDupinRootlineConditionDoesNotMatchPageIdNotInRootline() { - $GLOBALS['TSFE']->tmpl->rootLine = $this->rootline; - $GLOBALS['TSFE']->id = 121; - $this->assertFalse($this->matchCondition->match('[PIDupinRootline = 999]')); - } - - /** - * Tests whether a page Id is found in the previous rootline entries. - * @test - */ - public function PIDupinRootlineConditionDoesNotMatchLastPageIdInRootline() { - $GLOBALS['TSFE']->tmpl->rootLine = $this->rootline; - $GLOBALS['TSFE']->id = 121; - $this->assertFalse($this->matchCondition->match('[PIDupinRootline = 121]')); - } - - /** - * Tests whether a page Id is found in all rootline entries. - * @test - */ - public function PIDinRootlineConditionMatchesSinglePageIdInRootline() { - $GLOBALS['TSFE']->tmpl->rootLine = $this->rootline; - $GLOBALS['TSFE']->id = 121; - $this->assertTrue($this->matchCondition->match('[PIDinRootline = 111]')); - } - - /** - * Tests whether a page Id is found in all rootline entries. - * @test - */ - public function PIDinRootlineConditionMatchesMultiplePageIdsInRootline() { - $GLOBALS['TSFE']->tmpl->rootLine = $this->rootline; - $GLOBALS['TSFE']->id = 121; - $this->assertTrue($this->matchCondition->match('[PIDinRootline = 999,111,101]')); - } - - /** - * Tests whether a page Id is found in all rootline entries. - * @test - */ - public function PIDinRootlineConditionMatchesLastPageIdInRootline() { - $GLOBALS['TSFE']->tmpl->rootLine = $this->rootline; - $GLOBALS['TSFE']->id = 121; - $this->assertTrue($this->matchCondition->match('[PIDinRootline = 121]')); - } - - /** - * Tests whether a page Id is found in all rootline entries. - * @test - */ - public function PIDinRootlineConditionDoesNotMatchPageIdNotInRootline() { - $GLOBALS['TSFE']->tmpl->rootLine = $this->rootline; - $GLOBALS['TSFE']->id = 121; - $this->assertFalse($this->matchCondition->match('[PIDinRootline = 999]')); - } - - /** - * Tests whether the compatibility version can be evaluated. - * (e.g. 4.9 is compatible to 4.0 but not to 5.0) - * @test - */ - public function compatVersionConditionMatchesOlderRelease() { - $GLOBALS['TYPO3_CONF_VARS']['SYS']['compat_version'] = '4.9'; - $this->assertTrue($this->matchCondition->match('[compatVersion = 4.0]')); - } - - /** - * Tests whether the compatibility version can be evaluated. - * (e.g. 4.9 is compatible to 4.0 but not to 5.0) - * @test - */ - public function compatVersionConditionMatchesSameRelease() { - $GLOBALS['TYPO3_CONF_VARS']['SYS']['compat_version'] = '4.9'; - $this->assertTrue($this->matchCondition->match('[compatVersion = 4.9]')); - } - - /** - * Tests whether the compatibility version can be evaluated. - * (e.g. 4.9 is compatible to 4.0 but not to 5.0) - * @test - */ - public function compatVersionConditionDoesNotMatchNewerRelease() { - $GLOBALS['TYPO3_CONF_VARS']['SYS']['compat_version'] = '4.9'; - $this->assertFalse($this->matchCondition->match('[compatVersion = 5.0]')); - } - - /** - * Tests whether the gneric fetching of variables works with the namespace 'GP'. - * @test - */ - public function genericGetVariablesSucceedsWithNamespaceGP() { - $_GET = array('testGet' => 'getTest'); - $_POST = array('testPost' => 'postTest'); - - $this->assertTrue($this->matchCondition->match('[globalString = GP:testGet = getTest]')); - $this->assertTrue($this->matchCondition->match('[globalString = GP:testPost = postTest]')); - } - - /** - * Tests whether the gneric fetching of variables works with the namespace 'TSFE'. - * @test - */ - public function genericGetVariablesSucceedsWithNamespaceTSFE() { - $GLOBALS['TSFE']->id = 1234567; - $GLOBALS['TSFE']->testSimpleObject = new stdClass(); - $GLOBALS['TSFE']->testSimpleObject->testSimpleVariable = 'testValue'; - - $this->assertTrue($this->matchCondition->match('[globalString = TSFE:id = 1234567]')); - $this->assertTrue($this->matchCondition->match('[globalString = TSFE:testSimpleObject|testSimpleVariable = testValue]')); - } - - /** - * Tests whether the gneric fetching of variables works with the namespace 'ENV'. - * @test - */ - public function genericGetVariablesSucceedsWithNamespaceENV() { - $testKey = uniqid('test'); - putenv($testKey .'=testValue'); - - $this->assertTrue($this->matchCondition->match('[globalString = ENV:' . $testKey . ' = testValue]')); - } - - /** - * Tests whether the gneric fetching of variables works with the namespace 'IENV'. - * @test - */ - public function genericGetVariablesSucceedsWithNamespaceIENV() { - $_SERVER['HTTP_HOST'] = t3lib_div::getIndpEnv('TYPO3_HOST_ONLY') . ':1234567'; - $this->assertTrue($this->matchCondition->match('[globalString = IENV:TYPO3_PORT = 1234567]')); - } - - /** - * Tests whether the gneric fetching of variables works with any global namespace. - * @test - */ - public function genericGetVariablesSucceedsWithAnyGlobalNamespace() { - $GLOBALS[$this->testGlobalNamespace] = array( - 'first' => 'testFirst', - 'second' => array('third' => 'testThird'), - ); - - $this->assertTrue($this->matchCondition->match( - '[globalString = ' . $this->testGlobalNamespace . '|first = testFirst]' - )); - $this->assertTrue($this->matchCondition->match( - '[globalString = ' . $this->testGlobalNamespace . '|second|third = testThird]' - )); - } -} -?> \ No newline at end of file Index: tests/t3lib/t3lib_extmgmTest.php =================================================================== --- tests/t3lib/t3lib_extmgmTest.php (Revision 7835) +++ tests/t3lib/t3lib_extmgmTest.php (Arbeitskopie) @@ -31,7 +31,7 @@ * @package TYPO3 * @subpackage t3lib */ -class t3lib_extmgm_testcase extends tx_phpunit_testcase { +class t3lib_extmgmTest extends tx_phpunit_testcase { /** * backup of defined GLOBALS * Index: tests/t3lib/t3lib_befuncTest.php =================================================================== --- tests/t3lib/t3lib_befuncTest.php (Revision 7835) +++ tests/t3lib/t3lib_befuncTest.php (Arbeitskopie) @@ -32,7 +32,7 @@ * * @author Oliver Klee */ -class t3lib_befunc_testcase extends tx_phpunit_testcase { +class t3lib_befuncTest extends tx_phpunit_testcase { /** * @var t3lib_BEfunc */ Index: tests/t3lib/t3lib_matchconditionTest.php =================================================================== --- tests/t3lib/t3lib_matchconditionTest.php (Revision 7835) +++ tests/t3lib/t3lib_matchconditionTest.php (Arbeitskopie) @@ -30,7 +30,7 @@ * @package TYPO3 * @subpackage t3lib */ -class t3lib_matchCondition_testcase extends tx_phpunit_testcase { +class t3lib_matchConditionTest extends tx_phpunit_testcase { /** * @var array */ Index: tests/t3lib/t3lib_registry_testcase.php =================================================================== --- tests/t3lib/t3lib_registry_testcase.php (Revision 7835) +++ tests/t3lib/t3lib_registry_testcase.php (Arbeitskopie) @@ -1,356 +0,0 @@ - -* All rights reserved -* -* This script is part of the TYPO3 project. The TYPO3 project is -* free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* The GNU General Public License can be found at -* http://www.gnu.org/copyleft/gpl.html. -* -* This script is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* This copyright notice MUST APPEAR in all copies of the script! -***************************************************************/ - - -/** - * Testcase for class t3lib_Registry - * - * @author Bastian Waidelich - * @package TYPO3 - * @subpackage t3lib - */ -class t3lib_Registry_testcase extends tx_phpunit_testcase { - - /** - * @var t3lib_Registry - */ - protected $registry; - - /** - * @var t3lib_DB - */ - protected $typo3DbBackup; - - /** - * Sets up this testcase - */ - public function setUp() { - $this->typo3DbBackup = $GLOBALS['TYPO3_DB']; - $GLOBALS['TYPO3_DB'] = $this->getMock('t3lib_DB', array()); - $GLOBALS['TYPO3_DB']->expects($this->any()) - ->method('fullQuoteStr') - ->will($this->onConsecutiveCalls('\'tx_phpunit\'', '\'someKey\'', '\'tx_phpunit\'', '\'someKey\'')); - - $this->registry = new t3lib_Registry(); - } - - /** - * Tears down this testcase - */ - public function tearDown() { - $GLOBALS['TYPO3_DB'] = $this->typo3DbBackup; - } - - /** - * @test - * @expectedException InvalidArgumentException - */ - public function getThrowsExceptionForInvalidNamespaces() { - $this->registry->get('invalidNamespace', 'someKey'); - } - - /** - * @test - */ - public function getRetrievesTheCorrectEntry() { - $testKey = 't3lib_Registry_testcase.testData.getRetrievesTheCorrectEntry'; - $testValue = 'getRetrievesTheCorrectEntry'; - - $GLOBALS['TYPO3_DB']->expects($this->once()) - ->method('exec_SELECTgetRows') - ->with('*', 'sys_registry', 'entry_namespace = \'tx_phpunit\'') - ->will( - $this->returnValue( - array( - array('entry_key' => $testKey, 'entry_value' => serialize($testValue)) - ) - ) - ); - - $this->assertEquals( - $this->registry->get('tx_phpunit', $testKey), - $testValue, - 'The actual data did not match the expected data.' - ); - } - - /** - * @test - */ - public function getLazyLoadsEntriesOfOneNamespace() { - $testKey1 = 't3lib_Registry_testcase.testData.getLazyLoadsEntriesOfOneNamespace1'; - $testValue1 = 'getLazyLoadsEntriesOfOneNamespace1'; - $testKey2 = 't3lib_Registry_testcase.testData.getLazyLoadsEntriesOfOneNamespace2'; - $testValue2 = 'getLazyLoadsEntriesOfOneNamespace2'; - - $GLOBALS['TYPO3_DB']->expects($this->once()) - ->method('exec_SELECTgetRows') - ->with('*', 'sys_registry', 'entry_namespace = \'tx_phpunit\'') - ->will( - $this->returnValue( - array( - array('entry_key' => $testKey1, 'entry_value' => serialize($testValue1)), - array('entry_key' => $testKey2, 'entry_value' => serialize($testValue2)) - ) - ) - ); - - $this->assertEquals( - $this->registry->get('tx_phpunit', $testKey1), - $testValue1, - 'The actual data did not match the expected data.' - ); - $this->assertEquals( - $this->registry->get('tx_phpunit', $testKey2), - $testValue2, - 'The actual data did not match the expected data.' - ); - } - - /** - * @test - */ - public function getReturnsTheDefaultValueIfTheRequestedKeyWasNotFound() { - $defaultValue = 'getReturnsTheDefaultValueIfTheRequestedKeyWasNotFound'; - - $GLOBALS['TYPO3_DB']->expects($this->once()) - ->method('exec_SELECTgetRows') - ->with('*', 'sys_registry', 'entry_namespace = \'tx_phpunit\'') - ->will( - $this->returnValue( - array( - array('entry_key' => 'foo', 'entry_value' => 'bar'), - ) - ) - ); - - $this->assertEquals( - $defaultValue, - $this->registry->get('tx_phpunit', 'someNonExistingKey', $defaultValue), - 'A value other than the default value was returned.' - ); - } - - /** - * @test - * @expectedException InvalidArgumentException - */ - public function setThrowsAnExceptionOnEmptyNamespace() { - $this->registry->set('', 'someKey', 'someValue'); - } - - /** - * @test - * @expectedException InvalidArgumentException - */ - public function setThrowsAnExceptionOnWrongNamespace() { - $this->registry->set('invalidNamespace', 'someKey', 'someValue'); - } - - /** - * @test - */ - public function setAllowsValidNamespaces() { - $this->registry->set('tx_thisIsValid', 'someKey', 'someValue'); - $this->registry->set('user_soIsThis', 'someKey', 'someValue'); - $this->registry->set('core', 'someKey', 'someValue'); - } - - /** - * @test - */ - public function setReallySavesTheGivenValueToTheDatabase() { - $GLOBALS['TYPO3_DB']->expects($this->once()) - ->method('exec_INSERTquery') - ->with( - 'sys_registry', - array( - 'entry_namespace' => 'tx_phpunit', - 'entry_key' => 'someKey', - 'entry_value' => serialize('someValue') - ) - ); - - $this->registry->set('tx_phpunit', 'someKey', 'someValue'); - } - - /** - * @test - */ - public function setUpdatesExistingKeys() { - $GLOBALS['TYPO3_DB']->expects($this->once()) - ->method('exec_SELECTquery') - ->with( - 'uid', - 'sys_registry', - 'entry_namespace = \'tx_phpunit\' AND entry_key = \'someKey\'' - ) - ->will( - $this->returnValue('DBResource') - ); - - $GLOBALS['TYPO3_DB']->expects($this->once()) - ->method('sql_num_rows') - ->with('DBResource') - ->will( - $this->returnValue(1) - ); - - $GLOBALS['TYPO3_DB']->expects($this->once()) - ->method('exec_UPDATEquery') - ->with( - 'sys_registry', - 'entry_namespace = \'tx_phpunit\' AND entry_key = \'someKey\'', - array( - 'entry_value' => serialize('someValue') - ) - ); - - $GLOBALS['TYPO3_DB']->expects($this->never()) - ->method('exec_INSERTquery'); - - $this->registry->set('tx_phpunit', 'someKey', 'someValue'); - } - - /** - * @test - */ - public function setStoresValueInTheInternalEntriesCache() { - $registry = $this->getMock('t3lib_Registry', array('loadEntriesByNamespace')); - $registry->expects($this->never()) - ->method('loadEntriesByNamespace'); - - $registry->set('tx_phpunit', 'someKey', 'someValue'); - - $this->assertEquals( - 'someValue', - $registry->get('tx_phpunit', 'someKey'), - 'The actual data did not match the expected data.' - ); - } - - /** - * @test - * @expectedException InvalidArgumentException - */ - public function removeThrowsAnExceptionOnWrongNamespace() { - $this->registry->remove('coreInvalid', 'someKey'); - } - - /** - * @test - */ - public function removeReallyRemovesTheEntryFromTheDatabase() { - $GLOBALS['TYPO3_DB']->expects($this->once()) - ->method('exec_DELETEquery') - ->with( - 'sys_registry', - 'entry_namespace = \'tx_phpunit\' AND entry_key = \'someKey\'' - ); - - $this->registry->remove('tx_phpunit', 'someKey'); - } - - /** - * @test - */ - public function removeUnsetsValueFromTheInternalEntriesCache() { - $registry = $this->getMock('t3lib_Registry', array('loadEntriesByNamespace')); - $registry->set('tx_phpunit', 'someKey', 'someValue'); - $registry->set('tx_phpunit', 'someOtherKey', 'someOtherValue'); - $registry->set('tx_otherNamespace', 'someKey', 'someValueInOtherNamespace'); - $registry->remove('tx_phpunit', 'someKey'); - - $this->assertEquals( - 'defaultValue', - $registry->get('tx_phpunit', 'someKey', 'defaultValue'), - 'A value other than the default value was returned, thus the entry was still present.' - ); - - $this->assertEquals( - 'someOtherValue', - $registry->get('tx_phpunit', 'someOtherKey', 'defaultValue'), - 'A value other than the stored value was returned, thus the entry was removed.' - ); - - $this->assertEquals( - 'someValueInOtherNamespace', - $registry->get('tx_otherNamespace', 'someKey', 'defaultValue'), - 'A value other than the stored value was returned, thus the entry was removed.' - ); - } - - /** - * @test - * @expectedException InvalidArgumentException - */ - public function removeAllByNamespaceThrowsAnExceptionOnWrongNamespace() { - $this->registry->removeAllByNamespace(''); - } - - /** - * @test - */ - public function removeAllByNamespaceReallyRemovesAllEntriesOfTheSpecifiedNamespaceFromTheDatabase() { - $GLOBALS['TYPO3_DB']->expects($this->once()) - ->method('exec_DELETEquery') - ->with( - 'sys_registry', - 'entry_namespace = \'tx_phpunit\'' - ); - - $this->registry->removeAllByNamespace('tx_phpunit'); - } - - /** - * @test - */ - public function removeAllByNamespaceUnsetsValuesOfTheSpecifiedNamespaceFromTheInternalEntriesCache() { - $registry = $this->getMock('t3lib_Registry', array('loadEntriesByNamespace')); - $registry->set('tx_phpunit', 'someKey', 'someValue'); - $registry->set('tx_phpunit', 'someOtherKey', 'someOtherValue'); - $registry->set('tx_otherNamespace', 'someKey', 'someValueInOtherNamespace'); - $registry->removeAllByNamespace('tx_phpunit'); - - $this->assertEquals( - 'defaultValue', - $registry->get('tx_phpunit', 'someKey', 'defaultValue'), - 'A value other than the default value was returned, thus the entry was still present.' - ); - - $this->assertEquals( - 'defaultValue', - $registry->get('tx_phpunit', 'someOtherKey', 'defaultValue'), - 'A value other than the default value was returned, thus the entry was still present.' - ); - - $this->assertEquals( - 'someValueInOtherNamespace', - $registry->get('tx_otherNamespace', 'someKey', 'defaultValue'), - 'A value other than the stored value was returned, thus the entry was removed.' - ); - } -} - -?> \ No newline at end of file Index: tests/t3lib/t3lib_pagerendererTest.php =================================================================== --- tests/t3lib/t3lib_pagerendererTest.php (Revision 7835) +++ tests/t3lib/t3lib_pagerendererTest.php (Arbeitskopie) @@ -31,7 +31,7 @@ * * @author Steffen Kamper (info@sk-typo3.de) */ -class t3lib_PageRenderer_testcase extends tx_phpunit_testcase { +class t3lib_PageRendererTest extends tx_phpunit_testcase { /** * @var t3lib_PageRenderer */ Index: tests/t3lib/t3lib_pageselect_testcase.php =================================================================== --- tests/t3lib/t3lib_pageselect_testcase.php (Revision 7835) +++ tests/t3lib/t3lib_pageselect_testcase.php (Arbeitskopie) @@ -1,114 +0,0 @@ - -* All rights reserved -* -* This script is part of the TYPO3 project. The TYPO3 project is -* free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* The GNU General Public License can be found at -* http://www.gnu.org/copyleft/gpl.html. -* -* This script is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* This copyright notice MUST APPEAR in all copies of the script! -***************************************************************/ - - -/** - * Testcase for class t3lib_page - * - * @author Christian Kuhn - * @package TYPO3 - * @subpackage t3lib - */ -class t3lib_pageselect_testcase extends tx_phpunit_testcase { - - /** - * @var t3lib_DB - */ - protected $typo3DbBackup; - - /** - * @var t3lib_pageSelect - */ - protected $pageSelectObject; - - /** - * Sets up this testcase - */ - public function setUp() { - $this->typo3DbBackup = $GLOBALS['TYPO3_DB']; - $GLOBALS['TYPO3_DB'] = $this->getMock('t3lib_DB', array('exec_SELECTquery', 'sql_fetch_assoc', 'sql_free_result')); - - $this->pageSelectObject = new t3lib_pageSelect(); - } - - /** - * Tears down this testcase - */ - public function tearDown() { - $GLOBALS['TYPO3_DB'] = $this->typo3DbBackup; - } - - /** - * Tests whether the getPage Hook is called correctly. - * - * @test - */ - public function isGetPageHookCalled() { - // Create a hook mock object - $className = uniqid('tx_coretest'); - $getPageHookMock = $this->getMock( - 't3lib_pageSelect_getPageHook', - array('getPage_preProcess'), - array(), - $className - ); - - // Register hook mock object - $GLOBALS['T3_VAR']['getUserObj'][$className] = $getPageHookMock; - $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_page.php']['getPage'][] = $className; - - // Test if hook is called and register a callback method to check given arguments - $getPageHookMock->expects($this->once())->method('getPage_preProcess') - ->will($this->returnCallback(array($this, 'isGetPagePreProcessCalledCallback'))); - - $this->pageSelectObject->getPage(42, FALSE); - } - - /** - * Handles the arguments that have been sent to the getPage_preProcess hook - */ - public function isGetPagePreProcessCalledCallback() { - list($uid, $disableGroupAccessCheck, $parent) = func_get_args(); - - $this->assertEquals(42, $uid); - $this->assertFalse($disableGroupAccessCheck); - $this->assertTrue($parent instanceof t3lib_pageSelect); - } - - - ///////////////////////////////////////// - // Tests concerning getPathFromRootline - ///////////////////////////////////////// - - /** - * @test - */ - public function getPathFromRootLineForEmptyRootLineReturnsEmptyString() { - $this->assertEquals( - '', - $this->pageSelectObject->getPathFromRootline(array()) - ); - } -} -?> Index: tests/t3lib/t3lib_registryTest.php =================================================================== --- tests/t3lib/t3lib_registryTest.php (Revision 7835) +++ tests/t3lib/t3lib_registryTest.php (Arbeitskopie) @@ -30,7 +30,7 @@ * @package TYPO3 * @subpackage t3lib */ -class t3lib_Registry_testcase extends tx_phpunit_testcase { +class t3lib_RegistryTest extends tx_phpunit_testcase { /** * @var t3lib_Registry @@ -74,7 +74,7 @@ * @test */ public function getRetrievesTheCorrectEntry() { - $testKey = 't3lib_Registry_testcase.testData.getRetrievesTheCorrectEntry'; + $testKey = 't3lib_RegistryTest.testData.getRetrievesTheCorrectEntry'; $testValue = 'getRetrievesTheCorrectEntry'; $GLOBALS['TYPO3_DB']->expects($this->once()) @@ -99,9 +99,9 @@ * @test */ public function getLazyLoadsEntriesOfOneNamespace() { - $testKey1 = 't3lib_Registry_testcase.testData.getLazyLoadsEntriesOfOneNamespace1'; + $testKey1 = 't3lib_RegistryTest.testData.getLazyLoadsEntriesOfOneNamespace1'; $testValue1 = 'getLazyLoadsEntriesOfOneNamespace1'; - $testKey2 = 't3lib_Registry_testcase.testData.getLazyLoadsEntriesOfOneNamespace2'; + $testKey2 = 't3lib_RegistryTest.testData.getLazyLoadsEntriesOfOneNamespace2'; $testValue2 = 'getLazyLoadsEntriesOfOneNamespace2'; $GLOBALS['TYPO3_DB']->expects($this->once()) Index: tests/t3lib/t3lib_tcemain_testcase.php =================================================================== --- tests/t3lib/t3lib_tcemain_testcase.php (Revision 7835) +++ tests/t3lib/t3lib_tcemain_testcase.php (Arbeitskopie) @@ -1,233 +0,0 @@ - - */ -class t3lib_tcemain_testcase extends tx_phpunit_testcase { - /** - * @var boolean - */ - protected $backupGlobals = true; - - /** - * @var t3lib_TCEmain - */ - private $fixture; - - /** - * @var t3lib_beUserAuth a mock logged-in back-end user - */ - private $backEndUser; - - public function setUp() { - $this->backEndUser = $this->getMock('t3lib_beUserAuth'); - - $this->fixture = new t3lib_TCEmain(); - $this->fixture->start(array(), '', $this->backEndUser); - } - - public function tearDown() { - unset( - $this->fixture->BE_USER, $this->fixture, $this->backEndUser - ); - } - - - ////////////////////////////////////// - // Tests for the basic functionality - ////////////////////////////////////// - - /** - * @test - */ - public function fixtureCanBeCreated() { - $this->assertTrue( - $this->fixture instanceof t3lib_TCEmain - ); - } - - - ////////////////////////////////////////// - // Test concerning checkModifyAccessList - ////////////////////////////////////////// - - /** - * @test - */ - public function adminIsAllowedToModifyNonAdminTable() { - $this->fixture->admin = true; - - $this->assertTrue( - $this->fixture->checkModifyAccessList('tt_content') - ); - } - - /** - * @test - */ - public function nonAdminIsNorAllowedToModifyNonAdminTable() { - $this->fixture->admin = false; - - $this->assertFalse( - $this->fixture->checkModifyAccessList('tt_content') - ); - } - - /** - * @test - */ - public function nonAdminWithTableModifyAccessIsAllowedToModifyNonAdminTable() { - $this->fixture->admin = false; - $this->backEndUser->groupData['tables_modify'] = 'tt_content'; - - $this->assertTrue( - $this->fixture->checkModifyAccessList('tt_content') - ); - } - - /** - * @test - */ - public function adminIsAllowedToModifyAdminTable() { - $this->fixture->admin = true; - - $this->assertTrue( - $this->fixture->checkModifyAccessList('be_users') - ); - } - - /** - * @test - */ - public function nonAdminIsNotAllowedToModifyAdminTable() { - $this->fixture->admin = false; - - $this->assertFalse( - $this->fixture->checkModifyAccessList('be_users') - ); - } - - /** - * @test - */ - public function nonAdminWithTableModifyAccessIsNotAllowedToModifyAdminTable() { - $this->fixture->admin = false; - $this->backEndUser->groupData['tables_modify'] = 'be_users'; - - $this->assertFalse( - $this->fixture->checkModifyAccessList('be_users') - ); - } - - /** - * @test - */ - public function evalCheckValueDouble2() { - $testData = array ( - '-0,5' => '-0.50', - '1000' => '1000.00', - '1000,10' => '1000.10', - '1000,0' => '1000.00', - '600.000.000,00' => '600000000.00', - '60aaa00' => '6000.00', - ); - foreach ($testData as $value => $expectedReturnValue){ - $returnValue = $this->fixture->checkValue_input_Eval($value, array('double2'), ''); - $this->assertSame( - $returnValue['value'], - $expectedReturnValue - ); - } - } - - - /////////////////////////////////////////// - // Tests concerning checkModifyAccessList - /////////////////////////////////////////// - - /** - * Tests whether a wrong interface on the 'checkModifyAccessList' hook throws an exception. - * @test - * @expectedException UnexpectedValueException - * @see t3lib_TCEmain::checkModifyAccessList() - */ - public function doesCheckModifyAccessListThrowExceptionOnWrongHookInterface() { - $hookClass = uniqid('tx_coretest'); - eval('class ' . $hookClass . ' {}'); - - $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['checkModifyAccessList'][] = $hookClass; - - $this->fixture->checkModifyAccessList('tt_content'); - } - - /** - * Tests whether the 'checkModifyAccessList' hook is called correctly. - * @test - * @see t3lib_TCEmain::checkModifyAccessList() - */ - public function doesCheckModifyAccessListHookGetsCalled() { - $hookClass = uniqid('tx_coretest'); - $hookMock = $this->getMock( - 't3lib_TCEmain_checkModifyAccessListHook', - array('checkModifyAccessList'), - array(), - $hookClass - ); - $hookMock->expects($this->once())->method('checkModifyAccessList'); - - $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['checkModifyAccessList'][] = $hookClass; - $GLOBALS['T3_VAR']['getUserObj'][$hookClass] = $hookMock; - - $this->fixture->checkModifyAccessList('tt_content'); - } - - /** - * Tests whether the 'checkModifyAccessList' hook modifies the $accessAllowed variable. - * @test - * @see t3lib_TCEmain::checkModifyAccessList() - */ - public function doesCheckModifyAccessListHookModifyAccessAllowed() { - $hookClass = uniqid('tx_coretest'); - eval(' - class ' . $hookClass . ' implements t3lib_TCEmain_checkModifyAccessListHook { - public function checkModifyAccessList(&$accessAllowed, $table, t3lib_TCEmain $parent) { $accessAllowed = true; } - } - '); - - $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['checkModifyAccessList'][] = $hookClass; - - $this->assertTrue($this->fixture->checkModifyAccessList('tt_content')); - } -} -?> Index: tests/t3lib/t3lib_pageselectTest.php =================================================================== --- tests/t3lib/t3lib_pageselectTest.php (Revision 7835) +++ tests/t3lib/t3lib_pageselectTest.php (Arbeitskopie) @@ -30,7 +30,7 @@ * @package TYPO3 * @subpackage t3lib */ -class t3lib_pageselect_testcase extends tx_phpunit_testcase { +class t3lib_pageselectTest extends tx_phpunit_testcase { /** * @var t3lib_DB Index: tests/t3lib/t3lib_div_testcase.php =================================================================== --- tests/t3lib/t3lib_div_testcase.php (Revision 7835) +++ tests/t3lib/t3lib_div_testcase.php (Arbeitskopie) @@ -1,1401 +0,0 @@ - -* All rights reserved -* -* This script is part of the TYPO3 project. The TYPO3 project is -* free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* The GNU General Public License can be found at -* http://www.gnu.org/copyleft/gpl.html. -* -* This script is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* This copyright notice MUST APPEAR in all copies of the script! -***************************************************************/ - - -/** - * Testcase for class t3lib_div - * - * @author Ingo Renner - * @author Oliver Klee - * - * @package TYPO3 - * @subpackage t3lib - */ -class t3lib_div_testcase extends tx_phpunit_testcase { - /** - * backup of the global variables _GET, _POST, _SERVER - * - * @var array - */ - private $backupGlobalVariables; - - public function setUp() { - $this->backupGlobalVariables = array( - '_GET' => $_GET, - '_POST' => $_POST, - '_SERVER' => $_SERVER, - 'TYPO3_CONF_VARS' => $GLOBALS['TYPO3_CONF_VARS'], - ); - } - - public function tearDown() { - foreach ($this->backupGlobalVariables as $key => $data) { - $GLOBALS[$key] = $data; - } - } - - - /** - * @test - */ - public function calcPriorityCalculatesBasicArithmeticOperation() { - $this->assertEquals(9, t3lib_div::calcPriority('6 + 3')); - $this->assertEquals(3, t3lib_div::calcPriority('6 - 3')); - $this->assertEquals(-3, t3lib_div::calcPriority('3 - 6')); - $this->assertEquals(6, t3lib_div::calcPriority('2 * 3')); - $this->assertEquals(2.5, t3lib_div::calcPriority('5 / 2')); - $this->assertEquals(1, t3lib_div::calcPriority('5 % 2')); - $this->assertEquals(8, t3lib_div::calcPriority('2 ^ 3')); - } - - /** - * @test - */ - public function calcPriorityCalculatesArithmeticOperationWithMultipleOperands() { - $this->assertEquals(6.5, t3lib_div::calcPriority('5 + 3 / 2')); - $this->assertEquals(14, t3lib_div::calcPriority('5 + 3 ^ 2')); - $this->assertEquals(4, t3lib_div::calcPriority('5 % 2 + 3')); - $this->assertEquals(3, t3lib_div::calcPriority('2 + 6 / 2 - 2')); - } - - /** - * @test - */ - public function checkIntExplodeConvertsStringsToInteger() { - $testString = '1,foo,2'; - $expectedArray = array(1, 0, 2); - $actualArray = t3lib_div::intExplode(',', $testString); - - $this->assertEquals($expectedArray, $actualArray); - } - - /** - * @test - */ - public function checkRevExplodeCorrectlyExplodesString() { - $testString = 'my:words:here'; - $expectedArray = array('my:words', 'here'); - $actualArray = t3lib_div::revExplode(':', $testString, 2); - - $this->assertEquals($expectedArray, $actualArray); - } - - /** - * @test - */ - public function checkTrimExplodeTrimsSpacesAtElementStartAndEnd() { - $testString = ' a , b , c ,d ,, e,f,'; - $expectedArray = array('a', 'b', 'c', 'd', '', 'e', 'f', ''); - $actualArray = t3lib_div::trimExplode(',', $testString); - - $this->assertEquals($expectedArray, $actualArray); - } - - /** - * @test - */ - public function checkTrimExplodeRemovesNewLines() { - $testString = ' a , b , ' . LF . ' ,d ,, e,f,'; - $expectedArray = array('a', 'b', 'd', 'e', 'f'); - $actualArray = t3lib_div::trimExplode(',', $testString, true); - - $this->assertEquals($expectedArray, $actualArray); - } - - /** - * @test - */ - public function checkTrimExplodeRemovesEmptyElements() { - $testString = 'a , b , c , ,d ,, ,e,f,'; - $expectedArray = array('a', 'b', 'c', 'd', 'e', 'f'); - $actualArray = t3lib_div::trimExplode(',', $testString, true); - - $this->assertEquals($expectedArray, $actualArray); - } - - /** - * @test - */ - public function checkTrimExplodeKeepsRemainingResultsWithEmptyItemsAfterReachingLimitWithPositiveParameter() { - $testString = ' a , b , c , , d,, ,e '; - $expectedArray = array('a', 'b', 'c,,d,,,e'); // limiting returns the rest of the string as the last element - $actualArray = t3lib_div::trimExplode(',', $testString, false, 3); - - $this->assertEquals($expectedArray, $actualArray); - } - - /** - * @test - */ - public function checkTrimExplodeKeepsRemainingResultsWithoutEmptyItemsAfterReachingLimitWithPositiveParameter() { - $testString = ' a , b , c , , d,, ,e '; - $expectedArray = array('a', 'b', 'c,d,e'); // limiting returns the rest of the string as the last element - $actualArray = t3lib_div::trimExplode(',', $testString, true, 3); - - $this->assertEquals($expectedArray, $actualArray); - } - - /** - * @test - */ - public function checkTrimExplodeKeepsRamainingResultsWithEmptyItemsAfterReachingLimitWithNegativeParameter() { - $testString = ' a , b , c , d, ,e, f , , '; - $expectedArray = array('a', 'b', 'c', 'd', '', 'e'); // limiting returns the rest of the string as the last element - $actualArray = t3lib_div::trimExplode(',', $testString, false, -3); - - $this->assertEquals($expectedArray, $actualArray); - } - - /** - * @test - */ - public function checkTrimExplodeKeepsRamainingResultsWithoutEmptyItemsAfterReachingLimitWithNegativeParameter() { - $testString = ' a , b , c , d, ,e, f , , '; - $expectedArray = array('a', 'b', 'c'); // limiting returns the rest of the string as the last element - $actualArray = t3lib_div::trimExplode(',', $testString, true, -3); - - $this->assertEquals($expectedArray, $actualArray); - } - - /** - * @test - */ - public function checkTrimExplodeReturnsExactResultsWithoutReachingLimitWithPositiveParameter() { - $testString = ' a , b , , c , , , '; - $expectedArray = array('a', 'b', 'c'); // limiting returns the rest of the string as the last element - $actualArray = t3lib_div::trimExplode(',', $testString, true, 4); - - $this->assertEquals($expectedArray, $actualArray); - } - - /** - * @test - */ - public function checkTrimExplodeKeepsZeroAsString() { - $testString = 'a , b , c , ,d ,, ,e,f, 0 ,'; - $expectedArray = array('a', 'b', 'c', 'd', 'e', 'f', '0'); - $actualArray = t3lib_div::trimExplode(',', $testString, true); - - $this->assertEquals($expectedArray, $actualArray); - } - - /** - * Checks whether measurement strings like "100k" return the accordant - * byte representation like 102400 in this case. - * - * @test - */ - public function checkGetBytesFromSizeMeasurement() { - $this->assertEquals( - '102400', - t3lib_div::getBytesFromSizeMeasurement('100k') - ); - - $this->assertEquals( - '104857600', - t3lib_div::getBytesFromSizeMeasurement('100m') - ); - - $this->assertEquals( - '107374182400', - t3lib_div::getBytesFromSizeMeasurement('100g') - ); - } - - /** - * @test - */ - public function checkIndpEnvTypo3SitePathNotEmpty() { - $actualEnv = t3lib_div::getIndpEnv('TYPO3_SITE_PATH'); - $this->assertTrue(strlen($actualEnv) >= 1); - $this->assertEquals('/', $actualEnv{0}); - $this->assertEquals('/', $actualEnv{strlen($actualEnv) - 1}); - } - - /** - * @test - * @see t3lib_div::underscoredToUpperCamelCase - */ - public function canConvertFromUnderscoredToUpperCamelCase() { - $this->assertEquals('BlogExample', t3lib_div::underscoredToUpperCamelCase('blog_example')); - $this->assertEquals('Blogexample', t3lib_div::underscoredToUpperCamelCase('blogexample')); - } - - /** - * @test - * @see t3lib_div::underscoredToLowerCamelCase - */ - public function canConvertFromUnderscoredToLowerCamelCase() { - $this->assertEquals('minimalValue', t3lib_div::underscoredToLowerCamelCase('minimal_value')); - $this->assertEquals('minimalvalue', t3lib_div::underscoredToLowerCamelCase('minimalvalue')); - } - - /** - * @test - * @see t3lib_div::camelCaseToLowerCaseUnderscored - */ - public function canConvertFromCamelCaseToLowerCaseUnderscored() { - $this->assertEquals('blog_example', t3lib_div::camelCaseToLowerCaseUnderscored('BlogExample')); - $this->assertEquals('blogexample', t3lib_div::camelCaseToLowerCaseUnderscored('Blogexample')); - $this->assertEquals('blogexample', t3lib_div::camelCaseToLowerCaseUnderscored('blogexample')); - - $this->assertEquals('minimal_value', t3lib_div::camelCaseToLowerCaseUnderscored('minimalValue')); - } - - /** - * @test - * @see t3lib_div::lcfirst - */ - public function canConvertFirstCharacterToBeLowerCase() { - $this->assertEquals('blogexample', t3lib_div::lcfirst('Blogexample')); - $this->assertEquals('blogExample', t3lib_div::lcfirst('BlogExample')); - $this->assertEquals('blogexample', t3lib_div::lcfirst('blogexample')); - } - - /** - * Tests whether whitespaces are encoded correctly in a quoted-printable mail header. - * @test - */ - public function areWhitespacesEncodedInQuotedPrintableMailHeader() { - $this->assertEquals( - '=?utf-8?Q?We_test_whether_the_copyright_character_=C2=A9_is_encoded_correctly?=', - t3lib_div::encodeHeader( - "We test whether the copyright character \xc2\xa9 is encoded correctly", - 'quoted-printable', - 'utf-8' - ) - ); - } - - /** - * Tests whether question marks are encoded correctly in a quoted-printable mail header. - * @test - */ - public function areQuestionMarksEncodedInQuotedPrintableMailHeader() { - $this->assertEquals( - '=?utf-8?Q?Is_the_copyright_character_=C2=A9_really_encoded_correctly=3F_Really=3F?=', - t3lib_div::encodeHeader( - "Is the copyright character \xc2\xa9 really encoded correctly? Really?", - 'quoted-printable', - 'utf-8' - ) - ); - } - - /** - * Data provider for valid URLs, like PHP's source code test cases - */ - public function validUrlDataProvider() { - return array( - array('http://example.com/index.html'), - array('http://www.example.com/index.php'), - array('http://www.example/img/test.png'), - array('http://www.example/img/dir/'), - array('http://www.example/img/dir'), - array('file:///tmp/test.c'), - array('ftp://ftp.example.com/tmp/'), - array('mailto:foo@bar.com'), - array('news:news.php.net'), - array('file://foo/bar'), - array('http://qwe'), - ); - } - - /** - * Data provider for invalid URLs, like PHP's source code test cases - */ - public function invalidUrlDataProvider() { - return array( - array('http//www.example/wrong/url/'), - array('http:/www.example'), - array('/tmp/test.c'), - array('/'), - array('http://'), - array('http:/'), - array('http:'), - array('http'), - array(''), - array('-1'), - array('array()'), - array('qwe'), - ); - } - - /** - * @test - * @dataProvider validUrlDataProvider - * @see t3lib_div::isValidUrl() - */ - public function checkisValidURL($url) { - $this->assertTrue(t3lib_div::isValidUrl($url)); - } - - /** - * @test - * @dataProvider invalidUrlDataProvider - * @see t3lib_div::isValidUrl() - */ - public function checkisInValidURL($url) { - $this->assertFalse(t3lib_div::isValidUrl($url)); - } - - /** - * @test - * @see t3lib_div::isValidUrl() - */ - public function checkisValidURLSucceedsWithWebRessource() { - $testUrl = 'http://www.example.org/'; - $this->assertTrue(t3lib_div::isValidUrl($testUrl)); - } - - /** - * @test - * @see t3lib_div::isValidUrl() - */ - public function checkisValidURLSucceedsWithExtentedWebRessource() { - $testUrl = 'https://user:pw@www.example.org:80/path?arg=value#fragment'; - $this->assertTrue(t3lib_div::isValidUrl($testUrl)); - } - - /** - * @test - * @see t3lib_div::isValidUrl() - */ - public function checkisValidURLSucceedsWithTelnetRessource() { - $testUrl = 'telnet://192.0.2.16:80/'; - $this->assertTrue(t3lib_div::isValidUrl($testUrl)); - } - - /** - * @test - */ - public function checkisValidURLSucceedsWithLdapRessource() { - $testUrl = 'ldap://[2001:db8::7]/c=GB?objectClass?one'; - $this->assertTrue(t3lib_div::isValidUrl($testUrl)); - } - - /** - * @test - * @see t3lib_div::isValidUrl() - */ - public function checkisValidURLSucceedsWithFileRessource() { - $testUrl = 'file:///etc/passwd'; - $this->assertTrue(t3lib_div::isValidUrl($testUrl)); - } - - /** - * @test - * @see t3lib_div::isValidUrl() - */ - public function checkisValidURLFailsWithHostnameOnly() { - $testUrl = 'www.example.org/'; - $this->assertFalse(t3lib_div::isValidUrl($testUrl)); - } - - /** - * @test - * @see t3lib_div::isOnCurrentHost() - */ - public function checkisOnCurrentHostFailsWithLocalhostIPOnly() { - $testUrl = '127.0.0.1'; - $this->assertFalse(t3lib_div::isOnCurrentHost($testUrl)); - } - - /** - * @test - * @see t3lib_div::isOnCurrentHost() - */ - public function checkisOnCurrentHostFailsWithPathsOnly() { - $testUrl = './relpath/file.txt'; - $this->assertFalse(t3lib_div::isOnCurrentHost($testUrl)); - $testUrl = '/abspath/file.txt?arg=value'; - $this->assertFalse(t3lib_div::isOnCurrentHost($testUrl)); - } - - /** - * @test - * @see t3lib_div::isOnCurrentHost() - */ - public function checkisOnCurrentHostFailsWithArbitraryString() { - $testUrl = 'arbitrary string'; - $this->assertFalse(t3lib_div::isOnCurrentHost($testUrl)); - } - - /** - * @test - * @see t3lib_div::isOnCurrentHost() - */ - public function checkisOnCurrentHostFailsWithEmptyUrl() { - $testUrl = ''; - $this->assertFalse(t3lib_div::isOnCurrentHost($testUrl)); - } - - /** - * @test - * @see t3lib_div::isOnCurrentHost() - */ - public function checkisOnCurrentHostFailsWithDifferentHost() { - $testUrl = t3lib_div::getIndpEnv('TYPO3_REQUEST_HOST') . '.example.org'; - $this->assertFalse(t3lib_div::isOnCurrentHost($testUrl)); - } - - /** - * @test - * @see t3lib_div::isOnCurrentHost() - */ - public function checkisOnCurrentHostSucceedsWithCurrentHost() { - $testUrl = t3lib_div::getIndpEnv('TYPO3_REQUEST_URL'); - $this->assertTrue(t3lib_div::isOnCurrentHost($testUrl)); - } - - - //////////////////////////////////////// - // Tests concerning sanitizeLocalUrl - //////////////////////////////////////// - - /** - * Data provider for valid URLs. - * @see sanitizeLocalUrlAcceptsValidUrls - */ - public function validLocalUrlDataProvider() { - return array( - array('alt_intro.php'), - array('alt_intro.php?foo=1&bar=2'), - array('/typo3/alt_intro.php'), - array('/index.php'), - array('../index.php'), - array('../typo3/alt_intro.php'), - array('../~userDirectory/index.php'), - array('../typo3/mod.php?var1=test-case&var2=~user'), - array(PATH_site . 'typo3/alt_intro.php'), - array(t3lib_div::getIndpEnv('TYPO3_SITE_URL') . 'typo3/alt_intro.php'), - array(t3lib_div::getIndpEnv('TYPO3_REQUEST_HOST') . '/index.php'), - ); - } - - /** - * Data provider for invalid URLs. - * @see sanitizeLocalUrlDeniesInvalidUrls - */ - public function invalidLocalUrlDataProvider() { - return array( - array(''), - array('http://www.google.de/'), - array('https://www.google.de/'), - array('../typo3/whatever.php?argument=javascript:alert(0)'), - ); - } - - /** - * Tests whether valid local URLs are handled correctly. - * @dataProvider validLocalUrlDataProvider - * @test - */ - public function sanitizeLocalUrlAcceptsPlainValidUrls($url) { - $this->assertEquals($url, t3lib_div::sanitizeLocalUrl($url)); - } - - /** - * Tests whether valid local URLs are handled correctly. - * @dataProvider validLocalUrlDataProvider - * @test - */ - public function sanitizeLocalUrlAcceptsEncodedValidUrls($url) { - $this->assertEquals(rawurlencode($url), t3lib_div::sanitizeLocalUrl(rawurlencode($url))); - } - - /** - * Tests whether valid local URLs are handled correctly. - * @dataProvider invalidLocalUrlDataProvider - * @test - */ - public function sanitizeLocalUrlDeniesPlainInvalidUrls($url) { - $this->assertEquals('', t3lib_div::sanitizeLocalUrl($url)); - } - - /** - * Tests whether valid local URLs are handled correctly. - * @dataProvider invalidLocalUrlDataProvider - * @test - */ - public function sanitizeLocalUrlDeniesEncodedInvalidUrls($url) { - $this->assertEquals('', t3lib_div::sanitizeLocalUrl(rawurlencode($url))); - } - - ////////////////////////////////////// - // Tests concerning arrayDiffAssocRecursive - ////////////////////////////////////// - - /** - * Test if a one dimensional array is correctly diffed. - * - * @test - * @see t3lib_div::arrayDiffAssocRecursive - */ - public function doesArrayDiffAssocRecursiveCorrectlyHandleOneDimensionalArrays() { - $array1 = array( - 'key1' => 'value1', - 'key2' => 'value2', - 'key3' => 'value3', - ); - $array2 = array( - 'key1' => 'value1', - 'key3' => 'value3', - ); - $expectedResult = array( - 'key2' => 'value2', - ); - $actualResult = t3lib_div::arrayDiffAssocRecursive($array1, $array2); - $this->assertEquals($expectedResult, $actualResult); - } - - /** - * Test if a three dimensional array is correctly diffed. - * - * @test - * @see t3lib_div::arrayDiffAssocRecursive - */ - public function doesArrayDiffAssocRecursiveCorrectlyHandleMultiDimensionalArrays() { - $array1 = array( - 'key1' => 'value1', - 'key2' => array( - 'key21' => 'value21', - 'key22' => 'value22', - 'key23' => array( - 'key231' => 'value231', - 'key232' => 'value232', - ), - ), - ); - $array2 = array( - 'key1' => 'value1', - 'key2' => array( - 'key21' => 'value21', - 'key23' => array( - 'key231' => 'value231', - ), - ), - ); - $expectedResult = array( - 'key2' => array( - 'key22' => 'value22', - 'key23' => array( - 'key232' => 'value232', - ), - ), - ); - $actualResult = t3lib_div::arrayDiffAssocRecursive($array1, $array2); - $this->assertEquals($expectedResult, $actualResult); - } - - /** - * Test if arrays are correctly diffed if types are different. - * - * @test - * @see t3lib_div::arrayDiffAssocRecursive - */ - public function doesArrayDiffAssocRecursiveCorrectlyHandleMixedArrays() { - $array1 = array( - 'key1' => array( - 'key11' => 'value11', - 'key12' => 'value12', - ), - 'key2' => 'value2', - 'key3' => 'value3', - ); - $array2 = array( - 'key1' => 'value1', - 'key2' => array( - 'key21' => 'value21', - ), - ); - $expectedResult = array( - 'key3' => 'value3', - ); - $actualResult = t3lib_div::arrayDiffAssocRecursive($array1, $array2); - $this->assertEquals($expectedResult, $actualResult); - } - - ////////////////////////////////////// - // Tests concerning removeDotsFromTS - ////////////////////////////////////// - - /** - * Tests whether removeDotsFromTS() behaves correctly. - * @test - * @see t3lib_div::removeDotsFromTS() - */ - public function doesRemoveDotsFromTypoScriptSucceed() { - $typoScript = array( - 'propertyA.' => array( - 'keyA.' => array( - 'valueA' => 1, - ), - 'keyB' => 2, - ), - 'propertyB' => 3, - ); - - $expectedResult = array( - 'propertyA' => array( - 'keyA' => array( - 'valueA' => 1, - ), - 'keyB' => 2, - ), - 'propertyB' => 3, - ); - - $this->assertEquals($expectedResult, t3lib_div::removeDotsFromTS($typoScript)); - } - - /** - * Tests whether removeDotsFromTS() behaves correctly. - * @test - * @see t3lib_div::removeDotsFromTS() - */ - public function doesRemoveDotsFromTypoScriptCorrectlyOverrideWithArray() { - $typoScript = array( - 'propertyA.' => array( - 'keyA' => 'getsOverridden', - 'keyA.' => array( - 'valueA' => 1, - ), - 'keyB' => 2, - ), - 'propertyB' => 3, - ); - - $expectedResult = array( - 'propertyA' => array( - 'keyA' => array( - 'valueA' => 1, - ), - 'keyB' => 2, - ), - 'propertyB' => 3, - ); - - $this->assertEquals($expectedResult, t3lib_div::removeDotsFromTS($typoScript)); - } - - /** - * Tests whether removeDotsFromTS() behaves correctly. - * @test - * @see t3lib_div::removeDotsFromTS() - */ - public function doesRemoveDotsFromTypoScriptCorrectlyOverrideWithScalar() { - $typoScript = array( - 'propertyA.' => array( - 'keyA.' => array( - 'valueA' => 1, - ), - 'keyA' => 'willOverride', - 'keyB' => 2, - ), - 'propertyB' => 3, - ); - - $expectedResult = array( - 'propertyA' => array( - 'keyA' => 'willOverride', - 'keyB' => 2, - ), - 'propertyB' => 3, - ); - - $this->assertEquals($expectedResult, t3lib_div::removeDotsFromTS($typoScript)); - } - - /** - * Tests whether getDirs() returns an array of diretories from a given path - * @test - * @see t3lib_div::getDirs($path) - */ - public function checkGetDirsReturnsArrayOfDirectoriesFromGivenDirectory() { - $path = PATH_t3lib; - $directories = t3lib_div::get_dirs($path); - - $this->assertType('array', $directories); - } - - /** - * Tests whether getDirs() returns the string 'error' in case of problems reading from the given path - * @test - * @see t3lib_div::getDirs($path) - */ - public function checkGetDirsReturnsStringErrorOnPathFailure() { - $path = 'foo'; - $result = t3lib_div::get_dirs($path); - $expectedResult = 'error'; - - $this->assertEquals($expectedResult, $result); - } - - - ////////////////////////////////// - // Tests concerning hmac - ////////////////////////////////// - - /** - * @test - */ - public function hmacReturnsHashOfProperLength() { - $hmac = t3lib_div::hmac('message'); - $this->assertTrue(!empty($hmac) && is_string($hmac)); - $this->assertTrue(strlen($hmac) == 40); - } - - /** - * @test - */ - public function hmacReturnsEqualHashesForEqualInput() { - $msg0 = 'message'; - $msg1 = 'message'; - $this->assertEquals(t3lib_div::hmac($msg0), t3lib_div::hmac($msg1)); - } - - /** - * @test - */ - public function hmacReturnsNotEqualHashesForNotEqualInput() { - $msg0 = 'message0'; - $msg1 = 'message1'; - $this->assertNotEquals(t3lib_div::hmac($msg0), t3lib_div::hmac($msg1)); - } - - - ////////////////////////////////// - // Tests concerning quoteJSvalue - ////////////////////////////////// - - /** - * @test - */ - public function quoteJSvalueHtmlspecialcharsDataByDefault() { - $this->assertContains( - '>', - t3lib_div::quoteJSvalue('>') - ); - } - - /** - * @test - */ - public function quoteJSvaluetHtmlspecialcharsDataWithinCDataSetToFalse() { - $this->assertContains( - '>', - t3lib_div::quoteJSvalue('>', false) - ); - } - - /** - * @test - */ - public function quoteJSvaluetNotHtmlspecialcharsDataWithinCDataSetToTrue() { - $this->assertContains( - '>', - t3lib_div::quoteJSvalue('>', true) - ); - } - - /** - * @test - */ - public function quoteJSvalueReturnsEmptyStringQuotedInSingleQuotes() { - $this->assertEquals( - "''", - t3lib_div::quoteJSvalue("", true) - ); - } - - /** - * @test - */ - public function quoteJSvalueNotModifiesStringWithoutSpecialCharacters() { - $this->assertEquals( - "'Hello world!'", - t3lib_div::quoteJSvalue("Hello world!", true) - ); - } - - /** - * @test - */ - public function quoteJSvalueEscapesSingleQuote() { - $this->assertEquals( - "'\\''", - t3lib_div::quoteJSvalue("'", true) - ); - } - - /** - * @test - */ - public function quoteJSvalueEscapesDoubleQuoteWithinCDataSetToTrue() { - $this->assertEquals( - "'\\\"'", - t3lib_div::quoteJSvalue('"', true) - ); - } - - /** - * @test - */ - public function quoteJSvalueEscapesAndHtmlspecialcharsDoubleQuoteWithinCDataSetToFalse() { - $this->assertEquals( - "'\\"'", - t3lib_div::quoteJSvalue('"', false) - ); - } - - /** - * @test - */ - public function quoteJSvalueEscapesTab() { - $this->assertEquals( - "'" . '\t' . "'", - t3lib_div::quoteJSvalue(TAB) - ); - } - - /** - * @test - */ - public function quoteJSvalueEscapesLinefeed() { - $this->assertEquals( - "'" . '\n' . "'", - t3lib_div::quoteJSvalue(LF) - ); - } - - /** - * @test - */ - public function quoteJSvalueEscapesCarriageReturn() { - $this->assertEquals( - "'" . '\r' . "'", - t3lib_div::quoteJSvalue(CR) - ); - } - - /** - * @test - */ - public function quoteJSvalueEscapesBackslah() { - $this->assertEquals( - "'\\\\'", - t3lib_div::quoteJSvalue('\\') - ); - } - - /** - * Tests the locallangXMLOverride feature of readLLfile() - * @test - */ - public function readLLfileLocallangXMLOverride() { - $unique = uniqid('locallangXMLOverrideTest'); - - $xml = ' - - - - - - - '; - - $file = PATH_site . 'typo3temp/' . $unique . '.xml'; - t3lib_div::writeFileToTypo3tempDir($file, $xml); - - // get default value - $defaultLL = t3lib_div::readLLfile('EXT:lang/locallang_core.xml', 'default'); - - // set override file - $GLOBALS['TYPO3_CONF_VARS']['SYS']['locallangXMLOverride']['EXT:lang/locallang_core.xml'][$unique] = $file; - - // get override value - $overrideLL = t3lib_div::readLLfile('EXT:lang/locallang_core.xml', 'default'); - - $this->assertNotEquals($overrideLL['default']['buttons.logout'], ''); - $this->assertNotEquals($defaultLL['default']['buttons.logout'], $overrideLL['default']['buttons.logout']); - $this->assertEquals($overrideLL['default']['buttons.logout'], 'EXIT'); - - unlink($file); - } - - - /////////////////////////////// - // Tests concerning _GETset() - /////////////////////////////// - - /** - * @test - */ - public function getSetCanSetWholeArray() { - $_GET = array(); - $GLOBALS['HTTP_GET_VARS'] = array(); - t3lib_div::_GETset(array('oneKey' => 'oneValue')); - - $this->assertEquals( - array('oneKey' => 'oneValue'), - $_GET - ); - $this->assertEquals( - array('oneKey' => 'oneValue'), - $GLOBALS['HTTP_GET_VARS'] - ); - } - - /** - * @test - */ - public function getSetForArrayDropsExistingValues() { - $_GET = array(); - $GLOBALS['HTTP_GET_VARS'] = array(); - - t3lib_div::_GETset(array('foo' => 'bar')); - t3lib_div::_GETset(array('oneKey' => 'oneValue')); - - $this->assertEquals( - array('oneKey' => 'oneValue'), - $_GET - ); - $this->assertEquals( - array('oneKey' => 'oneValue'), - $GLOBALS['HTTP_GET_VARS'] - ); - } - - /** - * @test - */ - public function getSetCanAssignOneValueToOneKey() { - $_GET = array(); - $GLOBALS['HTTP_GET_VARS'] = array(); - - t3lib_div::_GETset('oneValue', 'oneKey'); - - $this->assertEquals( - 'oneValue', - $_GET['oneKey'] - ); - $this->assertEquals( - 'oneValue', - $GLOBALS['HTTP_GET_VARS']['oneKey'] - ); - } - - /** - * @test - */ - public function getSetForOneValueNotDropsExistingValues() { - $_GET = array(); - $GLOBALS['HTTP_GET_VARS'] = array(); - - t3lib_div::_GETset(array('foo' => 'bar')); - t3lib_div::_GETset('oneValue', 'oneKey'); - - $this->assertEquals( - array('foo' => 'bar', 'oneKey' => 'oneValue'), - $_GET - ); - $this->assertEquals( - array('foo' => 'bar', 'oneKey' => 'oneValue'), - $GLOBALS['HTTP_GET_VARS'] - ); - } - - /** - * @test - */ - public function getSetCanAssignAnArrayToSpecificArrayElement() { - $_GET = array(); - $GLOBALS['HTTP_GET_VARS'] = array(); - - t3lib_div::_GETset(array('childKey' => 'oneValue'), 'parentKey'); - - $this->assertEquals( - array('parentKey' => array('childKey' => 'oneValue')), - $_GET - ); - $this->assertEquals( - array('parentKey' => array('childKey' => 'oneValue')), - $GLOBALS['HTTP_GET_VARS'] - ); - } - - /** - * @test - */ - public function getSetCanAssignAValueToSpecificArrayChildElement() { - $_GET = array(); - $GLOBALS['HTTP_GET_VARS'] = array(); - - t3lib_div::_GETset('oneValue', 'parentKey|childKey'); - - $this->assertEquals( - array('parentKey' => array('childKey' => 'oneValue')), - $_GET - ); - $this->assertEquals( - array('parentKey' => array('childKey' => 'oneValue')), - $GLOBALS['HTTP_GET_VARS'] - ); - } - - /** - * @test - */ - public function getSetCanAssignAnArrayToSpecificArrayChildElement() { - $_GET = array(); - $GLOBALS['HTTP_GET_VARS'] = array(); - - t3lib_div::_GETset( - array('key1' => 'value1', 'key2' => 'value2'), - 'parentKey|childKey' - ); - - $this->assertEquals( - array( - 'parentKey' => array( - 'childKey' => array('key1' => 'value1', 'key2' => 'value2') - ) - ), - $_GET - ); - $this->assertEquals( - array( - 'parentKey' => array( - 'childKey' => array('key1' => 'value1', 'key2' => 'value2') - ) - ), - $GLOBALS['HTTP_GET_VARS'] - ); - } - - /** - * Checks if t3lib_div::fixPermissions() correctly sets permissions to single file - * This test assumes directory 'PATH_site'/typo3temp exists - * This test is not available on windows OS - * - * @test - * @see t3lib_div::fixPermissions() - */ - public function checkFixPermissionsCorrectlySetsPermissionsToFile() { - if (TYPO3_OS == 'WIN') { - $this->markTestSkipped('fixPermissions() tests not available on Windows'); - } - - // Create and prepare test file - $filename = PATH_site . 'typo3temp/' . uniqid('test_'); - t3lib_div::writeFileToTypo3tempDir($filename, '42'); - chmod($filename, 0742); - - // Set target permissions and run method - $GLOBALS['TYPO3_CONF_VARS']['BE']['fileCreateMask'] = '0660'; - $GLOBALS['TYPO3_CONF_VARS']['BE']['createGroup'] = posix_getegid(); - $fixPermissionsResult = t3lib_div::fixPermissions($filename); - - // Get actual permissions and clean up - clearstatcache(); - $resultFilePermissions = substr(decoct(fileperms($filename)), 2); - $resultFileGroup = filegroup($filename); - unlink($filename); - - // Test if everything was ok - $this->assertTrue($fixPermissionsResult); - $this->assertEquals($resultFilePermissions, '0660'); - $this->assertEquals($resultFileGroup, posix_getegid()); - } - - /** - * Checks if t3lib_div::fixPermissions() correctly sets permissions to hidden file - * This test assumes directory 'PATH_site'/typo3temp exists - * This test is not available on windows OS - * - * @test - * @see t3lib_div::fixPermissions() - */ - public function checkFixPermissionsCorrectlySetsPermissionsToHiddenFile() { - if (TYPO3_OS == 'WIN') { - $this->markTestSkipped('fixPermissions() tests not available on Windows'); - } - - // Create and prepare test file - $filename = PATH_site . 'typo3temp/' . uniqid('.test_'); - t3lib_div::writeFileToTypo3tempDir($filename, '42'); - chmod($filename, 0742); - - // Set target permissions and run method - $GLOBALS['TYPO3_CONF_VARS']['BE']['fileCreateMask'] = '0660'; - $GLOBALS['TYPO3_CONF_VARS']['BE']['createGroup'] = posix_getegid(); - $fixPermissionsResult = t3lib_div::fixPermissions($filename); - - // Get actual permissions and clean up - clearstatcache(); - $resultFilePermissions = substr(decoct(fileperms($filename)), 2); - $resultFileGroup = filegroup($filename); - unlink($filename); - - // Test if everything was ok - $this->assertTrue($fixPermissionsResult); - $this->assertEquals($resultFilePermissions, '0660'); - $this->assertEquals($resultFileGroup, posix_getegid()); - } - - /** - * Checks if t3lib_div::fixPermissions() correctly sets permissions to directory with trailing slash - * This test assumes directory 'PATH_site'/typo3temp exists - * This test is not available on windows OS - * - * @test - * @see t3lib_div::fixPermissions() - */ - public function checkFixPermissionsCorrectlySetsPermissionsToDirectory() { - if (TYPO3_OS == 'WIN') { - $this->markTestSkipped('fixPermissions() tests not available on Windows'); - } - - // Create and prepare test directory - $directory = PATH_site . 'typo3temp/' . uniqid('test_'); - t3lib_div::mkdir($directory); - chmod($directory, 1551); - - // Set target permissions and run method - $GLOBALS['TYPO3_CONF_VARS']['BE']['folderCreateMask'] = '0770'; - $GLOBALS['TYPO3_CONF_VARS']['BE']['createGroup'] = posix_getegid(); - $fixPermissionsResult = t3lib_div::fixPermissions($directory . '/'); - - // Get actual permissions and clean up - clearstatcache(); - $resultDirectoryPermissions = substr(decoct(fileperms($directory)), 1); - $resultDirectoryGroup = filegroup($directory); - t3lib_div::rmdir($directory); - - // Test if everything was ok - $this->assertTrue($fixPermissionsResult); - $this->assertEquals($resultDirectoryPermissions, '0770'); - $this->assertEquals($resultDirectoryGroup, posix_getegid()); - } - - /** - * Checks if t3lib_div::fixPermissions() correctly sets permissions to hidden directory - * This test assumes directory 'PATH_site'/typo3temp exists - * This test is not available on windows OS - * - * @test - * @see t3lib_div::fixPermissions() - */ - public function checkFixPermissionsCorrectlySetsPermissionsToHiddenDirectory() { - if (TYPO3_OS == 'WIN') { - $this->markTestSkipped('fixPermissions() tests not available on Windows'); - } - - // Create and prepare test directory - $directory = PATH_site . 'typo3temp/' . uniqid('.test_'); - t3lib_div::mkdir($directory); - chmod($directory, 1551); - - // Set target permissions and run method - $GLOBALS['TYPO3_CONF_VARS']['BE']['folderCreateMask'] = '0770'; - $GLOBALS['TYPO3_CONF_VARS']['BE']['createGroup'] = posix_getegid(); - $fixPermissionsResult = t3lib_div::fixPermissions($directory); - - // Get actual permissions and clean up - clearstatcache(); - $resultDirectoryPermissions = substr(decoct(fileperms($directory)), 1); - $resultDirectoryGroup = filegroup($directory); - t3lib_div::rmdir($directory); - - // Test if everything was ok - $this->assertTrue($fixPermissionsResult); - $this->assertEquals($resultDirectoryPermissions, '0770'); - $this->assertEquals($resultDirectoryGroup, posix_getegid()); - } - - /** - * Checks if t3lib_div::fixPermissions() correctly sets permissions recursivly - * This test assumes directory 'PATH_site'/typo3temp exists - * This test is not available on windows OS - * - * @test - * @see t3lib_div::fixPermissions() - */ - public function checkFixPermissionsCorrectlySetsPermissionsRecursive() { - if (TYPO3_OS == 'WIN') { - $this->markTestSkipped('fixPermissions() tests not available on Windows'); - } - - // Create and prepare test directory and file structure - $baseDirectory = PATH_site . 'typo3temp/' . uniqid('test_'); - t3lib_div::mkdir($baseDirectory); - chmod($baseDirectory, 1751); - t3lib_div::writeFileToTypo3tempDir($baseDirectory . '/file', '42'); - chmod($baseDirectory . '/file', 0742); - t3lib_div::mkdir($baseDirectory . '/foo'); - chmod($baseDirectory . '/foo', 1751); - t3lib_div::writeFileToTypo3tempDir($baseDirectory . '/foo/file', '42'); - chmod($baseDirectory . '/foo/file', 0742); - t3lib_div::mkdir($baseDirectory . '/.bar'); - chmod($baseDirectory . '/.bar', 1751); - // Use this if writeFileToTypo3tempDir is fixed to create hidden files in subdirectories - // t3lib_div::writeFileToTypo3tempDir($baseDirectory . '/.bar/.file', '42'); - // t3lib_div::writeFileToTypo3tempDir($baseDirectory . '/.bar/..file2', '42'); - touch($baseDirectory . '/.bar/.file', '42'); - chmod($baseDirectory . '/.bar/.file', 0742); - touch($baseDirectory . '/.bar/..file2', '42'); - chmod($baseDirectory . '/.bar/..file2', 0742); - - // Set target permissions and run method - $GLOBALS['TYPO3_CONF_VARS']['BE']['fileCreateMask'] = '0660'; - $GLOBALS['TYPO3_CONF_VARS']['BE']['folderCreateMask'] = '0770'; - $GLOBALS['TYPO3_CONF_VARS']['BE']['createGroup'] = posix_getegid(); - $fixPermissionsResult = t3lib_div::fixPermissions($baseDirectory, TRUE); - - // Get actual permissions - clearstatcache(); - $resultBaseDirectoryPermissions = substr(decoct(fileperms($baseDirectory)), 1); - $resultBaseDirectoryGroup = filegroup($baseDirectory); - $resultBaseFilePermissions = substr(decoct(fileperms($baseDirectory . '/file')), 2); - $resultBaseFileGroup = filegroup($baseDirectory . '/file'); - $resultFooDirectoryPermissions = substr(decoct(fileperms($baseDirectory . '/foo')), 1); - $resultFooDirectoryGroup = filegroup($baseDirectory . '/foo'); - $resultFooFilePermissions = substr(decoct(fileperms($baseDirectory . '/foo/file')), 2); - $resultFooFileGroup = filegroup($baseDirectory . '/foo/file'); - $resultBarDirectoryPermissions = substr(decoct(fileperms($baseDirectory . '/.bar')), 1); - $resultBarDirectoryGroup = filegroup($baseDirectory . '/.bar'); - $resultBarFilePermissions = substr(decoct(fileperms($baseDirectory . '/.bar/.file')), 2); - $resultBarFileGroup = filegroup($baseDirectory . '/.bar/.file'); - $resultBarFile2Permissions = substr(decoct(fileperms($baseDirectory . '/.bar/..file2')), 2); - $resultBarFile2Group = filegroup($baseDirectory . '/.bar/..file2'); - - // Clean up - unlink($baseDirectory . '/file'); - unlink($baseDirectory . '/foo/file'); - unlink($baseDirectory . '/.bar/.file'); - unlink($baseDirectory . '/.bar/..file2'); - t3lib_div::rmdir($baseDirectory . '/foo'); - t3lib_div::rmdir($baseDirectory . '/.bar'); - t3lib_div::rmdir($baseDirectory); - - // Test if everything was ok - $this->assertTrue($fixPermissionsResult); - $this->assertEquals($resultBaseDirectoryPermissions, '0770'); - $this->assertEquals($resultBaseDirectoryGroup, posix_getegid()); - $this->assertEquals($resultBaseFilePermissions, '0660'); - $this->assertEquals($resultBaseFileGroup, posix_getegid()); - $this->assertEquals($resultFooDirectoryPermissions, '0770'); - $this->assertEquals($resultFooDirectoryGroup, posix_getegid()); - $this->assertEquals($resultFooFilePermissions, '0660'); - $this->assertEquals($resultFooFileGroup, posix_getegid()); - $this->assertEquals($resultBarDirectoryPermissions, '0770'); - $this->assertEquals($resultBarDirectoryGroup, posix_getegid()); - $this->assertEquals($resultBarFilePermissions, '0660'); - $this->assertEquals($resultBarFileGroup, posix_getegid()); - $this->assertEquals($resultBarFile2Permissions, '0660'); - $this->assertEquals($resultBarFile2Group, posix_getegid()); - } - - /** - * Checks if t3lib_div::fixPermissions() does not fix permissions on not allowed path - * This test assumes directory 'PATH_site'/typo3temp exists - * This test is not available on windows OS - * - * @test - * @see t3lib_div::fixPermissions() - */ - public function checkFixPermissionsDoesNotSetPermissionsToNotAllowedPath() { - if (TYPO3_OS == 'WIN') { - $this->markTestSkipped('fixPermissions() tests not available on Windows'); - } - - // Create and prepare test file - $filename = PATH_site . 'typo3temp/../typo3temp/' . uniqid('test_'); - touch($filename); - chmod($filename, 0742); - - // Set target permissions and run method - $GLOBALS['TYPO3_CONF_VARS']['BE']['fileCreateMask'] = '0660'; - $fixPermissionsResult = t3lib_div::fixPermissions($filename); - - // Get actual permissions and clean up - clearstatcache(); - $resultFilePermissions = substr(decoct(fileperms($filename)), 2); - unlink($filename); - - // Test if everything was ok - $this->assertFalse($fixPermissionsResult); - $this->assertEquals($resultFilePermissions, '0742'); - } - - /** - * Checks if t3lib_div::mkdir() correctly creates a directory - * This test assumes directory 'PATH_site'/typo3temp exists - * - * @test - * @see t3lib_div::mkdir() - */ - public function checkMkdirCorrectlyCreatesDirectory() { - $directory = PATH_site . 'typo3temp/' . uniqid('test_'); - $mkdirResult = t3lib_div::mkdir($directory); - $directoryCreated = is_dir($directory); - t3lib_div::rmdir($directory); - $this->assertTrue($mkdirResult); - $this->assertTrue($directoryCreated); - } - - /** - * Checks if t3lib_div::mkdir() correctly creates a hidden directory - * This test assumes directory 'PATH_site'/typo3temp exists - * - * @test - * @see t3lib_div::mkdir() - */ - public function checkMkdirCorrectlyCreatesHiddenDirectory() { - $directory = PATH_site . 'typo3temp/' . uniqid('.test_'); - $mkdirResult = t3lib_div::mkdir($directory); - $directoryCreated = is_dir($directory); - t3lib_div::rmdir($directory); - $this->assertTrue($mkdirResult); - $this->assertTrue($directoryCreated); - } - - /** - * Checks if t3lib_div::mkdir() correctly creates a directory with trailing slash - * This test assumes directory 'PATH_site'/typo3temp exists - * - * @test - * @see t3lib_div::mkdir() - */ - public function checkMkdirCorrectlyCreatesDirectoryWithTrailingSlash() { - $directory = PATH_site . 'typo3temp/' . uniqid('test_'); - $mkdirResult = t3lib_div::mkdir($directory); - $directoryCreated = is_dir($directory); - t3lib_div::rmdir($directory); - $this->assertTrue($mkdirResult); - $this->assertTrue($directoryCreated); - } -} -?> \ No newline at end of file Index: tests/t3lib/matchcondition/t3lib_matchcondition_frontend_testcase.php =================================================================== --- tests/t3lib/matchcondition/t3lib_matchcondition_frontend_testcase.php (Revision 7835) +++ tests/t3lib/matchcondition/t3lib_matchcondition_frontend_testcase.php (Arbeitskopie) @@ -1,624 +0,0 @@ - -* All rights reserved -* -* This script is part of the TYPO3 project. The TYPO3 project is -* free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* The GNU General Public License can be found at -* http://www.gnu.org/copyleft/gpl.html. -* -* This script is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* This copyright notice MUST APPEAR in all copies of the script! -***************************************************************/ - - -/** - * Testcase for class t3lib_matchCondition_frontend. - * - * @author Oliver Hader - * @package TYPO3 - * @subpackage t3lib - */ -class t3lib_matchCondition_frontend_testcase extends tx_phpunit_testcase { - /** - * @var array - */ - private $backupGlobalVariables; - - /** - * @var array - */ - private $rootline; - - /** - * @var t3lib_matchCondition - */ - private $matchCondition; - - public function setUp() { - $this->backupGlobalVariables = array( - '_ENV' => $_ENV, - '_GET' => $_GET, - '_POST' => $_POST, - '_SERVER' => $_SERVER, - 'TYPO3_CONF_VARS' => $GLOBALS['TYPO3_CONF_VARS'], - 'T3_VAR' => $GLOBALS['T3_VAR'], - ); - - $this->testGlobalNamespace = uniqid('TEST'); - $GLOBALS[$this->testGlobalNamespace] = array(); - - $this->setUpTSFE(); - $this->matchCondition = t3lib_div::makeInstance('t3lib_matchCondition_frontend'); - } - - public function tearDown() { - foreach ($this->backupGlobalVariables as $key => $data) { - $GLOBALS[$key] = $data; - } - - unset($this->matchCondition); - unset($this->backupGlobalVariables); - unset($GLOBALS[$this->testGlobalNamespace]); - } - - private function setUpTSFE() { - $this->rootline = array( - 2 => array('uid' => 121, 'pid' => 111), - 1 => array('uid' => 111, 'pid' => 101,), - 0 => array('uid' => 101, 'pid' => 0,), - ); - - $GLOBALS['TSFE'] = $this->getMock('tslib_fe', array(), array(), '', FALSE); - $GLOBALS['TSFE']->tmpl = $this->getMock('t3lib_TStemplate'); - } - - /** - * Tests whether a faulty expression fails. - * @test - */ - public function simulateDisabledMatchAllConditionsFailsOnFaultyExpression() { - $this->matchCondition->matchAll = false; - $this->assertFalse($this->matchCondition->match('[nullCondition = This expression would return false in general]')); - } - - /** - * Tests whether simulating positive matches for all conditions succeeds. - * @test - */ - public function simulateEnabledMatchAllConditionsSucceeds() { - $this->matchCondition->setSimulateMatchResult(true); - $this->assertTrue($this->matchCondition->match('[nullCondition = This expression would return false in general]')); - } - - /** - * Tests whether simulating positive matches for specific conditions succeeds. - * @test - */ - public function simulateEnabledMatchSpecificConditionsSucceeds() { - $testCondition = '[' . uniqid('test') . ' = Any condition to simulate a positive match]'; - $this->matchCondition->setSimulateMatchConditions(array($testCondition)); - $this->assertTrue($this->matchCondition->match($testCondition)); - } - - /** - * Tests whether a condition matches Internet Explorer 7 on Windows. - * - * @return void - * @test - */ - public function conditionMatchesInternetExplorer7Windows() { - $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)'; - $result = $this->matchCondition->match('[browser = msie] && [version = 7] && [system = winNT]'); - $this->assertTrue($result); - } - - /** - * Tests whether a condition does not match Internet Explorer 7 on Windows. - * - * @return void - * @test - */ - public function conditionDoesNotMatchInternetExplorer7Windows() { - $_SERVER['HTTP_USER_AGENT'] = 'Opera/9.25 (Windows NT 6.0; U; en)'; - $result = $this->matchCondition->match('[browser = msie] && [version = 7] && [system = winNT]'); - $this->assertFalse($result); - } - - /** - * Tests whether a device type condition matches a crawler. - * @test - */ - public function deviceConditionMatchesRobot() { - $_SERVER['HTTP_USER_AGENT'] = 'Googlebot/2.1 (+http://www.google.com/bot.html)'; - $result = $this->matchCondition->match('[device = robot]'); - $this->assertTrue($result); - } - - /** - * Tests whether a device type condition does not match a crawler. - * @test - */ - public function deviceConditionDoesNotMatchRobot() { - $_SERVER['HTTP_USER_AGENT'] = md5('Some strange user agent'); - $result = $this->matchCondition->match('[device = robot]'); - $this->assertFalse($result); - } - - /** - * Tests whether the browserInfo hook is called. - * - * @return void - * @test - */ - public function deprecatedBrowserInfoHookIsCalled() { - $GLOBALS['TYPO3_CONF_VARS']['SYS']['enableDeprecationLog'] = FALSE; - - $classRef = uniqid('tx_browserInfoHook'); - $browserInfoHookMock = $this->getMock($classRef, array('browserInfo')); - $browserInfoHookMock->expects($this->atLeastOnce())->method('browserInfo'); - - $GLOBALS['T3_VAR']['getUserObj'][$classRef] = $browserInfoHookMock; - $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_matchcondition.php']['matchConditionClass'][$classRef] = $classRef; - - $this->matchCondition->__construct(); - $this->matchCondition->match('[browser = msie] && [version = 7] && [system = winNT]'); - } - - /** - * Tests whether the whichDevice hook is called. - * - * @return void - * @test - */ - public function deprecatedWhichDeviceHookIsCalled() { - $GLOBALS['TYPO3_CONF_VARS']['SYS']['enableDeprecationLog'] = FALSE; - - $classRef = uniqid('tx_whichDeviceHook'); - $whichDeviceHookMock = $this->getMock($classRef, array('whichDevice')); - $whichDeviceHookMock->expects($this->atLeastOnce())->method('whichDevice'); - - $GLOBALS['T3_VAR']['getUserObj'][$classRef] = $whichDeviceHookMock; - $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_matchcondition.php']['matchConditionClass'][$classRef] = $classRef; - - $this->matchCondition->__construct(); - $this->matchCondition->match('[device = robot]'); - } - - /** - * Tests whether the language comparison matches. - * @test - */ - public function languageConditionMatchesSingleLanguageExpression() { - $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'de-de,de;q=0.8,en-us;q=0.5,en;q=0.3'; - $this->assertTrue($this->matchCondition->match('[language = *de*]')); - $this->assertTrue($this->matchCondition->match('[language = *de-de*]')); - } - - /** - * Tests whether the language comparison matches. - * @test - */ - public function languageConditionMatchesMultipleLanguagesExpression() { - $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'de-de,de;q=0.8,en-us;q=0.5,en;q=0.3'; - $this->assertTrue($this->matchCondition->match('[language = *en*,*de*]')); - $this->assertTrue($this->matchCondition->match('[language = *en-us*,*de-de*]')); - } - - /** - * Tests whether the language comparison matches. - * @test - */ - public function languageConditionMatchesCompleteLanguagesExpression() { - $this->markTestSkipped('This comparison seems to be incomplete in t3lib_matchCondition.'); - - $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'de-de,de;q=0.8,en-us;q=0.5,en;q=0.3'; - $this->assertTrue($this->matchCondition->match('[language = de-de,de;q=0.8]')); - } - - /** - * Tests whether usergroup comparison matches. - * @test - */ - public function usergroupConditionMatchesSingleGroupId() { - $GLOBALS['TSFE']->gr_list = '13,14,15'; - $this->assertTrue($this->matchCondition->match('[usergroup = 13]')); - } - - /** - * Tests whether usergroup comparison matches. - * @test - */ - public function usergroupConditionMatchesMultipleUserGroupId() { - $GLOBALS['TSFE']->gr_list = '13,14,15'; - $this->assertTrue($this->matchCondition->match('[usergroup = 999,15,14,13]')); - } - - /** - * Tests whether usergroup comparison matches. - * @test - */ - public function usergroupConditionDoesNotMatchDefaulUserGroupIds() { - $GLOBALS['TSFE']->gr_list = '0,-1'; - $this->assertFalse($this->matchCondition->match('[usergroup = 0,-1]')); - } - - /** - * Tests whether user comparison matches. - * @test - */ - public function loginUserConditionMatchesAnyLoggedInUser() { - $GLOBALS['TSFE']->loginUser = TRUE; - $GLOBALS['TSFE']->fe_user->user['uid'] = 13; - $this->assertTrue($this->matchCondition->match('[loginUser = *]')); - } - - /** - * Tests whether user comparison matches. - * @test - */ - public function loginUserConditionMatchesSingleLoggedInUser() { - $GLOBALS['TSFE']->loginUser = TRUE; - $GLOBALS['TSFE']->fe_user->user['uid'] = 13; - $this->assertTrue($this->matchCondition->match('[loginUser = 13]')); - } - - /** - * Tests whether user comparison matches. - * @test - */ - public function loginUserConditionMatchesMultipleLoggedInUsers() { - $GLOBALS['TSFE']->loginUser = TRUE; - $GLOBALS['TSFE']->fe_user->user['uid'] = 13; - $this->assertTrue($this->matchCondition->match('[loginUser = 999,13]')); - } - - /** - * Tests whether user comparison matches. - * @test - */ - public function loginUserConditionDoesNotMatchIfNotUserIsLoggedId() { - $GLOBALS['TSFE']->loginUser = FALSE; - $GLOBALS['TSFE']->fe_user->user['uid'] = 13; - $this->assertFalse($this->matchCondition->match('[loginUser = *]')); - $this->assertFalse($this->matchCondition->match('[loginUser = 13]')); - } - - /** - * Tests whether numerical comparison matches. - * @test - */ - public function globalVarConditionMatchesOnEqualExpression() { - $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 = 10]')); - $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 = 10.1]')); - - $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 == 10]')); - $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 == 10.1]')); - } - - /** - * Tests whether numerical comparison matches. - * @test - */ - public function globalVarConditionMatchesOnNotEqualExpression() { - $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 != 20]')); - $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 != 10.2]')); - } - - /** - * Tests whether numerical comparison matches. - * @test - */ - public function globalVarConditionMatchesOnLowerThanExpression() { - $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 < 20]')); - $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 < 10.2]')); - } - - /** - * Tests whether numerical comparison matches. - * @test - */ - public function globalVarConditionMatchesOnLowerThanOrEqualExpression() { - $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 <= 10]')); - $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 <= 20]')); - - $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 <= 10.1]')); - $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 <= 10.2]')); - } - - /** - * Tests whether numerical comparison matches. - * @test - */ - public function globalVarConditionMatchesOnGreaterThanExpression() { - $this->assertTrue($this->matchCondition->match('[globalVar = LIT:20 > 10]')); - $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.2 > 10.1]')); - } - - /** - * Tests whether numerical comparison matches. - * @test - */ - public function globalVarConditionMatchesOnGreaterThanOrEqualExpression() { - $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 >= 10]')); - $this->assertTrue($this->matchCondition->match('[globalVar = LIT:20 >= 10]')); - - $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 >= 10.1]')); - $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.2 >= 10.1]')); - } - - /** - * Tests whether numerical comparison matches. - * @test - */ - public function globalVarConditionMatchesOnEmptyExpressionWithNoValueSet() { - $testKey = uniqid('test'); - $this->assertTrue($this->matchCondition->match('[globalVar = GP:' . $testKey . '=]')); - $this->assertTrue($this->matchCondition->match('[globalVar = GP:' . $testKey . ' = ]')); - } - - /** - * Tests whether numerical comparison matches. - * @test - */ - public function globalVarConditionDoesNotMatchOnEmptyExpressionWithValueSetToZero() { - $testKey = uniqid('test'); - - $_GET = array(); - $_POST = array($testKey => 0); - - $this->assertFalse($this->matchCondition->match('[globalVar = GP:' . $testKey . '=]')); - $this->assertFalse($this->matchCondition->match('[globalVar = GP:' . $testKey . ' = ]')); - } - - /** - * Tests whether string comparison matches. - * @test - */ - public function globalStringConditionMatchesOnEqualExpression() { - $this->assertTrue($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = TYPO3.Test.Condition]')); - $this->assertFalse($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = TYPO3]')); - } - - /** - * Tests whether string comparison matches. - * @test - */ - public function globalStringConditionMatchesWildcardExpression() { - $this->assertTrue($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = TYPO3?Test?Condition]')); - $this->assertTrue($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = TYPO3.T*t.Condition]')); - $this->assertTrue($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = TYPO3?T*t?Condition]')); - } - - /** - * Tests whether string comparison matches. - * @test - */ - public function globalStringConditionMatchesRegularExpression() { - $this->assertTrue($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = /^[A-Za-z3.]+$/]')); - $this->assertTrue($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = /^TYPO3\..+Condition$/]')); - $this->assertFalse($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = /^FALSE/]')); - } - - /** - * Tests whether string comparison matches. - * @test - */ - public function globalStringConditionMatchesEmptyRegularExpression() { - $testKey = uniqid('test'); - $_SERVER[$testKey] = ''; - $this->assertTrue($this->matchCondition->match('[globalString = _SERVER|' . $testKey . ' = /^$/]')); - } - - /** - * Tests whether treeLevel comparison matches. - * @test - */ - public function treeLevelConditionMatchesSingleValue() { - $GLOBALS['TSFE']->tmpl->rootLine = $this->rootline; - $this->assertTrue($this->matchCondition->match('[treeLevel = 2]')); - } - - /** - * Tests whether treeLevel comparison matches. - * @test - */ - public function treeLevelConditionMatchesMultipleValues() { - $GLOBALS['TSFE']->tmpl->rootLine = $this->rootline; - $this->assertTrue($this->matchCondition->match('[treeLevel = 999,998,2]')); - } - - /** - * Tests whether treeLevel comparison matches. - * @test - */ - public function treeLevelConditionDoesNotMatchFaultyValue() { - $GLOBALS['TSFE']->tmpl->rootLine = $this->rootline; - $this->assertFalse($this->matchCondition->match('[treeLevel = 999]')); - } - - /** - * Tests whether a page Id is found in the previous rootline entries. - * @test - */ - public function PIDupinRootlineConditionMatchesSinglePageIdInRootline() { - $GLOBALS['TSFE']->tmpl->rootLine = $this->rootline; - $GLOBALS['TSFE']->id = 121; - $this->assertTrue($this->matchCondition->match('[PIDupinRootline = 111]')); - } - - /** - * Tests whether a page Id is found in the previous rootline entries. - * @test - */ - public function PIDupinRootlineConditionMatchesMultiplePageIdsInRootline() { - $GLOBALS['TSFE']->tmpl->rootLine = $this->rootline; - $GLOBALS['TSFE']->id = 121; - $this->assertTrue($this->matchCondition->match('[PIDupinRootline = 999,111,101]')); - } - - /** - * Tests whether a page Id is found in the previous rootline entries. - * @test - */ - public function PIDupinRootlineConditionDoesNotMatchPageIdNotInRootline() { - $GLOBALS['TSFE']->tmpl->rootLine = $this->rootline; - $GLOBALS['TSFE']->id = 121; - $this->assertFalse($this->matchCondition->match('[PIDupinRootline = 999]')); - } - - /** - * Tests whether a page Id is found in the previous rootline entries. - * @test - */ - public function PIDupinRootlineConditionDoesNotMatchLastPageIdInRootline() { - $GLOBALS['TSFE']->tmpl->rootLine = $this->rootline; - $GLOBALS['TSFE']->id = 121; - $this->assertFalse($this->matchCondition->match('[PIDupinRootline = 121]')); - } - - /** - * Tests whether a page Id is found in all rootline entries. - * @test - */ - public function PIDinRootlineConditionMatchesSinglePageIdInRootline() { - $GLOBALS['TSFE']->tmpl->rootLine = $this->rootline; - $GLOBALS['TSFE']->id = 121; - $this->assertTrue($this->matchCondition->match('[PIDinRootline = 111]')); - } - - /** - * Tests whether a page Id is found in all rootline entries. - * @test - */ - public function PIDinRootlineConditionMatchesMultiplePageIdsInRootline() { - $GLOBALS['TSFE']->tmpl->rootLine = $this->rootline; - $GLOBALS['TSFE']->id = 121; - $this->assertTrue($this->matchCondition->match('[PIDinRootline = 999,111,101]')); - } - - /** - * Tests whether a page Id is found in all rootline entries. - * @test - */ - public function PIDinRootlineConditionMatchesLastPageIdInRootline() { - $GLOBALS['TSFE']->tmpl->rootLine = $this->rootline; - $GLOBALS['TSFE']->id = 121; - $this->assertTrue($this->matchCondition->match('[PIDinRootline = 121]')); - } - - /** - * Tests whether a page Id is found in all rootline entries. - * @test - */ - public function PIDinRootlineConditionDoesNotMatchPageIdNotInRootline() { - $GLOBALS['TSFE']->tmpl->rootLine = $this->rootline; - $GLOBALS['TSFE']->id = 121; - $this->assertFalse($this->matchCondition->match('[PIDinRootline = 999]')); - } - - /** - * Tests whether the compatibility version can be evaluated. - * (e.g. 4.9 is compatible to 4.0 but not to 5.0) - * @test - */ - public function compatVersionConditionMatchesOlderRelease() { - $GLOBALS['TYPO3_CONF_VARS']['SYS']['compat_version'] = '4.9'; - $this->assertTrue($this->matchCondition->match('[compatVersion = 4.0]')); - } - - /** - * Tests whether the compatibility version can be evaluated. - * (e.g. 4.9 is compatible to 4.0 but not to 5.0) - * @test - */ - public function compatVersionConditionMatchesSameRelease() { - $GLOBALS['TYPO3_CONF_VARS']['SYS']['compat_version'] = '4.9'; - $this->assertTrue($this->matchCondition->match('[compatVersion = 4.9]')); - } - - /** - * Tests whether the compatibility version can be evaluated. - * (e.g. 4.9 is compatible to 4.0 but not to 5.0) - * @test - */ - public function compatVersionConditionDoesNotMatchNewerRelease() { - $GLOBALS['TYPO3_CONF_VARS']['SYS']['compat_version'] = '4.9'; - $this->assertFalse($this->matchCondition->match('[compatVersion = 5.0]')); - } - - /** - * Tests whether the generic fetching of variables works with the namespace 'GP'. - * @test - */ - public function genericGetVariablesSucceedsWithNamespaceGP() { - $_GET = array('testGet' => 'getTest'); - $_POST = array('testPost' => 'postTest'); - - $this->assertTrue($this->matchCondition->match('[globalString = GP:testGet = getTest]')); - $this->assertTrue($this->matchCondition->match('[globalString = GP:testPost = postTest]')); - } - - /** - * Tests whether the generic fetching of variables works with the namespace 'TSFE'. - * @test - */ - public function genericGetVariablesSucceedsWithNamespaceTSFE() { - $GLOBALS['TSFE']->id = 1234567; - $GLOBALS['TSFE']->testSimpleObject = new stdClass(); - $GLOBALS['TSFE']->testSimpleObject->testSimpleVariable = 'testValue'; - - $this->assertTrue($this->matchCondition->match('[globalString = TSFE:id = 1234567]')); - $this->assertTrue($this->matchCondition->match('[globalString = TSFE:testSimpleObject|testSimpleVariable = testValue]')); - } - - /** - * Tests whether the generic fetching of variables works with the namespace 'ENV'. - * @test - */ - public function genericGetVariablesSucceedsWithNamespaceENV() { - $testKey = uniqid('test'); - putenv($testKey .'=testValue'); - - $this->assertTrue($this->matchCondition->match('[globalString = ENV:' . $testKey . ' = testValue]')); - } - - /** - * Tests whether the generic fetching of variables works with the namespace 'IENV'. - * @test - */ - public function genericGetVariablesSucceedsWithNamespaceIENV() { - $_SERVER['HTTP_HOST'] = t3lib_div::getIndpEnv('TYPO3_HOST_ONLY') . ':1234567'; - $this->assertTrue($this->matchCondition->match('[globalString = IENV:TYPO3_PORT = 1234567]')); - } - - /** - * Tests whether the generic fetching of variables works with any global namespace. - * @test - */ - public function genericGetVariablesSucceedsWithAnyGlobalNamespace() { - $GLOBALS[$this->testGlobalNamespace] = array( - 'first' => 'testFirst', - 'second' => array('third' => 'testThird'), - ); - - $this->assertTrue($this->matchCondition->match( - '[globalString = ' . $this->testGlobalNamespace . '|first = testFirst]' - )); - $this->assertTrue($this->matchCondition->match( - '[globalString = ' . $this->testGlobalNamespace . '|second|third = testThird]' - )); - } -} -?> \ No newline at end of file Index: tests/t3lib/matchcondition/t3lib_matchcondition_frontendTest.php =================================================================== --- tests/t3lib/matchcondition/t3lib_matchcondition_frontendTest.php (Revision 7835) +++ tests/t3lib/matchcondition/t3lib_matchcondition_frontendTest.php (Arbeitskopie) @@ -30,7 +30,7 @@ * @package TYPO3 * @subpackage t3lib */ -class t3lib_matchCondition_frontend_testcase extends tx_phpunit_testcase { +class t3lib_matchCondition_frontendTest extends tx_phpunit_testcase { /** * @var array */ Index: tests/t3lib/matchcondition/t3lib_matchcondition_backend_testcase.php =================================================================== --- tests/t3lib/matchcondition/t3lib_matchcondition_backend_testcase.php (Revision 7835) +++ tests/t3lib/matchcondition/t3lib_matchcondition_backend_testcase.php (Arbeitskopie) @@ -1,867 +0,0 @@ - -* All rights reserved -* -* This script is part of the TYPO3 project. The TYPO3 project is -* free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* The GNU General Public License can be found at -* http://www.gnu.org/copyleft/gpl.html. -* -* This script is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* This copyright notice MUST APPEAR in all copies of the script! -***************************************************************/ - - -/** - * Testcase for class t3lib_matchCondition_frontend. - * - * @author Oliver Hader - * @package TYPO3 - * @subpackage t3lib - */ -class t3lib_matchCondition_backend_testcase extends tx_phpunit_testcase { - /** - * @var array - */ - private $backupGlobalVariables; - - /** - * @var array - */ - private $rootline; - - /** - * @var t3lib_matchCondition_backend - */ - private $matchCondition; - - /** - * @var string - */ - private $testTableName; - - public function setUp() { - $this->backupGlobalVariables = array( - '_ENV' => $_ENV, - '_GET' => $_GET, - '_POST' => $_POST, - '_SERVER' => $_SERVER, - 'TCA' => $GLOBALS['TCA'], - 'TYPO3_DB' => $GLOBALS['TYPO3_DB'], - 'TYPO3_CONF_VARS' => $GLOBALS['TYPO3_CONF_VARS'], - 'T3_VAR' => $GLOBALS['T3_VAR'], - 'BE_USER' => $GLOBALS['BE_USER'], - 'SOBE' => $GLOBALS['SOBE'], - ); - - $this->testTableName = 't3lib_matchCondition_backend_testTable'; - $this->testGlobalNamespace = uniqid('TEST'); - - $GLOBALS['TCA'][$this->testTableName] = array('ctrl' => array()); - $GLOBALS[$this->testGlobalNamespace] = array(); - - $this->setUpBackend(); - - $this->matchCondition = t3lib_div::makeInstance('t3lib_matchCondition_backend'); - } - - public function tearDown() { - foreach ($this->backupGlobalVariables as $key => $data) { - $GLOBALS[$key] = $data; - } - - unset($this->matchCondition); - unset($this->backupGlobalVariables); - unset($GLOBALS[$this->testGlobalNamespace]); - } - - private function setUpBackend() { - $this->rootline = array( - 2 => array('uid' => 121, 'pid' => 111), - 1 => array('uid' => 111, 'pid' => 101,), - 0 => array('uid' => 101, 'pid' => 0,), - ); - - $GLOBALS['BE_USER'] = $this->getMock('beUserAuth', array(), array(), '', FALSE); - } - - private function setUpDatabaseMockForDeterminePageId() { - $GLOBALS['TYPO3_DB'] = $this->getMock('t3lib_DB', array('exec_SELECTquery', 'sql_fetch_assoc', 'sql_free_result')); - $GLOBALS['TYPO3_DB']->expects($this->any())->method('exec_SELECTquery')->will( - $this->returnCallback(array($this, 'determinePageIdByRecordDatabaseExecuteCallback')) - ); - $GLOBALS['TYPO3_DB']->expects($this->any())->method('sql_fetch_assoc')->will( - $this->returnCallback(array($this, 'determinePageIdByRecordDatabaseFetchCallback')) - ); - } - - /** - * Tests whether a faulty expression fails. - * @test - */ - public function simulateDisabledMatchAllConditionsFailsOnFaultyExpression() { - $this->matchCondition->matchAll = false; - $this->assertFalse($this->matchCondition->match('[nullCondition = This expression would return false in general]')); - } - - /** - * Tests whether simulating positive matches for all conditions succeeds. - * @test - */ - public function simulateEnabledMatchAllConditionsSucceeds() { - $this->matchCondition->setSimulateMatchResult(true); - $this->assertTrue($this->matchCondition->match('[nullCondition = This expression would return false in general]')); - } - - /** - * Tests whether simulating positive matches for specific conditions succeeds. - * @test - */ - public function simulateEnabledMatchSpecificConditionsSucceeds() { - $testCondition = '[' . uniqid('test') . ' = Any condition to simulate a positive match]'; - $this->matchCondition->setSimulateMatchConditions(array($testCondition)); - $this->assertTrue($this->matchCondition->match($testCondition)); - } - - /** - * Tests whether a condition matches Internet Explorer 7 on Windows. - * - * @return void - * @test - */ - public function conditionMatchesInternetExplorer7Windows() { - $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)'; - $result = $this->matchCondition->match('[browser = msie] && [version = 7] && [system = winNT]'); - $this->assertTrue($result); - } - - /** - * Tests whether a condition does not match Internet Explorer 7 on Windows. - * - * @return void - * @test - */ - public function conditionDoesNotMatchInternetExplorer7Windows() { - $_SERVER['HTTP_USER_AGENT'] = 'Opera/9.25 (Windows NT 6.0; U; en)'; - $result = $this->matchCondition->match('[browser = msie] && [version = 7] && [system = winNT]'); - $this->assertFalse($result); - } - - /** - * Tests whether a device type condition matches a crawler. - * @test - */ - public function deviceConditionMatchesRobot() { - $_SERVER['HTTP_USER_AGENT'] = 'Googlebot/2.1 (+http://www.google.com/bot.html)'; - $result = $this->matchCondition->match('[device = robot]'); - $this->assertTrue($result); - } - - /** - * Tests whether a device type condition does not match a crawler. - * @test - */ - public function deviceConditionDoesNotMatchRobot() { - $_SERVER['HTTP_USER_AGENT'] = md5('Some strange user agent'); - $result = $this->matchCondition->match('[device = robot]'); - $this->assertFalse($result); - } - - /** - * Tests whether the language comparison matches. - * @test - */ - public function languageConditionMatchesSingleLanguageExpression() { - $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'de-de,de;q=0.8,en-us;q=0.5,en;q=0.3'; - $this->assertTrue($this->matchCondition->match('[language = *de*]')); - $this->assertTrue($this->matchCondition->match('[language = *de-de*]')); - } - - /** - * Tests whether the language comparison matches. - * @test - */ - public function languageConditionMatchesMultipleLanguagesExpression() { - $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'de-de,de;q=0.8,en-us;q=0.5,en;q=0.3'; - $this->assertTrue($this->matchCondition->match('[language = *en*,*de*]')); - $this->assertTrue($this->matchCondition->match('[language = *en-us*,*de-de*]')); - } - - /** - * Tests whether the language comparison matches. - * @test - */ - public function languageConditionMatchesCompleteLanguagesExpression() { - $this->markTestSkipped('This comparison seems to be incomplete in t3lib_matchCondition.'); - - $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'de-de,de;q=0.8,en-us;q=0.5,en;q=0.3'; - $this->assertTrue($this->matchCondition->match('[language = de-de,de;q=0.8]')); - } - - /** - * Tests whether usergroup comparison matches. - * @test - */ - public function usergroupConditionMatchesSingleGroupId() { - $GLOBALS['BE_USER']->groupList = '13,14,15'; - $this->assertTrue($this->matchCondition->match('[usergroup = 13]')); - } - - /** - * Tests whether usergroup comparison matches. - * @test - */ - public function usergroupConditionMatchesMultipleUserGroupId() { - $GLOBALS['BE_USER']->groupList = '13,14,15'; - $this->assertTrue($this->matchCondition->match('[usergroup = 999,15,14,13]')); - } - - /** - * Tests whether user comparison matches. - * @test - */ - public function loginUserConditionMatchesAnyLoggedInUser() { - $GLOBALS['BE_USER']->user['uid'] = 13; - $this->assertTrue($this->matchCondition->match('[loginUser = *]')); - } - - /** - * Tests whether user comparison matches. - * @test - */ - public function loginUserConditionMatchesSingleLoggedInUser() { - $GLOBALS['BE_USER']->user['uid'] = 13; - $this->assertTrue($this->matchCondition->match('[loginUser = 13]')); - } - - /** - * Tests whether user comparison matches. - * @test - */ - public function loginUserConditionDoesNotMatchSingleLoggedInUser() { - $GLOBALS['BE_USER']->user['uid'] = 13; - $this->assertFalse($this->matchCondition->match('[loginUser = 999]')); - } - - /** - * Tests whether user comparison matches. - * @test - */ - public function loginUserConditionMatchesMultipleLoggedInUsers() { - $GLOBALS['BE_USER']->user['uid'] = 13; - $this->assertTrue($this->matchCondition->match('[loginUser = 999,13]')); - } - - /** - * Tests whether checkinf for an admin user matches - * @test - */ - public function adminUserConditionMatchesAdminUser() { - $GLOBALS['BE_USER']->user['uid'] = 13; - $GLOBALS['BE_USER']->user['admin'] = 1; - $this->assertTrue($this->matchCondition->match('[adminUser = 1]')); - } - - /** - * Tests whether checkinf for an admin user matches - * @test - */ - public function adminUserConditionMatchesRegularUser() { - $GLOBALS['BE_USER']->user['uid'] = 14; - $GLOBALS['BE_USER']->user['admin'] = 0; - $this->assertTrue($this->matchCondition->match('[adminUser = 0]')); - } - - /** - * Tests whether checkinf for an admin user matches - * @test - */ - public function adminUserConditionDoesNotMatchRegularUser() { - $GLOBALS['BE_USER']->user['uid'] = 14; - $GLOBALS['BE_USER']->user['admin'] = 0; - $this->assertFalse($this->matchCondition->match('[adminUser = 1]')); - } - - /** - * Tests whether numerical comparison matches. - * @test - */ - public function globalVarConditionMatchesOnEqualExpression() { - $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 = 10]')); - $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 = 10.1]')); - - $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 == 10]')); - $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 == 10.1]')); - } - - /** - * Tests whether numerical comparison matches. - * @test - */ - public function globalVarConditionMatchesOnNotEqualExpression() { - $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 != 20]')); - $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 != 10.2]')); - } - - /** - * Tests whether numerical comparison matches. - * @test - */ - public function globalVarConditionMatchesOnLowerThanExpression() { - $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 < 20]')); - $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 < 10.2]')); - } - - /** - * Tests whether numerical comparison matches. - * @test - */ - public function globalVarConditionMatchesOnLowerThanOrEqualExpression() { - $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 <= 10]')); - $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 <= 20]')); - - $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 <= 10.1]')); - $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 <= 10.2]')); - } - - /** - * Tests whether numerical comparison matches. - * @test - */ - public function globalVarConditionMatchesOnGreaterThanExpression() { - $this->assertTrue($this->matchCondition->match('[globalVar = LIT:20 > 10]')); - $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.2 > 10.1]')); - } - - /** - * Tests whether numerical comparison matches. - * @test - */ - public function globalVarConditionMatchesOnGreaterThanOrEqualExpression() { - $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 >= 10]')); - $this->assertTrue($this->matchCondition->match('[globalVar = LIT:20 >= 10]')); - - $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 >= 10.1]')); - $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.2 >= 10.1]')); - } - - /** - * Tests whether numerical comparison matches. - * @test - */ - public function globalVarConditionMatchesOnEmptyExpressionWithNoValueSet() { - $testKey = uniqid('test'); - $this->assertTrue($this->matchCondition->match('[globalVar = GP:' . $testKey . '=]')); - $this->assertTrue($this->matchCondition->match('[globalVar = GP:' . $testKey . ' = ]')); - } - - /** - * Tests whether numerical comparison matches. - * @test - */ - public function globalVarConditionDoesNotMatchOnEmptyExpressionWithValueSetToZero() { - $testKey = uniqid('test'); - - $_GET = array(); - $_POST = array($testKey => 0); - - $this->assertFalse($this->matchCondition->match('[globalVar = GP:' . $testKey . '=]')); - $this->assertFalse($this->matchCondition->match('[globalVar = GP:' . $testKey . ' = ]')); - } - - /** - * Tests whether string comparison matches. - * @test - */ - public function globalStringConditionMatchesOnEqualExpression() { - $this->assertTrue($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = TYPO3.Test.Condition]')); - $this->assertFalse($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = TYPO3]')); - } - - /** - * Tests whether string comparison matches. - * @test - */ - public function globalStringConditionMatchesWildcardExpression() { - $this->assertTrue($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = TYPO3?Test?Condition]')); - $this->assertTrue($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = TYPO3.T*t.Condition]')); - $this->assertTrue($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = TYPO3?T*t?Condition]')); - } - - /** - * Tests whether string comparison matches. - * @test - */ - public function globalStringConditionMatchesRegularExpression() { - $this->assertTrue($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = /^[A-Za-z3.]+$/]')); - $this->assertTrue($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = /^TYPO3\..+Condition$/]')); - $this->assertFalse($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = /^FALSE/]')); - } - - /** - * Tests whether string comparison matches. - * @test - */ - public function globalStringConditionMatchesEmptyRegularExpression() { - $testKey = uniqid('test'); - $_SERVER[$testKey] = ''; - $this->assertTrue($this->matchCondition->match('[globalString = _SERVER|' . $testKey . ' = /^$/]')); - } - - /** - * Tests whether treeLevel comparison matches. - * @test - */ - public function treeLevelConditionMatchesSingleValue() { - $this->matchCondition->setRootline($this->rootline); - $this->assertTrue($this->matchCondition->match('[treeLevel = 2]')); - } - - /** - * Tests whether treeLevel comparison matches. - * @test - */ - public function treeLevelConditionMatchesMultipleValues() { - $this->matchCondition->setRootline($this->rootline); - $this->assertTrue($this->matchCondition->match('[treeLevel = 999,998,2]')); - } - - /** - * Tests whether treeLevel comparison matches. - * @test - */ - public function treeLevelConditionDoesNotMatchFaultyValue() { - $this->matchCondition->setRootline($this->rootline); - $this->assertFalse($this->matchCondition->match('[treeLevel = 999]')); - } - - /** - * Tests whether treeLevel comparison matches when creating new pages. - * @test - */ - public function treeLevelConditionMatchesCurrentPageIdWhileEditingNewPage() { - $GLOBALS['SOBE'] = $this->getMock('SC_alt_doc', array()); - $GLOBALS['SOBE']->elementsData = array( - array( - 'table' => 'pages', - 'uid' => 'NEW4adc6021e37e7', - 'pid' => 121, - 'cmd' => 'new', - 'deleteAccess' => 0, - ), - ); - $GLOBALS['SOBE']->data = array(); - - $this->matchCondition->setRootline($this->rootline); - $this->matchCondition->setPageId(121); - $this->assertTrue($this->matchCondition->match('[treeLevel = 3]')); - } - - /** - * Tests whether treeLevel comparison matches when creating new pages. - * @test - */ - public function treeLevelConditionMatchesCurrentPageIdWhileSavingNewPage() { - $GLOBALS['SOBE'] = $this->getMock('SC_alt_doc', array()); - $GLOBALS['SOBE']->elementsData = array( - array( - 'table' => 'pages', - /// 999 is the uid of the page that was just created - 'uid' => 999, - 'pid' => 121, - 'cmd' => 'edit', - 'deleteAccess' => 1, - ), - ); - $GLOBALS['SOBE']->data = array( - 'pages' => array( - 'NEW4adc6021e37e7' => array( - 'pid' => 121, - ), - ), - ); - - $this->matchCondition->setRootline($this->rootline); - $this->matchCondition->setPageId(121); - $this->assertTrue($this->matchCondition->match('[treeLevel = 3]')); - } - - /** - * Tests whether a page Id is found in the previous rootline entries. - * @test - */ - public function PIDupinRootlineConditionMatchesSinglePageIdInRootline() { - $this->matchCondition->setRootline($this->rootline); - $this->matchCondition->setPageId(121); - $this->assertTrue($this->matchCondition->match('[PIDupinRootline = 111]')); - } - - /** - * Tests whether a page Id is found in the previous rootline entries. - * @test - */ - public function PIDupinRootlineConditionMatchesMultiplePageIdsInRootline() { - $this->matchCondition->setRootline($this->rootline); - $this->matchCondition->setPageId(121); - $this->assertTrue($this->matchCondition->match('[PIDupinRootline = 999,111,101]')); - } - - /** - * Tests whether a page Id is found in the previous rootline entries. - * @test - */ - public function PIDupinRootlineConditionDoesNotMatchPageIdNotInRootline() { - $this->matchCondition->setRootline($this->rootline); - $this->matchCondition->setPageId(121); - $this->assertFalse($this->matchCondition->match('[PIDupinRootline = 999]')); - } - - /** - * Tests whether a page Id is found in the previous rootline entries. - * @test - */ - public function PIDupinRootlineConditionDoesNotMatchLastPageIdInRootline() { - $this->matchCondition->setRootline($this->rootline); - $this->matchCondition->setPageId(121); - $this->assertFalse($this->matchCondition->match('[PIDupinRootline = 121]')); - } - - /** - * Tests whether a page Id is found in the previous rootline entries. - * @test - */ - public function PIDupinRootlineConditionMatchesCurrentPageIdWhileEditingNewPage() { - $GLOBALS['SOBE'] = $this->getMock('SC_alt_doc', array()); - $GLOBALS['SOBE']->elementsData = array( - array( - 'table' => 'pages', - 'uid' => 'NEW4adc6021e37e7', - 'pid' => 121, - 'cmd' => 'new', - 'deleteAccess' => 0, - ), - ); - $GLOBALS['SOBE']->data = array(); - - $this->matchCondition->setRootline($this->rootline); - $this->matchCondition->setPageId(121); - $this->assertTrue($this->matchCondition->match('[PIDupinRootline = 121]')); - } - - /** - * Tests whether a page Id is found in the previous rootline entries. - * @test - */ - public function PIDupinRootlineConditionMatchesCurrentPageIdWhileSavingNewPage() { - $GLOBALS['SOBE'] = $this->getMock('SC_alt_doc', array()); - $GLOBALS['SOBE']->elementsData = array( - array( - 'table' => 'pages', - /// 999 is the uid of the page that was just created - 'uid' => 999, - 'pid' => 121, - 'cmd' => 'edit', - 'deleteAccess' => 1, - ), - ); - $GLOBALS['SOBE']->data = array( - 'pages' => array( - 'NEW4adc6021e37e7' => array( - 'pid' => 121, - ), - ), - ); - - $this->matchCondition->setRootline($this->rootline); - $this->matchCondition->setPageId(121); - $this->assertTrue($this->matchCondition->match('[PIDupinRootline = 121]')); - } - - /** - * Tests whether a page Id is found in all rootline entries. - * @test - */ - public function PIDinRootlineConditionMatchesSinglePageIdInRootline() { - $this->matchCondition->setRootline($this->rootline); - $this->matchCondition->setPageId(121); - $this->assertTrue($this->matchCondition->match('[PIDinRootline = 111]')); - } - - /** - * Tests whether a page Id is found in all rootline entries. - * @test - */ - public function PIDinRootlineConditionMatchesMultiplePageIdsInRootline() { - $this->matchCondition->setRootline($this->rootline); - $this->matchCondition->setPageId(121); - $this->assertTrue($this->matchCondition->match('[PIDinRootline = 999,111,101]')); - } - - /** - * Tests whether a page Id is found in all rootline entries. - * @test - */ - public function PIDinRootlineConditionMatchesLastPageIdInRootline() { - $this->matchCondition->setRootline($this->rootline); - $this->matchCondition->setPageId(121); - $this->assertTrue($this->matchCondition->match('[PIDinRootline = 121]')); - } - - /** - * Tests whether a page Id is found in all rootline entries. - * @test - */ - public function PIDinRootlineConditionDoesNotMatchPageIdNotInRootline() { - $this->matchCondition->setRootline($this->rootline); - $this->matchCondition->setPageId(121); - $this->assertFalse($this->matchCondition->match('[PIDinRootline = 999]')); - } - - /** - * Tests whether the compatibility version can be evaluated. - * (e.g. 4.9 is compatible to 4.0 but not to 5.0) - * @test - */ - public function compatVersionConditionMatchesOlderRelease() { - $GLOBALS['TYPO3_CONF_VARS']['SYS']['compat_version'] = '4.9'; - $this->assertTrue($this->matchCondition->match('[compatVersion = 4.0]')); - } - - /** - * Tests whether the compatibility version can be evaluated. - * (e.g. 4.9 is compatible to 4.0 but not to 5.0) - * @test - */ - public function compatVersionConditionMatchesSameRelease() { - $GLOBALS['TYPO3_CONF_VARS']['SYS']['compat_version'] = '4.9'; - $this->assertTrue($this->matchCondition->match('[compatVersion = 4.9]')); - } - - /** - * Tests whether the compatibility version can be evaluated. - * (e.g. 4.9 is compatible to 4.0 but not to 5.0) - * @test - */ - public function compatVersionConditionDoesNotMatchNewerRelease() { - $GLOBALS['TYPO3_CONF_VARS']['SYS']['compat_version'] = '4.9'; - $this->assertFalse($this->matchCondition->match('[compatVersion = 5.0]')); - } - - /** - * Tests whether the generic fetching of variables works with the namespace 'GP'. - * @test - */ - public function genericGetVariablesSucceedsWithNamespaceGP() { - $_GET = array('testGet' => 'getTest'); - $_POST = array('testPost' => 'postTest'); - - $this->assertTrue($this->matchCondition->match('[globalString = GP:testGet = getTest]')); - $this->assertTrue($this->matchCondition->match('[globalString = GP:testPost = postTest]')); - } - - /** - * Tests whether the generic fetching of variables does not work with the namespace 'TSFE', - * since we are in the backend context here. - * @test - */ - public function genericGetVariablesFailsWithNamespaceTSFE() { - $GLOBALS['TSFE'] = new stdClass(); - $GLOBALS['TSFE']->id = 1234567; - - $this->assertFalse($this->matchCondition->match('[globalString = TSFE:id = 1234567]')); - } - - /** - * Tests whether the generic fetching of variables works with the namespace 'ENV'. - * @test - */ - public function genericGetVariablesSucceedsWithNamespaceENV() { - $testKey = uniqid('test'); - putenv($testKey .'=testValue'); - - $this->assertTrue($this->matchCondition->match('[globalString = ENV:' . $testKey . ' = testValue]')); - } - - /** - * Tests whether the generic fetching of variables works with the namespace 'IENV'. - * @test - */ - public function genericGetVariablesSucceedsWithNamespaceIENV() { - $_SERVER['HTTP_HOST'] = t3lib_div::getIndpEnv('TYPO3_HOST_ONLY') . ':1234567'; - $this->assertTrue($this->matchCondition->match('[globalString = IENV:TYPO3_PORT = 1234567]')); - } - - /** - * Tests whether the generic fetching of variables works with any global namespace. - * @test - */ - public function genericGetVariablesSucceedsWithAnyGlobalNamespace() { - $GLOBALS[$this->testGlobalNamespace] = array( - 'first' => 'testFirst', - 'second' => array('third' => 'testThird'), - ); - - $this->assertTrue($this->matchCondition->match( - '[globalString = ' . $this->testGlobalNamespace . '|first = testFirst]' - )); - $this->assertTrue($this->matchCondition->match( - '[globalString = ' . $this->testGlobalNamespace . '|second|third = testThird]' - )); - } - - /** - * Tests whether determining a pageId works. - * @test - */ - public function pageIdCanBeDeterminedWhileCallingModuleWithPageTree() { - $_GET['id'] = 999; - - $this->matchCondition->match('[globalVar = LIT:10 = 10]'); - $this->assertEquals(999, $this->matchCondition->getPageId()); - } - - /** - * Tests whether determining a pageId works. - * @test - */ - public function pageIdCanBeDeterminedWhileEditingAPageRecord() { - $_GET['edit']['pages'][999] = 'edit'; - - $this->matchCondition->match('[globalVar = LIT:10 = 10]'); - $this->assertEquals(999, $this->matchCondition->getPageId()); - } - - /** - * Tests whether determining a pageId works. - * @test - */ - public function pageIdCanBeDeterminedWhileEditingARegularRecord() { - $this->setUpDatabaseMockForDeterminePageId(); - - $_GET['edit'][$this->testTableName][13] = 'edit'; - - $this->matchCondition->match('[globalVar = LIT:10 = 10]'); - $this->assertEquals(999, $this->matchCondition->getPageId()); - } - - /** - * Tests whether determining a pageId works. - * @test - */ - public function pageIdCanBeDeterminedWhileCreatingARecord() { - $_GET['edit']['pages'][999] = 'new'; - - $this->matchCondition->match('[globalVar = LIT:10 = 10]'); - $this->assertEquals(999, $this->matchCondition->getPageId()); - } - - /** - * Tests whether determining a pageId works. - * @test - */ - public function pageIdCanBeDeterminedWhileCreatingARecordAfterAnExistingRecord() { - $this->setUpDatabaseMockForDeterminePageId(); - - $_GET['edit'][$this->testTableName][-13] = 'new'; - - $this->matchCondition->match('[globalVar = LIT:10 = 10]'); - $this->assertEquals(999, $this->matchCondition->getPageId()); - } - - /** - * Tests whether determining a pageId works. - * @test - */ - public function pageIdCanBeDeterminedWhileDeletingAPageRecord() { - $_GET['cmd']['pages'][999]['delete'] = 1; - - $this->matchCondition->match('[globalVar = LIT:10 = 10]'); - $this->assertEquals(999, $this->matchCondition->getPageId()); - } - - /** - * Tests whether determining a pageId works. - * @test - */ - public function pageIdCanBeDeterminedWhileCopyingARecordToAnotherPage() { - $_GET['cmd']['pages'][121]['copy'] = 999; - - $this->matchCondition->match('[globalVar = LIT:10 = 10]'); - $this->assertEquals(999, $this->matchCondition->getPageId()); - } - - /** - * Tests whether determining a pageId works. - * @test - */ - public function pageIdCanBeDeterminedWhileCopyingARecordAfterAnExistingRecord() { - $this->setUpDatabaseMockForDeterminePageId(); - - $_GET['cmd'][$this->testTableName][121]['copy'] = -13; - - $this->matchCondition->match('[globalVar = LIT:10 = 10]'); - $this->assertEquals(999, $this->matchCondition->getPageId()); - } - - /** - * Tests whether determining a pageId works. - * @test - */ - public function pageIdCanBeDeterminedWhileMovingARecordToAnotherPage() { - $_GET['cmd']['pages'][121]['move'] = 999; - - $this->matchCondition->match('[globalVar = LIT:10 = 10]'); - $this->assertEquals(999, $this->matchCondition->getPageId()); - } - - /** - * Callback method for pageIdCanBeDetermined test cases. - * Simulates TYPO3_DB->exec_SELECTquery(). - * - * @param string $fields - * @param string $table - * @param string $where - * @return mixed - */ - public function determinePageIdByRecordDatabaseExecuteCallback($fields, $table, $where) { - if ($table === $this->testTableName) { - return array( - 'scope' => $this->testTableName, - 'processed' => false, - 'data' => array( - 'pid' => 999, - ), - ); - } else { - return FALSE; - } - } - - /** - * Callback method for pageIdCanBeDetermined test cases. - * Simulates TYPO3_DB->sql_fetch_assoc(). - * - * @param mixed $resource - * @return mixed - */ - public function determinePageIdByRecordDatabaseFetchCallback(&$resource) { - if (is_array($resource) && !$resource['processed'] && $resource['scope'] === $this->testTableName) { - $resource['processed'] = true; - return $resource['data']; - } else { - return FALSE; - } - } -} -?> \ No newline at end of file Index: tests/t3lib/matchcondition/t3lib_matchcondition_backendTest.php =================================================================== --- tests/t3lib/matchcondition/t3lib_matchcondition_backendTest.php (Revision 7835) +++ tests/t3lib/matchcondition/t3lib_matchcondition_backendTest.php (Arbeitskopie) @@ -30,7 +30,7 @@ * @package TYPO3 * @subpackage t3lib */ -class t3lib_matchCondition_backend_testcase extends tx_phpunit_testcase { +class t3lib_matchCondition_backendTest extends tx_phpunit_testcase { /** * @var array */ Index: tests/t3lib/cache/frontend/t3lib_cache_frontend_abstractfrontendtestcase.php =================================================================== --- tests/t3lib/cache/frontend/t3lib_cache_frontend_abstractfrontendtestcase.php (Revision 7835) +++ tests/t3lib/cache/frontend/t3lib_cache_frontend_abstractfrontendtestcase.php (Arbeitskopie) @@ -1,197 +0,0 @@ - -* All rights reserved -* -* This script is part of the TYPO3 project. The TYPO3 project is -* free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* The GNU General Public License can be found at -* http://www.gnu.org/copyleft/gpl.html. -* -* This script is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* This copyright notice MUST APPEAR in all copies of the script! -***************************************************************/ - - -require_once(PATH_t3lib . 'cache/frontend/class.t3lib_cache_frontend_stringfrontend.php'); - -/** - * Testcase for the abstract cache frontend - * - * This file is a backport from FLOW3 - * - * @author Ingo Renner - * @package TYPO3 - * @subpackage tests - * @version $Id$ - */ -class t3lib_cache_frontend_AbstractFrontendTestCase extends tx_phpunit_testcase { - - /** - * @test - * @author Robert Lemke - * @author Ingo Renner - */ - public function theConstructorAcceptsValidIdentifiers() { - $mockBackend = $this->getMock('t3lib_cache_backend_AbstractBackend', array('get', 'set', 'has', 'remove', 'findIdentifiersByTag', 'findIdentifiersByTags', 'flush', 'flushByTag', 'flushByTags', 'collectGarbage'), array(), '', FALSE); - foreach (array('x', 'someValue', '123fivesixseveneight', 'some&', 'ab_cd%', rawurlencode('resource://some/äöü$&% sadf'), str_repeat('x', 250)) as $identifier) { - $abstractCache = $this->getMock('t3lib_cache_frontend_StringFrontend', array('__construct', 'get', 'set', 'has', 'remove', 'getByTag', 'flush', 'flushByTag', 'collectGarbage'), array($identifier, $mockBackend)); - } - } - - /** - * @test - * @author Robert Lemke - * @author Ingo Renner - */ - public function theConstructorRejectsInvalidIdentifiers() { - $mockBackend = $this->getMock('t3lib_cache_backend_AbstractBackend', array('get', 'set', 'has', 'remove', 'findIdentifiersByTag', 'findIdentifiersByTags', 'flush', 'flushByTag', 'flushByTags', 'collectGarbage'), array(), '', FALSE); - foreach (array('', 'abc def', 'foo!', 'bar:', 'some/', 'bla*', 'one+', 'äöü', str_repeat('x', 251), 'x$', '\\a', 'b#') as $identifier) { - try { - $abstractCache = $this->getMock('t3lib_cache_frontend_StringFrontend', array('__construct', 'get', 'set', 'has', 'remove', 'getByTag', 'flush', 'flushByTag', 'collectGarbage'), array($identifier, $mockBackend)); - $this->fail('Identifier "' . $identifier . '" was not rejected.'); - } catch (InvalidArgumentException $exception) { - } - } - } - - /** - * @test - * @author Karsten Dambekalns - * @author Ingo Renner - */ - public function flushCallsBackend() { - $identifier = 'someCacheIdentifier'; - $backend = $this->getMock('t3lib_cache_backend_AbstractBackend', array('get', 'set', 'has', 'remove', 'findIdentifiersByTag', 'findIdentifiersByTags', 'flush', 'flushByTag', 'flushByTags', 'collectGarbage'), array(), '', FALSE); - $backend->expects($this->once())->method('flush'); - - $cache = $this->getMock('t3lib_cache_frontend_StringFrontend', array('__construct', 'get', 'set', 'has', 'remove', 'getByTag'), array($identifier, $backend)); - $cache->flush(); - } - - - /** - * @test - * @expectedException InvalidArgumentException - * @author Robert Lemke - * @author Ingo Renner - */ - public function flushByTagRejectsInvalidTags() { - $identifier = 'someCacheIdentifier'; - $backend = $this->getMock('t3lib_cache_backend_Backend', array(), array(), '', FALSE); - $backend->expects($this->never())->method('flushByTag'); - - $cache = $this->getMock('t3lib_cache_frontend_StringFrontend', array('__construct', 'get', 'set', 'has', 'remove', 'getByTag'), array($identifier, $backend)); - $cache->flushByTag('SomeInvalid\Tag'); - } - - /** - * @test - * @author Karsten Dambekalns - * @author Ingo Renner - */ - public function flushByTagCallsBackend() { - $tag = 'sometag'; - $identifier = 'someCacheIdentifier'; - $backend = $this->getMock('t3lib_cache_backend_AbstractBackend', array('get', 'set', 'has', 'remove', 'findIdentifiersByTag', 'findIdentifiersByTags', 'flush', 'flushByTag', 'flushByTags', 'collectGarbage'), array(), '', FALSE); - $backend->expects($this->once())->method('flushByTag')->with($tag); - - $cache = $this->getMock('t3lib_cache_frontend_StringFrontend', array('__construct', 'get', 'set', 'has', 'remove', 'getByTag'), array($identifier, $backend)); - $cache->flushByTag($tag); - } - - /** - * @test - * @author Karsten Dambekalns - * @author Ingo Renner - */ - public function collectGarbageCallsBackend() { - $identifier = 'someCacheIdentifier'; - $backend = $this->getMock('t3lib_cache_backend_AbstractBackend', array('get', 'set', 'has', 'remove', 'findIdentifiersByTag', 'findIdentifiersByTags', 'flush', 'flushByTag', 'flushByTags', 'collectGarbage'), array(), '', FALSE); - $backend->expects($this->once())->method('collectGarbage'); - - $cache = $this->getMock('t3lib_cache_frontend_StringFrontend', array('__construct', 'get', 'set', 'has', 'remove', 'getByTag'), array($identifier, $backend)); - $cache->collectGarbage(); - } - - /** - * @test - * @author Robert Lemke - * @author Ingo Renner - */ - public function getClassTagRendersTagWhichCanBeUsedToTagACacheEntryWithACertainClass() { - $identifier = 'someCacheIdentifier'; - $backend = $this->getMock('t3lib_cache_backend_AbstractBackend', array('get', 'set', 'has', 'remove', 'findIdentifiersByTag', 'findIdentifiersByTags', 'flush', 'flushByTag', 'flushByTags', 'collectGarbage'), array(), '', FALSE); - - $cache = $this->getMock('t3lib_cache_frontend_StringFrontend', array('__construct', 'get', 'set', 'has', 'remove', 'getByTag'), array($identifier, $backend)); - $this->assertEquals('%CLASS%F3_Foo_Bar_Baz', $cache->getClassTag('F3\Foo\Bar\Baz')); - } - - /** - * @test - * @author Robert Lemke - * @author Ingo Renner - */ - public function invalidEntryIdentifiersAreRecognizedAsInvalid() { - $identifier = 'someCacheIdentifier'; - $backend = $this->getMock('t3lib_cache_backend_AbstractBackend', array(), array(), '', FALSE); - $cache = $this->getMock('t3lib_cache_frontend_StringFrontend', array('__construct', 'get', 'set', 'has', 'remove', 'getByTag'), array($identifier, $backend)); - foreach (array('', 'abc def', 'foo!', 'bar:', 'some/', 'bla*', 'one+', 'äöü', str_repeat('x', 251), 'x$', '\\a', 'b#') as $entryIdentifier) { - $this->assertFalse($cache->isValidEntryIdentifier($entryIdentifier), 'Invalid identifier "' . $entryIdentifier . '" was not rejected.'); - } - } - - /** - * @test - * @author Robert Lemke - * @author Ingo Renner - */ - public function validEntryIdentifiersAreRecognizedAsValid() { - $identifier = 'someCacheIdentifier'; - $backend = $this->getMock('t3lib_cache_backend_AbstractBackend', array(), array(), '', FALSE); - $cache = $this->getMock('t3lib_cache_frontend_StringFrontend', array('__construct', 'get', 'set', 'has', 'remove', 'getByTag'), array($identifier, $backend)); - foreach (array('_', 'abcdef', 'foo', 'bar123', '3some', '_bl_a', 'some&', 'one%TWO', str_repeat('x', 250)) as $entryIdentifier) { - $this->assertTrue($cache->isValidEntryIdentifier($entryIdentifier), 'Valid identifier "' . $entryIdentifier . '" was not accepted.'); - } - } - - /** - * @test - * @author Robert Lemke - * @author Ingo Renner - */ - public function invalidTagsAreRecognizedAsInvalid() { - $identifier = 'someCacheIdentifier'; - $backend = $this->getMock('t3lib_cache_backend_AbstractBackend', array(), array(), '', FALSE); - $cache = $this->getMock('t3lib_cache_frontend_StringFrontend', array('__construct', 'get', 'set', 'has', 'remove', 'getByTag'), array($identifier, $backend)); - foreach (array('', 'abc def', 'foo!', 'bar:', 'some/', 'bla*', 'one+', 'äöü', str_repeat('x', 251), 'x$', '\\a', 'b#') as $tag) { - $this->assertFalse($cache->isValidTag($tag), 'Invalid tag "' . $tag . '" was not rejected.'); - } - } - - /** - * @test - * @author Robert Lemke - * @author Ingo Renner - */ - public function validTagsAreRecognizedAsValid() { - $identifier = 'someCacheIdentifier'; - $backend = $this->getMock('t3lib_cache_backend_AbstractBackend', array(), array(), '', FALSE); - $cache = $this->getMock('t3lib_cache_frontend_StringFrontend', array('__construct', 'get', 'set', 'has', 'remove', 'getByTag'), array($identifier, $backend)); - foreach (array('abcdef', 'foo-bar', 'foo_baar', 'bar123', '3some', 'file%Thing', 'some&', '%x%', str_repeat('x', 250)) as $tag) { - $this->assertTrue($cache->isValidTag($tag), 'Valid tag "' . $tag . '" was not accepted.'); - } - } -} - -?> \ No newline at end of file Index: tests/t3lib/cache/frontend/t3lib_cache_frontend_variablefrontendtestcase.php =================================================================== --- tests/t3lib/cache/frontend/t3lib_cache_frontend_variablefrontendtestcase.php (Revision 7835) +++ tests/t3lib/cache/frontend/t3lib_cache_frontend_variablefrontendtestcase.php (Arbeitskopie) @@ -1,195 +0,0 @@ - -* All rights reserved -* -* This script is part of the TYPO3 project. The TYPO3 project is -* free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* The GNU General Public License can be found at -* http://www.gnu.org/copyleft/gpl.html. -* -* This script is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* This copyright notice MUST APPEAR in all copies of the script! -***************************************************************/ - - -/** - * Testcase for the variable cache frontend - * - * This file is a backport from FLOW3 - * - * @author Ingo Renner - * @package TYPO3 - * @subpackage tests - * @version $Id$ - */ -class t3lib_cache_frontend_VariableFrontendTestCase extends tx_phpunit_testcase { - - /** - * @expectedException InvalidArgumentException - * @test - * @author Robert Lemke - * @author Ingo Renner - */ - public function setChecksIfTheIdentifierIsValid() { - $cache = $this->getMock('t3lib_cache_frontend_StringFrontend', array('isValidEntryIdentifier'), array(), '', FALSE); - $cache->expects($this->once())->method('isValidEntryIdentifier')->with('foo')->will($this->returnValue(FALSE)); - $cache->set('foo', 'bar'); - } - - /** - * @test - * @author Robert Lemke - * @author Ingo Renner - */ - public function setPassesSerializedStringToBackend() { - $theString = 'Just some value'; - $backend = $this->getMock('t3lib_cache_backend_AbstractBackend', array('get', 'set', 'has', 'remove', 'findIdentifiersByTag', 'findIdentifiersByTags', 'flush', 'flushByTag', 'flushByTags', 'collectGarbage'), array(), '', FALSE); - $backend->expects($this->once())->method('set')->with($this->equalTo('VariableCacheTest'), $this->equalTo(serialize($theString))); - - $cache = new t3lib_cache_frontend_VariableFrontend('VariableFrontend', $backend); - $cache->set('VariableCacheTest', $theString); - } - - /** - * @test - * @author Robert Lemke - * @author Ingo Renner - */ - public function setPassesSerializedArrayToBackend() { - $theArray = array('Just some value', 'and another one.'); - $backend = $this->getMock('t3lib_cache_backend_AbstractBackend', array('get', 'set', 'has', 'remove', 'findIdentifiersByTag', 'findIdentifiersByTags', 'flush', 'flushByTag', 'flushByTags', 'collectGarbage'), array(), '', FALSE); - $backend->expects($this->once())->method('set')->with($this->equalTo('VariableCacheTest'), $this->equalTo(serialize($theArray))); - - $cache = new t3lib_cache_frontend_VariableFrontend('VariableFrontend', $backend); - $cache->set('VariableCacheTest', $theArray); - } - - /** - * @test - * @author Karsten Dambekalns - * @author Ingo Renner - */ - public function setPassesLifetimeToBackend() { - $theString = 'Just some value'; - $theLifetime = 1234; - $backend = $this->getMock('t3lib_cache_backend_AbstractBackend', array('get', 'set', 'has', 'remove', 'findIdentifiersByTag', 'findIdentifiersByTags', 'flush', 'flushByTag', 'flushByTags', 'collectGarbage'), array(), '', FALSE); - $backend->expects($this->once())->method('set')->with($this->equalTo('VariableCacheTest'), $this->equalTo(serialize($theString)), $this->equalTo(array()), $this->equalTo($theLifetime)); - - $cache = new t3lib_cache_frontend_VariableFrontend('VariableFrontend', $backend); - $cache->set('VariableCacheTest', $theString, array(), $theLifetime); - } - - /** - * @test - * @author Robert Lemke - * @author Ingo Renner - */ - public function getFetchesStringValueFromBackend() { - $backend = $this->getMock('t3lib_cache_backend_AbstractBackend', array('get', 'set', 'has', 'remove', 'findIdentifiersByTag', 'findIdentifiersByTags', 'flush', 'flushByTag', 'flushByTags', 'collectGarbage'), array(), '', FALSE); - $backend->expects($this->once())->method('get')->will($this->returnValue(serialize('Just some value'))); - - $cache = new t3lib_cache_frontend_VariableFrontend('VariableFrontend', $backend); - $this->assertEquals('Just some value', $cache->get('VariableCacheTest'), 'The returned value was not the expected string.'); - } - - /** - * @test - * @author Robert Lemke - * @author Ingo Renner - */ - public function getFetchesArrayValueFromBackend() { - $theArray = array('Just some value', 'and another one.'); - $backend = $this->getMock('t3lib_cache_backend_AbstractBackend', array('get', 'set', 'has', 'remove', 'findIdentifiersByTag', 'findIdentifiersByTags', 'flush', 'flushByTag', 'flushByTags', 'collectGarbage'), array(), '', FALSE); - $backend->expects($this->once())->method('get')->will($this->returnValue(serialize($theArray))); - - $cache = new t3lib_cache_frontend_VariableFrontend('VariableFrontend', $backend); - $this->assertEquals($theArray, $cache->get('VariableCacheTest'), 'The returned value was not the expected unserialized array.'); - } - - /** - * @test - * @author Robert Lemke - * @author Ingo Renner - */ - public function getFetchesFalseBooleanValueFromBackend() { - $backend = $this->getMock('t3lib_cache_backend_AbstractBackend', array('get', 'set', 'has', 'remove', 'findIdentifiersByTag', 'findIdentifiersByTags', 'flush', 'flushByTag', 'flushByTags', 'collectGarbage'), array(), '', FALSE); - $backend->expects($this->once())->method('get')->will($this->returnValue(serialize(FALSE))); - - $cache = new t3lib_cache_frontend_VariableFrontend('VariableFrontend', $backend); - $this->assertFalse($cache->get('VariableCacheTest'), 'The returned value was not the FALSE.'); - } - - /** - * @test - * @author Robert Lemke - * @author Ingo Renner - */ - public function hasReturnsResultFromBackend() { - $backend = $this->getMock('t3lib_cache_backend_AbstractBackend', array('get', 'set', 'has', 'remove', 'findIdentifiersByTag', 'findIdentifiersByTags', 'flush', 'flushByTag', 'flushByTags', 'collectGarbage'), array(), '', FALSE); - $backend->expects($this->once())->method('has')->with($this->equalTo('VariableCacheTest'))->will($this->returnValue(TRUE)); - - $cache = new t3lib_cache_frontend_VariableFrontend('VariableFrontend', $backend); - $this->assertTrue($cache->has('VariableCacheTest'), 'has() did not return TRUE.'); - } - - /** - * @test - * @author Sebastian Kurfuerst - * @author Ingo Renner - */ - public function removeCallsBackend() { - $cacheIdentifier = 'someCacheIdentifier'; - $backend = $this->getMock('t3lib_cache_backend_AbstractBackend', array('get', 'set', 'has', 'remove', 'findIdentifiersByTag', 'findIdentifiersByTags', 'flush', 'flushByTag', 'flushByTags', 'collectGarbage'), array(), '', FALSE); - - $backend->expects($this->once())->method('remove')->with($this->equalTo($cacheIdentifier))->will($this->returnValue(TRUE)); - - $cache = new t3lib_cache_frontend_VariableFrontend('VariableFrontend', $backend); - $this->assertTrue($cache->remove($cacheIdentifier), 'remove() did not return TRUE'); - } - - /** - * @test - * @expectedException InvalidArgumentException - * @author Karsten Dambekalns - * @author Ingo Renner - */ - public function getByTagRejectsInvalidTags() { - $backend = $this->getMock('t3lib_cache_backend_Backend', array(), array(), '', FALSE); - $backend->expects($this->never())->method('getByTag'); - - $cache = new t3lib_cache_frontend_VariableFrontend('VariableFrontend', $backend); - $cache->getByTag('SomeInvalid\Tag'); - } - - /** - * @test - * @author Karsten Dambekalns - * @author Ingo Renner - */ - public function getByTagCallsBackend() { - $tag = 'sometag'; - $identifiers = array('one', 'two'); - $entries = array('one value', 'two value'); - $backend = $this->getMock('t3lib_cache_backend_AbstractBackend', array('get', 'set', 'has', 'remove', 'findIdentifiersByTag', 'findIdentifiersByTags', 'flush', 'flushByTag', 'flushByTags', 'collectGarbage'), array(), '', FALSE); - - $backend->expects($this->once())->method('findIdentifiersByTag')->with($this->equalTo($tag))->will($this->returnValue($identifiers)); - $backend->expects($this->exactly(2))->method('get')->will($this->onConsecutiveCalls(serialize('one value'), serialize('two value'))); - - $cache = new t3lib_cache_frontend_VariableFrontend('VariableFrontend', $backend); - $this->assertEquals($entries, $cache->getByTag($tag), 'Did not receive the expected entries'); - } - -} - -?> \ No newline at end of file Index: tests/t3lib/cache/frontend/t3lib_cache_frontend_stringfrontendtestcase.php =================================================================== --- tests/t3lib/cache/frontend/t3lib_cache_frontend_stringfrontendtestcase.php (Revision 7835) +++ tests/t3lib/cache/frontend/t3lib_cache_frontend_stringfrontendtestcase.php (Arbeitskopie) @@ -1,169 +0,0 @@ - -* All rights reserved -* -* This script is part of the TYPO3 project. The TYPO3 project is -* free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* The GNU General Public License can be found at -* http://www.gnu.org/copyleft/gpl.html. -* -* This script is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* This copyright notice MUST APPEAR in all copies of the script! -***************************************************************/ - - -require_once(PATH_t3lib . 'cache/frontend/class.t3lib_cache_frontend_stringfrontend.php'); - -/** - * Testcase for the string cache frontend - * - * This file is a backport from FLOW3 - * - * @author Ingo Renner - * @package TYPO3 - * @subpackage tests - * @version $Id$ - */ -class t3lib_cache_frontend_StringFrontendTestCase extends tx_phpunit_testcase { - - /** - * @expectedException InvalidArgumentException - * @test - * @author Robert Lemke - * @author Ingo Renner - */ - public function setChecksIfTheIdentifierIsValid() { - $cache = $this->getMock('t3lib_cache_frontend_StringFrontend', array('isValidEntryIdentifier'), array(), '', FALSE); - $cache->expects($this->once())->method('isValidEntryIdentifier')->with('foo')->will($this->returnValue(FALSE)); - $cache->set('foo', 'bar'); - } - - /** - * @test - * @author Karsten Dambekalns - * @author Ingo Renner - */ - public function setPassesStringToBackend() { - $theString = 'Just some value'; - $backend = $this->getMock('t3lib_cache_backend_AbstractBackend', array('get', 'set', 'has', 'remove', 'findIdentifiersByTag', 'findIdentifiersByTags', 'flush', 'flushByTag', 'flushByTags', 'collectGarbage'), array(), '', FALSE); - $backend->expects($this->once())->method('set')->with($this->equalTo('StringCacheTest'), $this->equalTo($theString)); - - $cache = new t3lib_cache_frontend_StringFrontend('StringFrontend', $backend); - $cache->set('StringCacheTest', $theString); - } - - /** - * @test - * @author Karsten Dambekalns - * @author Ingo Renner - */ - public function setPassesLifetimeToBackend() { - $theString = 'Just some value'; - $theLifetime = 1234; - $backend = $this->getMock('t3lib_cache_backend_AbstractBackend', array('get', 'set', 'has', 'remove', 'findIdentifiersByTag', 'findIdentifiersByTags', 'flush', 'flushByTag', 'flushByTags', 'collectGarbage'), array(), '', FALSE); - $backend->expects($this->once())->method('set')->with($this->equalTo('StringCacheTest'), $this->equalTo($theString), $this->equalTo(array()), $this->equalTo($theLifetime)); - - $cache = new t3lib_cache_frontend_StringFrontend('StringFrontend', $backend); - $cache->set('StringCacheTest', $theString, array(), $theLifetime); - } - - /** - * @test - * @author Karsten Dambekalns - * @author Ingo Renner - * @expectedException t3lib_cache_exception_InvalidData - */ - public function setThrowsInvalidDataExceptionOnNonStringValues() { - $backend = $this->getMock('t3lib_cache_backend_AbstractBackend', array('get', 'set', 'has', 'remove', 'findIdentifiersByTag', 'findIdentifiersByTags', 'flush', 'flushByTag', 'flushByTags', 'collectGarbage'), array(), '', FALSE); - - $cache = new t3lib_cache_frontend_StringFrontend('StringFrontend', $backend); - $cache->set('StringCacheTest', array()); - } - - /** - * @test - * @author Robert Lemke - * @author Karsten Dambekalns - * @author Ingo Renner - */ - public function getFetchesStringValueFromBackend() { - $backend = $this->getMock('t3lib_cache_backend_AbstractBackend', array('get', 'set', 'has', 'remove', 'findIdentifiersByTag', 'findIdentifiersByTags', 'flush', 'flushByTag', 'flushByTags', 'collectGarbage'), array(), '', FALSE); - $backend->expects($this->once())->method('get')->will($this->returnValue('Just some value')); - - $cache = new t3lib_cache_frontend_StringFrontend('StringFrontend', $backend); - $this->assertEquals('Just some value', $cache->get('StringCacheTest'), 'The returned value was not the expected string.'); - } - - /** - * @test - * @author Robert Lemke - * @author Ingo Renner - */ - public function hasReturnsResultFromBackend() { - $backend = $this->getMock('t3lib_cache_backend_AbstractBackend', array('get', 'set', 'has', 'remove', 'findIdentifiersByTag', 'findIdentifiersByTags', 'flush', 'flushByTag', 'flushByTags', 'collectGarbage'), array(), '', FALSE); - $backend->expects($this->once())->method('has')->with($this->equalTo('StringCacheTest'))->will($this->returnValue(TRUE)); - - $cache = new t3lib_cache_frontend_StringFrontend('StringFrontend', $backend); - $this->assertTrue($cache->has('StringCacheTest'), 'has() did not return TRUE.'); - } - - /** - * @test - * @author Sebastian Kurfuerst - * @author Ingo Renner - */ - public function removeCallsBackend() { - $cacheIdentifier = 'someCacheIdentifier'; - $backend = $this->getMock('t3lib_cache_backend_AbstractBackend', array('get', 'set', 'has', 'remove', 'findIdentifiersByTag', 'findIdentifiersByTags', 'flush', 'flushByTag', 'flushByTags', 'collectGarbage'), array(), '', FALSE); - - $backend->expects($this->once())->method('remove')->with($this->equalTo($cacheIdentifier))->will($this->returnValue(TRUE)); - - $cache = new t3lib_cache_frontend_StringFrontend('StringFrontend', $backend); - $this->assertTrue($cache->remove($cacheIdentifier), 'remove() did not return TRUE'); - } - - /** - * @test - * @expectedException InvalidArgumentException - * @author Karsten Dambekalns - * @author Ingo Renner - */ - public function getByTagRejectsInvalidTags() { - $backend = $this->getMock('t3lib_cache_backend_Backend', array(), array(), '', FALSE); - $backend->expects($this->never())->method('getByTag'); - - $cache = new t3lib_cache_frontend_StringFrontend('StringFrontend', $backend); - $cache->getByTag('SomeInvalid\Tag'); - } - - /** - * @test - * @author Karsten Dambekalns - * @author Ingo Renner - */ - public function getByTagCallsBackend() { - $tag = 'sometag'; - $identifiers = array('one', 'two'); - $entries = array('one value', 'two value'); - $backend = $this->getMock('t3lib_cache_backend_AbstractBackend', array('get', 'set', 'has', 'remove', 'findIdentifiersByTag', 'findIdentifiersByTags', 'flush', 'flushByTag', 'flushByTags', 'collectGarbage'), array(), '', FALSE); - - $backend->expects($this->once())->method('findIdentifiersByTag')->with($this->equalTo($tag))->will($this->returnValue($identifiers)); - $backend->expects($this->exactly(2))->method('get')->will($this->onConsecutiveCalls('one value', 'two value')); - - $cache = new t3lib_cache_frontend_StringFrontend('StringFrontend', $backend); - $this->assertEquals($entries, $cache->getByTag($tag), 'Did not receive the expected entries'); - } -} - -?> \ No newline at end of file Index: tests/t3lib/cache/frontend/t3lib_cache_frontend_abstractfrontendTest.php =================================================================== --- tests/t3lib/cache/frontend/t3lib_cache_frontend_abstractfrontendTest.php (Revision 7835) +++ tests/t3lib/cache/frontend/t3lib_cache_frontend_abstractfrontendTest.php (Arbeitskopie) @@ -35,7 +35,7 @@ * @subpackage tests * @version $Id$ */ -class t3lib_cache_frontend_AbstractFrontendTestCase extends tx_phpunit_testcase { +class t3lib_cache_frontend_AbstractFrontendTest extends tx_phpunit_testcase { /** * @test Index: tests/t3lib/cache/frontend/t3lib_cache_frontend_variablefrontendTest.php =================================================================== --- tests/t3lib/cache/frontend/t3lib_cache_frontend_variablefrontendTest.php (Revision 7835) +++ tests/t3lib/cache/frontend/t3lib_cache_frontend_variablefrontendTest.php (Arbeitskopie) @@ -33,7 +33,7 @@ * @subpackage tests * @version $Id$ */ -class t3lib_cache_frontend_VariableFrontendTestCase extends tx_phpunit_testcase { +class t3lib_cache_frontend_VariableFrontendTest extends tx_phpunit_testcase { /** * @expectedException InvalidArgumentException Index: tests/t3lib/cache/frontend/t3lib_cache_frontend_stringfrontendTest.php =================================================================== --- tests/t3lib/cache/frontend/t3lib_cache_frontend_stringfrontendTest.php (Revision 7835) +++ tests/t3lib/cache/frontend/t3lib_cache_frontend_stringfrontendTest.php (Arbeitskopie) @@ -35,7 +35,7 @@ * @subpackage tests * @version $Id$ */ -class t3lib_cache_frontend_StringFrontendTestCase extends tx_phpunit_testcase { +class t3lib_cache_frontend_StringFrontendTest extends tx_phpunit_testcase { /** * @expectedException InvalidArgumentException Index: tests/t3lib/cache/t3lib_cache_managerTest.php =================================================================== --- tests/t3lib/cache/t3lib_cache_managerTest.php (Revision 7835) +++ tests/t3lib/cache/t3lib_cache_managerTest.php (Arbeitskopie) @@ -33,7 +33,7 @@ * @subpackage tests * @version $Id$ */ -class t3lib_cache_ManagerTestCase extends tx_phpunit_testcase { +class t3lib_cache_ManagerTest extends tx_phpunit_testcase { /** * @test Index: tests/t3lib/cache/backend/t3lib_cache_backend_filebackendtestcase.php =================================================================== --- tests/t3lib/cache/backend/t3lib_cache_backend_filebackendtestcase.php (Revision 7835) +++ tests/t3lib/cache/backend/t3lib_cache_backend_filebackendtestcase.php (Arbeitskopie) @@ -1,726 +0,0 @@ - -* All rights reserved -* -* This script is part of the TYPO3 project. The TYPO3 project is -* free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* The GNU General Public License can be found at -* http://www.gnu.org/copyleft/gpl.html. -* -* This script is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* This copyright notice MUST APPEAR in all copies of the script! -***************************************************************/ - - - // TODO implement autoloading so that we only require stuff we really need -require_once(PATH_t3lib . 'class.t3lib_cache.php'); - -require_once(PATH_t3lib . 'cache/backend/interfaces/interface.t3lib_cache_backend_backend.php'); -require_once(PATH_t3lib . 'cache/frontend/interfaces/interface.t3lib_cache_frontend_frontend.php'); - -require_once(PATH_t3lib . 'cache/backend/class.t3lib_cache_backend_abstractbackend.php'); -require_once(PATH_t3lib . 'cache/frontend/class.t3lib_cache_frontend_abstractfrontend.php'); -require_once(PATH_t3lib . 'cache/class.t3lib_cache_exception.php'); -require_once(PATH_t3lib . 'cache/class.t3lib_cache_factory.php'); -require_once(PATH_t3lib . 'cache/class.t3lib_cache_manager.php'); -require_once(PATH_t3lib . 'cache/frontend/class.t3lib_cache_frontend_variablefrontend.php'); - -require_once(PATH_t3lib . 'cache/exception/class.t3lib_cache_exception_classalreadyloaded.php'); -require_once(PATH_t3lib . 'cache/exception/class.t3lib_cache_exception_duplicateidentifier.php'); -require_once(PATH_t3lib . 'cache/exception/class.t3lib_cache_exception_invalidbackend.php'); -require_once(PATH_t3lib . 'cache/exception/class.t3lib_cache_exception_invalidcache.php'); -require_once(PATH_t3lib . 'cache/exception/class.t3lib_cache_exception_invaliddata.php'); -require_once(PATH_t3lib . 'cache/exception/class.t3lib_cache_exception_nosuchcache.php'); - -require_once(PATH_t3lib . 'cache/backend/class.t3lib_cache_backend_filebackend.php'); - -/** - * Testcase for the File cache backend - * - * This file is a backport from FLOW3 - * - * @author Ingo Renner - * @package TYPO3 - * @subpackage tests - * @version $Id$ - */ -class t3lib_cache_backend_FileBackendTestCase extends tx_phpunit_testcase { - - /** - * If set, the tearDown() method will clean up the cache subdirectory used by this unit test. - * - * @var t3lib_cache_backend_FileBackend - */ - protected $backend; - - protected $testingCacheDirectory; - - /** - * Sets up this testcase - * - * @return void - */ - public function setUp() { - $this->testingCacheDirectory = 'typo3temp/cache/testing/'; - - $this->backend = t3lib_div::makeInstance( - 't3lib_cache_backend_FileBackend', - array('cacheDirectory' => $this->testingCacheDirectory) - ); - } - - /** - * @test - * @author Robert Lemke - * @author Ingo Renner - */ - public function defaultCacheDirectoryIsWritable() { - $cacheDirectory = $this->backend->getCacheDirectory(); - - $this->assertTrue(is_writable($cacheDirectory), 'The default cache directory "' . $cacheDirectory . '" is not writable.'); - } - - /** - * @test - * @author Robert Lemke - * @expectedException t3lib_cache_Exception - */ - public function setCacheDirectoryThrowsExceptionOnNonWritableDirectory() { - if (DIRECTORY_SEPARATOR == '\\') { - $this->markTestSkipped('test not reliable in Windows environment'); - } - $directoryName = '/sbin'; - - $this->backend->setCacheDirectory($directoryName); - } - - /** - * @test - * @author Robert Lemke - * @author Ingo Renner - */ - public function getCacheDirectoryReturnsThePreviouslySetDirectory() { - $directory = $this->testingCacheDirectory; - $fullPathToDirectory = t3lib_div::getIndpEnv('TYPO3_DOCUMENT_ROOT') . '/' . $directory; - - $this->backend->setCacheDirectory($directory); - $this->assertEquals($fullPathToDirectory, $this->backend->getCacheDirectory(), 'getCacheDirectory() did not return the expected value.'); - } - - /** - * @test - * @author Robert Lemke - * @author Ingo Renner - * @expectedException t3lib_cache_exception_InvalidData - */ - public function setThrowsExceptionIfDataIsNotAString() { - $cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend', - array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'), - array(), - '', - FALSE - ); - - $data = array('Some data'); - $entryIdentifier = 'BackendFileTest'; - - $this->backend->setCache($cache); - - $this->backend->set($entryIdentifier, $data); - } - - /** - * @test - * @author Robert Lemke - * @author Ingo Renner - */ - public function setReallySavesToTheSpecifiedDirectory() { - $cacheIdentifier = 'UnitTestCache'; - $cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend', - array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'), - array(), - '', - FALSE - ); - - $cache->expects($this->atLeastOnce()) - ->method('getIdentifier') - ->will($this->returnValue($cacheIdentifier)); - - $data = 'some data' . microtime(); - $entryIdentifier = 'BackendFileTest'; - $entryIdentifierHash = sha1($entryIdentifier); - - $this->backend->setCache($cache); - $this->backend->set($entryIdentifier, $data); - - $cacheDirectory = $this->backend->getCacheDirectory(); - $pathAndFilename = $cacheDirectory - . 'data/' - . $cacheIdentifier . '/' - . $entryIdentifierHash[0] . '/' - . $entryIdentifierHash[1] . '/' - . $entryIdentifier; - $this->assertTrue(file_exists($pathAndFilename), 'File does not exist.'); - $retrievedData = file_get_contents($pathAndFilename, NULL, NULL, t3lib_cache_backend_FileBackend::EXPIRYTIME_LENGTH); - $this->assertEquals( - $data, - $retrievedData, - 'The original and the retrieved data don\'t match.' - ); - } - - /** - * @test - * @author Robert Lemke - * @author Ingo Renner - */ - public function setOverwritesAnAlreadyExistingCacheEntryForTheSameIdentifier() { - $cacheIdentifier = 'UnitTestCache'; - $cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend', - array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'), - array(), - '', - FALSE - ); - $cache->expects($this->atLeastOnce()) - ->method('getIdentifier') - ->will($this->returnValue($cacheIdentifier)); - - $data1 = 'some data' . microtime(); - $data2 = 'some data' . microtime(); - $entryIdentifier = 'BackendFileRemoveBeforeSetTest'; - $entryIdentifierHash = sha1($entryIdentifier); - - $this->backend->setCache($cache); - $this->backend->set($entryIdentifier, $data1, array(), 500); - // setting a second entry with the same identifier, but different - // data, this should _replace_ the existing one we set before - $this->backend->set($entryIdentifier, $data2, array(), 200); - - $cacheDirectory = $this->backend->getCacheDirectory(); - $pathAndFilename = $cacheDirectory - . 'data/' - . $cacheIdentifier . '/' - . $entryIdentifierHash[0] . '/' - . $entryIdentifierHash[1] . '/' - . $entryIdentifier; - $this->assertTrue(file_exists($pathAndFilename), 'File does not exist.'); - $retrievedData = file_get_contents($pathAndFilename, NULL, NULL, t3lib_cache_backend_FileBackend::EXPIRYTIME_LENGTH); - $this->assertEquals($data2, $retrievedData); - } - - /** - * @test - * @author Robert Lemke - * @author Ingo Renner - */ - public function setReallySavesSpecifiedTags() { - $cacheIdentifier = 'UnitTestCache'; - $cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend', - array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'), - array(), - '', - FALSE - ); - $cache->expects($this->atLeastOnce()) - ->method('getIdentifier') - ->will($this->returnValue($cacheIdentifier)); - - $data = 'some data' . microtime(); - $entryIdentifier = 'BackendFileTest'; - $entryIdentifierHash = sha1($entryIdentifier); - - $this->backend->setCache($cache); - $tagsDirectory = $this->backend->getCacheDirectory() . 'tags/'; - - $this->backend->set($entryIdentifier, $data, array('UnitTestTag%tag1', 'UnitTestTag%tag2')); - - $this->assertTrue(is_dir($tagsDirectory . 'UnitTestTag%tag1'), 'Tag directory UnitTestTag%tag1 does not exist.'); - $this->assertTrue(is_dir($tagsDirectory . 'UnitTestTag%tag2'), 'Tag directory UnitTestTag%tag2 does not exist.'); - - $filename = $tagsDirectory . 'UnitTestTag%tag1/' . $cacheIdentifier . t3lib_cache_backend_FileBackend::SEPARATOR . $entryIdentifier; - $this->assertTrue(file_exists($filename), 'File "' . $filename . '" does not exist.'); - - $filename = $tagsDirectory . 'UnitTestTag%tag2/' . $cacheIdentifier . t3lib_cache_backend_FileBackend::SEPARATOR . $entryIdentifier; - $this->assertTrue(file_exists($filename), 'File "' . $filename . '" does not exist.'); - } - - /** - * @test - * @author Robert Lemke - * @author Ingo Renner - */ - public function getReturnsContentOfTheCorrectCacheFile() { - $cacheIdentifier = 'UnitTestCache'; - $cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend', - array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'), - array(), - '', - FALSE - ); - $cache->expects($this->atLeastOnce()) - ->method('getIdentifier') - ->will($this->returnValue($cacheIdentifier)); - - $this->backend->setCache($cache); - - $entryIdentifier = 'BackendFileTest'; - - $data = 'some data' . microtime(); - $this->backend->set($entryIdentifier, $data, array(), 500); - - $data = 'some other data' . microtime(); - $this->backend->set($entryIdentifier, $data, array(), 100); - - $loadedData = $this->backend->get($entryIdentifier); - - $this->assertEquals($data, $loadedData, 'The original and the retrieved data don\'t match.'); - } - - /** - * @test - * @author Robert Lemke - * @author Ingo Renner - */ - public function hasReturnsTheCorrectResult() { - $cacheIdentifier = 'UnitTestCache'; - $cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend', - array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'), - array(), - '', - FALSE - ); - $cache->expects($this->atLeastOnce()) - ->method('getIdentifier') - ->will($this->returnValue($cacheIdentifier)); - - $this->backend->setCache($cache); - - $entryIdentifier = 'BackendFileTest'; - - $data = 'some data' . microtime(); - $this->backend->set($entryIdentifier, $data); - - $this->assertTrue($this->backend->has($entryIdentifier), 'has() did not return TRUE.'); - $this->assertFalse($this->backend->has($entryIdentifier . 'Not'), 'has() did not return FALSE.'); - } - - /** - * @test - * @author Robert Lemke - * @author Ingo Renner - */ - public function removeReallyRemovesACacheEntry() { - $cacheIdentifier = 'UnitTestCache'; - $cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend', - array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'), - array(), - '', - FALSE - ); - $cache->expects($this->atLeastOnce()) - ->method('getIdentifier') - ->will($this->returnValue($cacheIdentifier)); - - $data = 'some data' . microtime(); - $entryIdentifier = 'BackendFileRemovalTest'; - $entryIdentifierHash = sha1($entryIdentifier); - - $cacheDirectory = $this->backend->getCacheDirectory(); - $this->backend->setCache($cache); - - $pathAndFilename = $cacheDirectory - . 'data/' - . $cacheIdentifier . '/' - . $entryIdentifierHash[0] . '/' - . $entryIdentifierHash[1] . '/' - . $entryIdentifier; - - $this->backend->set($entryIdentifier, $data); - $this->assertTrue(file_exists($pathAndFilename), 'The cache entry does not exist.'); - - $this->backend->remove($entryIdentifier); - $this->assertFalse(file_exists($pathAndFilename), 'The cache entry still exists.'); - } - - /** - * @test - * @author Robert Lemke - * @author Karsten Dambekalns - * @author Ingo Renner - */ - public function collectGarbageReallyRemovesAnExpiredCacheEntry() { - $cacheIdentifier = 'UnitTestCache'; - $cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend', - array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'), - array(), - '', - FALSE - ); - $cache->expects($this->atLeastOnce()) - ->method('getIdentifier') - ->will($this->returnValue($cacheIdentifier)); - - $data = 'some data' . microtime(); - $entryIdentifier = 'BackendFileRemovalTest'; - $entryIdentifierHash = sha1($entryIdentifier); - - $cacheDirectory = $this->backend->getCacheDirectory(); - $this->backend->setCache($cache); - - $pathAndFilename = $cacheDirectory - . 'data/' - . $cacheIdentifier . '/' - . $entryIdentifierHash[0] . '/' - . $entryIdentifierHash[1] . '/' - . $entryIdentifier; - - $this->backend->set($entryIdentifier, $data, array(), 1); - $this->assertTrue(file_exists($pathAndFilename), 'The cache entry does not exist.'); - - sleep(2); - - $this->backend->collectGarbage(); - $this->assertFalse(file_exists($pathAndFilename), 'The cache entry still exists.'); - } - - /** - * @test - * @author Robert Lemke - * @author Karsten Dambekalns - * @author Ingo Renner - */ - public function collectGarbageReallyRemovesAllExpiredCacheEntries() { - $cacheIdentifier = 'UnitTestCache'; - $cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend', - array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'), - array(), - '', - FALSE - ); - $cache->expects($this->atLeastOnce()) - ->method('getIdentifier') - ->will($this->returnValue($cacheIdentifier)); - - $data = 'some data' . microtime(); - $entryIdentifier = 'BackendFileRemovalTest'; - - $cacheDirectory = $this->backend->getCacheDirectory(); - $this->backend->setCache($cache); - - $pattern = $cacheDirectory - . 'data/' - . $cacheIdentifier . '/*/*/' - . $entryIdentifier - . '?'; - - $this->backend->set($entryIdentifier . 'A', $data, array(), 1); - $this->backend->set($entryIdentifier . 'B', $data, array(), 1); - $this->backend->set($entryIdentifier . 'C', $data, array(), 1); - $filesFound = glob($pattern); - $this->assertTrue(is_array($filesFound) && count($filesFound) > 0, 'The cache entries do not exist.'); - - sleep(2); - - $this->backend->collectGarbage(); - $filesFound = is_array(glob($pattern)) ? glob($pattern) : array(); - $this->assertTrue(count($filesFound) === 0, 'The cache entries still exist.'); - } - - /** - * @test - * @author Robert Lemke - * @author Ingo Renner - */ - public function removeReallyRemovesTagsOfRemovedEntry() { - $cacheIdentifier = 'UnitTestCache'; - $cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend', - array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'), - array(), - '', - FALSE - ); - $cache->expects($this->atLeastOnce()) - ->method('getIdentifier') - ->will($this->returnValue($cacheIdentifier)); - - $data = 'some data' . microtime(); - $entryIdentifier = 'BackendFileTest'; - - $this->backend->setCache($cache); - - $tagsDirectory = $this->backend->getCacheDirectory() . 'tags/'; - - $this->backend->set($entryIdentifier, $data, array('UnitTestTag%tag1', 'UnitTestTag%tag2')); - $this->backend->remove($entryIdentifier); - - $this->assertTrue(!file_exists($tagsDirectory . 'UnitTestTag%tag1/' . $entryIdentifier), 'File "' . $tagsDirectory . 'UnitTestTag%tag1/' . $entryIdentifier . '" still exists.'); - $this->assertTrue(!file_exists($tagsDirectory . 'UnitTestTag%tag2/' . $entryIdentifier), 'File "' . $tagsDirectory . 'UnitTestTag%tag2/' . $entryIdentifier . '" still exists.'); - } - - /** - * @test - * @author Robert Lemke - * @author Ingo Renner - */ - public function findIdentifiersByTagFindsCacheEntriesWithSpecifiedTag() { - $cacheIdentifier = 'UnitTestCache'; - $cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend', - array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'), - array(), - '', - FALSE - ); - $cache->expects($this->atLeastOnce()) - ->method('getIdentifier') - ->will($this->returnValue($cacheIdentifier)); - - $this->backend->setCache($cache); - - $data = 'some data' . microtime(); - $this->backend->set('BackendFileTest1', $data, array('UnitTestTag%test', 'UnitTestTag%boring')); - $this->backend->set('BackendFileTest2', $data, array('UnitTestTag%test', 'UnitTestTag%special')); - $this->backend->set('BackendFileTest3', $data, array('UnitTestTag%test')); - - $expectedEntry = 'BackendFileTest2'; - - $actualEntries = $this->backend->findIdentifiersByTag('UnitTestTag%special'); - $this->assertTrue(is_array($actualEntries), 'actualEntries is not an array.'); - - $this->assertEquals($expectedEntry, array_pop($actualEntries)); - } - - /** - * @test - * @author Robert Lemke - * @author Ingo Renner - */ - public function flushRemovesAllCacheEntriesAndRelatedTags() { - $cacheIdentifier = 'UnitTestCache'; - $cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend', - array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'), - array(), - '', - FALSE - ); - $cache->expects($this->atLeastOnce()) - ->method('getIdentifier') - ->will($this->returnValue($cacheIdentifier)); - - $this->backend->setCache($cache); - - $tagsDirectory = $this->backend->getCacheDirectory() . 'tags/'; - $cacheDirectory = $this->backend->getCacheDirectory() . 'data/' . $cacheIdentifier . '/'; - - $data = 'some data' . microtime(); - $this->backend->set('BackendFileTest1', $data, array('UnitTestTag%test')); - $this->backend->set('BackendFileTest2', $data, array('UnitTestTag%test', 'UnitTestTag%special')); - $this->backend->set('BackendFileTest3', $data, array('UnitTestTag%test')); - - $this->backend->flush(); - - $pattern = $cacheDirectory . '*/*/*'; - $filesFound = is_array(glob($pattern)) ? glob($pattern) : array(); - $this->assertTrue(count($filesFound) === 0, 'Still files in the cache directory'); - - $tagPrefixTest = $tagsDirectory . 'UnitTestTag%test/' . $cacheIdentifier . '^'; - $tagPrefixSpecial = $tagsDirectory . 'UnitTestTag%special/' . $cacheIdentifier . '^'; - $entryIdentifier = 'BackendFileTest1'; - $this->assertTrue(!file_exists($tagPrefixTest . $entryIdentifier), 'File "' . $tagPrefixTest . $entryIdentifier . '" still exists.'); - $entryIdentifier = 'BackendFileTest2'; - $this->assertTrue(!file_exists($tagPrefixTest . $entryIdentifier), 'File "' . $tagPrefixTest . $entryIdentifier . '" still exists.'); - $this->assertTrue(!file_exists($tagPrefixSpecial . $entryIdentifier), 'File "' . $tagPrefixSpecial . $entryIdentifier . '" still exists.'); - $entryIdentifier = 'BackendFileTest3'; - $this->assertTrue(!file_exists($tagPrefixTest . $entryIdentifier), 'File "' . $tagPrefixTest . $entryIdentifier . '" still exists.'); - } - - /** - * @test - * @author Robert Lemke - * @author Ingo Renner - */ - public function flushByTagRemovesCacheEntriesWithSpecifiedTag() { - $cacheIdentifier = 'UnitTestCache'; - $cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend', - array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'), - array(), - '', - FALSE - ); - $cache->expects($this->atLeastOnce()) - ->method('getIdentifier') - ->will($this->returnValue($cacheIdentifier)); - - $this->backend->setCache($cache); - - $data = 'some data' . microtime(); - $this->backend->set('BackendFileTest1', $data, array('UnitTestTag%test', 'UnitTestTag%boring')); - $this->backend->set('BackendFileTest2', $data, array('UnitTestTag%test', 'UnitTestTag%special')); - $this->backend->set('BackendFileTest3', $data, array('UnitTestTag%test')); - - $this->backend->flushByTag('UnitTestTag%special'); - - $this->assertTrue($this->backend->has('BackendFileTest1'), 'BackendFileTest1'); - $this->assertFalse($this->backend->has('BackendFileTest2'), 'BackendFileTest2'); - $this->assertTrue($this->backend->has('BackendFileTest3'), 'BackendFileTest3'); - } - - - /** - * @test - * @author Robert Lemke - * @author Karsten Dambekalns - * @author Ingo Renner - */ - public function hasReturnsTheCorrectResultForEntryWithExceededLifetime() { - $cacheIdentifier = 'UnitTestCache'; - $cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend', - array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'), - array(), - '', - FALSE - ); - $cache->expects($this->atLeastOnce()) - ->method('getIdentifier') - ->will($this->returnValue($cacheIdentifier)); - - $this->backend->setCache($cache); - - $entryIdentifier = 'BackendFileTest'; - $data = 'some data' . microtime(); - $this->backend->set($entryIdentifier, $data); - - $expiredEntryIdentifier = 'ExpiredBackendFileTest'; - $expiredData = 'some old data' . microtime(); - $this->backend->set($expiredEntryIdentifier, $expiredData, array(), 1); - - sleep(2); - - $this->assertFalse($this->backend->has($expiredEntryIdentifier), 'has() did not return FALSE.'); - } - - /** - * @test - * @author Karsten Dambekalns - * @author Ingo Renner - */ - public function getReturnsFalseForEntryWithExceededLifetime() { - $cacheIdentifier = 'UnitTestCache'; - $cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend', - array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'), - array(), - '', - FALSE - ); - $cache->expects($this->atLeastOnce()) - ->method('getIdentifier') - ->will($this->returnValue($cacheIdentifier)); - - $this->backend->setCache($cache); - - $entryIdentifier = 'BackendFileTest'; - $data = 'some data' . microtime(); - $this->backend->set($entryIdentifier, $data); - - $expiredEntryIdentifier = 'ExpiredBackendFileTest'; - $expiredData = 'some old data' . microtime(); - $this->backend->set($expiredEntryIdentifier, $expiredData, array(), 1); - - sleep(2); - - $this->assertEquals($data, $this->backend->get($entryIdentifier), 'The original and the retrieved data don\'t match.'); - $this->assertFalse($this->backend->get($expiredEntryIdentifier), 'The expired entry could be loaded.'); - } - - /** - * @test - * @author Karsten Dambekalns - * @author Ingo Renner - */ - public function findIdentifiersByTagReturnsEmptyArrayForEntryWithExceededLifetime() { - $cacheIdentifier = 'UnitTestCache'; - $cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend', - array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'), - array(), - '', - FALSE - ); - $cache->expects($this->atLeastOnce()) - ->method('getIdentifier') - ->will($this->returnValue($cacheIdentifier)); - - $this->backend->setCache($cache); - - $this->backend->set('BackendFileTest', 'some data', array('UnitTestTag%special'), 1); - - sleep(2); - - $this->assertEquals(array(), $this->backend->findIdentifiersByTag('UnitTestTag%special')); - } - - /** - * @test - * @author Robert Lemke - * @author Karsten Dambekalns - * @author Ingo Renner - */ - public function setWithUnlimitedLifetimeWritesCorrectEntry() { - $cacheIdentifier = 'UnitTestCache'; - $cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend', - array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'), - array(), - '', - FALSE - ); - $cache->expects($this->atLeastOnce()) - ->method('getIdentifier') - ->will($this->returnValue($cacheIdentifier)); - - $data = 'some data' . microtime(); - $entryIdentifier = 'BackendFileTest'; - $entryIdentifierHash = sha1($entryIdentifier); - - $this->backend->setCache($cache); - $this->backend->set($entryIdentifier, $data, array(), 0); - - $cacheDirectory = $this->backend->getCacheDirectory(); - - $pathAndFilename = $cacheDirectory - . 'data/' - . $cacheIdentifier . '/' - . $entryIdentifierHash[0] . '/' - . $entryIdentifierHash[1] . '/' - . $entryIdentifier; - $this->assertTrue(file_exists($pathAndFilename), 'File not found.'); - - $retrievedData = file_get_contents($pathAndFilename, NULL, NULL, t3lib_cache_backend_FileBackend::EXPIRYTIME_LENGTH); - $this->assertEquals($data, $retrievedData, 'The original and the retrieved data don\'t match.'); - } - - /** - * @author Robert Lemke - * @author Ingo Renner - */ - public function tearDown() { - if (is_object($this->backend)) { - $directory = $this->backend->getCacheDirectory(); - if (is_dir($directory)) { - t3lib_div::rmdir($directory, true); - } - } - } -} - -?> \ No newline at end of file Index: tests/t3lib/cache/backend/t3lib_cache_backend_transientmemorybackendtestcase.php =================================================================== --- tests/t3lib/cache/backend/t3lib_cache_backend_transientmemorybackendtestcase.php (Revision 7835) +++ tests/t3lib/cache/backend/t3lib_cache_backend_transientmemorybackendtestcase.php (Arbeitskopie) @@ -1,241 +0,0 @@ - -* All rights reserved -* -* This script is part of the TYPO3 project. The TYPO3 project is -* free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* The GNU General Public License can be found at -* http://www.gnu.org/copyleft/gpl.html. -* -* This script is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* This copyright notice MUST APPEAR in all copies of the script! -***************************************************************/ - - - // TODO implement autoloading so that we only require stuff we really need -require_once(PATH_t3lib . 'class.t3lib_cache.php'); - -require_once(PATH_t3lib . 'cache/backend/interfaces/interface.t3lib_cache_backend_backend.php'); -require_once(PATH_t3lib . 'cache/frontend/interfaces/interface.t3lib_cache_frontend_frontend.php'); - -require_once(PATH_t3lib . 'cache/backend/class.t3lib_cache_backend_abstractbackend.php'); -require_once(PATH_t3lib . 'cache/frontend/class.t3lib_cache_frontend_abstractfrontend.php'); -require_once(PATH_t3lib . 'cache/class.t3lib_cache_exception.php'); -require_once(PATH_t3lib . 'cache/class.t3lib_cache_factory.php'); -require_once(PATH_t3lib . 'cache/class.t3lib_cache_manager.php'); -require_once(PATH_t3lib . 'cache/frontend/class.t3lib_cache_frontend_variablefrontend.php'); - -require_once(PATH_t3lib . 'cache/exception/class.t3lib_cache_exception_classalreadyloaded.php'); -require_once(PATH_t3lib . 'cache/exception/class.t3lib_cache_exception_duplicateidentifier.php'); -require_once(PATH_t3lib . 'cache/exception/class.t3lib_cache_exception_invalidbackend.php'); -require_once(PATH_t3lib . 'cache/exception/class.t3lib_cache_exception_invalidcache.php'); -require_once(PATH_t3lib . 'cache/exception/class.t3lib_cache_exception_invaliddata.php'); -require_once(PATH_t3lib . 'cache/exception/class.t3lib_cache_exception_nosuchcache.php'); - -require_once(PATH_t3lib . 'cache/backend/class.t3lib_cache_backend_transientmemorybackend.php'); - -/** - * Testcase for the TransientMemory cache backend - * - * This file is a backport from FLOW3 - * - * @author Ingo Renner - * @package TYPO3 - * @subpackage tests - * @version $Id$ - */ -class t3lib_cache_backend_TransientMemoryBackendTestCase extends tx_phpunit_testcase { - - /** - * @expectedException t3lib_cache_Exception - * @test - * @author Robert Lemke - */ - public function setThrowsExceptionIfNoFrontEndHasBeenSet() { - $backend = new t3lib_cache_backend_TransientMemoryBackend(); - - $data = 'Some data'; - $identifier = 'MyIdentifier'; - $backend->set($identifier, $data); - } - - /** - * @test - * @author Robert Lemke - * @author Ingo Renner - */ - public function itIsPossibleToSetAndCheckExistenceInCache() { - $cache = $this->getMock('t3lib_cache_frontend_Frontend', array(), array(), '', FALSE); - $backend = new t3lib_cache_backend_TransientMemoryBackend(); - $backend->setCache($cache); - - $data = 'Some data'; - $identifier = 'MyIdentifier'; - $backend->set($identifier, $data); - $inCache = $backend->has($identifier); - $this->assertTrue($inCache); - } - - /** - * @test - * @author Robert Lemke - * @author Ingo Renner - */ - public function itIsPossibleToSetAndGetEntry() { - $cache = $this->getMock('t3lib_cache_frontend_Frontend', array(), array(), '', FALSE); - $backend = new t3lib_cache_backend_TransientMemoryBackend(); - $backend->setCache($cache); - - $data = 'Some data'; - $identifier = 'MyIdentifier'; - $backend->set($identifier, $data); - $fetchedData = $backend->get($identifier); - $this->assertEquals($data, $fetchedData); - } - - /** - * @test - * @author Robert Lemke - * @author Ingo Renner - */ - public function itIsPossibleToRemoveEntryFromCache() { - $cache = $this->getMock('t3lib_cache_frontend_Frontend', array(), array(), '', FALSE); - $backend = new t3lib_cache_backend_TransientMemoryBackend(); - $backend->setCache($cache); - - $data = 'Some data'; - $identifier = 'MyIdentifier'; - $backend->set($identifier, $data); - $backend->remove($identifier); - $inCache = $backend->has($identifier); - $this->assertFalse($inCache); - } - - /** - * @test - * @author Robert Lemke - * @author Ingo Renner - */ - public function itIsPossibleToOverwriteAnEntryInTheCache() { - $cache = $this->getMock('t3lib_cache_frontend_Frontend', array(), array(), '', FALSE); - $backend = new t3lib_cache_backend_TransientMemoryBackend(); - $backend->setCache($cache); - - $data = 'Some data'; - $identifier = 'MyIdentifier'; - $backend->set($identifier, $data); - $otherData = 'some other data'; - $backend->set($identifier, $otherData); - $fetchedData = $backend->get($identifier); - $this->assertEquals($otherData, $fetchedData); - } - - /** - * @test - * @author Robert Lemke - * @author Ingo Renner - */ - public function findIdentifiersByTagFindsCacheEntriesWithSpecifiedTag() { - $cache = $this->getMock('t3lib_cache_frontend_Frontend', array(), array(), '', FALSE); - $backend = new t3lib_cache_backend_TransientMemoryBackend(); - $backend->setCache($cache); - - $data = 'Some data'; - $entryIdentifier = 'MyIdentifier'; - $backend->set($entryIdentifier, $data, array('UnitTestTag%tag1', 'UnitTestTag%tag2')); - - $retrieved = $backend->findIdentifiersByTag('UnitTestTag%tag1'); - $this->assertEquals($entryIdentifier, $retrieved[0]); - - $retrieved = $backend->findIdentifiersByTag('UnitTestTag%tag2'); - $this->assertEquals($entryIdentifier, $retrieved[0]); - } - - /** - * @test - * @author Robert Lemke - * @author Ingo Renner - */ - public function hasReturnsFalseIfTheEntryDoesntExist() { - $cache = $this->getMock('t3lib_cache_frontend_Frontend', array(), array(), '', FALSE); - $backend = new t3lib_cache_backend_TransientMemoryBackend(); - $backend->setCache($cache); - - $identifier = 'NonExistingIdentifier'; - $inCache = $backend->has($identifier); - $this->assertFalse($inCache); - } - - /** - * @test - * @author Robert Lemke - * @author Ingo Renner - */ - public function removeReturnsFalseIfTheEntryDoesntExist() { - $cache = $this->getMock('t3lib_cache_frontend_Frontend', array(), array(), '', FALSE); - $backend = new t3lib_cache_backend_TransientMemoryBackend(); - $backend->setCache($cache); - - $identifier = 'NonExistingIdentifier'; - $inCache = $backend->remove($identifier); - $this->assertFalse($inCache); - } - - /** - * @test - * @author Robert Lemke - * @author Karsten Dambekalns - * @author Ingo Renner - */ - public function flushByTagRemovesCacheEntriesWithSpecifiedTag() { - $cache = $this->getMock('t3lib_cache_frontend_Frontend', array(), array(), '', FALSE); - $backend = new t3lib_cache_backend_TransientMemoryBackend(); - $backend->setCache($cache); - - $data = 'some data' . microtime(); - $backend->set('TransientMemoryBackendTest1', $data, array('UnitTestTag%test', 'UnitTestTag%boring')); - $backend->set('TransientMemoryBackendTest2', $data, array('UnitTestTag%test', 'UnitTestTag%special')); - $backend->set('TransientMemoryBackendTest3', $data, array('UnitTestTag%test')); - - $backend->flushByTag('UnitTestTag%special'); - - $this->assertTrue($backend->has('TransientMemoryBackendTest1'), 'TransientMemoryBackendTest1'); - $this->assertFalse($backend->has('TransientMemoryBackendTest2'), 'TransientMemoryBackendTest2'); - $this->assertTrue($backend->has('TransientMemoryBackendTest3'), 'TransientMemoryBackendTest3'); - } - - /** - * @test - * @author Karsten Dambekalns - * @author Ingo Renner - */ - public function flushRemovesAllCacheEntries() { - $cache = $this->getMock('t3lib_cache_frontend_Frontend', array(), array(), '', FALSE); - $backend = new t3lib_cache_backend_TransientMemoryBackend(); - $backend->setCache($cache); - - $data = 'some data' . microtime(); - $backend->set('TransientMemoryBackendTest1', $data); - $backend->set('TransientMemoryBackendTest2', $data); - $backend->set('TransientMemoryBackendTest3', $data); - - $backend->flush(); - - $this->assertFalse($backend->has('TransientMemoryBackendTest1'), 'TransientMemoryBackendTest1'); - $this->assertFalse($backend->has('TransientMemoryBackendTest2'), 'TransientMemoryBackendTest2'); - $this->assertFalse($backend->has('TransientMemoryBackendTest3'), 'TransientMemoryBackendTest3'); - } -} - -?> \ No newline at end of file Index: tests/t3lib/cache/backend/class.t3lib_cache_backend_mockbackend.php =================================================================== --- tests/t3lib/cache/backend/class.t3lib_cache_backend_mockbackend.php (Revision 7835) +++ tests/t3lib/cache/backend/class.t3lib_cache_backend_mockbackend.php (Arbeitskopie) @@ -25,7 +25,7 @@ /** * A caching backend which forgets everything immediately - * Used in t3lib_cache_FactoryTestCase + * Used in t3lib_cache_FactoryTest * * This file is a backport from FLOW3 * Index: tests/t3lib/cache/backend/t3lib_cache_backend_abstractbackendtestcase.php =================================================================== --- tests/t3lib/cache/backend/t3lib_cache_backend_abstractbackendtestcase.php (Revision 7835) +++ tests/t3lib/cache/backend/t3lib_cache_backend_abstractbackendtestcase.php (Arbeitskopie) @@ -1,84 +0,0 @@ - -* All rights reserved -* -* This script is part of the TYPO3 project. The TYPO3 project is -* free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* The GNU General Public License can be found at -* http://www.gnu.org/copyleft/gpl.html. -* -* This script is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* This copyright notice MUST APPEAR in all copies of the script! -***************************************************************/ - - -/** - * Testcase for the abstract cache backend - * - * This file is a backport from FLOW3 - * - * @author Ingo Renner - * @package TYPO3 - * @subpackage tests - * @version $Id$ - */ -class t3lib_cache_backend_AbstractBackendTestCase extends tx_phpunit_testcase { - - /** - * @var t3lib_cache_backend_AbstractBackend - */ - protected $backend; - - /** - * @return void - * @author Robert Lemke - * @author Ingo Renner - */ - public function setUp() { - $className = uniqid('ConcreteBackend_'); - eval(' - class ' . $className. ' extends t3lib_cache_backend_AbstractBackend { - public function set($entryIdentifier, $data, array $tags = array(), $lifetime = NULL) {} - public function get($entryIdentifier) {} - public function has($entryIdentifier) {} - public function remove($entryIdentifier) {} - public function flush() {} - public function flushByTag($tag) {} - public function flushByTags(array $tags) {} - public function findIdentifiersByTag($tag) {} - public function findIdentifiersByTags(array $tags) {} - public function collectGarbage() {} - public function setSomeOption($value) { - $this->someOption = $value; - } - public function getSomeOption() { - return $this->someOption; - } - } - '); - $this->backend = new $className(); - } - - /** - * @test - * @author Robert Lemke - */ - public function theConstructorCallsSetterMethodsForAllSpecifiedOptions() { - $className = get_class($this->backend); - $backend = new $className(array('someOption' => 'someValue')); - $this->assertSame('someValue', $backend->getSomeOption()); - } -} - -?> \ No newline at end of file Index: tests/t3lib/cache/backend/t3lib_cache_backend_apcbackendtestcase.php =================================================================== --- tests/t3lib/cache/backend/t3lib_cache_backend_apcbackendtestcase.php (Revision 7835) +++ tests/t3lib/cache/backend/t3lib_cache_backend_apcbackendtestcase.php (Arbeitskopie) @@ -1,293 +0,0 @@ - -* All rights reserved -* -* This script is part of the TYPO3 project. The TYPO3 project is -* free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* The GNU General Public License can be found at -* http://www.gnu.org/copyleft/gpl.html. -* -* This script is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* This copyright notice MUST APPEAR in all copies of the script! -***************************************************************/ - - - // TODO implement autoloading so that we only require stuff we really need -require_once(PATH_t3lib . 'class.t3lib_cache.php'); - -require_once(PATH_t3lib . 'cache/backend/interfaces/interface.t3lib_cache_backend_backend.php'); -require_once(PATH_t3lib . 'cache/frontend/interfaces/interface.t3lib_cache_frontend_frontend.php'); - -require_once(PATH_t3lib . 'cache/backend/class.t3lib_cache_backend_abstractbackend.php'); -require_once(PATH_t3lib . 'cache/frontend/class.t3lib_cache_frontend_abstractfrontend.php'); -require_once(PATH_t3lib . 'cache/class.t3lib_cache_exception.php'); -require_once(PATH_t3lib . 'cache/class.t3lib_cache_factory.php'); -require_once(PATH_t3lib . 'cache/class.t3lib_cache_manager.php'); -require_once(PATH_t3lib . 'cache/frontend/class.t3lib_cache_frontend_variablefrontend.php'); - -require_once(PATH_t3lib . 'cache/exception/class.t3lib_cache_exception_classalreadyloaded.php'); -require_once(PATH_t3lib . 'cache/exception/class.t3lib_cache_exception_duplicateidentifier.php'); -require_once(PATH_t3lib . 'cache/exception/class.t3lib_cache_exception_invalidbackend.php'); -require_once(PATH_t3lib . 'cache/exception/class.t3lib_cache_exception_invalidcache.php'); -require_once(PATH_t3lib . 'cache/exception/class.t3lib_cache_exception_invaliddata.php'); -require_once(PATH_t3lib . 'cache/exception/class.t3lib_cache_exception_nosuchcache.php'); - -require_once(PATH_t3lib . 'cache/backend/class.t3lib_cache_backend_apcbackend.php'); - -/** - * Testcase for the APC cache backend - * - * This file is a backport from FLOW3 - * - * @author Ingo Renner - * @package TYPO3 - * @subpackage tests - * @version $Id$ - */ -class t3lib_cache_backend_ApcBackendTestCase extends tx_phpunit_testcase { - - /** - * Sets up this testcase - * - * @return void - * @author Karsten Dambekalns - * @author Ingo Renner - */ - public function setUp() { - if (!extension_loaded('apc')) { - $this->markTestSkipped('APC extension was not available'); - } - } - - /** - * @test - * @author Christian Jul Jensen - * @author Karsten Dambekalns - * @expectedException t3lib_cache_Exception - */ - public function setThrowsExceptionIfNoFrontEndHasBeenSet() { - $backend = new t3lib_cache_backend_ApcBackend(); - $data = 'Some data'; - $identifier = 'MyIdentifier'; - $backend->set($identifier, $data); - } - - /** - * @test - * @author Christian Jul Jensen - */ - public function itIsPossibleToSetAndCheckExistenceInCache() { - $backend = $this->setUpBackend(); - $data = 'Some data'; - $identifier = 'MyIdentifier'; - $backend->set($identifier, $data); - $inCache = $backend->has($identifier); - $this->assertTrue($inCache, 'APC backend failed to set and check entry'); - } - - /** - * @test - * @author Christian Jul Jensen - */ - public function itIsPossibleToSetAndGetEntry() { - $backend = $this->setUpBackend(); - $data = 'Some data'; - $identifier = 'MyIdentifier'; - $backend->set($identifier, $data); - $fetchedData = $backend->get($identifier); - $this->assertEquals($data, $fetchedData, 'APC backend failed to set and retrieve data'); - } - - /** - * @test - * @author Christian Jul Jensen - */ - public function itIsPossibleToRemoveEntryFromCache() { - $backend = $this->setUpBackend(); - $data = 'Some data'; - $identifier = 'MyIdentifier'; - $backend->set($identifier, $data); - $backend->remove($identifier); - $inCache = $backend->has($identifier); - $this->assertFalse($inCache, 'Failed to set and remove data from APC backend'); - } - - /** - * @test - * @author Christian Jul Jensen - */ - public function itIsPossibleToOverwriteAnEntryInTheCache() { - $backend = $this->setUpBackend(); - $data = 'Some data'; - $identifier = 'MyIdentifier'; - $backend->set($identifier, $data); - $otherData = 'some other data'; - $backend->set($identifier, $otherData); - $fetchedData = $backend->get($identifier); - $this->assertEquals($otherData, $fetchedData, 'APC backend failed to overwrite and retrieve data'); - } - - /** - * @test - * @author Karsten Dambekalns - */ - public function findIdentifiersByTagFindsSetEntries() { - $backend = $this->setUpBackend(); - - $data = 'Some data'; - $entryIdentifier = 'MyIdentifier'; - $backend->set($entryIdentifier, $data, array('UnitTestTag%tag1', 'UnitTestTag%tag2')); - - $retrieved = $backend->findIdentifiersByTag('UnitTestTag%tag1'); - $this->assertEquals($entryIdentifier, $retrieved[0], 'Could not retrieve expected entry by tag.'); - - $retrieved = $backend->findIdentifiersByTag('UnitTestTag%tag2'); - $this->assertEquals($entryIdentifier, $retrieved[0], 'Could not retrieve expected entry by tag.'); - } - - /** - * @test - * @author Karsten Dambekalns - */ - public function setRemovesTagsFromPreviousSet() { - $backend = $this->setUpBackend(); - - $data = 'Some data'; - $entryIdentifier = 'MyIdentifier'; - $backend->set($entryIdentifier, $data, array('UnitTestTag%tag1', 'UnitTestTag%tag2')); - $backend->set($entryIdentifier, $data, array('UnitTestTag%tag3')); - - $retrieved = $backend->findIdentifiersByTag('UnitTestTag%tag2'); - $this->assertEquals(array(), $retrieved, 'Found entry which should no longer exist.'); - } - - /** - * @test - * @author Christian Jul Jensen - */ - public function hasReturnsFalseIfTheEntryDoesntExist() { - $backend = $this->setUpBackend(); - $identifier = 'NonExistingIdentifier'; - $inCache = $backend->has($identifier); - $this->assertFalse($inCache,'"has" did not return false when checking on non existing identifier'); - } - - /** - * @test - * @author Christian Jul Jensen - */ - public function removeReturnsFalseIfTheEntryDoesntExist() { - $backend = $this->setUpBackend(); - $identifier = 'NonExistingIdentifier'; - $inCache = $backend->remove($identifier); - $this->assertFalse($inCache,'"remove" did not return false when checking on non existing identifier'); - } - - /** - * @test - * @author Robert Lemke - * @author Karsten Dambekalns - */ - public function flushByTagRemovesCacheEntriesWithSpecifiedTag() { - $backend = $this->setUpBackend(); - - $data = 'some data' . microtime(); - $backend->set('BackendAPCTest1', $data, array('UnitTestTag%test', 'UnitTestTag%boring')); - $backend->set('BackendAPCTest2', $data, array('UnitTestTag%test', 'UnitTestTag%special')); - $backend->set('BackendAPCTest3', $data, array('UnitTestTag%test')); - - $backend->flushByTag('UnitTestTag%special'); - - $this->assertTrue($backend->has('BackendAPCTest1'), 'BackendAPCTest1'); - $this->assertFalse($backend->has('BackendAPCTest2'), 'BackendAPCTest2'); - $this->assertTrue($backend->has('BackendAPCTest3'), 'BackendAPCTest3'); - } - - /** - * @test - * @author Karsten Dambekalns - */ - public function flushRemovesAllCacheEntries() { - $backend = $this->setUpBackend(); - - $data = 'some data' . microtime(); - $backend->set('BackendAPCTest1', $data); - $backend->set('BackendAPCTest2', $data); - $backend->set('BackendAPCTest3', $data); - - $backend->flush(); - - $this->assertFalse($backend->has('BackendAPCTest1'), 'BackendAPCTest1'); - $this->assertFalse($backend->has('BackendAPCTest2'), 'BackendAPCTest2'); - $this->assertFalse($backend->has('BackendAPCTest3'), 'BackendAPCTest3'); - } - - /** - * @test - * @author Karsten Dambekalns - * @author Ingo Renner - */ - public function flushRemovesOnlyOwnEntries() { - $thisCache = $this->getMock('t3lib_cache_frontend_Frontend', array(), array(), '', FALSE); - $thisCache->expects($this->any())->method('getIdentifier')->will($this->returnValue('thisCache')); - $thisBackend = new t3lib_cache_backend_ApcBackend(); - $thisBackend->setCache($thisCache); - - $thatCache = $this->getMock('t3lib_cache_frontend_Frontend', array(), array(), '', FALSE); - $thatCache->expects($this->any())->method('getIdentifier')->will($this->returnValue('thatCache')); - $thatBackend = new t3lib_cache_backend_ApcBackend(); - $thatBackend->setCache($thatCache); - - $thisBackend->set('thisEntry', 'Hello'); - $thatBackend->set('thatEntry', 'World!'); - $thatBackend->flush(); - - $this->assertEquals('Hello', $thisBackend->get('thisEntry')); - $this->assertFalse($thatBackend->has('thatEntry')); - } - - /** - * Check if we can store ~5 MB of data - * - * @test - * @author Karsten Dambekalns - */ - public function largeDataIsStored() { - $backend = $this->setUpBackend(); - - $data = str_repeat('abcde', 1024 * 1024); - $backend->set('tooLargeData', $data); - - $this->assertTrue($backend->has('tooLargeData')); - $this->assertEquals($backend->get('tooLargeData'), $data); - } - - /** - * Sets up the APC backend used for testing - * - * @param array $backendOptions Options for the APC backend - * @return t3lib_cache_backend_ApcBackend - * @author Karsten Dambekalns - * @author Ingo Renner - */ - protected function setUpBackend() { - $cache = $this->getMock('t3lib_cache_frontend_Frontend', array(), array(), '', FALSE); - $backend = new t3lib_cache_backend_ApcBackend(); - $backend->setCache($cache); - - return $backend; - } -} - -?> \ No newline at end of file Index: tests/t3lib/cache/backend/t3lib_cache_backend_filebackendTest.php =================================================================== --- tests/t3lib/cache/backend/t3lib_cache_backend_filebackendTest.php (Revision 7835) +++ tests/t3lib/cache/backend/t3lib_cache_backend_filebackendTest.php (Arbeitskopie) @@ -55,7 +55,7 @@ * @subpackage tests * @version $Id$ */ -class t3lib_cache_backend_FileBackendTestCase extends tx_phpunit_testcase { +class t3lib_cache_backend_FileBackendTest extends tx_phpunit_testcase { /** * If set, the tearDown() method will clean up the cache subdirectory used by this unit test. Index: tests/t3lib/cache/backend/t3lib_cache_backend_transientmemorybackendTest.php =================================================================== --- tests/t3lib/cache/backend/t3lib_cache_backend_transientmemorybackendTest.php (Revision 7835) +++ tests/t3lib/cache/backend/t3lib_cache_backend_transientmemorybackendTest.php (Arbeitskopie) @@ -55,7 +55,7 @@ * @subpackage tests * @version $Id$ */ -class t3lib_cache_backend_TransientMemoryBackendTestCase extends tx_phpunit_testcase { +class t3lib_cache_backend_TransientMemoryBackendTest extends tx_phpunit_testcase { /** * @expectedException t3lib_cache_Exception Index: tests/t3lib/cache/backend/t3lib_cache_backend_dbbackendtestcase.php =================================================================== --- tests/t3lib/cache/backend/t3lib_cache_backend_dbbackendtestcase.php (Revision 7835) +++ tests/t3lib/cache/backend/t3lib_cache_backend_dbbackendtestcase.php (Arbeitskopie) @@ -1,628 +0,0 @@ - -* All rights reserved -* -* This script is part of the TYPO3 project. The TYPO3 project is -* free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* The GNU General Public License can be found at -* http://www.gnu.org/copyleft/gpl.html. -* -* This script is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* This copyright notice MUST APPEAR in all copies of the script! -***************************************************************/ - - - // TODO implement autoloading so that we only require stuff we really need -require_once(PATH_t3lib . 'class.t3lib_cache.php'); - -require_once(PATH_t3lib . 'cache/backend/interfaces/interface.t3lib_cache_backend_backend.php'); -require_once(PATH_t3lib . 'cache/frontend/interfaces/interface.t3lib_cache_frontend_frontend.php'); - -require_once(PATH_t3lib . 'cache/backend/class.t3lib_cache_backend_abstractbackend.php'); -require_once(PATH_t3lib . 'cache/frontend/class.t3lib_cache_frontend_abstractfrontend.php'); -require_once(PATH_t3lib . 'cache/class.t3lib_cache_exception.php'); -require_once(PATH_t3lib . 'cache/class.t3lib_cache_factory.php'); -require_once(PATH_t3lib . 'cache/class.t3lib_cache_manager.php'); -require_once(PATH_t3lib . 'cache/frontend/class.t3lib_cache_frontend_variablefrontend.php'); - -require_once(PATH_t3lib . 'cache/exception/class.t3lib_cache_exception_classalreadyloaded.php'); -require_once(PATH_t3lib . 'cache/exception/class.t3lib_cache_exception_duplicateidentifier.php'); -require_once(PATH_t3lib . 'cache/exception/class.t3lib_cache_exception_invalidbackend.php'); -require_once(PATH_t3lib . 'cache/exception/class.t3lib_cache_exception_invalidcache.php'); -require_once(PATH_t3lib . 'cache/exception/class.t3lib_cache_exception_invaliddata.php'); -require_once(PATH_t3lib . 'cache/exception/class.t3lib_cache_exception_nosuchcache.php'); - -require_once(PATH_t3lib . 'cache/backend/class.t3lib_cache_backend_dbbackend.php'); - -/** - * Testcase for the DB cache backend - * - * @author Ingo Renner - * @package TYPO3 - * @subpackage tests - * @version $Id$ - */ -class t3lib_cache_backend_DbBackendTestCase extends tx_phpunit_testcase { - - /** - * If set, the tearDown() method will clean up the cache table used by this unit test. - * - * @var t3lib_cache_backend_DbBackend - */ - protected $backend; - - protected $testingCacheTable; - protected $testingTagsTable; - - /** - * Sets up this testcase - * - * @return void - * @author Ingo Renner - */ - public function setUp() { - $this->testingCacheTable = 'test_cache_dbbackend'; - $this->testingTagsTable = 'test_cache_dbbackend_tags'; - - $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, - lifetime int(11) unsigned DEFAULT \'0\' NOT NULL, - PRIMARY KEY (id), - KEY cache_id (identifier) - ) ENGINE=InnoDB; - '); - - $GLOBALS['TYPO3_DB']->sql_query('CREATE TABLE ' . $this->testingTagsTable . ' ( - id int(11) unsigned NOT NULL auto_increment, - identifier varchar(128) DEFAULT \'\' NOT NULL, - tag varchar(128) DEFAULT \'\' NOT NULL, - PRIMARY KEY (id), - KEY cache_id (identifier), - KEY cache_tag (tag) - ) ENGINE=InnoDB; - '); - - $this->backend = t3lib_div::makeInstance( - 't3lib_cache_backend_DbBackend', - array( - 'cacheTable' => $this->testingCacheTable, - 'tagsTable' => $this->testingTagsTable, - ) - ); - } - - /** - * @test - * @expectedException t3lib_cache_Exception - * @author Ingo Renner - */ -# deactivated as the according check in the DB backend causes trouble during TYPO3's initialization -# public function setCacheTableThrowsExceptionOnNonExistentTable() { -# $this->backend->setCacheTable('test_cache_non_existent_table'); -# } - - /** - * @test - * @author Ingo Renner - */ - public function getCacheTableReturnsThePreviouslySetTable() { - $this->backend->setCacheTable($this->testingCacheTable); - $this->assertEquals($this->testingCacheTable, $this->backend->getCacheTable(), 'getCacheTable() did not return the expected value.'); - } - - /** - * @test - * @expectedException t3lib_cache_exception_InvalidData - * @author Ingo Renner - */ - public function setThrowsExceptionIfDataIsNotAString() { - $cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend', - array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'), - array(), - '', - FALSE - ); - - $data = array('Some data'); - $entryIdentifier = 'BackendDbTest'; - - $this->backend->setCache($cache); - - $this->backend->set($entryIdentifier, $data); - } - - /** - * @test - * @author Ingo Renner - */ - public function setReallySavesToTheSpecifiedTable() { - $cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend', - array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'), - array(), - '', - FALSE - ); - - $data = 'some data' . microtime(); - $entryIdentifier = 'BackendDbTest'; - - $this->backend->setCache($cache); - $this->backend->set($entryIdentifier, $data); - - $entriesFound = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows( - '*', - $this->testingCacheTable, - 'identifier = \'' . $entryIdentifier . '\'' - ); - - $this->assertEquals( - $data, - $entriesFound[0]['content'], - 'The original and the retrieved data don\'t match.' - ); - } - - /** - * @test - * @author Ingo Renner - */ - public function setRemovesAnAlreadyExistingCacheEntryForTheSameIdentifier() { - $cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend', - array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'), - array(), - '', - FALSE - ); - - $data1 = 'some data' . microtime(); - $data2 = 'some data' . microtime(); - $entryIdentifier = 'BackendDbRemoveBeforeSetTest'; - - $this->backend->setCache($cache); - $this->backend->set($entryIdentifier, $data1, array(), 500); - // setting a second entry with the same identifier, but different - // data, this should _replace_ the existing one we set before - $this->backend->set($entryIdentifier, $data2, array(), 200); - - $entriesFound = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows( - '*', - $this->testingCacheTable, - 'identifier = \'' . $entryIdentifier . '\'' - ); - - $this->assertEquals(1, count($entriesFound), 'There was not exactly one cache entry.'); - } - - /** - * @test - * @author Ingo Renner - */ - public function setReallySavesSpecifiedTags() { - $cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend', - array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'), - array(), - '', - FALSE - ); - - $data = 'some data' . microtime(); - $entryIdentifier = 'BackendDbTest'; - - $this->backend->setCache($cache); - $this->backend->set($entryIdentifier, $data, array('UnitTestTag%tag1', 'UnitTestTag%tag2')); - - $entriesFound = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows( - '*', - $this->testingTagsTable, - 'identifier = \'' . $entryIdentifier . '\'' - ); - - $tags = array(); - - foreach ($entriesFound as $entry) { - $tags[] = $entry['tag']; - } - - $this->assertTrue(count($tags) > 0, 'The tags do not exist.'); - $this->assertTrue(in_array('UnitTestTag%tag1', $tags), 'Tag UnitTestTag%tag1 does not exist.'); - $this->assertTrue(in_array('UnitTestTag%tag2', $tags), 'Tag UnitTestTag%tag2 does not exist.'); - } - - /** - * @test - * @author Ingo Renner - */ - public function getReturnsContentOfTheCorrectCacheEntry() { - $cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend', - array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'), - array(), - '', - FALSE - ); - - $data = 'some data' . microtime(); - $entryIdentifier = 'BackendDbTest'; - - $this->backend->setCache($cache); - $this->backend->set($entryIdentifier, $data, array(), 500); - - $data = 'some other data' . microtime(); - $this->backend->set($entryIdentifier, $data, array(), 100); - - $loadedData = $this->backend->get($entryIdentifier); - - $this->assertEquals($data, $loadedData, 'The original and the retrieved data don\'t match.'); - } - - /** - * @test - * @author Ingo Renner - */ - public function hasReturnsTheCorrectResult() { - $cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend', - array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'), - array(), - '', - FALSE - ); - - $data = 'some data' . microtime(); - $entryIdentifier = 'BackendDbTest'; - - $this->backend->setCache($cache); - $this->backend->set($entryIdentifier, $data); - - $this->assertTrue($this->backend->has($entryIdentifier), 'has() did not return TRUE.'); - $this->assertFalse($this->backend->has($entryIdentifier . 'Not'), 'has() did not return FALSE.'); - } - - /** - * @test - * @author Ingo Renner - */ - public function removeReallyRemovesACacheEntry() { - $cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend', - array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'), - array(), - '', - FALSE - ); - - $data = 'some data' . microtime(); - $entryIdentifier = 'BackendDbRemovalTest'; - - $this->backend->setCache($cache); - $this->backend->set($entryIdentifier, $data); - - $entriesFound = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows( - '*', - $this->testingCacheTable, - 'identifier = \'' . $entryIdentifier . '\'' - ); - - $this->assertTrue(is_array($entriesFound) && count($entriesFound) > 0, 'The cache entry does not exist.'); - - $this->backend->remove($entryIdentifier); - - $entriesFound = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows( - '*', - $this->testingCacheTable, - 'identifier = \'' . $entryIdentifier . '\'' - ); - - $this->assertTrue(count($entriesFound) == 0, 'The cache entry still exists.'); - } - - /** - * @test - * @author Ingo Renner - */ - public function collectGarbageReallyRemovesAnExpiredCacheEntry() { - $cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend', - array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'), - array(), - '', - FALSE - ); - - $data = 'some data' . microtime(); - $entryIdentifier = 'BackendDbRemovalTest'; - - $this->backend->setCache($cache); - $this->backend->set($entryIdentifier, $data, array(), 1); - - $entriesFound = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows( - '*', - $this->testingCacheTable, - 'identifier = \'' . $entryIdentifier . '\'' - ); - - $this->assertTrue(is_array($entriesFound) && count($entriesFound) > 0, 'The cache entry does not exist.'); - - sleep(2); - $GLOBALS['EXEC_TIME'] += 2; - $this->backend->collectGarbage(); - - $entriesFound = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows( - '*', - $this->testingCacheTable, - 'identifier = \'' . $entryIdentifier . '\'' - ); - - $this->assertTrue(count($entriesFound) == 0, 'The cache entry still exists.'); - } - - /** - * @test - * @author Ingo Renner - */ - public function collectGarbageReallyRemovesAllExpiredCacheEntries() { - $cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend', - array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'), - array(), - '', - FALSE - ); - - $data = 'some data' . microtime(); - $entryIdentifier = 'BackendDbRemovalTest'; - - $this->backend->setCache($cache); - - $this->backend->set($entryIdentifier . 'A', $data, array(), 1); - $this->backend->set($entryIdentifier . 'B', $data, array(), 1); - $this->backend->set($entryIdentifier . 'C', $data, array(), 1); - - $entriesFound = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows( - '*', - $this->testingCacheTable, - '' - ); - - $this->assertTrue(is_array($entriesFound) && count($entriesFound) > 0, 'The cache entries do not exist.'); - - sleep(2); - $GLOBALS['EXEC_TIME'] += 2; - $this->backend->collectGarbage(); - - $entriesFound = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows( - '*', - $this->testingCacheTable, - '' - ); - - $this->assertTrue(count($entriesFound) == 0, 'The cache entries still exist.'); - } - - /** - * @test - * @author Ingo Renner - */ - public function findIdentifiersByTagFindsCacheEntriesWithSpecifiedTag() { - $cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend', - array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'), - array(), - '', - FALSE - ); - - $this->backend->setCache($cache); - - $data = 'some data' . microtime(); - $this->backend->set('BackendDbTest1', $data, array('UnitTestTag%test', 'UnitTestTag%boring')); - $this->backend->set('BackendDbTest2', $data, array('UnitTestTag%test', 'UnitTestTag%special')); - $this->backend->set('BackendDbTest3', $data, array('UnitTestTag%test')); - - $expectedEntry = 'BackendDbTest2'; - - $actualEntries = $this->backend->findIdentifiersByTag('UnitTestTag%special'); - $this->assertTrue(is_array($actualEntries), 'actualEntries is not an array.'); - - $this->assertEquals($expectedEntry, array_pop($actualEntries)); - } - - /** - * @test - * @author Ingo Renner - */ - public function flushRemovesAllCacheEntries() { - $cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend', - array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'), - array(), - '', - FALSE - ); - - $this->backend->setCache($cache); - - $data = 'some data' . microtime(); - $this->backend->set('BackendDbTest1', $data, array('UnitTestTag%test')); - $this->backend->set('BackendDbTest2', $data, array('UnitTestTag%test', 'UnitTestTag%special')); - $this->backend->set('BackendDbTest3', $data, array('UnitTestTag%test')); - - $this->backend->flush(); - - $entriesFound = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows( - '*', - $this->testingCacheTable, - '' - ); - - $this->assertTrue(count($entriesFound) == 0, 'Still entries in the cache table'); - } - - /** - * @test - * @author Ingo Renner - */ - public function flushByTagRemovesCacheEntriesWithSpecifiedTag() { - $cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend', - array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'), - array(), - '', - FALSE - ); - - $this->backend->setCache($cache); - - $data = 'some data' . microtime(); - $this->backend->set('BackendDbTest1', $data, array('UnitTestTag%test', 'UnitTestTag%boring')); - $this->backend->set('BackendDbTest2', $data, array('UnitTestTag%test', 'UnitTestTag%special')); - $this->backend->set('BackendDbTest3', $data, array('UnitTestTag%test')); - - $this->backend->flushByTag('UnitTestTag%special'); - - $this->assertTrue($this->backend->has('BackendDbTest1'), 'BackendDbTest1 does not exist anymore.'); - $this->assertFalse($this->backend->has('BackendDbTest2'), 'BackendDbTest2 still exists.'); - $this->assertTrue($this->backend->has('BackendDbTest3'), 'BackendDbTest3 does not exist anymore.'); - - $tagEntriesFound = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows( - '*', - $this->testingTagsTable, - 'tag = ' . $GLOBALS['TYPO3_DB']->fullQuoteStr('UnitTestTag%special', $this->testingTagsTable) - ); - $this->assertEquals(0, count($tagEntriesFound), 'UnitTestTag%special still exists in tags table'); - } - - - /** - * @test - * @author Ingo Renner - */ - public function hasReturnsTheCorrectResultForEntryWithExceededLifetime() { - $cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend', - array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'), - array(), - '', - FALSE - ); - - $data = 'some data' . microtime(); - $entryIdentifier = 'BackendDbTest'; - - $this->backend->setCache($cache); - $this->backend->set($entryIdentifier, $data); - - $expiredEntryIdentifier = 'ExpiredBackendDbTest'; - $expiredData = 'some old data' . microtime(); - $this->backend->set($expiredEntryIdentifier, $expiredData, array(), 1); - - sleep(2); - $GLOBALS['EXEC_TIME'] += 2; - - $this->assertFalse($this->backend->has($expiredEntryIdentifier), 'has() did not return FALSE.'); - } - - /** - * @test - * @author Ingo Renner - */ - public function getReturnsFalseForEntryWithExceededLifetime() { - $cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend', - array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'), - array(), - '', - FALSE - ); - - $data = 'some data' . microtime(); - $entryIdentifier = 'BackendDbTest'; - - $this->backend->setCache($cache); - $this->backend->set($entryIdentifier, $data); - - $expiredEntryIdentifier = 'ExpiredBackendDbTest'; - $expiredData = 'some old data' . microtime(); - $this->backend->set($expiredEntryIdentifier, $expiredData, array(), 1); - - sleep(2); - $GLOBALS['EXEC_TIME'] += 2; - - $this->assertEquals($data, $this->backend->get($entryIdentifier), 'The original and the retrieved data don\'t match.'); - $this->assertFalse($this->backend->get($expiredEntryIdentifier), 'The expired entry could be loaded.'); - } - - /** - * @test - * @author Ingo Renner - */ - public function findIdentifiersByTagReturnsEmptyArrayForEntryWithExceededLifetime() { - $cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend', - array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'), - array(), - '', - FALSE - ); - - $this->backend->setCache($cache); - $this->backend->set('BackendDbTest', 'some data', array('UnitTestTag%special'), 1); - - sleep(2); - $GLOBALS['EXEC_TIME'] += 2; - // Not required, but used to update the pre-calculated queries: - $this->backend->setTagsTable($this->testingTagsTable); - - $this->assertEquals(array(), $this->backend->findIdentifiersByTag('UnitTestTag%special')); - } - - /** - * @test - * @author Ingo Renner - */ - public function setWithUnlimitedLifetimeWritesCorrectEntry() { - $cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend', - array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove'), - array(), - '', - FALSE - ); - - $data = 'some data' . microtime(); - $entryIdentifier = 'BackendFileTest'; - - $this->backend->setCache($cache); - $this->backend->set($entryIdentifier, $data, array(), 0); - - $entriesFound = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows( - '*', - $this->testingCacheTable, - '' - ); - - $this->assertTrue(is_array($entriesFound), 'entriesFound is not an array.'); - - $retrievedData = $entriesFound[0]['content']; - $this->assertEquals($data, $retrievedData, 'The original and the retrieved data don\'t match.'); - } - - - /** - * @author Ingo Renner - */ - public function tearDown() { - $GLOBALS['TYPO3_DB']->sql_query( - 'DROP TABLE ' . $this->testingCacheTable . ';' - ); - - $GLOBALS['TYPO3_DB']->sql_query( - 'DROP TABLE ' . $this->testingTagsTable . ';' - ); - } - -} - -?> \ No newline at end of file Index: tests/t3lib/cache/backend/t3lib_cache_backend_memcachedbackendtestcase.php =================================================================== --- tests/t3lib/cache/backend/t3lib_cache_backend_memcachedbackendtestcase.php (Revision 7835) +++ tests/t3lib/cache/backend/t3lib_cache_backend_memcachedbackendtestcase.php (Arbeitskopie) @@ -1,350 +0,0 @@ - -* All rights reserved -* -* This script is part of the TYPO3 project. The TYPO3 project is -* free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* The GNU General Public License can be found at -* http://www.gnu.org/copyleft/gpl.html. -* -* This script is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* This copyright notice MUST APPEAR in all copies of the script! -***************************************************************/ - - - // TODO implement autoloading so that we only require stuff we really need -require_once(PATH_t3lib . 'class.t3lib_cache.php'); - -require_once(PATH_t3lib . 'cache/backend/interfaces/interface.t3lib_cache_backend_backend.php'); -require_once(PATH_t3lib . 'cache/frontend/interfaces/interface.t3lib_cache_frontend_frontend.php'); - -require_once(PATH_t3lib . 'cache/backend/class.t3lib_cache_backend_abstractbackend.php'); -require_once(PATH_t3lib . 'cache/frontend/class.t3lib_cache_frontend_abstractfrontend.php'); -require_once(PATH_t3lib . 'cache/class.t3lib_cache_exception.php'); -require_once(PATH_t3lib . 'cache/class.t3lib_cache_factory.php'); -require_once(PATH_t3lib . 'cache/class.t3lib_cache_manager.php'); -require_once(PATH_t3lib . 'cache/frontend/class.t3lib_cache_frontend_variablefrontend.php'); - -require_once(PATH_t3lib . 'cache/exception/class.t3lib_cache_exception_classalreadyloaded.php'); -require_once(PATH_t3lib . 'cache/exception/class.t3lib_cache_exception_duplicateidentifier.php'); -require_once(PATH_t3lib . 'cache/exception/class.t3lib_cache_exception_invalidbackend.php'); -require_once(PATH_t3lib . 'cache/exception/class.t3lib_cache_exception_invalidcache.php'); -require_once(PATH_t3lib . 'cache/exception/class.t3lib_cache_exception_invaliddata.php'); -require_once(PATH_t3lib . 'cache/exception/class.t3lib_cache_exception_nosuchcache.php'); - -require_once(PATH_t3lib . 'cache/backend/class.t3lib_cache_backend_memcachedbackend.php'); - -/** - * Testcase for the cache to memcached backend - * - * This file is a backport from FLOW3 - * - * @author Ingo Renner - * @package TYPO3 - * @subpackage tests - * @version $Id$ - */ -class t3lib_cache_backend_MemcachedBackendTestCase extends tx_phpunit_testcase { - - /** - * Sets up this testcase - * - * @return void - * @author Christian Jul Jensen - * @author Ingo Renner - */ - public function setUp() { - if (!extension_loaded('memcache')) { - $this->markTestSkipped('memcache extension was not available'); - } - - try { - if (!fsockopen('localhost', 11211)) { - $this->markTestSkipped('memcached not reachable'); - } - } catch (Exception $e) { - $this->markTestSkipped('memcached not reachable'); - } - } - - /** - * @test - * @author Christian Jul Jensen - * @author Ingo Renner - * @expectedException t3lib_cache_Exception - */ - public function setThrowsExceptionIfNoFrontEndHasBeenSet() { - $backendOptions = array('servers' => array('localhost:11211')); - $backend = new t3lib_cache_backend_MemcachedBackend($backendOptions); - - $data = 'Some data'; - $identifier = 'MyIdentifier'; - $backend->set($identifier, $data); - } - - /** - * @test - * @author Robert Lemke - * @author Ingo Renner - * @expectedException t3lib_cache_Exception - */ - public function constructorThrowsExceptionIfNoMemcacheServerIsConfigured() { - $backend = new t3lib_cache_backend_MemcachedBackend(); - } - - /** - * @test - * @author Christian Jul Jensen - * @author Ingo Renner - * @expectedException t3lib_cache_Exception - */ - public function setThrowsExceptionIfConfiguredServersAreUnreachable() { - $backend = $this->setUpBackend(array('servers' => array('julle.did.this:1234'))); - $data = 'Somedata'; - $identifier = 'MyIdentifier'; - $backend->set($identifier, $data); - } - - /** - * @test - * @author Christian Jul Jensen - */ - public function itIsPossibleToSetAndCheckExistenceInCache() { - $backend = $this->setUpBackend(); - $data = 'Some data'; - $identifier = 'MyIdentifier'; - $backend->set($identifier, $data); - $inCache = $backend->has($identifier); - $this->assertTrue($inCache, 'Memcache failed to set and check entry'); - } - - /** - * @test - * @author Christian Jul Jensen - */ - public function itIsPossibleToSetAndGetEntry() { - $backend = $this->setUpBackend(); - $data = 'Some data'; - $identifier = 'MyIdentifier'; - $backend->set($identifier, $data); - $fetchedData = $backend->get($identifier); - $this->assertEquals($data, $fetchedData, 'Memcache failed to set and retrieve data'); - } - - /** - * @test - * @author Christian Jul Jensen - */ - public function itIsPossibleToRemoveEntryFromCache() { - $backend = $this->setUpBackend(); - $data = 'Some data'; - $identifier = 'MyIdentifier'; - $backend->set($identifier, $data); - $backend->remove($identifier); - $inCache = $backend->has($identifier); - $this->assertFalse($inCache, 'Failed to set and remove data from Memcache'); - } - - /** - * @test - * @author Christian Jul Jensen - */ - public function itIsPossibleToOverwriteAnEntryInTheCache() { - $backend = $this->setUpBackend(); - $data = 'Some data'; - $identifier = 'MyIdentifier'; - $backend->set($identifier, $data); - $otherData = 'some other data'; - $backend->set($identifier, $otherData); - $fetchedData = $backend->get($identifier); - $this->assertEquals($otherData, $fetchedData, 'Memcache failed to overwrite and retrieve data'); - } - - /** - * @test - * @author Karsten Dambekalns - */ - public function findIdentifiersByTagFindsCacheEntriesWithSpecifiedTag() { - $backend = $this->setUpBackend(); - - $data = 'Some data'; - $entryIdentifier = 'MyIdentifier'; - $backend->set($entryIdentifier, $data, array('UnitTestTag%tag1', 'UnitTestTag%tag2')); - - $retrieved = $backend->findIdentifiersByTag('UnitTestTag%tag1'); - $this->assertEquals($entryIdentifier, $retrieved[0], 'Could not retrieve expected entry by tag.'); - - $retrieved = $backend->findIdentifiersByTag('UnitTestTag%tag2'); - $this->assertEquals($entryIdentifier, $retrieved[0], 'Could not retrieve expected entry by tag.'); - } - - /** - * @test - * @author Karsten Dambekalns - */ - public function setRemovesTagsFromPreviousSet() { - $backend = $this->setUpBackend(); - - $data = 'Some data'; - $entryIdentifier = 'MyIdentifier'; - $backend->set($entryIdentifier, $data, array('UnitTestTag%tag1', 'UnitTestTag%tag2')); - $backend->set($entryIdentifier, $data, array('UnitTestTag%tag3')); - - $retrieved = $backend->findIdentifiersByTag('UnitTestTag%tag2'); - $this->assertEquals(array(), $retrieved, 'Found entry which should no longer exist.'); - } - - /** - * @test - * @author Christian Jul Jensen - */ - public function hasReturnsFalseIfTheEntryDoesntExist() { - $backend = $this->setUpBackend(); - $identifier = 'NonExistingIdentifier'; - $inCache = $backend->has($identifier); - $this->assertFalse($inCache,'"has" did not return false when checking on non existing identifier'); - } - - /** - * @test - * @author Christian Jul Jensen - */ - public function removeReturnsFalseIfTheEntryDoesntExist() { - $backend = $this->setUpBackend(); - $identifier = 'NonExistingIdentifier'; - $inCache = $backend->remove($identifier); - $this->assertFalse($inCache,'"remove" did not return false when checking on non existing identifier'); - } - - /** - * @test - * @author Robert Lemke - * @author Karsten Dambekalns - */ - public function flushByTagRemovesCacheEntriesWithSpecifiedTag() { - $backend = $this->setUpBackend(); - - $data = 'some data' . microtime(); - $backend->set('BackendMemcacheTest1', $data, array('UnitTestTag%test', 'UnitTestTag%boring')); - $backend->set('BackendMemcacheTest2', $data, array('UnitTestTag%test', 'UnitTestTag%special')); - $backend->set('BackendMemcacheTest3', $data, array('UnitTestTag%test')); - - $backend->flushByTag('UnitTestTag%special'); - - $this->assertTrue($backend->has('BackendMemcacheTest1'), 'BackendMemcacheTest1'); - $this->assertFalse($backend->has('BackendMemcacheTest2'), 'BackendMemcacheTest2'); - $this->assertTrue($backend->has('BackendMemcacheTest3'), 'BackendMemcacheTest3'); - } - - /** - * @test - * @author Karsten Dambekalns - */ - public function flushRemovesAllCacheEntries() { - $backend = $this->setUpBackend(); - - $data = 'some data' . microtime(); - $backend->set('BackendMemcacheTest1', $data); - $backend->set('BackendMemcacheTest2', $data); - $backend->set('BackendMemcacheTest3', $data); - - $backend->flush(); - - $this->assertFalse($backend->has('BackendMemcacheTest1'), 'BackendMemcacheTest1'); - $this->assertFalse($backend->has('BackendMemcacheTest2'), 'BackendMemcacheTest2'); - $this->assertFalse($backend->has('BackendMemcacheTest3'), 'BackendMemcacheTest3'); - } - - /** - * @test - * @author Karsten Dambekalns - * @author Ingo Renner - */ - public function flushRemovesOnlyOwnEntries() { - $backendOptions = array('servers' => array('localhost:11211')); - - $thisCache = $this->getMock( - 't3lib_cache_frontend_AbstractFrontend', - array(), - array(), - '', - FALSE - ); - $thisCache->expects($this->any()) - ->method('getIdentifier') - ->will($this->returnValue('thisCache')); - $thisBackend = new t3lib_cache_backend_MemcachedBackend($backendOptions); - $thisBackend->setCache($thisCache); - - $thatCache = $this->getMock( - 't3lib_cache_frontend_AbstractFrontend', - array(), - array(), - '', - FALSE - ); - $thatCache->expects($this->any()) - ->method('getIdentifier') - ->will($this->returnValue('thatCache')); - $thatBackend = new t3lib_cache_backend_MemcachedBackend($backendOptions); - $thatBackend->setCache($thatCache); - - $thisBackend->set('thisEntry', 'Hello'); - $thatBackend->set('thatEntry', 'World!'); - $thatBackend->flush(); - - $this->assertEquals('Hello', $thisBackend->get('thisEntry')); - $this->assertFalse($thatBackend->has('thatEntry')); - } - - /** - * Check if we can store ~5 MB of data, this gives some headroom for the - * reflection data. - * - * @test - * @author Karsten Dambekalns - */ - public function largeDataIsStored() { - $backend = $this->setUpBackend(); - - $data = str_repeat('abcde', 1024 * 1024); - $backend->set('tooLargeData', $data); - - $this->assertTrue($backend->has('tooLargeData')); - $this->assertEquals($backend->get('tooLargeData'), $data); - } - - /** - * Sets up the memcached backend used for testing - * - * @param array $backendOptions Options for the memcache backend - * @return t3lib_cache_backend_MemcachedBackend - * @author Christian Jul Jensen - * @author Karsten Dambekalns - * @author Ingo Renner - */ - protected function setUpBackend(array $backendOptions = array()) { - $cache = $this->getMock('t3lib_cache_frontend_Frontend', array(), array(), '', FALSE); - if (empty($backendOptions)) { - $backendOptions = array('servers' => array('localhost:11211')); - } - - $backend = new t3lib_cache_backend_MemcachedBackend($backendOptions); - $backend->setCache($cache); - - return $backend; - } -} - -?> \ No newline at end of file Index: tests/t3lib/cache/backend/t3lib_cache_backend_abstractbackendTest.php =================================================================== --- tests/t3lib/cache/backend/t3lib_cache_backend_abstractbackendTest.php (Revision 7835) +++ tests/t3lib/cache/backend/t3lib_cache_backend_abstractbackendTest.php (Arbeitskopie) @@ -33,7 +33,7 @@ * @subpackage tests * @version $Id$ */ -class t3lib_cache_backend_AbstractBackendTestCase extends tx_phpunit_testcase { +class t3lib_cache_backend_AbstractBackendTest extends tx_phpunit_testcase { /** * @var t3lib_cache_backend_AbstractBackend Index: tests/t3lib/cache/backend/t3lib_cache_backend_apcbackendTest.php =================================================================== --- tests/t3lib/cache/backend/t3lib_cache_backend_apcbackendTest.php (Revision 7835) +++ tests/t3lib/cache/backend/t3lib_cache_backend_apcbackendTest.php (Arbeitskopie) @@ -55,7 +55,7 @@ * @subpackage tests * @version $Id$ */ -class t3lib_cache_backend_ApcBackendTestCase extends tx_phpunit_testcase { +class t3lib_cache_backend_ApcBackendTest extends tx_phpunit_testcase { /** * Sets up this testcase Index: tests/t3lib/cache/backend/t3lib_cache_backend_dbbackendTest.php =================================================================== --- tests/t3lib/cache/backend/t3lib_cache_backend_dbbackendTest.php (Revision 7835) +++ tests/t3lib/cache/backend/t3lib_cache_backend_dbbackendTest.php (Arbeitskopie) @@ -53,7 +53,7 @@ * @subpackage tests * @version $Id$ */ -class t3lib_cache_backend_DbBackendTestCase extends tx_phpunit_testcase { +class t3lib_cache_backend_DbBackendTest extends tx_phpunit_testcase { /** * If set, the tearDown() method will clean up the cache table used by this unit test. Index: tests/t3lib/cache/backend/t3lib_cache_backend_memcachedbackendTest.php =================================================================== --- tests/t3lib/cache/backend/t3lib_cache_backend_memcachedbackendTest.php (Revision 7835) +++ tests/t3lib/cache/backend/t3lib_cache_backend_memcachedbackendTest.php (Arbeitskopie) @@ -55,7 +55,7 @@ * @subpackage tests * @version $Id$ */ -class t3lib_cache_backend_MemcachedBackendTestCase extends tx_phpunit_testcase { +class t3lib_cache_backend_MemcachedBackendTest extends tx_phpunit_testcase { /** * Sets up this testcase Index: tests/t3lib/cache/t3lib_cache_factorytestcase.php =================================================================== --- tests/t3lib/cache/t3lib_cache_factorytestcase.php (Revision 7835) +++ tests/t3lib/cache/t3lib_cache_factorytestcase.php (Arbeitskopie) @@ -1,133 +0,0 @@ - -* All rights reserved -* -* This script is part of the TYPO3 project. The TYPO3 project is -* free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* The GNU General Public License can be found at -* http://www.gnu.org/copyleft/gpl.html. -* -* This script is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* This copyright notice MUST APPEAR in all copies of the script! -***************************************************************/ - - -require_once(PATH_t3lib . 'cache/backend/class.t3lib_cache_backend_nullbackend.php'); -require_once('backend/class.t3lib_cache_backend_mockbackend.php'); - -/** - * Testcase for the Cache Factory - * - * This file is a backport from FLOW3 - * - * @author Ingo Renner - * @package TYPO3 - * @subpackage tests - * @version $Id$ - */ -class t3lib_cache_FactoryTestCase extends tx_phpunit_testcase { - - /** - * Sets up this testcase - * - * @return void - * @author Ingo Renner - */ - public function setUp() { - $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheBackends']['t3lib_cache_backend_MockBackend'] = 'typo3_src/tests/t3lib/cache/backend/class.t3lib_cache_backend_mockbackend.php:t3lib_cache_backend_MockBackend'; - } - - /** - * @test - * @author Robert Lemke - * @author Karsten Dambekalns - * @author Ingo Renner - */ - public function createReturnsInstanceOfTheSpecifiedCacheFrontend() { - $backend = $this->getMock('t3lib_cache_backend_NullBackend', array(), array(), '', FALSE); - $cache = $this->getMock('t3lib_cache_frontend_VariableFrontend', array(), array(), '', FALSE); - - $mockCacheManager = $this->getMock('t3lib_cache_Manager', array('registerCache'), array(), '', FALSE); - $factory = new t3lib_cache_Factory(); - $factory->setCacheManager($mockCacheManager); - - $cache = $factory->create('TYPO3_Cache_FactoryTest_Cache', 't3lib_cache_frontend_VariableFrontend', 't3lib_cache_backend_NullBackend'); - $this->assertType('t3lib_cache_frontend_VariableFrontend', $cache); - } - - /** - * @test - * @author Robert Lemke - * @author Karsten Dambekalns - * @author Ingo Renner - */ - public function createInjectsAnInstanceOfTheSpecifiedBackendIntoTheCacheFrontend() { - $backend = $this->getMock('t3lib_cache_backend_FileBackend', array(), array(), '', FALSE); - $cache = $this->getMock('t3lib_cache_frontend_VariableFrontend', array(), array(), '', FALSE); - - $mockCacheManager = $this->getMock('t3lib_cache_Manager', array('registerCache'), array(), '', FALSE); - $factory = new t3lib_cache_Factory(); - $factory->setCacheManager($mockCacheManager); - - $factory->create('TYPO3_Cache_FactoryTest_Cache', 't3lib_cache_frontend_VariableFrontend', 't3lib_cache_backend_FileBackend'); - } - - /** - * @test - * @author Robert Lemke - * @author Karsten Dambekalns - * @author Ingo Renner - */ - public function createPassesBackendOptionsToTheCreatedBackend() { - $someValue = microtime(); - $backendOptions = array('someOption' => $someValue); - - $cache = $this->getMock('t3lib_cache_frontend_VariableFrontend', array(), array(), '', FALSE); - - $mockCacheManager = $this->getMock('t3lib_cache_Manager', array('registerCache'), array(), '', FALSE); - $factory = new t3lib_cache_Factory(); - $factory->setCacheManager($mockCacheManager); - - $cache = $factory->create('TYPO3_Cache_FactoryTest_Cache', 't3lib_cache_frontend_VariableFrontend', 't3lib_cache_backend_MockBackend', $backendOptions); - - $this->assertEquals($someValue, $cache->getBackend()->getSomeOption(), 'create() did not pass the backend options to the backend.'); - } - - /** - * @test - * @author Robert Lemke - * @author Karsten Dambekalns - * @author Ingo Renner - */ -/* - Not working yet - - public function createRegistersTheCacheAtTheCacheManager() { - $cacheIdentifier = 'TYPO3_Cache_FactoryTest_Cache'; - $backend = $this->getMock('t3lib_cache_backend_NullBackend', array(), array(), '', FALSE); - $cache = $this->getMock('t3lib_cache_frontend_VariableFrontend', array('getCache'), array($cacheIdentifier, $backend), '', true); - $cache->getBackend()->setCache($cache); - - $mockCacheManager = $this->getMock('t3lib_cache_Manager', array('registerCache'), array(), '', FALSE); - $mockCacheManager->expects($this->once())->method('registerCache')->with($cache); -# $mockCacheManager->expects($this->once())->method('registerCache')->with('t3lib_cache_frontend_VariableFrontend'); - $factory = new t3lib_cache_Factory(); - $factory->setCacheManager($mockCacheManager); - - $factory->create($cacheIdentifier, 't3lib_cache_frontend_VariableFrontend', 't3lib_cache_backend_NullBackend'); - } -*/ -} - -?> \ No newline at end of file Index: tests/t3lib/cache/t3lib_cache_managertestcase.php =================================================================== --- tests/t3lib/cache/t3lib_cache_managertestcase.php (Revision 7835) +++ tests/t3lib/cache/t3lib_cache_managertestcase.php (Arbeitskopie) @@ -1,183 +0,0 @@ - -* All rights reserved -* -* This script is part of the TYPO3 project. The TYPO3 project is -* free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* The GNU General Public License can be found at -* http://www.gnu.org/copyleft/gpl.html. -* -* This script is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* This copyright notice MUST APPEAR in all copies of the script! -***************************************************************/ - - -/** - * Testcase for the Cache Manager - * - * This file is a backport from FLOW3 - * - * @author Ingo Renner - * @package TYPO3 - * @subpackage tests - * @version $Id$ - */ -class t3lib_cache_ManagerTestCase extends tx_phpunit_testcase { - - /** - * @test - * @author Robert Lemke - * @author Ingo Renner - */ - public function initializeCreatesAndRegistersAllCachesDefinedInTheCachesConfiguration() { - $mockCacheFactory = $this->getMock('t3lib_cache_Factory', array(), array(), '', FALSE); - $mockCacheFactory->expects($this->at(1))->method('create')->with('cache1', 't3lib_cache_frontend_VariableFrontend', 't3lib_cache_backend_FileBackend', array()); - $mockCacheFactory->expects($this->at(2))->method('create')->with('cache2', 't3lib_cache_frontend_StringFrontend', 't3lib_cache_backend_NullBackend', array('foo' => 'bar')); - - $cacheConfigurations = array( - 'cache1' => array(), - 'cache2' => array( - 'frontend' => 't3lib_cache_frontend_StringFrontend', - 'backend' => 't3lib_cache_backend_NullBackend', - 'backendOptions' => array('foo' => 'bar') - ), - ); - - $manager = new t3lib_cache_Manager(); - $manager->setCacheConfigurations($cacheConfigurations); - $manager->setCacheFactory($mockCacheFactory); - $manager->initialize(); - } - - /** - * @test - * @author Robert Lemke - * @author Ingo Renner - * @expectedException t3lib_cache_exception_DuplicateIdentifier - */ - public function managerThrowsExceptionOnCacheRegistrationWithAlreadyExistingIdentifier() { - $manager = new t3lib_cache_Manager(); - $backend = $this->getMock('t3lib_cache_backend_AbstractBackend', array(), array(), '', FALSE); - - $cache1 = $this->getMock('t3lib_cache_frontend_AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag'), array(), '', FALSE); - $cache1->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('test')); - - $cache2 = $this->getMock('t3lib_cache_frontend_AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag'), array(), '', FALSE); - $cache2->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('test')); - - $manager->registerCache($cache1); - $manager->registerCache($cache2); - } - - /** - * @test - * @author Robert Lemke - * @author Ingo Renner - */ - public function managerReturnsThePreviouslyRegisteredCache() { - $manager = new t3lib_cache_Manager(); - $backend = $this->getMock('t3lib_cache_backend_AbstractBackend', array(), array(), '', FALSE); - - $cache1 = $this->getMock('t3lib_cache_frontend_AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag'), array(), '', FALSE); - $cache1->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('cache1')); - - $cache2 = $this->getMock('t3lib_cache_frontend_AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag'), array(), '', FALSE); - $cache2->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('cache2')); - - $manager->registerCache($cache1); - $manager->registerCache($cache2); - - $this->assertSame($cache2, $manager->getCache('cache2'), 'The cache returned by getCache() was not the same I registered.'); - } - - /** - * @test - * @author Robert Lemke - * @author Ingo Renner - * @expectedException t3lib_cache_exception_NoSuchCache - */ - public function getCacheThrowsExceptionForNonExistingIdentifier() { - $manager = new t3lib_cache_Manager(); - $backend = $this->getMock('t3lib_cache_backend_AbstractBackend', array(), array(), '', FALSE); - $cache = $this->getMock('t3lib_cache_frontend_AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag'), array(), '', FALSE); - $cache->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('someidentifier')); - - $manager->registerCache($cache); - $manager->getCache('someidentifier'); - - $manager->getCache('doesnotexist'); - } - - /** - * @test - * @author Robert Lemke - * @author Ingo Renner - */ - public function hasCacheReturnsCorrectResult() { - $manager = new t3lib_cache_Manager(); - $backend = $this->getMock('t3lib_cache_backend_AbstractBackend', array(), array(), '', FALSE); - $cache1 = $this->getMock('t3lib_cache_frontend_AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag'), array(), '', FALSE); - $cache1->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('cache1')); - $manager->registerCache($cache1); - - $this->assertTrue($manager->hasCache('cache1'), 'hasCache() did not return TRUE.'); - $this->assertFalse($manager->hasCache('cache2'), 'hasCache() did not return FALSE.'); - } - - /** - * @test - * @author Robert Lemke - * @author Ingo Renner - */ - public function flushCachesByTagCallsTheFlushByTagMethodOfAllRegisteredCaches() { - $manager = new t3lib_cache_Manager(); - - $backend = $this->getMock('t3lib_cache_backend_AbstractBackend', array(), array(), '', FALSE); - - $cache1 = $this->getMock('t3lib_cache_frontend_AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag'), array(), '', FALSE); - $cache1->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('cache1')); - $cache1->expects($this->once())->method('flushByTag')->with($this->equalTo('theTag')); - $manager->registerCache($cache1); - - $cache2 = $this->getMock('t3lib_cache_frontend_AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag'), array(), '', FALSE); - $cache2->expects($this->once())->method('flushByTag')->with($this->equalTo('theTag')); - $manager->registerCache($cache2); - - $manager->flushCachesByTag('theTag'); - } - - /** - * @test - * @author Robert Lemke - * @author Ingo Renner - */ - public function flushCachesCallsTheFlushMethodOfAllRegisteredCaches() { - $manager = new t3lib_cache_Manager(); - $backend = $this->getMock('t3lib_cache_backend_AbstractBackend', array(), array(), '', FALSE); - - $cache1 = $this->getMock('t3lib_cache_frontend_AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag'), array(), '', FALSE); - $cache1->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('cache1')); - $cache1->expects($this->once())->method('flush'); - $manager->registerCache($cache1); - - $cache2 = $this->getMock('t3lib_cache_frontend_AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag'), array(), '', FALSE); - $cache2->expects($this->once())->method('flush'); - $manager->registerCache($cache2); - - $manager->flushCaches(); - } - -} - -?> \ No newline at end of file Index: tests/t3lib/cache/t3lib_cache_factoryTest.php =================================================================== --- tests/t3lib/cache/t3lib_cache_factoryTest.php (Revision 7835) +++ tests/t3lib/cache/t3lib_cache_factoryTest.php (Arbeitskopie) @@ -36,7 +36,7 @@ * @subpackage tests * @version $Id$ */ -class t3lib_cache_FactoryTestCase extends tx_phpunit_testcase { +class t3lib_cache_FactoryTest extends tx_phpunit_testcase { /** * Sets up this testcase Index: tests/t3lib/utility/t3lib_utility_mail_testcase.php =================================================================== --- tests/t3lib/utility/t3lib_utility_mail_testcase.php (Revision 7835) +++ tests/t3lib/utility/t3lib_utility_mail_testcase.php (Arbeitskopie) @@ -1,98 +0,0 @@ - - */ -class t3lib_utility_mail_testcase extends tx_phpunit_testcase { - /** - * backed-up TYPO3_CONF_VARS SC_OPTIONS - * - * @var array - */ - private $scOptionsBackup = array(); - - /** - * backed-up T3_VAR callUserFunction - * - * @var array - */ - private $callUserFunctionBackup = array(); - - public function setUp() { - $this->scOptionsBackup = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']; - $this->callUserFunctionBackup = $GLOBALS['T3_VAR']['callUserFunction']; - } - - public function tearDown() { - $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'] = $this->scOptionsBackup; - $GLOBALS['T3_VAR']['callUserFunction'] = $this->callUserFunctionBackup; - } - - - ////////////////////////// - // Tests concerning mail - ////////////////////////// - - /** - * @test - */ - public function mailCallsHook() { - $to = 'john@example.com'; - $subject = 'Good news everybody!'; - $messageBody = 'The hooks works!'; - $additionalHeaders = 'Reply-to: jane@example.com'; - $additionalParameters = '-f postmaster@example.com'; - - $mockMailer = $this->getMock('mockMailer', array('mail')); - $mockMailer->expects($this->once())->method('mail') - ->with( - array( - 'to' => $to, - 'subject' => $subject, - 'messageBody' => $messageBody, - 'additionalHeaders' => $additionalHeaders, - 'additionalParameters' => $additionalParameters, - ), - FALSE - ); - $GLOBALS['T3_VAR']['callUserFunction']['mockMailer->mail'] - = array('obj' => $mockMailer, 'method' => 'mail'); - - $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'] - ['t3lib/utility/class.t3lib_utility_mail.php'] - ['substituteMailDelivery'] = array('mockMailer->mail'); - - t3lib_utility_Mail::mail( - $to, $subject, $messageBody, $additionalHeaders, - $additionalParameters - ); - } -} -?> \ No newline at end of file Index: tests/t3lib/utility/t3lib_utility_mailTest.php =================================================================== --- tests/t3lib/utility/t3lib_utility_mailTest.php (Revision 7835) +++ tests/t3lib/utility/t3lib_utility_mailTest.php (Arbeitskopie) @@ -30,7 +30,7 @@ * * @author Oliver Klee */ -class t3lib_utility_mail_testcase extends tx_phpunit_testcase { +class t3lib_utility_mailTest extends tx_phpunit_testcase { /** * backed-up TYPO3_CONF_VARS SC_OPTIONS * Index: tests/t3lib/t3lib_tcemainTest.php =================================================================== --- tests/t3lib/t3lib_tcemainTest.php (Revision 7835) +++ tests/t3lib/t3lib_tcemainTest.php (Arbeitskopie) @@ -34,7 +34,7 @@ * * @author Oliver Klee */ -class t3lib_tcemain_testcase extends tx_phpunit_testcase { +class t3lib_tcemainTest extends tx_phpunit_testcase { /** * @var boolean */ Index: tests/t3lib/t3lib_divTest.php =================================================================== --- tests/t3lib/t3lib_divTest.php (Revision 7835) +++ tests/t3lib/t3lib_divTest.php (Arbeitskopie) @@ -32,7 +32,7 @@ * @package TYPO3 * @subpackage t3lib */ -class t3lib_div_testcase extends tx_phpunit_testcase { +class t3lib_divTest extends tx_phpunit_testcase { /** * backup of the global variables _GET, _POST, _SERVER * Index: tests/typo3/sysext/cms/tslib/tslib_content_testcase.php =================================================================== --- tests/typo3/sysext/cms/tslib/tslib_content_testcase.php (Revision 7835) +++ tests/typo3/sysext/cms/tslib/tslib_content_testcase.php (Arbeitskopie) @@ -1,634 +0,0 @@ - -* All rights reserved -* -* This script is part of the TYPO3 project. The TYPO3 project is -* free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* The GNU General Public License can be found at -* http://www.gnu.org/copyleft/gpl.html. -* -* This script is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* This copyright notice MUST APPEAR in all copies of the script! -***************************************************************/ - -/** - * Testcase for the "tslib_cObj" class in the TYPO3 Core. - * - * @package TYPO3 - * @subpackage tslib - * - * @author Oliver Hader - * @author Oliver Klee - */ -class tslib_content_testcase extends tx_phpunit_testcase { - /** - * @var array - */ - private $backupGlobalVariables; - - /** - * @var tslib_cObj - */ - private $cObj; - - /** - * @var tslib_fe - */ - private $tsfe; - - /** - * @var t3lib_TStemplate - */ - private $template; - - /** - * @var array - */ - private $typoScriptImage; - - public function setUp() { - $this->backupGlobalVariables = array( - '_GET' => $_GET, - '_POST' => $_POST, - '_SERVER' => $_SERVER, - 'TYPO3_CONF_VARS' => $GLOBALS['TYPO3_CONF_VARS'], - ); - - $this->template = $this->getMock( - 't3lib_TStemplate', array('getFileName', 'linkData') - ); - $this->tsfe = $this->getMock('tslib_fe', array(), array(), '', false); - $this->tsfe->tmpl = $this->template; - $this->tsfe->config = array(); - $GLOBALS['TSFE'] = $this->tsfe; - $GLOBALS['TSFE']->csConvObj = new t3lib_cs(); - $GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] = 'mbstring'; - - $className = 'tslib_cObj_' . uniqid('test'); - eval(' - class ' . $className . ' extends tslib_cObj { - public $stdWrapHookObjects = array(); - public $getImgResourceHookObjects; - } - '); - - $this->cObj = new $className(); - $this->cObj->start(array(), 'tt_content'); - - $this->typoScriptImage = array( - 'file' => 'typo3/clear.gif', - ); - } - - public function tearDown() { - foreach ($this->backupGlobalVariables as $key => $data) { - $GLOBALS[$key] = $data; - } - - $GLOBALS['TSFE'] = null; - - unset($this->cObj, $this->tsfe, $this->template, $this->typoScriptImage); - } - - - //////////////////////// - // Utitility functions - //////////////////////// - - /** - * Converts the subject and the expected result into the target charset. - * - * @param string $charset the target charset - * @param string $subject the subject, will be modified - * @param string $expected the expected result, will be modified - */ - protected function handleCharset($charset, &$subject, &$expected) { - $GLOBALS['TSFE']->renderCharset = $charset; - $subject = $GLOBALS['TSFE']->csConvObj->conv($subject, 'iso-8859-1', $charset); - $expected = $GLOBALS['TSFE']->csConvObj->conv($expected, 'iso-8859-1', $charset); - } - - - ///////////////////////////////////////////// - // Tests concerning the getImgResource hook - ///////////////////////////////////////////// - - /** - * @test - */ - public function getImgResourceHookGetsCalled() { - $this->template->expects($this->atLeastOnce())->method('getFileName') - ->with('typo3/clear.gif')->will($this->returnValue('typo3/clear.gif')); - - $className = uniqid('tx_coretest'); - $getImgResourceHookMock = $this->getMock( - 'tslib_cObj_getImgResourceHook', - array('getImgResourcePostProcess'), - array(), - $className - ); - - $getImgResourceHookMock->expects($this->once())->method('getImgResourcePostProcess') - ->will($this->returnCallback(array($this, 'isGetImgResourceHookCalledCallback'))); - $this->cObj->getImgResourceHookObjects = array($getImgResourceHookMock); - - $this->cObj->IMAGE($this->typoScriptImage); - } - - /** - * Handles the arguments that have been sent to the getImgResource hook. - * - * @return array - * - * @see getImgResourceHookGetsCalled - */ - public function isGetImgResourceHookCalledCallback() { - list($file, $fileArray, $imageResource, $parent) = func_get_args(); - - $this->assertEquals('typo3/clear.gif', $file); - $this->assertEquals('typo3/clear.gif', $imageResource['origFile']); - $this->assertTrue(is_array($fileArray)); - $this->assertTrue($parent instanceof tslib_cObj); - - return $imageResource; - } - - - ////////////////////////// - // Tests concerning FORM - ////////////////////////// - - /** - * @test - */ - public function formWithSecureFormMailEnabledDoesNotContainRecipientField() { - $GLOBALS['TYPO3_CONF_VARS']['FE']['secureFormmail'] = TRUE; - - $this->assertNotContains( - 'name="recipient', - $this->cObj->FORM( - array('recipient' => 'foo@bar.com', 'recipient.' => array()), - array() - ) - ); - } - - /** - * @test - */ - public function formWithSecureFormMailDisabledDoesNotContainRecipientField() { - $GLOBALS['TYPO3_CONF_VARS']['FE']['secureFormmail'] = FALSE; - - $this->assertContains( - 'name="recipient', - $this->cObj->FORM( - array('recipient' => 'foo@bar.com', 'recipient.' => array()), - array() - ) - ); - } - - - ///////////////////////////////////////// - // Tests concerning getQueryArguments() - ///////////////////////////////////////// - - /** - * @test - */ - public function getQueryArgumentsExcludesParameters() { - $_SERVER['QUERY_STRING'] = - 'key1=value1' . - '&key2=value2' . - '&key3[key31]=value31' . - '&key3[key32][key321]=value321' . - '&key3[key32][key322]=value322'; - - $getQueryArgumentsConfiguration = array(); - $getQueryArgumentsConfiguration['exclude'] = array(); - $getQueryArgumentsConfiguration['exclude'][] = 'key1'; - $getQueryArgumentsConfiguration['exclude'][] = 'key3[key31]'; - $getQueryArgumentsConfiguration['exclude'][] = 'key3[key32][key321]'; - $getQueryArgumentsConfiguration['exclude'] = implode(',', $getQueryArgumentsConfiguration['exclude']); - - $expectedResult = '&key2=value2&key3[key32][key322]=value322'; - $actualResult = $this->cObj->getQueryArguments($getQueryArgumentsConfiguration); - $this->assertEquals($expectedResult, $actualResult); - } - - /** - * @test - */ - public function getQueryArgumentsExcludesGetParameters() { - $_GET = array( - 'key1' => 'value1', - 'key2' => 'value2', - 'key3' => array( - 'key31' => 'value31', - 'key32' => array( - 'key321' => 'value321', - 'key322' => 'value322', - ), - ), - ); - - $getQueryArgumentsConfiguration = array(); - $getQueryArgumentsConfiguration['method'] = 'GET'; - $getQueryArgumentsConfiguration['exclude'] = array(); - $getQueryArgumentsConfiguration['exclude'][] = 'key1'; - $getQueryArgumentsConfiguration['exclude'][] = 'key3[key31]'; - $getQueryArgumentsConfiguration['exclude'][] = 'key3[key32][key321]'; - $getQueryArgumentsConfiguration['exclude'] = implode(',', $getQueryArgumentsConfiguration['exclude']); - - $expectedResult = '&key2=value2&key3[key32][key322]=value322'; - $actualResult = $this->cObj->getQueryArguments($getQueryArgumentsConfiguration); - $this->assertEquals($expectedResult, $actualResult); - } - - /** - * @test - */ - public function getQueryArgumentsOverrulesSingleParameter() { - $_SERVER['QUERY_STRING'] = 'key1=value1'; - - $getQueryArgumentsConfiguration = array(); - - $overruleArguments = array( - // Should be overriden - 'key1' => 'value1Overruled', - // Shouldn't be set: Parameter doesn't exist in source array and is not forced - 'key2' => 'value2Overruled', - ); - - $expectedResult = '&key1=value1Overruled'; - $actualResult = $this->cObj->getQueryArguments($getQueryArgumentsConfiguration, $overruleArguments); - $this->assertEquals($expectedResult, $actualResult); - } - - /** - * @test - */ - public function getQueryArgumentsOverrulesMultiDimensionalParameters() { - $_POST = array( - 'key1' => 'value1', - 'key2' => 'value2', - 'key3' => array( - 'key31' => 'value31', - 'key32' => array( - 'key321' => 'value321', - 'key322' => 'value322', - ), - ), - ); - - $getQueryArgumentsConfiguration = array(); - $getQueryArgumentsConfiguration['method'] = 'POST'; - $getQueryArgumentsConfiguration['exclude'] = array(); - $getQueryArgumentsConfiguration['exclude'][] = 'key1'; - $getQueryArgumentsConfiguration['exclude'][] = 'key3[key31]'; - $getQueryArgumentsConfiguration['exclude'][] = 'key3[key32][key321]'; - $getQueryArgumentsConfiguration['exclude'] = implode(',', $getQueryArgumentsConfiguration['exclude']); - - $overruleArguments = array( - // Should be overriden - 'key2' => 'value2Overruled', - 'key3' => array( - 'key32' => array( - // Shouldn't be set: Parameter is excluded and not forced - 'key321' => 'value321Overruled', - // Should be overriden: Parameter is not excluded - 'key322' => 'value322Overruled', - // Shouldn't be set: Parameter doesn't exist in source array and is not forced - 'key323' => 'value323Overruled', - ), - ), - ); - - $expectedResult = '&key2=value2Overruled&key3[key32][key322]=value322Overruled'; - $actualResult = $this->cObj->getQueryArguments($getQueryArgumentsConfiguration, $overruleArguments); - $this->assertEquals($expectedResult, $actualResult); - } - - /** - * @test - */ - public function getQueryArgumentsOverrulesMultiDimensionalForcedParameters() { - $_SERVER['QUERY_STRING'] = - 'key1=value1' . - '&key2=value2' . - '&key3[key31]=value31' . - '&key3[key32][key321]=value321' . - '&key3[key32][key322]=value322'; - - $_POST = array( - 'key1' => 'value1', - 'key2' => 'value2', - 'key3' => array( - 'key31' => 'value31', - 'key32' => array( - 'key321' => 'value321', - 'key322' => 'value322', - ), - ), - ); - - $getQueryArgumentsConfiguration = array(); - $getQueryArgumentsConfiguration['exclude'] = array(); - $getQueryArgumentsConfiguration['exclude'][] = 'key1'; - $getQueryArgumentsConfiguration['exclude'][] = 'key3[key31]'; - $getQueryArgumentsConfiguration['exclude'][] = 'key3[key32][key321]'; - $getQueryArgumentsConfiguration['exclude'][] = 'key3[key32][key322]'; - $getQueryArgumentsConfiguration['exclude'] = implode(',', $getQueryArgumentsConfiguration['exclude']); - - $overruleArguments = array( - // Should be overriden - 'key2' => 'value2Overruled', - 'key3' => array( - 'key32' => array( - // Should be set: Parameter is excluded but forced - 'key321' => 'value321Overruled', - // Should be set: Parameter doesn't exist in source array but is forced - 'key323' => 'value323Overruled', - ), - ), - ); - - $expectedResult = '&key2=value2Overruled&key3[key32][key321]=value321Overruled&key3[key32][key323]=value323Overruled'; - $actualResult = $this->cObj->getQueryArguments($getQueryArgumentsConfiguration, $overruleArguments, TRUE); - $this->assertEquals($expectedResult, $actualResult); - - $getQueryArgumentsConfiguration['method'] = 'POST'; - $actualResult = $this->cObj->getQueryArguments($getQueryArgumentsConfiguration, $overruleArguments, TRUE); - $this->assertEquals($expectedResult, $actualResult); - } - - - ////////////////////////////// - // Tests concerning cropHTML - ////////////////////////////// - - /** - * This is the data provider for the tests of crop and cropHTML below. It provides all combinations - * of charset, text type, and configuration options to be tested. - * - * @return array two-dimensional array with the second level like this: - * 0 => the settings for the crop function, for example "-58|..." - * 1 => the string to crop - * 2 => the expected cropped result - * 3 => the charset that will be set as renderCharset - * - * @see cropHtmlWithDataProvider - */ - public function cropHtmlDataProvider() { - $plainText = 'Kasper Sk' . chr(229) . 'rh' . chr(248) . - 'j implemented the original version of the crop function.'; - $textWithMarkup = 'Kasper Sk' . - chr(229) . 'rh' . chr(248) . 'j' . - ' implemented the original version of the crop function.'; - $textWithEntities = 'Kasper Skårhøj implemented the; original ' . - 'version of the crop function.'; - - $charsets = array('iso-8859-1', 'utf-8', 'ascii', 'big5'); - - $data = array(); - foreach ($charsets as $charset) { - $data = array_merge($data, array( - $charset . ' plain text; 11|...' => array( - '11|...', $plainText, 'Kasper Sk' . chr(229) . 'r...', $charset - ), - $charset . ' plain text; -58|...' => array( - '-58|...', $plainText, '...h' . chr(248) . 'j implemented the original version of the crop function.', $charset - ), - $charset . ' plain text; 20|...|1' => array( - '20|...|1', $plainText, 'Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j...', $charset - ), - $charset . ' plain text; -49|...|1' => array( - '-49|...|1', $plainText, '...the original version of the crop function.', $charset - ), - $charset . ' text with markup; 11|...' => array( - '11|...', $textWithMarkup, 'Kasper Sk' . chr(229) . 'r...', $charset - ), - $charset . ' text with markup; 13|...' => array( - '13|...', $textWithMarkup, 'Kasper Sk' . chr(229) . 'rh' . chr(248) . '...', $charset - ), - $charset . ' text with markup; 14|...' => array( - '14|...', $textWithMarkup, 'Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j...', $charset - ), - $charset . ' text with markup; 15|...' => array( - '15|...', $textWithMarkup, 'Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j ...', $charset - ), - $charset . ' text with markup; 29|...' => array( - '29|...', $textWithMarkup, 'Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j implemented th...', $charset - ), - $charset . ' text with markup; -58|...' => array( - '-58|...', $textWithMarkup, '...h' . chr(248) . 'j implemented the original version of the crop function.', $charset - ), - $charset . ' text with markup; 11|...|1' => array( - '11|...|1', $textWithMarkup, 'Kasper...', $charset - ), - $charset . ' text with markup; 13|...|1' => array( - '13|...|1', $textWithMarkup, 'Kasper...', $charset - ), - $charset . ' text with markup; 14|...|1' => array( - '14|...|1', $textWithMarkup, 'Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j...', $charset - ), - $charset . ' text with markup; 15|...|1' => array( - '15|...|1', $textWithMarkup, 'Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j...', $charset - ), - $charset . ' text with markup; 29|...|1' => array( - '29|...|1', $textWithMarkup, 'Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j implemented...', $charset - ), - $charset . ' text with markup; -66|...|1' => array( - '-66|...|1', $textWithMarkup, '...Sk' . chr(229) . 'rh' . chr(248) . 'j implemented the original version of the crop function.', $charset - ), - $charset . ' text with entities 9|...' => array( - '9|...', $textWithEntities, 'Kasper Sk...', $charset - ), - $charset . ' text with entities 10|...' => array( - '10|...', $textWithEntities, 'Kasper Skå...', $charset - ), - $charset . ' text with entities 11|...' => array( - '11|...', $textWithEntities, 'Kasper Skår...', $charset - ), - $charset . ' text with entities 13|...' => array( - '13|...', $textWithEntities, 'Kasper Skårhø...', $charset - ), - $charset . ' text with entities 14|...' => array( - '14|...', $textWithEntities, 'Kasper Skårhøj...', $charset - ), - $charset . ' text with entities 15|...' => array( - '15|...', $textWithEntities, 'Kasper Skårhøj ...', $charset - ), - $charset . ' text with entities 16|...' => array( - '16|...', $textWithEntities, 'Kasper Skårhøj i...', $charset - ), - $charset . ' text with entities -57|...' => array( - '-57|...', $textWithEntities, '...j implemented the; original version of the crop function.', $charset - ), - $charset . ' text with entities -58|...' => array( - '-58|...', $textWithEntities, '...øj implemented the; original version of the crop function.', $charset - ), - $charset . ' text with entities -59|...' => array( - '-59|...', $textWithEntities, '...høj implemented the; original version of the crop function.', $charset - ), - $charset . ' text with entities 9|...|1' => array( - '9|...|1', $textWithEntities, 'Kasper...', $charset - ), - $charset . ' text with entities 10|...|1' => array( - '10|...|1', $textWithEntities, 'Kasper...', $charset - ), - $charset . ' text with entities 11|...|1' => array( - '11|...|1', $textWithEntities, 'Kasper...', $charset - ), - $charset . ' text with entities 13|...|1' => array( - '13|...|1', $textWithEntities, 'Kasper...', $charset - ), - $charset . ' text with entities 14|...|1' => array( - '14|...|1', $textWithEntities, 'Kasper Skårhøj...', $charset - ), - $charset . ' text with entities 15|...|1' => array( - '15|...|1', $textWithEntities, 'Kasper Skårhøj...', $charset - ), - $charset . ' text with entities 16|...|1' => array( - '16|...|1', $textWithEntities, 'Kasper Skårhøj...', $charset - ), - $charset . ' text with entities -57|...|1' => array( - '-57|...|1', $textWithEntities, '...implemented the; original version of the crop function.', $charset - ), - $charset . ' text with entities -58|...|1' => array( - '-58|...|1', $textWithEntities, '...implemented the; original version of the crop function.', $charset - ), - $charset . ' text with entities -59|...|1' => array( - '-59|...|1', $textWithEntities, '...implemented the; original version of the crop function.', $charset - ), - )); - } - return $data; - } - - /** - * Checks if stdWrap.cropHTML works with plain text cropping from left - * - * @test - * - * @dataProvider cropHtmlDataProvider - * - * @param string $settings - * the settings for the crop function, for example "-58|..." - * @param string $subject the string to crop - * @param string $expected the expected cropped result - * @param string $charset the charset that will be set as renderCharset - */ - public function cropHtmlWithDataProvider($settings, $subject, $expected, $charset) { - $this->handleCharset($charset, $subject, $expected); - - $this->assertEquals( - $expected, - $this->cObj->cropHTML($subject, $settings), - 'cropHTML failed with settings: "' . $settings . '" and charset "' . $charset . '"' - ); - } - - /** - * Checks if stdWrap.cropHTML works with a complex content with many tags. Currently cropHTML - * counts multiple invisible characters not as one (as the browser will output the content). - * - * @test - */ - public function cropHtmlWorksWithComplexContent() { - $GLOBALS['TSFE']->renderCharset = 'iso-8859-1'; - $subject = ' -

Blog Example

-
-
-

Welcome to Blog #1

-
-

- A blog about TYPO3 extension development. In order to start blogging, read the Help section. If you have any further questions, feel free to contact the administrator John Doe (john.doe@example.com). -

-
-

- Below are the most recent posts: -

-
    -
  • -

    - The Post #1 -

    -

    - Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut... -

    - -

    - Tags: [MVC] [Domain Driven Design] 
    - read more >>
    - Edit Delete -

    -
  • -
-

- Create a new Post -

-
-
-

- ? TYPO3 Association -

-'; - - $result = $this->cObj->cropHTML($subject, '300'); - $expected = ' -

Blog Example

-
-
-

Welcome to Blog #1

-
-

- A blog about TYPO3 extension development. In order to start blogging, read the Help section. If you have any further questions, feel free to contact the administrator John Doe (john.doe@example.com). -

-
-

- Below are the most recent posts: -

-
'; - $this->assertEquals($expected, $result); - - $result = $this->cObj->cropHTML($subject, '-100'); - $expected = '
-

- Create a new Post -

-
-
-

- ? TYPO3 Association -

-'; - $this->assertEquals( - $expected, - $result - ); - } -} -?> \ No newline at end of file Index: tests/typo3/sysext/cms/tslib/tslib_fe_testcase.php =================================================================== --- tests/typo3/sysext/cms/tslib/tslib_fe_testcase.php (Revision 7835) +++ tests/typo3/sysext/cms/tslib/tslib_fe_testcase.php (Arbeitskopie) @@ -1,134 +0,0 @@ - - */ -class tslib_fe_testcase extends tx_phpunit_testcase { - /** - * @var tslib_fe - */ - private $fixture; - - public function setUp() { - // This creates an instance of the class without calling the - // original constructor. - $className = uniqid('tslib_fe'); - eval( - 'class ' . $className . ' extends tslib_fe {' . - 'public function ' . $className . '() {}' . - 'public function roundTripCryptString($string) {' . - 'return parent::roundTripCryptString($string);' . - '}' . - '}' - ); - - $this->fixture = new $className(); - $this->fixture->TYPO3_CONF_VARS = $GLOBALS['TYPO3_CONF_VARS']; - $this->fixture->TYPO3_CONF_VARS['SYS']['encryptionKey'] - = '170928423746123078941623042360abceb12341234231'; - } - - public function tearDown() { - unset($this->fixture); - } - - - //////////////////////////////// - // Tests concerning codeString - //////////////////////////////// - - /** - * @test - */ - public function codeStringForNonEmptyStringReturns10CharacterHashAndCodedString() { - $this->assertRegExp( - '/^[0-9a-f]{10}:[a-zA-Z0-9+=\/]+$/', - $this->fixture->codeString('Hello world!') - ); - } - - /** - * @test - */ - public function decodingCodedStringReturnsOriginalString() { - $clearText = 'Hello world!'; - - $this->assertEquals( - $clearText, - $this->fixture->codeString( - $this->fixture->codeString($clearText), TRUE - ) - ); - } - - - ////////////////////////////////////////// - // Tests concerning roundTripCryptString - ////////////////////////////////////////// - - /** - * @test - */ - public function roundTripCryptStringCreatesStringWithSameLengthAsInputString() { - $clearText = 'Hello world!'; - - $this->assertEquals( - strlen($clearText), - strlen($this->fixture->roundTripCryptString($clearText)) - ); - } - - /** - * @test - */ - public function roundTripCryptStringCreatesResultDifferentFromInputString() { - $clearText = 'Hello world!'; - - $this->assertNotEquals( - $clearText, - $this->fixture->roundTripCryptString($clearText) - ); - } - - /** - * @test - */ - public function roundTripCryptStringAppliedTwoTimesReturnsOriginalString() { - $clearText = 'Hello world!'; - - $this->assertEquals( - $clearText, - $this->fixture->roundTripCryptString( - $this->fixture->roundTripCryptString($clearText) - ) - ); - } -} -?> Index: tests/typo3/sysext/cms/tslib/tslib_contentTest.php =================================================================== --- tests/typo3/sysext/cms/tslib/tslib_contentTest.php (Revision 7835) +++ tests/typo3/sysext/cms/tslib/tslib_contentTest.php (Arbeitskopie) @@ -31,7 +31,7 @@ * @author Oliver Hader * @author Oliver Klee */ -class tslib_content_testcase extends tx_phpunit_testcase { +class tslib_contentTest extends tx_phpunit_testcase { /** * @var array */ Index: tests/typo3/sysext/cms/tslib/tslib_feTest.php =================================================================== --- tests/typo3/sysext/cms/tslib/tslib_feTest.php (Revision 7835) +++ tests/typo3/sysext/cms/tslib/tslib_feTest.php (Arbeitskopie) @@ -30,7 +30,7 @@ * * @author Oliver Klee */ -class tslib_fe_testcase extends tx_phpunit_testcase { +class tslib_feTest extends tx_phpunit_testcase { /** * @var tslib_fe */