TYPO3 API  SVNRelease
t3lib_matchcondition_frontendTest.php
Go to the documentation of this file.
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_frontendTest 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
00046      */
00047     private $matchCondition;
00048 
00049     public function setUp() {
00050         $this->backupGlobalVariables = array(
00051             '_ENV' => $_ENV,
00052             '_GET' => $_GET,
00053             '_POST' => $_POST,
00054             '_SERVER' => $_SERVER,
00055             'TYPO3_CONF_VARS' => $GLOBALS['TYPO3_CONF_VARS'],
00056             'T3_VAR' => $GLOBALS['T3_VAR'],
00057         );
00058 
00059         $this->testGlobalNamespace = uniqid('TEST');
00060         $GLOBALS[$this->testGlobalNamespace] = array();
00061 
00062         $this->setUpTSFE();
00063         $this->matchCondition = t3lib_div::makeInstance('t3lib_matchCondition_frontend');
00064     }
00065 
00066     public function tearDown() {
00067         foreach ($this->backupGlobalVariables as $key => $data) {
00068             $GLOBALS[$key] = $data;
00069         }
00070 
00071         unset($this->matchCondition);
00072         unset($this->backupGlobalVariables);
00073         unset($GLOBALS[$this->testGlobalNamespace]);
00074     }
00075 
00076     private function setUpTSFE() {
00077         $this->rootline = array(
00078             2 => array('uid' => 121, 'pid' => 111),
00079             1 => array('uid' => 111, 'pid' => 101,),
00080             0 => array('uid' => 101, 'pid' => 0,),
00081         );
00082 
00083         $GLOBALS['TSFE'] = $this->getMock('tslib_fe', array(), array(), '', FALSE);
00084         $GLOBALS['TSFE']->tmpl = $this->getMock('t3lib_TStemplate');
00085     }
00086 
00087     /**
00088      * Tests whether a faulty expression fails.
00089      * @test
00090      */
00091     public function simulateDisabledMatchAllConditionsFailsOnFaultyExpression() {
00092         $this->matchCondition->matchAll = false;
00093         $this->assertFalse($this->matchCondition->match('[nullCondition = This expression would return false in general]'));
00094     }
00095 
00096     /**
00097      * Tests whether simulating positive matches for all conditions succeeds.
00098      * @test
00099      */
00100     public function simulateEnabledMatchAllConditionsSucceeds() {
00101         $this->matchCondition->setSimulateMatchResult(true);
00102         $this->assertTrue($this->matchCondition->match('[nullCondition = This expression would return false in general]'));
00103     }
00104 
00105     /**
00106      * Tests whether simulating positive matches for specific conditions succeeds.
00107      * @test
00108      */
00109     public function simulateEnabledMatchSpecificConditionsSucceeds() {
00110         $testCondition = '[' . uniqid('test') . ' = Any condition to simulate a positive match]';
00111         $this->matchCondition->setSimulateMatchConditions(array($testCondition));
00112         $this->assertTrue($this->matchCondition->match($testCondition));
00113     }
00114 
00115     /**
00116      * Tests whether a condition matches Internet Explorer 7 on Windows.
00117      *
00118      * @return  void
00119      * @test
00120      */
00121     public function conditionMatchesInternetExplorer7Windows() {
00122         $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)';
00123         $result = $this->matchCondition->match('[browser = msie] && [version = 7] && [system = winNT]');
00124         $this->assertTrue($result);
00125     }
00126 
00127     /**
00128      * Tests whether a condition does not match Internet Explorer 7 on Windows.
00129      *
00130      * @return  void
00131      * @test
00132      */
00133     public function conditionDoesNotMatchInternetExplorer7Windows() {
00134         $_SERVER['HTTP_USER_AGENT'] = 'Opera/9.25 (Windows NT 6.0; U; en)';
00135         $result = $this->matchCondition->match('[browser = msie] && [version = 7] && [system = winNT]');
00136         $this->assertFalse($result);
00137     }
00138 
00139     /**
00140      * Tests whether a condition does match the iOS with the correct and more recent 'iOS'
00141      * @test
00142      */
00143     public function conditionDoesMatchIosWithCorrectSystemKey() {
00144         $_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';
00145         $result = $this->matchCondition->match('[system = iOS]');
00146         $this->assertTrue($result);
00147     }
00148 
00149     /**
00150      * Tests whether a condition does match the iOS with the old 'mac'
00151      * @test
00152      */
00153     public function conditionDoesMatchIosWithOldSystemKey() {
00154         $_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';
00155         $result = $this->matchCondition->match('[system = mac]');
00156         $this->assertTrue($result);
00157     }
00158 
00159     /**
00160      * Tests whether a condition does match Windows 2000 with the correct and more recent 'win2k'
00161      * @test
00162      */
00163     public function conditionDoesMatchWindows2kWithNewSystemKey() {
00164         $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; SV1)';
00165         $result = $this->matchCondition->match('[system = win2k]');
00166         $this->assertTrue($result);
00167     }
00168 
00169     /**
00170      * Tests whether a condition does match Windows 2000 with the old 'winNT'
00171      * @test
00172      */
00173     public function conditionDoesMatchWindows2kWithOldSystemKey() {
00174         $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; SV1)';
00175         $result = $this->matchCondition->match('[system = winNT]');
00176         $this->assertTrue($result);
00177     }
00178 
00179     /**
00180      * Tests whether a condition does match Windows NT with 'winNT'
00181      * @test
00182      */
00183     public function conditionDoesMatchWindowsNtWithSystemKey() {
00184         $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 4.0)';
00185         $result = $this->matchCondition->match('[system = winNT]');
00186         $this->assertTrue($result);
00187     }
00188 
00189 
00190     /**
00191      * Tests whether a condition does match Android with the correct and more recent 'android'
00192      * @test
00193      */
00194     public function conditionDoesMatchAndroidWithNewSystemKey() {
00195         $_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';
00196         $result = $this->matchCondition->match('[system = android]');
00197         $this->assertTrue($result);
00198     }
00199 
00200     /**
00201      * Tests whether a condition does match Android with the old 'linux'
00202      * @test
00203      */
00204     public function conditionDoesMatchAndroidWithOldSystemKey() {
00205         $_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';
00206         $result = $this->matchCondition->match('[system = linux]');
00207         $this->assertTrue($result);
00208     }
00209 
00210     /**
00211      * Tests whether a device type condition matches a crawler.
00212      * @test
00213      */
00214     public function deviceConditionMatchesRobot() {
00215         $_SERVER['HTTP_USER_AGENT'] = 'Googlebot/2.1 (+http://www.google.com/bot.html)';
00216         $result = $this->matchCondition->match('[device = robot]');
00217         $this->assertTrue($result);
00218     }
00219 
00220     /**
00221      * Tests whether a device type condition does not match a crawler.
00222      * @test
00223      */
00224     public function deviceConditionDoesNotMatchRobot() {
00225         $_SERVER['HTTP_USER_AGENT'] = md5('Some strange user agent');
00226         $result = $this->matchCondition->match('[device = robot]');
00227         $this->assertFalse($result);
00228     }
00229 
00230     /**
00231      * Tests whether the language comparison matches.
00232      * @test
00233      */
00234     public function languageConditionMatchesSingleLanguageExpression() {
00235         $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'de-de,de;q=0.8,en-us;q=0.5,en;q=0.3';
00236         $this->assertTrue($this->matchCondition->match('[language = *de*]'));
00237         $this->assertTrue($this->matchCondition->match('[language = *de-de*]'));
00238     }
00239 
00240     /**
00241      * Tests whether the language comparison matches.
00242      * @test
00243      */
00244     public function languageConditionMatchesMultipleLanguagesExpression() {
00245         $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'de-de,de;q=0.8,en-us;q=0.5,en;q=0.3';
00246         $this->assertTrue($this->matchCondition->match('[language = *en*,*de*]'));
00247         $this->assertTrue($this->matchCondition->match('[language = *en-us*,*de-de*]'));
00248     }
00249 
00250     /**
00251      * Tests whether the language comparison matches.
00252      * @test
00253      */
00254     public function languageConditionMatchesCompleteLanguagesExpression() {
00255         $this->markTestSkipped('This comparison seems to be incomplete in t3lib_matchCondition.');
00256 
00257         $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'de-de,de;q=0.8,en-us;q=0.5,en;q=0.3';
00258         $this->assertTrue($this->matchCondition->match('[language = de-de,de;q=0.8]'));
00259     }
00260 
00261     /**
00262      * Tests whether usergroup comparison matches.
00263      * @test
00264      */
00265     public function usergroupConditionMatchesSingleGroupId() {
00266         $GLOBALS['TSFE']->gr_list = '13,14,15';
00267         $this->assertTrue($this->matchCondition->match('[usergroup = 13]'));
00268     }
00269 
00270     /**
00271      * Tests whether usergroup comparison matches.
00272      * @test
00273      */
00274     public function usergroupConditionMatchesMultipleUserGroupId() {
00275         $GLOBALS['TSFE']->gr_list = '13,14,15';
00276         $this->assertTrue($this->matchCondition->match('[usergroup = 999,15,14,13]'));
00277     }
00278 
00279     /**
00280      * Tests whether usergroup comparison matches.
00281      * @test
00282      */
00283     public function usergroupConditionDoesNotMatchDefaulUserGroupIds() {
00284         $GLOBALS['TSFE']->gr_list = '0,-1';
00285         $this->assertFalse($this->matchCondition->match('[usergroup = 0,-1]'));
00286     }
00287 
00288     /**
00289      * Tests whether user comparison matches.
00290      * @test
00291      */
00292     public function loginUserConditionMatchesAnyLoggedInUser() {
00293         $GLOBALS['TSFE']->loginUser = TRUE;
00294         $GLOBALS['TSFE']->fe_user->user['uid'] = 13;
00295         $this->assertTrue($this->matchCondition->match('[loginUser = *]'));
00296     }
00297 
00298     /**
00299      * Tests whether user comparison matches.
00300      * @test
00301      */
00302     public function loginUserConditionMatchesSingleLoggedInUser() {
00303         $GLOBALS['TSFE']->loginUser = TRUE;
00304         $GLOBALS['TSFE']->fe_user->user['uid'] = 13;
00305         $this->assertTrue($this->matchCondition->match('[loginUser = 13]'));
00306     }
00307 
00308     /**
00309      * Tests whether user comparison matches.
00310      * @test
00311      */
00312     public function loginUserConditionMatchesMultipleLoggedInUsers() {
00313         $GLOBALS['TSFE']->loginUser = TRUE;
00314         $GLOBALS['TSFE']->fe_user->user['uid'] = 13;
00315         $this->assertTrue($this->matchCondition->match('[loginUser = 999,13]'));
00316     }
00317 
00318     /**
00319      * Tests whether user comparison matches.
00320      * @test
00321      */
00322     public function loginUserConditionDoesNotMatchIfNotUserIsLoggedId() {
00323         $GLOBALS['TSFE']->loginUser = FALSE;
00324         $GLOBALS['TSFE']->fe_user->user['uid'] = 13;
00325         $this->assertFalse($this->matchCondition->match('[loginUser = *]'));
00326         $this->assertFalse($this->matchCondition->match('[loginUser = 13]'));
00327     }
00328 
00329     /**
00330      * Tests whether user is not logged in
00331      * @test
00332      */
00333     public function loginUserConditionMatchIfUserIsNotLoggedIn() {
00334         $GLOBALS['TSFE']->loginUser = FALSE;
00335         $this->assertTrue($this->matchCondition->match('[loginUser = ]'));
00336     }
00337 
00338     /**
00339      * Tests whether numerical comparison matches.
00340      * @test
00341      */
00342     public function globalVarConditionMatchesOnEqualExpression() {
00343         $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 = 10]'));
00344         $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 = 10.1]'));
00345 
00346         $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 == 10]'));
00347         $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 == 10.1]'));
00348     }
00349 
00350     /**
00351      * Tests whether numerical comparison matches.
00352      * @test
00353      */
00354     public function globalVarConditionMatchesOnNotEqualExpression() {
00355         $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 != 20]'));
00356         $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 != 10.2]'));
00357     }
00358 
00359     /**
00360      * Tests whether numerical comparison matches.
00361      * @test
00362      */
00363     public function globalVarConditionMatchesOnLowerThanExpression() {
00364         $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 < 20]'));
00365         $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 < 10.2]'));
00366     }
00367 
00368     /**
00369      * Tests whether numerical comparison matches.
00370      * @test
00371      */
00372     public function globalVarConditionMatchesOnLowerThanOrEqualExpression() {
00373         $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 <= 10]'));
00374         $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 <= 20]'));
00375 
00376         $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 <= 10.1]'));
00377         $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 <= 10.2]'));
00378     }
00379 
00380     /**
00381      * Tests whether numerical comparison matches.
00382      * @test
00383      */
00384     public function globalVarConditionMatchesOnGreaterThanExpression() {
00385         $this->assertTrue($this->matchCondition->match('[globalVar = LIT:20 > 10]'));
00386         $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.2 > 10.1]'));
00387     }
00388 
00389     /**
00390      * Tests whether numerical comparison matches.
00391      * @test
00392      */
00393     public function globalVarConditionMatchesOnGreaterThanOrEqualExpression() {
00394         $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 >= 10]'));
00395         $this->assertTrue($this->matchCondition->match('[globalVar = LIT:20 >= 10]'));
00396 
00397         $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 >= 10.1]'));
00398         $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.2 >= 10.1]'));
00399     }
00400 
00401     /**
00402      * Tests whether numerical comparison matches.
00403      * @test
00404      */
00405     public function globalVarConditionMatchesOnEmptyExpressionWithNoValueSet() {
00406         $testKey = uniqid('test');
00407         $this->assertTrue($this->matchCondition->match('[globalVar = GP:' . $testKey . '=]'));
00408         $this->assertTrue($this->matchCondition->match('[globalVar = GP:' . $testKey . ' = ]'));
00409     }
00410 
00411     /**
00412      * Tests whether numerical comparison matches.
00413      * @test
00414      */
00415     public function globalVarConditionDoesNotMatchOnEmptyExpressionWithValueSetToZero() {
00416         $testKey = uniqid('test');
00417 
00418         $_GET = array();
00419         $_POST = array($testKey => 0);
00420 
00421         $this->assertFalse($this->matchCondition->match('[globalVar = GP:' . $testKey . '=]'));
00422         $this->assertFalse($this->matchCondition->match('[globalVar = GP:' . $testKey . ' = ]'));
00423     }
00424 
00425     /**
00426      * Tests whether string comparison matches.
00427      * @test
00428      */
00429     public function globalStringConditionMatchesOnEqualExpression() {
00430         $this->assertTrue($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = TYPO3.Test.Condition]'));
00431         $this->assertFalse($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = TYPO3]'));
00432     }
00433 
00434     /**
00435      * Tests whether string comparison matches.
00436      * @test
00437      */
00438     public function globalStringConditionMatchesWildcardExpression() {
00439         $this->assertTrue($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = TYPO3?Test?Condition]'));
00440         $this->assertTrue($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = TYPO3.T*t.Condition]'));
00441         $this->assertTrue($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = TYPO3?T*t?Condition]'));
00442     }
00443 
00444     /**
00445      * Tests whether string comparison matches.
00446      * @test
00447      */
00448     public function globalStringConditionMatchesRegularExpression() {
00449         $this->assertTrue($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = /^[A-Za-z3.]+$/]'));
00450         $this->assertTrue($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = /^TYPO3\..+Condition$/]'));
00451         $this->assertFalse($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = /^FALSE/]'));
00452     }
00453 
00454     /**
00455      * Tests whether string comparison matches.
00456      * @test
00457      */
00458     public function globalStringConditionMatchesEmptyRegularExpression() {
00459         $testKey = uniqid('test');
00460         $_SERVER[$testKey] = '';
00461         $this->assertTrue($this->matchCondition->match('[globalString = _SERVER|' . $testKey . ' = /^$/]'));
00462     }
00463 
00464     /**
00465      * Tests whether treeLevel comparison matches.
00466      * @test
00467      */
00468     public function treeLevelConditionMatchesSingleValue() {
00469         $GLOBALS['TSFE']->tmpl->rootLine = $this->rootline;
00470         $this->assertTrue($this->matchCondition->match('[treeLevel = 2]'));
00471     }
00472 
00473     /**
00474      * Tests whether treeLevel comparison matches.
00475      * @test
00476      */
00477     public function treeLevelConditionMatchesMultipleValues() {
00478         $GLOBALS['TSFE']->tmpl->rootLine = $this->rootline;
00479         $this->assertTrue($this->matchCondition->match('[treeLevel = 999,998,2]'));
00480     }
00481 
00482     /**
00483      * Tests whether treeLevel comparison matches.
00484      * @test
00485      */
00486     public function treeLevelConditionDoesNotMatchFaultyValue() {
00487         $GLOBALS['TSFE']->tmpl->rootLine = $this->rootline;
00488         $this->assertFalse($this->matchCondition->match('[treeLevel = 999]'));
00489     }
00490 
00491     /**
00492      * Tests whether a page Id is found in the previous rootline entries.
00493      * @test
00494      */
00495     public function PIDupinRootlineConditionMatchesSinglePageIdInRootline() {
00496         $GLOBALS['TSFE']->tmpl->rootLine = $this->rootline;
00497         $GLOBALS['TSFE']->id = 121;
00498         $this->assertTrue($this->matchCondition->match('[PIDupinRootline = 111]'));
00499     }
00500 
00501     /**
00502      * Tests whether a page Id is found in the previous rootline entries.
00503      * @test
00504      */
00505     public function PIDupinRootlineConditionMatchesMultiplePageIdsInRootline() {
00506         $GLOBALS['TSFE']->tmpl->rootLine = $this->rootline;
00507         $GLOBALS['TSFE']->id = 121;
00508         $this->assertTrue($this->matchCondition->match('[PIDupinRootline = 999,111,101]'));
00509     }
00510 
00511     /**
00512      * Tests whether a page Id is found in the previous rootline entries.
00513      * @test
00514      */
00515     public function PIDupinRootlineConditionDoesNotMatchPageIdNotInRootline() {
00516         $GLOBALS['TSFE']->tmpl->rootLine = $this->rootline;
00517         $GLOBALS['TSFE']->id = 121;
00518         $this->assertFalse($this->matchCondition->match('[PIDupinRootline = 999]'));
00519     }
00520 
00521     /**
00522      * Tests whether a page Id is found in the previous rootline entries.
00523      * @test
00524      */
00525     public function PIDupinRootlineConditionDoesNotMatchLastPageIdInRootline() {
00526         $GLOBALS['TSFE']->tmpl->rootLine = $this->rootline;
00527         $GLOBALS['TSFE']->id = 121;
00528         $this->assertFalse($this->matchCondition->match('[PIDupinRootline = 121]'));
00529     }
00530 
00531     /**
00532      * Tests whether a page Id is found in all rootline entries.
00533      * @test
00534      */
00535     public function PIDinRootlineConditionMatchesSinglePageIdInRootline() {
00536         $GLOBALS['TSFE']->tmpl->rootLine = $this->rootline;
00537         $GLOBALS['TSFE']->id = 121;
00538         $this->assertTrue($this->matchCondition->match('[PIDinRootline = 111]'));
00539     }
00540 
00541     /**
00542      * Tests whether a page Id is found in all rootline entries.
00543      * @test
00544      */
00545     public function PIDinRootlineConditionMatchesMultiplePageIdsInRootline() {
00546         $GLOBALS['TSFE']->tmpl->rootLine = $this->rootline;
00547         $GLOBALS['TSFE']->id = 121;
00548         $this->assertTrue($this->matchCondition->match('[PIDinRootline = 999,111,101]'));
00549     }
00550 
00551     /**
00552      * Tests whether a page Id is found in all rootline entries.
00553      * @test
00554      */
00555     public function PIDinRootlineConditionMatchesLastPageIdInRootline() {
00556         $GLOBALS['TSFE']->tmpl->rootLine = $this->rootline;
00557         $GLOBALS['TSFE']->id = 121;
00558         $this->assertTrue($this->matchCondition->match('[PIDinRootline = 121]'));
00559     }
00560 
00561     /**
00562      * Tests whether a page Id is found in all rootline entries.
00563      * @test
00564      */
00565     public function PIDinRootlineConditionDoesNotMatchPageIdNotInRootline() {
00566         $GLOBALS['TSFE']->tmpl->rootLine = $this->rootline;
00567         $GLOBALS['TSFE']->id = 121;
00568         $this->assertFalse($this->matchCondition->match('[PIDinRootline = 999]'));
00569     }
00570 
00571     /**
00572      * Tests whether the compatibility version can be evaluated.
00573      * (e.g. 4.9 is compatible to 4.0 but not to 5.0)
00574      * @test
00575      */
00576     public function compatVersionConditionMatchesOlderRelease() {
00577         $GLOBALS['TYPO3_CONF_VARS']['SYS']['compat_version'] = '4.9';
00578         $this->assertTrue($this->matchCondition->match('[compatVersion = 4.0]'));
00579     }
00580 
00581     /**
00582      * Tests whether the compatibility version can be evaluated.
00583      * (e.g. 4.9 is compatible to 4.0 but not to 5.0)
00584      * @test
00585      */
00586     public function compatVersionConditionMatchesSameRelease() {
00587         $GLOBALS['TYPO3_CONF_VARS']['SYS']['compat_version'] = '4.9';
00588         $this->assertTrue($this->matchCondition->match('[compatVersion = 4.9]'));
00589     }
00590 
00591     /**
00592      * Tests whether the compatibility version can be evaluated.
00593      * (e.g. 4.9 is compatible to 4.0 but not to 5.0)
00594      * @test
00595      */
00596     public function compatVersionConditionDoesNotMatchNewerRelease() {
00597         $GLOBALS['TYPO3_CONF_VARS']['SYS']['compat_version'] = '4.9';
00598         $this->assertFalse($this->matchCondition->match('[compatVersion = 5.0]'));
00599     }
00600 
00601     /**
00602      * Tests whether the generic fetching of variables works with the namespace 'GP'.
00603      * @test
00604      */
00605     public function genericGetVariablesSucceedsWithNamespaceGP() {
00606         $_GET = array('testGet' => 'getTest');
00607         $_POST = array('testPost' => 'postTest');
00608 
00609         $this->assertTrue($this->matchCondition->match('[globalString = GP:testGet = getTest]'));
00610         $this->assertTrue($this->matchCondition->match('[globalString = GP:testPost = postTest]'));
00611     }
00612 
00613     /**
00614      * Tests whether the generic fetching of variables works with the namespace 'TSFE'.
00615      * @test
00616      */
00617     public function genericGetVariablesSucceedsWithNamespaceTSFE() {
00618         $GLOBALS['TSFE']->id = 1234567;
00619         $GLOBALS['TSFE']->testSimpleObject = new stdClass();
00620         $GLOBALS['TSFE']->testSimpleObject->testSimpleVariable = 'testValue';
00621 
00622         $this->assertTrue($this->matchCondition->match('[globalString = TSFE:id = 1234567]'));
00623         $this->assertTrue($this->matchCondition->match('[globalString = TSFE:testSimpleObject|testSimpleVariable = testValue]'));
00624     }
00625 
00626     /**
00627      * Tests whether the generic fetching of variables works with the namespace 'ENV'.
00628      * @test
00629      */
00630     public function genericGetVariablesSucceedsWithNamespaceENV() {
00631         $testKey = uniqid('test');
00632         putenv($testKey .'=testValue');
00633 
00634         $this->assertTrue($this->matchCondition->match('[globalString = ENV:' . $testKey . ' = testValue]'));
00635     }
00636 
00637     /**
00638      * Tests whether the generic fetching of variables works with the namespace 'IENV'.
00639      * @test
00640      */
00641     public function genericGetVariablesSucceedsWithNamespaceIENV() {
00642         $_SERVER['HTTP_HOST'] = t3lib_div::getIndpEnv('TYPO3_HOST_ONLY') . ':1234567';
00643         $this->assertTrue($this->matchCondition->match('[globalString = IENV:TYPO3_PORT = 1234567]'));
00644     }
00645 
00646     /**
00647      * Tests whether the generic fetching of variables works with any global namespace.
00648      * @test
00649      */
00650     public function genericGetVariablesSucceedsWithAnyGlobalNamespace() {
00651         $GLOBALS[$this->testGlobalNamespace] = array(
00652             'first' => 'testFirst',
00653             'second' => array('third' => 'testThird'),
00654         );
00655 
00656         $this->assertTrue($this->matchCondition->match(
00657             '[globalString = ' . $this->testGlobalNamespace . '|first = testFirst]'
00658         ));
00659         $this->assertTrue($this->matchCondition->match(
00660             '[globalString = ' . $this->testGlobalNamespace . '|second|third = testThird]'
00661         ));
00662     }
00663 }
00664 ?>