PageRenderTime 55ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 1ms

/tests/t3lib/matchcondition/t3lib_matchcondition_frontendTest.php

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