|
TYPO3 API
SVNRelease
|
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 2009-2011 Oliver Hader <oliver@typo3.org> 00006 * All rights reserved 00007 * 00008 * This script is part of the TYPO3 project. The TYPO3 project is 00009 * free software; you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation; either version 2 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * The GNU General Public License can be found at 00015 * http://www.gnu.org/copyleft/gpl.html. 00016 * 00017 * This script is distributed in the hope that it will be useful, 00018 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 * GNU General Public License for more details. 00021 * 00022 * This copyright notice MUST APPEAR in all copies of the script! 00023 ***************************************************************/ 00024 00025 00026 /** 00027 * Testcase for class t3lib_matchCondition_frontend. 00028 * 00029 * @author Oliver Hader <oliver@typo3.org> 00030 * @package TYPO3 00031 * @subpackage t3lib 00032 */ 00033 class t3lib_matchCondition_backendTest extends tx_phpunit_testcase { 00034 /** 00035 * @var array 00036 */ 00037 private $backupGlobalVariables; 00038 00039 /** 00040 * @var array 00041 */ 00042 private $rootline; 00043 00044 /** 00045 * @var t3lib_matchCondition_backend 00046 */ 00047 private $matchCondition; 00048 00049 /** 00050 * @var string 00051 */ 00052 private $testTableName; 00053 00054 public function setUp() { 00055 $this->backupGlobalVariables = array( 00056 '_ENV' => $_ENV, 00057 '_GET' => $_GET, 00058 '_POST' => $_POST, 00059 '_SERVER' => $_SERVER, 00060 'TCA' => $GLOBALS['TCA'], 00061 'TYPO3_DB' => $GLOBALS['TYPO3_DB'], 00062 'TYPO3_CONF_VARS' => $GLOBALS['TYPO3_CONF_VARS'], 00063 'T3_VAR' => $GLOBALS['T3_VAR'], 00064 'BE_USER' => $GLOBALS['BE_USER'], 00065 'SOBE' => $GLOBALS['SOBE'], 00066 ); 00067 00068 $this->testTableName = 't3lib_matchCondition_backend_testTable'; 00069 $this->testGlobalNamespace = uniqid('TEST'); 00070 00071 $GLOBALS['TCA'][$this->testTableName] = array('ctrl' => array()); 00072 $GLOBALS[$this->testGlobalNamespace] = array(); 00073 00074 $this->setUpBackend(); 00075 00076 $this->matchCondition = t3lib_div::makeInstance('t3lib_matchCondition_backend'); 00077 } 00078 00079 public function tearDown() { 00080 foreach ($this->backupGlobalVariables as $key => $data) { 00081 $GLOBALS[$key] = $data; 00082 } 00083 00084 unset($this->matchCondition); 00085 unset($this->backupGlobalVariables); 00086 unset($GLOBALS[$this->testGlobalNamespace]); 00087 } 00088 00089 private function setUpBackend() { 00090 $this->rootline = array( 00091 2 => array('uid' => 121, 'pid' => 111), 00092 1 => array('uid' => 111, 'pid' => 101,), 00093 0 => array('uid' => 101, 'pid' => 0,), 00094 ); 00095 00096 $GLOBALS['BE_USER'] = $this->getMock('beUserAuth', array(), array(), '', FALSE); 00097 } 00098 00099 private function setUpDatabaseMockForDeterminePageId() { 00100 $GLOBALS['TYPO3_DB'] = $this->getMock('t3lib_DB', array('exec_SELECTquery', 'sql_fetch_assoc', 'sql_free_result')); 00101 $GLOBALS['TYPO3_DB']->expects($this->any())->method('exec_SELECTquery')->will( 00102 $this->returnCallback(array($this, 'determinePageIdByRecordDatabaseExecuteCallback')) 00103 ); 00104 $GLOBALS['TYPO3_DB']->expects($this->any())->method('sql_fetch_assoc')->will( 00105 $this->returnCallback(array($this, 'determinePageIdByRecordDatabaseFetchCallback')) 00106 ); 00107 } 00108 00109 /** 00110 * Tests whether a faulty expression fails. 00111 * @test 00112 */ 00113 public function simulateDisabledMatchAllConditionsFailsOnFaultyExpression() { 00114 $this->matchCondition->matchAll = FALSE; 00115 $this->assertFalse($this->matchCondition->match('[nullCondition = This expression would return false in general]')); 00116 } 00117 00118 /** 00119 * Tests whether simulating positive matches for all conditions succeeds. 00120 * @test 00121 */ 00122 public function simulateEnabledMatchAllConditionsSucceeds() { 00123 $this->matchCondition->setSimulateMatchResult(true); 00124 $this->assertTrue($this->matchCondition->match('[nullCondition = This expression would return false in general]')); 00125 } 00126 00127 /** 00128 * Tests whether simulating positive matches for specific conditions succeeds. 00129 * @test 00130 */ 00131 public function simulateEnabledMatchSpecificConditionsSucceeds() { 00132 $testCondition = '[' . uniqid('test') . ' = Any condition to simulate a positive match]'; 00133 $this->matchCondition->setSimulateMatchConditions(array($testCondition)); 00134 $this->assertTrue($this->matchCondition->match($testCondition)); 00135 } 00136 00137 /** 00138 * Tests whether a condition matches Internet Explorer 7 on Windows. 00139 * 00140 * @return void 00141 * @test 00142 */ 00143 public function conditionMatchesInternetExplorer7Windows() { 00144 $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)'; 00145 $result = $this->matchCondition->match('[browser = msie] && [version = 7] && [system = winNT]'); 00146 $this->assertTrue($result); 00147 } 00148 00149 /** 00150 * Tests whether a condition does not match Internet Explorer 7 on Windows. 00151 * 00152 * @return void 00153 * @test 00154 */ 00155 public function conditionDoesNotMatchInternetExplorer7Windows() { 00156 $_SERVER['HTTP_USER_AGENT'] = 'Opera/9.25 (Windows NT 6.0; U; en)'; 00157 $result = $this->matchCondition->match('[browser = msie] && [version = 7] && [system = winNT]'); 00158 $this->assertFalse($result); 00159 } 00160 00161 00162 /** 00163 * Tests whether a condition does match the iOS with the correct and more recent 'iOS' 00164 * @test 00165 */ 00166 public function conditionDoesMatchIosWithCorrectSystemKey() { 00167 $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7W367a Safari/531.21.10'; 00168 $result = $this->matchCondition->match('[system = iOS]'); 00169 $this->assertTrue($result); 00170 } 00171 00172 /** 00173 * Tests whether a condition does match the iOS with the old 'mac' 00174 * @test 00175 */ 00176 public function conditionDoesMatchIosWithOldSystemKey() { 00177 $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7W367a Safari/531.21.10'; 00178 $result = $this->matchCondition->match('[system = mac]'); 00179 $this->assertTrue($result); 00180 } 00181 00182 /** 00183 * Tests whether a condition does match Windows 2000 with the correct and more recent 'win2k' 00184 * @test 00185 */ 00186 public function conditionDoesMatchWindows2kWithNewSystemKey() { 00187 $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; SV1)'; 00188 $result = $this->matchCondition->match('[system = win2k]'); 00189 $this->assertTrue($result); 00190 } 00191 00192 /** 00193 * Tests whether a condition does match Windows 2000 with the old 'winNT' 00194 * @test 00195 */ 00196 public function conditionDoesMatchWindows2kWithOldSystemKey() { 00197 $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; SV1)'; 00198 $result = $this->matchCondition->match('[system = winNT]'); 00199 $this->assertTrue($result); 00200 } 00201 00202 /** 00203 * Tests whether a condition does match Windows NT with 'winNT' 00204 * @test 00205 */ 00206 public function conditionDoesMatchWindowsNtWithSystemKey() { 00207 $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 4.0)'; 00208 $result = $this->matchCondition->match('[system = winNT]'); 00209 $this->assertTrue($result); 00210 } 00211 00212 00213 /** 00214 * Tests whether a condition does match Android with the correct and more recent 'android' 00215 * @test 00216 */ 00217 public function conditionDoesMatchAndroidWithNewSystemKey() { 00218 $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Linux; U; Android 2.3; en-US; sdk Build/GRH55) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1'; 00219 $result = $this->matchCondition->match('[system = android]'); 00220 $this->assertTrue($result); 00221 } 00222 00223 /** 00224 * Tests whether a condition does match Android with the old 'linux' 00225 * @test 00226 */ 00227 public function conditionDoesMatchAndroidWithOldSystemKey() { 00228 $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Linux; U; Android 2.3; en-US; sdk Build/GRH55) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1'; 00229 $result = $this->matchCondition->match('[system = linux]'); 00230 $this->assertTrue($result); 00231 } 00232 00233 /** 00234 * Tests whether a device type condition matches a crawler. 00235 * @test 00236 */ 00237 public function deviceConditionMatchesRobot() { 00238 $_SERVER['HTTP_USER_AGENT'] = 'Googlebot/2.1 (+http://www.google.com/bot.html)'; 00239 $result = $this->matchCondition->match('[device = robot]'); 00240 $this->assertTrue($result); 00241 } 00242 00243 /** 00244 * Tests whether a device type condition does not match a crawler. 00245 * @test 00246 */ 00247 public function deviceConditionDoesNotMatchRobot() { 00248 $_SERVER['HTTP_USER_AGENT'] = md5('Some strange user agent'); 00249 $result = $this->matchCondition->match('[device = robot]'); 00250 $this->assertFalse($result); 00251 } 00252 00253 /** 00254 * Tests whether the language comparison matches. 00255 * @test 00256 */ 00257 public function languageConditionMatchesSingleLanguageExpression() { 00258 $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'de-de,de;q=0.8,en-us;q=0.5,en;q=0.3'; 00259 $this->assertTrue($this->matchCondition->match('[language = *de*]')); 00260 $this->assertTrue($this->matchCondition->match('[language = *de-de*]')); 00261 } 00262 00263 /** 00264 * Tests whether the language comparison matches. 00265 * @test 00266 */ 00267 public function languageConditionMatchesMultipleLanguagesExpression() { 00268 $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'de-de,de;q=0.8,en-us;q=0.5,en;q=0.3'; 00269 $this->assertTrue($this->matchCondition->match('[language = *en*,*de*]')); 00270 $this->assertTrue($this->matchCondition->match('[language = *en-us*,*de-de*]')); 00271 } 00272 00273 /** 00274 * Tests whether the language comparison matches. 00275 * @test 00276 */ 00277 public function languageConditionMatchesCompleteLanguagesExpression() { 00278 $this->markTestSkipped('This comparison seems to be incomplete in t3lib_matchCondition.'); 00279 00280 $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'de-de,de;q=0.8,en-us;q=0.5,en;q=0.3'; 00281 $this->assertTrue($this->matchCondition->match('[language = de-de,de;q=0.8]')); 00282 } 00283 00284 /** 00285 * Tests whether usergroup comparison matches. 00286 * @test 00287 */ 00288 public function usergroupConditionMatchesSingleGroupId() { 00289 $GLOBALS['BE_USER']->groupList = '13,14,15'; 00290 $this->assertTrue($this->matchCondition->match('[usergroup = 13]')); 00291 } 00292 00293 /** 00294 * Tests whether usergroup comparison matches. 00295 * @test 00296 */ 00297 public function usergroupConditionMatchesMultipleUserGroupId() { 00298 $GLOBALS['BE_USER']->groupList = '13,14,15'; 00299 $this->assertTrue($this->matchCondition->match('[usergroup = 999,15,14,13]')); 00300 } 00301 00302 /** 00303 * Tests whether user comparison matches. 00304 * @test 00305 */ 00306 public function loginUserConditionMatchesAnyLoggedInUser() { 00307 $GLOBALS['BE_USER']->user['uid'] = 13; 00308 $this->assertTrue($this->matchCondition->match('[loginUser = *]')); 00309 } 00310 00311 /** 00312 * Tests whether user comparison matches. 00313 * @test 00314 */ 00315 public function loginUserConditionMatchesSingleLoggedInUser() { 00316 $GLOBALS['BE_USER']->user['uid'] = 13; 00317 $this->assertTrue($this->matchCondition->match('[loginUser = 13]')); 00318 } 00319 00320 /** 00321 * Tests whether user comparison matches. 00322 * @test 00323 */ 00324 public function loginUserConditionDoesNotMatchSingleLoggedInUser() { 00325 $GLOBALS['BE_USER']->user['uid'] = 13; 00326 $this->assertFalse($this->matchCondition->match('[loginUser = 999]')); 00327 } 00328 00329 /** 00330 * Tests whether user comparison matches. 00331 * @test 00332 */ 00333 public function loginUserConditionMatchesMultipleLoggedInUsers() { 00334 $GLOBALS['BE_USER']->user['uid'] = 13; 00335 $this->assertTrue($this->matchCondition->match('[loginUser = 999,13]')); 00336 } 00337 00338 /** 00339 * Tests whether checkinf for an admin user matches 00340 * @test 00341 */ 00342 public function adminUserConditionMatchesAdminUser() { 00343 $GLOBALS['BE_USER']->user['uid'] = 13; 00344 $GLOBALS['BE_USER']->user['admin'] = 1; 00345 $this->assertTrue($this->matchCondition->match('[adminUser = 1]')); 00346 } 00347 00348 /** 00349 * Tests whether checkinf for an admin user matches 00350 * @test 00351 */ 00352 public function adminUserConditionMatchesRegularUser() { 00353 $GLOBALS['BE_USER']->user['uid'] = 14; 00354 $GLOBALS['BE_USER']->user['admin'] = 0; 00355 $this->assertTrue($this->matchCondition->match('[adminUser = 0]')); 00356 } 00357 00358 /** 00359 * Tests whether checkinf for an admin user matches 00360 * @test 00361 */ 00362 public function adminUserConditionDoesNotMatchRegularUser() { 00363 $GLOBALS['BE_USER']->user['uid'] = 14; 00364 $GLOBALS['BE_USER']->user['admin'] = 0; 00365 $this->assertFalse($this->matchCondition->match('[adminUser = 1]')); 00366 } 00367 00368 /** 00369 * Tests whether numerical comparison matches. 00370 * @test 00371 */ 00372 public function globalVarConditionMatchesOnEqualExpression() { 00373 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 = 10]')); 00374 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 = 10.1]')); 00375 00376 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 == 10]')); 00377 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 == 10.1]')); 00378 } 00379 00380 /** 00381 * Tests whether numerical comparison matches. 00382 * @test 00383 */ 00384 public function globalVarConditionMatchesOnNotEqualExpression() { 00385 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 != 20]')); 00386 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 != 10.2]')); 00387 } 00388 00389 /** 00390 * Tests whether numerical comparison matches. 00391 * @test 00392 */ 00393 public function globalVarConditionMatchesOnLowerThanExpression() { 00394 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 < 20]')); 00395 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 < 10.2]')); 00396 } 00397 00398 /** 00399 * Tests whether numerical comparison matches. 00400 * @test 00401 */ 00402 public function globalVarConditionMatchesOnLowerThanOrEqualExpression() { 00403 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 <= 10]')); 00404 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 <= 20]')); 00405 00406 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 <= 10.1]')); 00407 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 <= 10.2]')); 00408 } 00409 00410 /** 00411 * Tests whether numerical comparison matches. 00412 * @test 00413 */ 00414 public function globalVarConditionMatchesOnGreaterThanExpression() { 00415 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:20 > 10]')); 00416 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.2 > 10.1]')); 00417 } 00418 00419 /** 00420 * Tests whether numerical comparison matches. 00421 * @test 00422 */ 00423 public function globalVarConditionMatchesOnGreaterThanOrEqualExpression() { 00424 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 >= 10]')); 00425 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:20 >= 10]')); 00426 00427 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 >= 10.1]')); 00428 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.2 >= 10.1]')); 00429 } 00430 00431 /** 00432 * Tests whether numerical comparison matches. 00433 * @test 00434 */ 00435 public function globalVarConditionMatchesOnEmptyExpressionWithNoValueSet() { 00436 $testKey = uniqid('test'); 00437 $this->assertTrue($this->matchCondition->match('[globalVar = GP:' . $testKey . '=]')); 00438 $this->assertTrue($this->matchCondition->match('[globalVar = GP:' . $testKey . ' = ]')); 00439 } 00440 00441 /** 00442 * Tests whether numerical comparison matches. 00443 * @test 00444 */ 00445 public function globalVarConditionDoesNotMatchOnEmptyExpressionWithValueSetToZero() { 00446 $testKey = uniqid('test'); 00447 00448 $_GET = array(); 00449 $_POST = array($testKey => 0); 00450 00451 $this->assertFalse($this->matchCondition->match('[globalVar = GP:' . $testKey . '=]')); 00452 $this->assertFalse($this->matchCondition->match('[globalVar = GP:' . $testKey . ' = ]')); 00453 } 00454 00455 /** 00456 * Tests whether string comparison matches. 00457 * @test 00458 */ 00459 public function globalStringConditionMatchesOnEqualExpression() { 00460 $this->assertTrue($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = TYPO3.Test.Condition]')); 00461 $this->assertFalse($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = TYPO3]')); 00462 } 00463 00464 /** 00465 * Tests whether string comparison matches. 00466 * @test 00467 */ 00468 public function globalStringConditionMatchesWildcardExpression() { 00469 $this->assertTrue($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = TYPO3?Test?Condition]')); 00470 $this->assertTrue($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = TYPO3.T*t.Condition]')); 00471 $this->assertTrue($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = TYPO3?T*t?Condition]')); 00472 } 00473 00474 /** 00475 * Tests whether string comparison matches. 00476 * @test 00477 */ 00478 public function globalStringConditionMatchesRegularExpression() { 00479 $this->assertTrue($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = /^[A-Za-z3.]+$/]')); 00480 $this->assertTrue($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = /^TYPO3\..+Condition$/]')); 00481 $this->assertFalse($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = /^FALSE/]')); 00482 } 00483 00484 /** 00485 * Tests whether string comparison matches. 00486 * @test 00487 */ 00488 public function globalStringConditionMatchesEmptyRegularExpression() { 00489 $testKey = uniqid('test'); 00490 $_SERVER[$testKey] = ''; 00491 $this->assertTrue($this->matchCondition->match('[globalString = _SERVER|' . $testKey . ' = /^$/]')); 00492 } 00493 00494 /** 00495 * Tests whether treeLevel comparison matches. 00496 * @test 00497 */ 00498 public function treeLevelConditionMatchesSingleValue() { 00499 $this->matchCondition->setRootline($this->rootline); 00500 $this->assertTrue($this->matchCondition->match('[treeLevel = 2]')); 00501 } 00502 00503 /** 00504 * Tests whether treeLevel comparison matches. 00505 * @test 00506 */ 00507 public function treeLevelConditionMatchesMultipleValues() { 00508 $this->matchCondition->setRootline($this->rootline); 00509 $this->assertTrue($this->matchCondition->match('[treeLevel = 999,998,2]')); 00510 } 00511 00512 /** 00513 * Tests whether treeLevel comparison matches. 00514 * @test 00515 */ 00516 public function treeLevelConditionDoesNotMatchFaultyValue() { 00517 $this->matchCondition->setRootline($this->rootline); 00518 $this->assertFalse($this->matchCondition->match('[treeLevel = 999]')); 00519 } 00520 00521 /** 00522 * Tests whether treeLevel comparison matches when creating new pages. 00523 * @test 00524 */ 00525 public function treeLevelConditionMatchesCurrentPageIdWhileEditingNewPage() { 00526 $GLOBALS['SOBE'] = $this->getMock('SC_alt_doc', array()); 00527 $GLOBALS['SOBE']->elementsData = array( 00528 array( 00529 'table' => 'pages', 00530 'uid' => 'NEW4adc6021e37e7', 00531 'pid' => 121, 00532 'cmd' => 'new', 00533 'deleteAccess' => 0, 00534 ), 00535 ); 00536 $GLOBALS['SOBE']->data = array(); 00537 00538 $this->matchCondition->setRootline($this->rootline); 00539 $this->matchCondition->setPageId(121); 00540 $this->assertTrue($this->matchCondition->match('[treeLevel = 3]')); 00541 } 00542 00543 /** 00544 * Tests whether treeLevel comparison matches when creating new pages. 00545 * @test 00546 */ 00547 public function treeLevelConditionMatchesCurrentPageIdWhileSavingNewPage() { 00548 $GLOBALS['SOBE'] = $this->getMock('SC_alt_doc', array()); 00549 $GLOBALS['SOBE']->elementsData = array( 00550 array( 00551 'table' => 'pages', 00552 /// 999 is the uid of the page that was just created 00553 'uid' => 999, 00554 'pid' => 121, 00555 'cmd' => 'edit', 00556 'deleteAccess' => 1, 00557 ), 00558 ); 00559 $GLOBALS['SOBE']->data = array( 00560 'pages' => array( 00561 'NEW4adc6021e37e7' => array( 00562 'pid' => 121, 00563 ), 00564 ), 00565 ); 00566 00567 $this->matchCondition->setRootline($this->rootline); 00568 $this->matchCondition->setPageId(121); 00569 $this->assertTrue($this->matchCondition->match('[treeLevel = 3]')); 00570 } 00571 00572 /** 00573 * Tests whether a page Id is found in the previous rootline entries. 00574 * @test 00575 */ 00576 public function PIDupinRootlineConditionMatchesSinglePageIdInRootline() { 00577 $this->matchCondition->setRootline($this->rootline); 00578 $this->matchCondition->setPageId(121); 00579 $this->assertTrue($this->matchCondition->match('[PIDupinRootline = 111]')); 00580 } 00581 00582 /** 00583 * Tests whether a page Id is found in the previous rootline entries. 00584 * @test 00585 */ 00586 public function PIDupinRootlineConditionMatchesMultiplePageIdsInRootline() { 00587 $this->matchCondition->setRootline($this->rootline); 00588 $this->matchCondition->setPageId(121); 00589 $this->assertTrue($this->matchCondition->match('[PIDupinRootline = 999,111,101]')); 00590 } 00591 00592 /** 00593 * Tests whether a page Id is found in the previous rootline entries. 00594 * @test 00595 */ 00596 public function PIDupinRootlineConditionDoesNotMatchPageIdNotInRootline() { 00597 $this->matchCondition->setRootline($this->rootline); 00598 $this->matchCondition->setPageId(121); 00599 $this->assertFalse($this->matchCondition->match('[PIDupinRootline = 999]')); 00600 } 00601 00602 /** 00603 * Tests whether a page Id is found in the previous rootline entries. 00604 * @test 00605 */ 00606 public function PIDupinRootlineConditionDoesNotMatchLastPageIdInRootline() { 00607 $this->matchCondition->setRootline($this->rootline); 00608 $this->matchCondition->setPageId(121); 00609 $this->assertFalse($this->matchCondition->match('[PIDupinRootline = 121]')); 00610 } 00611 00612 /** 00613 * Tests whether a page Id is found in the previous rootline entries. 00614 * @test 00615 */ 00616 public function PIDupinRootlineConditionMatchesCurrentPageIdWhileEditingNewPage() { 00617 $GLOBALS['SOBE'] = $this->getMock('SC_alt_doc', array()); 00618 $GLOBALS['SOBE']->elementsData = array( 00619 array( 00620 'table' => 'pages', 00621 'uid' => 'NEW4adc6021e37e7', 00622 'pid' => 121, 00623 'cmd' => 'new', 00624 'deleteAccess' => 0, 00625 ), 00626 ); 00627 $GLOBALS['SOBE']->data = array(); 00628 00629 $this->matchCondition->setRootline($this->rootline); 00630 $this->matchCondition->setPageId(121); 00631 $this->assertTrue($this->matchCondition->match('[PIDupinRootline = 121]')); 00632 } 00633 00634 /** 00635 * Tests whether a page Id is found in the previous rootline entries. 00636 * @test 00637 */ 00638 public function PIDupinRootlineConditionMatchesCurrentPageIdWhileSavingNewPage() { 00639 $GLOBALS['SOBE'] = $this->getMock('SC_alt_doc', array()); 00640 $GLOBALS['SOBE']->elementsData = array( 00641 array( 00642 'table' => 'pages', 00643 /// 999 is the uid of the page that was just created 00644 'uid' => 999, 00645 'pid' => 121, 00646 'cmd' => 'edit', 00647 'deleteAccess' => 1, 00648 ), 00649 ); 00650 $GLOBALS['SOBE']->data = array( 00651 'pages' => array( 00652 'NEW4adc6021e37e7' => array( 00653 'pid' => 121, 00654 ), 00655 ), 00656 ); 00657 00658 $this->matchCondition->setRootline($this->rootline); 00659 $this->matchCondition->setPageId(121); 00660 $this->assertTrue($this->matchCondition->match('[PIDupinRootline = 121]')); 00661 } 00662 00663 /** 00664 * Tests whether a page Id is found in all rootline entries. 00665 * @test 00666 */ 00667 public function PIDinRootlineConditionMatchesSinglePageIdInRootline() { 00668 $this->matchCondition->setRootline($this->rootline); 00669 $this->matchCondition->setPageId(121); 00670 $this->assertTrue($this->matchCondition->match('[PIDinRootline = 111]')); 00671 } 00672 00673 /** 00674 * Tests whether a page Id is found in all rootline entries. 00675 * @test 00676 */ 00677 public function PIDinRootlineConditionMatchesMultiplePageIdsInRootline() { 00678 $this->matchCondition->setRootline($this->rootline); 00679 $this->matchCondition->setPageId(121); 00680 $this->assertTrue($this->matchCondition->match('[PIDinRootline = 999,111,101]')); 00681 } 00682 00683 /** 00684 * Tests whether a page Id is found in all rootline entries. 00685 * @test 00686 */ 00687 public function PIDinRootlineConditionMatchesLastPageIdInRootline() { 00688 $this->matchCondition->setRootline($this->rootline); 00689 $this->matchCondition->setPageId(121); 00690 $this->assertTrue($this->matchCondition->match('[PIDinRootline = 121]')); 00691 } 00692 00693 /** 00694 * Tests whether a page Id is found in all rootline entries. 00695 * @test 00696 */ 00697 public function PIDinRootlineConditionDoesNotMatchPageIdNotInRootline() { 00698 $this->matchCondition->setRootline($this->rootline); 00699 $this->matchCondition->setPageId(121); 00700 $this->assertFalse($this->matchCondition->match('[PIDinRootline = 999]')); 00701 } 00702 00703 /** 00704 * Tests whether the compatibility version can be evaluated. 00705 * (e.g. 4.9 is compatible to 4.0 but not to 5.0) 00706 * @test 00707 */ 00708 public function compatVersionConditionMatchesOlderRelease() { 00709 $GLOBALS['TYPO3_CONF_VARS']['SYS']['compat_version'] = '4.9'; 00710 $this->assertTrue($this->matchCondition->match('[compatVersion = 4.0]')); 00711 } 00712 00713 /** 00714 * Tests whether the compatibility version can be evaluated. 00715 * (e.g. 4.9 is compatible to 4.0 but not to 5.0) 00716 * @test 00717 */ 00718 public function compatVersionConditionMatchesSameRelease() { 00719 $GLOBALS['TYPO3_CONF_VARS']['SYS']['compat_version'] = '4.9'; 00720 $this->assertTrue($this->matchCondition->match('[compatVersion = 4.9]')); 00721 } 00722 00723 /** 00724 * Tests whether the compatibility version can be evaluated. 00725 * (e.g. 4.9 is compatible to 4.0 but not to 5.0) 00726 * @test 00727 */ 00728 public function compatVersionConditionDoesNotMatchNewerRelease() { 00729 $GLOBALS['TYPO3_CONF_VARS']['SYS']['compat_version'] = '4.9'; 00730 $this->assertFalse($this->matchCondition->match('[compatVersion = 5.0]')); 00731 } 00732 00733 /** 00734 * Tests whether the generic fetching of variables works with the namespace 'GP'. 00735 * @test 00736 */ 00737 public function genericGetVariablesSucceedsWithNamespaceGP() { 00738 $_GET = array('testGet' => 'getTest'); 00739 $_POST = array('testPost' => 'postTest'); 00740 00741 $this->assertTrue($this->matchCondition->match('[globalString = GP:testGet = getTest]')); 00742 $this->assertTrue($this->matchCondition->match('[globalString = GP:testPost = postTest]')); 00743 } 00744 00745 /** 00746 * Tests whether the generic fetching of variables does not work with the namespace 'TSFE', 00747 * since we are in the backend context here. 00748 * @test 00749 */ 00750 public function genericGetVariablesFailsWithNamespaceTSFE() { 00751 $GLOBALS['TSFE'] = new stdClass(); 00752 $GLOBALS['TSFE']->id = 1234567; 00753 00754 $this->assertFalse($this->matchCondition->match('[globalString = TSFE:id = 1234567]')); 00755 } 00756 00757 /** 00758 * Tests whether the generic fetching of variables works with the namespace 'ENV'. 00759 * @test 00760 */ 00761 public function genericGetVariablesSucceedsWithNamespaceENV() { 00762 $testKey = uniqid('test'); 00763 putenv($testKey .'=testValue'); 00764 00765 $this->assertTrue($this->matchCondition->match('[globalString = ENV:' . $testKey . ' = testValue]')); 00766 } 00767 00768 /** 00769 * Tests whether the generic fetching of variables works with the namespace 'IENV'. 00770 * @test 00771 */ 00772 public function genericGetVariablesSucceedsWithNamespaceIENV() { 00773 $_SERVER['HTTP_HOST'] = t3lib_div::getIndpEnv('TYPO3_HOST_ONLY') . ':1234567'; 00774 $this->assertTrue($this->matchCondition->match('[globalString = IENV:TYPO3_PORT = 1234567]')); 00775 } 00776 00777 /** 00778 * Tests whether the generic fetching of variables works with any global namespace. 00779 * @test 00780 */ 00781 public function genericGetVariablesSucceedsWithAnyGlobalNamespace() { 00782 $GLOBALS[$this->testGlobalNamespace] = array( 00783 'first' => 'testFirst', 00784 'second' => array('third' => 'testThird'), 00785 ); 00786 00787 $this->assertTrue($this->matchCondition->match( 00788 '[globalString = ' . $this->testGlobalNamespace . '|first = testFirst]' 00789 )); 00790 $this->assertTrue($this->matchCondition->match( 00791 '[globalString = ' . $this->testGlobalNamespace . '|second|third = testThird]' 00792 )); 00793 } 00794 00795 /** 00796 * Tests whether determining a pageId works. 00797 * @test 00798 */ 00799 public function pageIdCanBeDeterminedWhileCallingModuleWithPageTree() { 00800 $_GET['id'] = 999; 00801 00802 $this->matchCondition->match('[globalVar = LIT:10 = 10]'); 00803 $this->assertEquals(999, $this->matchCondition->getPageId()); 00804 } 00805 00806 /** 00807 * Tests whether determining a pageId works. 00808 * @test 00809 */ 00810 public function pageIdCanBeDeterminedWhileEditingAPageRecord() { 00811 $_GET['edit']['pages'][999] = 'edit'; 00812 00813 $this->matchCondition->match('[globalVar = LIT:10 = 10]'); 00814 $this->assertEquals(999, $this->matchCondition->getPageId()); 00815 } 00816 00817 /** 00818 * Tests whether determining a pageId works. 00819 * @test 00820 */ 00821 public function pageIdCanBeDeterminedWhileEditingARegularRecord() { 00822 $this->setUpDatabaseMockForDeterminePageId(); 00823 00824 $_GET['edit'][$this->testTableName][13] = 'edit'; 00825 00826 $this->matchCondition->match('[globalVar = LIT:10 = 10]'); 00827 $this->assertEquals(999, $this->matchCondition->getPageId()); 00828 } 00829 00830 /** 00831 * Tests whether determining a pageId works. 00832 * @test 00833 */ 00834 public function pageIdCanBeDeterminedWhileCreatingARecord() { 00835 $_GET['edit']['pages'][999] = 'new'; 00836 00837 $this->matchCondition->match('[globalVar = LIT:10 = 10]'); 00838 $this->assertEquals(999, $this->matchCondition->getPageId()); 00839 } 00840 00841 /** 00842 * Tests whether determining a pageId works. 00843 * @test 00844 */ 00845 public function pageIdCanBeDeterminedWhileCreatingARecordAfterAnExistingRecord() { 00846 $this->setUpDatabaseMockForDeterminePageId(); 00847 00848 $_GET['edit'][$this->testTableName][-13] = 'new'; 00849 00850 $this->matchCondition->match('[globalVar = LIT:10 = 10]'); 00851 $this->assertEquals(999, $this->matchCondition->getPageId()); 00852 } 00853 00854 /** 00855 * Tests whether determining a pageId works. 00856 * @test 00857 */ 00858 public function pageIdCanBeDeterminedWhileDeletingAPageRecord() { 00859 $_GET['cmd']['pages'][999]['delete'] = 1; 00860 00861 $this->matchCondition->match('[globalVar = LIT:10 = 10]'); 00862 $this->assertEquals(999, $this->matchCondition->getPageId()); 00863 } 00864 00865 /** 00866 * Tests whether determining a pageId works. 00867 * @test 00868 */ 00869 public function pageIdCanBeDeterminedWhileCopyingARecordToAnotherPage() { 00870 $_GET['cmd']['pages'][121]['copy'] = 999; 00871 00872 $this->matchCondition->match('[globalVar = LIT:10 = 10]'); 00873 $this->assertEquals(999, $this->matchCondition->getPageId()); 00874 } 00875 00876 /** 00877 * Tests whether determining a pageId works. 00878 * @test 00879 */ 00880 public function pageIdCanBeDeterminedWhileCopyingARecordAfterAnExistingRecord() { 00881 $this->setUpDatabaseMockForDeterminePageId(); 00882 00883 $_GET['cmd'][$this->testTableName][121]['copy'] = -13; 00884 00885 $this->matchCondition->match('[globalVar = LIT:10 = 10]'); 00886 $this->assertEquals(999, $this->matchCondition->getPageId()); 00887 } 00888 00889 /** 00890 * Tests whether determining a pageId works. 00891 * @test 00892 */ 00893 public function pageIdCanBeDeterminedWhileMovingARecordToAnotherPage() { 00894 $_GET['cmd']['pages'][121]['move'] = 999; 00895 00896 $this->matchCondition->match('[globalVar = LIT:10 = 10]'); 00897 $this->assertEquals(999, $this->matchCondition->getPageId()); 00898 } 00899 00900 /** 00901 * Callback method for pageIdCanBeDetermined test cases. 00902 * Simulates TYPO3_DB->exec_SELECTquery(). 00903 * 00904 * @param string $fields 00905 * @param string $table 00906 * @param string $where 00907 * @return mixed 00908 */ 00909 public function determinePageIdByRecordDatabaseExecuteCallback($fields, $table, $where) { 00910 if ($table === $this->testTableName) { 00911 return array( 00912 'scope' => $this->testTableName, 00913 'data' => array( 00914 'pid' => 999, 00915 ), 00916 ); 00917 } else { 00918 return FALSE; 00919 } 00920 } 00921 00922 /** 00923 * Callback method for pageIdCanBeDetermined test cases. 00924 * Simulates TYPO3_DB->sql_fetch_assoc(). 00925 * 00926 * @param mixed $resource 00927 * @return mixed 00928 */ 00929 public function determinePageIdByRecordDatabaseFetchCallback($resource) { 00930 if (is_array($resource) && ($resource['scope'] === $this->testTableName)) { 00931 return $resource['data']; 00932 } else { 00933 return FALSE; 00934 } 00935 } 00936 } 00937 ?>
1.8.0