PageRenderTime 45ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/t3lib/t3lib_matchconditionTest.php

https://github.com/foxsoft/typo3v4core
PHP | 631 lines | 301 code | 77 blank | 253 comment | 0 complexity | d40808ff6b44cd67789651e558c283f7 MD5 | raw file
Possible License(s): Apache-2.0
  1. <?php
  2. /***************************************************************
  3. * Copyright notice
  4. *
  5. * (c) 2009-2010 Oliver Hader <oliver@typo3.org>
  6. * All rights reserved
  7. *
  8. * This script is part of the TYPO3 project. The TYPO3 project is
  9. * free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * The GNU General Public License can be found at
  15. * http://www.gnu.org/copyleft/gpl.html.
  16. *
  17. * This script is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * This copyright notice MUST APPEAR in all copies of the script!
  23. ***************************************************************/
  24. /**
  25. * Testcase for class t3lib_matchCondition.
  26. *
  27. * @author Oliver Hader <oliver@typo3.org>
  28. * @package TYPO3
  29. * @subpackage t3lib
  30. */
  31. class t3lib_matchConditionTest extends tx_phpunit_testcase {
  32. /**
  33. * @var array
  34. */
  35. private $backupGlobalVariables;
  36. /**
  37. * @var array
  38. */
  39. private $rootline;
  40. /**
  41. * @var t3lib_matchCondition
  42. */
  43. private $matchCondition;
  44. public function setUp() {
  45. $this->backupGlobalVariables = array(
  46. '_ENV' => $_ENV,
  47. '_GET' => $_GET,
  48. '_POST' => $_POST,
  49. '_SERVER' => $_SERVER,
  50. 'TYPO3_CONF_VARS' => $GLOBALS['TYPO3_CONF_VARS'],
  51. 'T3_VAR' => $GLOBALS['T3_VAR'],
  52. );
  53. $GLOBALS['TYPO3_CONF_VARS']['SYS']['enableDeprecationLog'] = FALSE;
  54. $this->testGlobalNamespace = uniqid('TEST');
  55. $GLOBALS[$this->testGlobalNamespace] = array();
  56. $this->setUpTSFE();
  57. $this->matchCondition = t3lib_div::makeInstance('t3lib_matchCondition');
  58. }
  59. public function tearDown() {
  60. foreach ($this->backupGlobalVariables as $key => $data) {
  61. $GLOBALS[$key] = $data;
  62. }
  63. unset($this->matchCondition);
  64. unset($this->backupGlobalVariables);
  65. unset($GLOBALS[$this->testGlobalNamespace]);
  66. }
  67. private function setUpTSFE() {
  68. $this->rootline = array(
  69. 2 => array('uid' => 121, 'pid' => 111),
  70. 1 => array('uid' => 111, 'pid' => 101,),
  71. 0 => array('uid' => 101, 'pid' => 0,),
  72. );
  73. $GLOBALS['TSFE'] = $this->getMock('tslib_fe', array(), array(), '', FALSE);
  74. $GLOBALS['TSFE']->tmpl = $this->getMock('t3lib_TStemplate');
  75. }
  76. /**
  77. * Tests whether a faulty expression fails.
  78. * @test
  79. */
  80. public function simulateDisabledMatchAllConditionsFailsOnFaultyExpression() {
  81. $this->matchCondition->matchAll = false;
  82. $this->assertFalse($this->matchCondition->match('[nullCondition = This expression would return false in general]'));
  83. }
  84. /**
  85. * Tests whether simulating positive matches for all conditions succeeds.
  86. * @test
  87. */
  88. public function simulateEnabledMatchAllConditionsSucceeds() {
  89. $this->matchCondition->matchAll = true;
  90. $this->assertTrue($this->matchCondition->match('[nullCondition = This expression would return false in general]'));
  91. }
  92. /**
  93. * Tests whether simulating positive matches for specific conditions succeeds.
  94. * @test
  95. */
  96. public function simulateEnabledMatchSpecificConditionsSucceeds() {
  97. $testCondition = '[' . uniqid('test') . ' = Any condition to simulate a positive match]';
  98. $this->matchCondition->matchAlternative = array($testCondition);
  99. $this->assertTrue($this->matchCondition->match($testCondition));
  100. }
  101. /**
  102. * Tests whether a condition matches Internet Explorer 7 on Windows.
  103. *
  104. * @return void
  105. * @test
  106. */
  107. public function conditionMatchesInternetExplorer7Windows() {
  108. $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)';
  109. $result = $this->matchCondition->match('[browser = msie] && [version = 7] && [system = winNT]');
  110. $this->assertTrue($result);
  111. }
  112. /**
  113. * Tests whether a condition does not match Internet Explorer 7 on Windows.
  114. *
  115. * @return void
  116. * @test
  117. */
  118. public function conditionDoesNotMatchInternetExplorer7Windows() {
  119. $_SERVER['HTTP_USER_AGENT'] = 'Opera/9.25 (Windows NT 6.0; U; en)';
  120. $result = $this->matchCondition->match('[browser = msie] && [version = 7] && [system = winNT]');
  121. $this->assertFalse($result);
  122. }
  123. /**
  124. * Tests whether the browserInfo hook is called.
  125. *
  126. * @return void
  127. * @test
  128. */
  129. public function deprecatedBrowserInfoHookIsCalled() {
  130. $classRef = uniqid('tx_browserInfoHook');
  131. $browserInfoHookMock = $this->getMock($classRef, array('browserInfo'));
  132. $browserInfoHookMock->expects($this->atLeastOnce())->method('browserInfo');
  133. $GLOBALS['T3_VAR']['getUserObj'][$classRef] = $browserInfoHookMock;
  134. $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_matchcondition.php']['matchConditionClass'][$classRef] = $classRef;
  135. $this->matchCondition->__construct();
  136. $this->matchCondition->match('[browser = msie] && [version = 7] && [system = winNT]');
  137. }
  138. /**
  139. * Tests whether a device type condition matches a crawler.
  140. * @test
  141. */
  142. public function deviceConditionMatchesRobot() {
  143. $_SERVER['HTTP_USER_AGENT'] = 'Googlebot/2.1 (+http://www.google.com/bot.html)';
  144. $result = $this->matchCondition->match('[device = robot]');
  145. $this->assertTrue($result);
  146. }
  147. /**
  148. * Tests whether a device type condition does not match a crawler.
  149. * @test
  150. */
  151. public function deviceConditionDoesNotMatchRobot() {
  152. $_SERVER['HTTP_USER_AGENT'] = md5('Some strange user agent');
  153. $result = $this->matchCondition->match('[device = robot]');
  154. $this->assertFalse($result);
  155. }
  156. /**
  157. * Tests whether the whichDevice hook is called.
  158. *
  159. * @return void
  160. * @test
  161. */
  162. public function deprecatedWhichDeviceHookIsCalled() {
  163. $classRef = uniqid('tx_whichDeviceHook');
  164. $whichDeviceHookMock = $this->getMock($classRef, array('whichDevice'));
  165. $whichDeviceHookMock->expects($this->atLeastOnce())->method('whichDevice');
  166. $GLOBALS['T3_VAR']['getUserObj'][$classRef] = $whichDeviceHookMock;
  167. $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_matchcondition.php']['matchConditionClass'][$classRef] = $classRef;
  168. $this->matchCondition->__construct();
  169. $this->matchCondition->match('[device = robot]');
  170. }
  171. /**
  172. * Tests whether the language comparison matches.
  173. * @test
  174. */
  175. public function languageConditionMatchesSingleLanguageExpression() {
  176. $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'de-de,de;q=0.8,en-us;q=0.5,en;q=0.3';
  177. $this->assertTrue($this->matchCondition->match('[language = *de*]'));
  178. $this->assertTrue($this->matchCondition->match('[language = *de-de*]'));
  179. }
  180. /**
  181. * Tests whether the language comparison matches.
  182. * @test
  183. */
  184. public function languageConditionMatchesMultipleLanguagesExpression() {
  185. $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'de-de,de;q=0.8,en-us;q=0.5,en;q=0.3';
  186. $this->assertTrue($this->matchCondition->match('[language = *en*,*de*]'));
  187. $this->assertTrue($this->matchCondition->match('[language = *en-us*,*de-de*]'));
  188. }
  189. /**
  190. * Tests whether the language comparison matches.
  191. * @test
  192. */
  193. public function languageConditionMatchesCompleteLanguagesExpression() {
  194. $this->markTestSkipped('This comparison seems to be incomplete in t3lib_matchCondition.');
  195. $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'de-de,de;q=0.8,en-us;q=0.5,en;q=0.3';
  196. $this->assertTrue($this->matchCondition->match('[language = de-de,de;q=0.8]'));
  197. }
  198. /**
  199. * Tests whether usergroup comparison matches.
  200. * @test
  201. */
  202. public function usergroupConditionMatchesSingleGroupId() {
  203. $GLOBALS['TSFE']->gr_list = '13,14,15';
  204. $this->assertTrue($this->matchCondition->match('[usergroup = 13]'));
  205. }
  206. /**
  207. * Tests whether usergroup comparison matches.
  208. * @test
  209. */
  210. public function usergroupConditionMatchesMultipleUserGroupId() {
  211. $GLOBALS['TSFE']->gr_list = '13,14,15';
  212. $this->assertTrue($this->matchCondition->match('[usergroup = 999,15,14,13]'));
  213. }
  214. /**
  215. * Tests whether usergroup comparison matches.
  216. * @test
  217. */
  218. public function usergroupConditionDoesNotMatchDefaulUserGroupIds() {
  219. $GLOBALS['TSFE']->gr_list = '0,-1';
  220. $this->assertFalse($this->matchCondition->match('[usergroup = 0,-1]'));
  221. }
  222. /**
  223. * Tests whether user comparison matches.
  224. * @test
  225. */
  226. public function loginUserConditionMatchesAnyLoggedInUser() {
  227. $GLOBALS['TSFE']->loginUser = TRUE;
  228. $GLOBALS['TSFE']->fe_user->user['uid'] = 13;
  229. $this->assertTrue($this->matchCondition->match('[loginUser = *]'));
  230. }
  231. /**
  232. * Tests whether user comparison matches.
  233. * @test
  234. */
  235. public function loginUserConditionMatchesSingleLoggedInUser() {
  236. $GLOBALS['TSFE']->loginUser = TRUE;
  237. $GLOBALS['TSFE']->fe_user->user['uid'] = 13;
  238. $this->assertTrue($this->matchCondition->match('[loginUser = 13]'));
  239. }
  240. /**
  241. * Tests whether user comparison matches.
  242. * @test
  243. */
  244. public function loginUserConditionMatchesMultipleLoggedInUsers() {
  245. $GLOBALS['TSFE']->loginUser = TRUE;
  246. $GLOBALS['TSFE']->fe_user->user['uid'] = 13;
  247. $this->assertTrue($this->matchCondition->match('[loginUser = 999,13]'));
  248. }
  249. /**
  250. * Tests whether user comparison matches.
  251. * @test
  252. */
  253. public function loginUserConditionDoesNotMatchIfNotUserIsLoggedId() {
  254. $GLOBALS['TSFE']->loginUser = FALSE;
  255. $GLOBALS['TSFE']->fe_user->user['uid'] = 13;
  256. $this->assertFalse($this->matchCondition->match('[loginUser = *]'));
  257. $this->assertFalse($this->matchCondition->match('[loginUser = 13]'));
  258. }
  259. /**
  260. * Tests whether user is not logged in
  261. * @test
  262. */
  263. public function loginUserConditionMatchIfUserIsNotLoggedIn() {
  264. $GLOBALS['TSFE']->loginUser = FALSE;
  265. $this->assertTrue($this->matchCondition->match('[loginUser = ]'));
  266. }
  267. /**
  268. * Tests whether numerical comparison matches.
  269. * @test
  270. */
  271. public function globalVarConditionMatchesOnEqualExpression() {
  272. $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 = 10]'));
  273. $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 = 10.1]'));
  274. $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 == 10]'));
  275. $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 == 10.1]'));
  276. }
  277. /**
  278. * Tests whether numerical comparison matches.
  279. * @test
  280. */
  281. public function globalVarConditionMatchesOnNotEqualExpression() {
  282. $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 != 20]'));
  283. $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 != 10.2]'));
  284. }
  285. /**
  286. * Tests whether numerical comparison matches.
  287. * @test
  288. */
  289. public function globalVarConditionMatchesOnLowerThanExpression() {
  290. $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 < 20]'));
  291. $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 < 10.2]'));
  292. }
  293. /**
  294. * Tests whether numerical comparison matches.
  295. * @test
  296. */
  297. public function globalVarConditionMatchesOnLowerThanOrEqualExpression() {
  298. $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 <= 10]'));
  299. $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 <= 20]'));
  300. $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 <= 10.1]'));
  301. $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 <= 10.2]'));
  302. }
  303. /**
  304. * Tests whether numerical comparison matches.
  305. * @test
  306. */
  307. public function globalVarConditionMatchesOnGreaterThanExpression() {
  308. $this->assertTrue($this->matchCondition->match('[globalVar = LIT:20 > 10]'));
  309. $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.2 > 10.1]'));
  310. }
  311. /**
  312. * Tests whether numerical comparison matches.
  313. * @test
  314. */
  315. public function globalVarConditionMatchesOnGreaterThanOrEqualExpression() {
  316. $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 >= 10]'));
  317. $this->assertTrue($this->matchCondition->match('[globalVar = LIT:20 >= 10]'));
  318. $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 >= 10.1]'));
  319. $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.2 >= 10.1]'));
  320. }
  321. /**
  322. * Tests whether numerical comparison matches.
  323. * @test
  324. */
  325. public function globalVarConditionMatchesOnEmptyExpressionWithNoValueSet() {
  326. $testKey = uniqid('test');
  327. $this->assertTrue($this->matchCondition->match('[globalVar = GP:' . $testKey . '=]'));
  328. $this->assertTrue($this->matchCondition->match('[globalVar = GP:' . $testKey . ' = ]'));
  329. }
  330. /**
  331. * Tests whether numerical comparison matches.
  332. * @test
  333. */
  334. public function globalVarConditionDoesNotMatchOnEmptyExpressionWithValueSetToZero() {
  335. $testKey = uniqid('test');
  336. $_GET = array();
  337. $_POST = array($testKey => 0);
  338. $this->assertFalse($this->matchCondition->match('[globalVar = GP:' . $testKey . '=]'));
  339. $this->assertFalse($this->matchCondition->match('[globalVar = GP:' . $testKey . ' = ]'));
  340. }
  341. /**
  342. * Tests whether string comparison matches.
  343. * @test
  344. */
  345. public function globalStringConditionMatchesOnEqualExpression() {
  346. $this->assertTrue($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = TYPO3.Test.Condition]'));
  347. $this->assertFalse($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = TYPO3]'));
  348. }
  349. /**
  350. * Tests whether string comparison matches.
  351. * @test
  352. */
  353. public function globalStringConditionMatchesWildcardExpression() {
  354. $this->assertTrue($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = TYPO3?Test?Condition]'));
  355. $this->assertTrue($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = TYPO3.T*t.Condition]'));
  356. $this->assertTrue($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = TYPO3?T*t?Condition]'));
  357. }
  358. /**
  359. * Tests whether string comparison matches.
  360. * @test
  361. */
  362. public function globalStringConditionMatchesRegularExpression() {
  363. $this->assertTrue($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = /^[A-Za-z3.]+$/]'));
  364. $this->assertTrue($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = /^TYPO3\..+Condition$/]'));
  365. $this->assertFalse($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = /^FALSE/]'));
  366. }
  367. /**
  368. * Tests whether string comparison matches.
  369. * @test
  370. */
  371. public function globalStringConditionMatchesEmptyRegularExpression() {
  372. $testKey = uniqid('test');
  373. $_SERVER[$testKey] = '';
  374. $this->assertTrue($this->matchCondition->match('[globalString = _SERVER|' . $testKey . ' = /^$/]'));
  375. }
  376. /**
  377. * Tests whether treeLevel comparison matches.
  378. * @test
  379. */
  380. public function treeLevelConditionMatchesSingleValue() {
  381. $GLOBALS['TSFE']->tmpl->rootLine = $this->rootline;
  382. $this->assertTrue($this->matchCondition->match('[treeLevel = 2]'));
  383. }
  384. /**
  385. * Tests whether treeLevel comparison matches.
  386. * @test
  387. */
  388. public function treeLevelConditionMatchesMultipleValues() {
  389. $GLOBALS['TSFE']->tmpl->rootLine = $this->rootline;
  390. $this->assertTrue($this->matchCondition->match('[treeLevel = 999,998,2]'));
  391. }
  392. /**
  393. * Tests whether treeLevel comparison matches.
  394. * @test
  395. */
  396. public function treeLevelConditionDoesNotMatchFaultyValue() {
  397. $GLOBALS['TSFE']->tmpl->rootLine = $this->rootline;
  398. $this->assertFalse($this->matchCondition->match('[treeLevel = 999]'));
  399. }
  400. /**
  401. * Tests whether a page Id is found in the previous rootline entries.
  402. * @test
  403. */
  404. public function PIDupinRootlineConditionMatchesSinglePageIdInRootline() {
  405. $GLOBALS['TSFE']->tmpl->rootLine = $this->rootline;
  406. $GLOBALS['TSFE']->id = 121;
  407. $this->assertTrue($this->matchCondition->match('[PIDupinRootline = 111]'));
  408. }
  409. /**
  410. * Tests whether a page Id is found in the previous rootline entries.
  411. * @test
  412. */
  413. public function PIDupinRootlineConditionMatchesMultiplePageIdsInRootline() {
  414. $GLOBALS['TSFE']->tmpl->rootLine = $this->rootline;
  415. $GLOBALS['TSFE']->id = 121;
  416. $this->assertTrue($this->matchCondition->match('[PIDupinRootline = 999,111,101]'));
  417. }
  418. /**
  419. * Tests whether a page Id is found in the previous rootline entries.
  420. * @test
  421. */
  422. public function PIDupinRootlineConditionDoesNotMatchPageIdNotInRootline() {
  423. $GLOBALS['TSFE']->tmpl->rootLine = $this->rootline;
  424. $GLOBALS['TSFE']->id = 121;
  425. $this->assertFalse($this->matchCondition->match('[PIDupinRootline = 999]'));
  426. }
  427. /**
  428. * Tests whether a page Id is found in the previous rootline entries.
  429. * @test
  430. */
  431. public function PIDupinRootlineConditionDoesNotMatchLastPageIdInRootline() {
  432. $GLOBALS['TSFE']->tmpl->rootLine = $this->rootline;
  433. $GLOBALS['TSFE']->id = 121;
  434. $this->assertFalse($this->matchCondition->match('[PIDupinRootline = 121]'));
  435. }
  436. /**
  437. * Tests whether a page Id is found in all rootline entries.
  438. * @test
  439. */
  440. public function PIDinRootlineConditionMatchesSinglePageIdInRootline() {
  441. $GLOBALS['TSFE']->tmpl->rootLine = $this->rootline;
  442. $GLOBALS['TSFE']->id = 121;
  443. $this->assertTrue($this->matchCondition->match('[PIDinRootline = 111]'));
  444. }
  445. /**
  446. * Tests whether a page Id is found in all rootline entries.
  447. * @test
  448. */
  449. public function PIDinRootlineConditionMatchesMultiplePageIdsInRootline() {
  450. $GLOBALS['TSFE']->tmpl->rootLine = $this->rootline;
  451. $GLOBALS['TSFE']->id = 121;
  452. $this->assertTrue($this->matchCondition->match('[PIDinRootline = 999,111,101]'));
  453. }
  454. /**
  455. * Tests whether a page Id is found in all rootline entries.
  456. * @test
  457. */
  458. public function PIDinRootlineConditionMatchesLastPageIdInRootline() {
  459. $GLOBALS['TSFE']->tmpl->rootLine = $this->rootline;
  460. $GLOBALS['TSFE']->id = 121;
  461. $this->assertTrue($this->matchCondition->match('[PIDinRootline = 121]'));
  462. }
  463. /**
  464. * Tests whether a page Id is found in all rootline entries.
  465. * @test
  466. */
  467. public function PIDinRootlineConditionDoesNotMatchPageIdNotInRootline() {
  468. $GLOBALS['TSFE']->tmpl->rootLine = $this->rootline;
  469. $GLOBALS['TSFE']->id = 121;
  470. $this->assertFalse($this->matchCondition->match('[PIDinRootline = 999]'));
  471. }
  472. /**
  473. * Tests whether the compatibility version can be evaluated.
  474. * (e.g. 4.9 is compatible to 4.0 but not to 5.0)
  475. * @test
  476. */
  477. public function compatVersionConditionMatchesOlderRelease() {
  478. $GLOBALS['TYPO3_CONF_VARS']['SYS']['compat_version'] = '4.9';
  479. $this->assertTrue($this->matchCondition->match('[compatVersion = 4.0]'));
  480. }
  481. /**
  482. * Tests whether the compatibility version can be evaluated.
  483. * (e.g. 4.9 is compatible to 4.0 but not to 5.0)
  484. * @test
  485. */
  486. public function compatVersionConditionMatchesSameRelease() {
  487. $GLOBALS['TYPO3_CONF_VARS']['SYS']['compat_version'] = '4.9';
  488. $this->assertTrue($this->matchCondition->match('[compatVersion = 4.9]'));
  489. }
  490. /**
  491. * Tests whether the compatibility version can be evaluated.
  492. * (e.g. 4.9 is compatible to 4.0 but not to 5.0)
  493. * @test
  494. */
  495. public function compatVersionConditionDoesNotMatchNewerRelease() {
  496. $GLOBALS['TYPO3_CONF_VARS']['SYS']['compat_version'] = '4.9';
  497. $this->assertFalse($this->matchCondition->match('[compatVersion = 5.0]'));
  498. }
  499. /**
  500. * Tests whether the gneric fetching of variables works with the namespace 'GP'.
  501. * @test
  502. */
  503. public function genericGetVariablesSucceedsWithNamespaceGP() {
  504. $_GET = array('testGet' => 'getTest');
  505. $_POST = array('testPost' => 'postTest');
  506. $this->assertTrue($this->matchCondition->match('[globalString = GP:testGet = getTest]'));
  507. $this->assertTrue($this->matchCondition->match('[globalString = GP:testPost = postTest]'));
  508. }
  509. /**
  510. * Tests whether the gneric fetching of variables works with the namespace 'TSFE'.
  511. * @test
  512. */
  513. public function genericGetVariablesSucceedsWithNamespaceTSFE() {
  514. $GLOBALS['TSFE']->id = 1234567;
  515. $GLOBALS['TSFE']->testSimpleObject = new stdClass();
  516. $GLOBALS['TSFE']->testSimpleObject->testSimpleVariable = 'testValue';
  517. $this->assertTrue($this->matchCondition->match('[globalString = TSFE:id = 1234567]'));
  518. $this->assertTrue($this->matchCondition->match('[globalString = TSFE:testSimpleObject|testSimpleVariable = testValue]'));
  519. }
  520. /**
  521. * Tests whether the gneric fetching of variables works with the namespace 'ENV'.
  522. * @test
  523. */
  524. public function genericGetVariablesSucceedsWithNamespaceENV() {
  525. $testKey = uniqid('test');
  526. putenv($testKey .'=testValue');
  527. $this->assertTrue($this->matchCondition->match('[globalString = ENV:' . $testKey . ' = testValue]'));
  528. }
  529. /**
  530. * Tests whether the gneric fetching of variables works with the namespace 'IENV'.
  531. * @test
  532. */
  533. public function genericGetVariablesSucceedsWithNamespaceIENV() {
  534. $_SERVER['HTTP_HOST'] = t3lib_div::getIndpEnv('TYPO3_HOST_ONLY') . ':1234567';
  535. $this->assertTrue($this->matchCondition->match('[globalString = IENV:TYPO3_PORT = 1234567]'));
  536. }
  537. /**
  538. * Tests whether the gneric fetching of variables works with any global namespace.
  539. * @test
  540. */
  541. public function genericGetVariablesSucceedsWithAnyGlobalNamespace() {
  542. $GLOBALS[$this->testGlobalNamespace] = array(
  543. 'first' => 'testFirst',
  544. 'second' => array('third' => 'testThird'),
  545. );
  546. $this->assertTrue($this->matchCondition->match(
  547. '[globalString = ' . $this->testGlobalNamespace . '|first = testFirst]'
  548. ));
  549. $this->assertTrue($this->matchCondition->match(
  550. '[globalString = ' . $this->testGlobalNamespace . '|second|third = testThird]'
  551. ));
  552. }
  553. }
  554. ?>