PageRenderTime 62ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/t3lib/matchcondition/t3lib_matchcondition_backendTest.php

https://github.com/foxsoft/typo3v4core
PHP | 867 lines | 442 code | 106 blank | 319 comment | 6 complexity | da36fe102edecbb7fc565843736864b7 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_backendTest 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_backend
  42. */
  43. private $matchCondition;
  44. /**
  45. * @var string
  46. */
  47. private $testTableName;
  48. public function setUp() {
  49. $this->backupGlobalVariables = array(
  50. '_ENV' => $_ENV,
  51. '_GET' => $_GET,
  52. '_POST' => $_POST,
  53. '_SERVER' => $_SERVER,
  54. 'TCA' => $GLOBALS['TCA'],
  55. 'TYPO3_DB' => $GLOBALS['TYPO3_DB'],
  56. 'TYPO3_CONF_VARS' => $GLOBALS['TYPO3_CONF_VARS'],
  57. 'T3_VAR' => $GLOBALS['T3_VAR'],
  58. 'BE_USER' => $GLOBALS['BE_USER'],
  59. 'SOBE' => $GLOBALS['SOBE'],
  60. );
  61. $this->testTableName = 't3lib_matchCondition_backend_testTable';
  62. $this->testGlobalNamespace = uniqid('TEST');
  63. $GLOBALS['TCA'][$this->testTableName] = array('ctrl' => array());
  64. $GLOBALS[$this->testGlobalNamespace] = array();
  65. $this->setUpBackend();
  66. $this->matchCondition = t3lib_div::makeInstance('t3lib_matchCondition_backend');
  67. }
  68. public function tearDown() {
  69. foreach ($this->backupGlobalVariables as $key => $data) {
  70. $GLOBALS[$key] = $data;
  71. }
  72. unset($this->matchCondition);
  73. unset($this->backupGlobalVariables);
  74. unset($GLOBALS[$this->testGlobalNamespace]);
  75. }
  76. private function setUpBackend() {
  77. $this->rootline = array(
  78. 2 => array('uid' => 121, 'pid' => 111),
  79. 1 => array('uid' => 111, 'pid' => 101,),
  80. 0 => array('uid' => 101, 'pid' => 0,),
  81. );
  82. $GLOBALS['BE_USER'] = $this->getMock('beUserAuth', array(), array(), '', FALSE);
  83. }
  84. private function setUpDatabaseMockForDeterminePageId() {
  85. $GLOBALS['TYPO3_DB'] = $this->getMock('t3lib_DB', array('exec_SELECTquery', 'sql_fetch_assoc', 'sql_free_result'));
  86. $GLOBALS['TYPO3_DB']->expects($this->any())->method('exec_SELECTquery')->will(
  87. $this->returnCallback(array($this, 'determinePageIdByRecordDatabaseExecuteCallback'))
  88. );
  89. $GLOBALS['TYPO3_DB']->expects($this->any())->method('sql_fetch_assoc')->will(
  90. $this->returnCallback(array($this, 'determinePageIdByRecordDatabaseFetchCallback'))
  91. );
  92. }
  93. /**
  94. * Tests whether a faulty expression fails.
  95. * @test
  96. */
  97. public function simulateDisabledMatchAllConditionsFailsOnFaultyExpression() {
  98. $this->matchCondition->matchAll = false;
  99. $this->assertFalse($this->matchCondition->match('[nullCondition = This expression would return false in general]'));
  100. }
  101. /**
  102. * Tests whether simulating positive matches for all conditions succeeds.
  103. * @test
  104. */
  105. public function simulateEnabledMatchAllConditionsSucceeds() {
  106. $this->matchCondition->setSimulateMatchResult(true);
  107. $this->assertTrue($this->matchCondition->match('[nullCondition = This expression would return false in general]'));
  108. }
  109. /**
  110. * Tests whether simulating positive matches for specific conditions succeeds.
  111. * @test
  112. */
  113. public function simulateEnabledMatchSpecificConditionsSucceeds() {
  114. $testCondition = '[' . uniqid('test') . ' = Any condition to simulate a positive match]';
  115. $this->matchCondition->setSimulateMatchConditions(array($testCondition));
  116. $this->assertTrue($this->matchCondition->match($testCondition));
  117. }
  118. /**
  119. * Tests whether a condition matches Internet Explorer 7 on Windows.
  120. *
  121. * @return void
  122. * @test
  123. */
  124. public function conditionMatchesInternetExplorer7Windows() {
  125. $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)';
  126. $result = $this->matchCondition->match('[browser = msie] && [version = 7] && [system = winNT]');
  127. $this->assertTrue($result);
  128. }
  129. /**
  130. * Tests whether a condition does not match Internet Explorer 7 on Windows.
  131. *
  132. * @return void
  133. * @test
  134. */
  135. public function conditionDoesNotMatchInternetExplorer7Windows() {
  136. $_SERVER['HTTP_USER_AGENT'] = 'Opera/9.25 (Windows NT 6.0; U; en)';
  137. $result = $this->matchCondition->match('[browser = msie] && [version = 7] && [system = winNT]');
  138. $this->assertFalse($result);
  139. }
  140. /**
  141. * Tests whether a device type condition matches a crawler.
  142. * @test
  143. */
  144. public function deviceConditionMatchesRobot() {
  145. $_SERVER['HTTP_USER_AGENT'] = 'Googlebot/2.1 (+http://www.google.com/bot.html)';
  146. $result = $this->matchCondition->match('[device = robot]');
  147. $this->assertTrue($result);
  148. }
  149. /**
  150. * Tests whether a device type condition does not match a crawler.
  151. * @test
  152. */
  153. public function deviceConditionDoesNotMatchRobot() {
  154. $_SERVER['HTTP_USER_AGENT'] = md5('Some strange user agent');
  155. $result = $this->matchCondition->match('[device = robot]');
  156. $this->assertFalse($result);
  157. }
  158. /**
  159. * Tests whether the language comparison matches.
  160. * @test
  161. */
  162. public function languageConditionMatchesSingleLanguageExpression() {
  163. $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'de-de,de;q=0.8,en-us;q=0.5,en;q=0.3';
  164. $this->assertTrue($this->matchCondition->match('[language = *de*]'));
  165. $this->assertTrue($this->matchCondition->match('[language = *de-de*]'));
  166. }
  167. /**
  168. * Tests whether the language comparison matches.
  169. * @test
  170. */
  171. public function languageConditionMatchesMultipleLanguagesExpression() {
  172. $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'de-de,de;q=0.8,en-us;q=0.5,en;q=0.3';
  173. $this->assertTrue($this->matchCondition->match('[language = *en*,*de*]'));
  174. $this->assertTrue($this->matchCondition->match('[language = *en-us*,*de-de*]'));
  175. }
  176. /**
  177. * Tests whether the language comparison matches.
  178. * @test
  179. */
  180. public function languageConditionMatchesCompleteLanguagesExpression() {
  181. $this->markTestSkipped('This comparison seems to be incomplete in t3lib_matchCondition.');
  182. $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'de-de,de;q=0.8,en-us;q=0.5,en;q=0.3';
  183. $this->assertTrue($this->matchCondition->match('[language = de-de,de;q=0.8]'));
  184. }
  185. /**
  186. * Tests whether usergroup comparison matches.
  187. * @test
  188. */
  189. public function usergroupConditionMatchesSingleGroupId() {
  190. $GLOBALS['BE_USER']->groupList = '13,14,15';
  191. $this->assertTrue($this->matchCondition->match('[usergroup = 13]'));
  192. }
  193. /**
  194. * Tests whether usergroup comparison matches.
  195. * @test
  196. */
  197. public function usergroupConditionMatchesMultipleUserGroupId() {
  198. $GLOBALS['BE_USER']->groupList = '13,14,15';
  199. $this->assertTrue($this->matchCondition->match('[usergroup = 999,15,14,13]'));
  200. }
  201. /**
  202. * Tests whether user comparison matches.
  203. * @test
  204. */
  205. public function loginUserConditionMatchesAnyLoggedInUser() {
  206. $GLOBALS['BE_USER']->user['uid'] = 13;
  207. $this->assertTrue($this->matchCondition->match('[loginUser = *]'));
  208. }
  209. /**
  210. * Tests whether user comparison matches.
  211. * @test
  212. */
  213. public function loginUserConditionMatchesSingleLoggedInUser() {
  214. $GLOBALS['BE_USER']->user['uid'] = 13;
  215. $this->assertTrue($this->matchCondition->match('[loginUser = 13]'));
  216. }
  217. /**
  218. * Tests whether user comparison matches.
  219. * @test
  220. */
  221. public function loginUserConditionDoesNotMatchSingleLoggedInUser() {
  222. $GLOBALS['BE_USER']->user['uid'] = 13;
  223. $this->assertFalse($this->matchCondition->match('[loginUser = 999]'));
  224. }
  225. /**
  226. * Tests whether user comparison matches.
  227. * @test
  228. */
  229. public function loginUserConditionMatchesMultipleLoggedInUsers() {
  230. $GLOBALS['BE_USER']->user['uid'] = 13;
  231. $this->assertTrue($this->matchCondition->match('[loginUser = 999,13]'));
  232. }
  233. /**
  234. * Tests whether checkinf for an admin user matches
  235. * @test
  236. */
  237. public function adminUserConditionMatchesAdminUser() {
  238. $GLOBALS['BE_USER']->user['uid'] = 13;
  239. $GLOBALS['BE_USER']->user['admin'] = 1;
  240. $this->assertTrue($this->matchCondition->match('[adminUser = 1]'));
  241. }
  242. /**
  243. * Tests whether checkinf for an admin user matches
  244. * @test
  245. */
  246. public function adminUserConditionMatchesRegularUser() {
  247. $GLOBALS['BE_USER']->user['uid'] = 14;
  248. $GLOBALS['BE_USER']->user['admin'] = 0;
  249. $this->assertTrue($this->matchCondition->match('[adminUser = 0]'));
  250. }
  251. /**
  252. * Tests whether checkinf for an admin user matches
  253. * @test
  254. */
  255. public function adminUserConditionDoesNotMatchRegularUser() {
  256. $GLOBALS['BE_USER']->user['uid'] = 14;
  257. $GLOBALS['BE_USER']->user['admin'] = 0;
  258. $this->assertFalse($this->matchCondition->match('[adminUser = 1]'));
  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. $this->matchCondition->setRootline($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. $this->matchCondition->setRootline($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. $this->matchCondition->setRootline($this->rootline);
  391. $this->assertFalse($this->matchCondition->match('[treeLevel = 999]'));
  392. }
  393. /**
  394. * Tests whether treeLevel comparison matches when creating new pages.
  395. * @test
  396. */
  397. public function treeLevelConditionMatchesCurrentPageIdWhileEditingNewPage() {
  398. $GLOBALS['SOBE'] = $this->getMock('SC_alt_doc', array());
  399. $GLOBALS['SOBE']->elementsData = array(
  400. array(
  401. 'table' => 'pages',
  402. 'uid' => 'NEW4adc6021e37e7',
  403. 'pid' => 121,
  404. 'cmd' => 'new',
  405. 'deleteAccess' => 0,
  406. ),
  407. );
  408. $GLOBALS['SOBE']->data = array();
  409. $this->matchCondition->setRootline($this->rootline);
  410. $this->matchCondition->setPageId(121);
  411. $this->assertTrue($this->matchCondition->match('[treeLevel = 3]'));
  412. }
  413. /**
  414. * Tests whether treeLevel comparison matches when creating new pages.
  415. * @test
  416. */
  417. public function treeLevelConditionMatchesCurrentPageIdWhileSavingNewPage() {
  418. $GLOBALS['SOBE'] = $this->getMock('SC_alt_doc', array());
  419. $GLOBALS['SOBE']->elementsData = array(
  420. array(
  421. 'table' => 'pages',
  422. /// 999 is the uid of the page that was just created
  423. 'uid' => 999,
  424. 'pid' => 121,
  425. 'cmd' => 'edit',
  426. 'deleteAccess' => 1,
  427. ),
  428. );
  429. $GLOBALS['SOBE']->data = array(
  430. 'pages' => array(
  431. 'NEW4adc6021e37e7' => array(
  432. 'pid' => 121,
  433. ),
  434. ),
  435. );
  436. $this->matchCondition->setRootline($this->rootline);
  437. $this->matchCondition->setPageId(121);
  438. $this->assertTrue($this->matchCondition->match('[treeLevel = 3]'));
  439. }
  440. /**
  441. * Tests whether a page Id is found in the previous rootline entries.
  442. * @test
  443. */
  444. public function PIDupinRootlineConditionMatchesSinglePageIdInRootline() {
  445. $this->matchCondition->setRootline($this->rootline);
  446. $this->matchCondition->setPageId(121);
  447. $this->assertTrue($this->matchCondition->match('[PIDupinRootline = 111]'));
  448. }
  449. /**
  450. * Tests whether a page Id is found in the previous rootline entries.
  451. * @test
  452. */
  453. public function PIDupinRootlineConditionMatchesMultiplePageIdsInRootline() {
  454. $this->matchCondition->setRootline($this->rootline);
  455. $this->matchCondition->setPageId(121);
  456. $this->assertTrue($this->matchCondition->match('[PIDupinRootline = 999,111,101]'));
  457. }
  458. /**
  459. * Tests whether a page Id is found in the previous rootline entries.
  460. * @test
  461. */
  462. public function PIDupinRootlineConditionDoesNotMatchPageIdNotInRootline() {
  463. $this->matchCondition->setRootline($this->rootline);
  464. $this->matchCondition->setPageId(121);
  465. $this->assertFalse($this->matchCondition->match('[PIDupinRootline = 999]'));
  466. }
  467. /**
  468. * Tests whether a page Id is found in the previous rootline entries.
  469. * @test
  470. */
  471. public function PIDupinRootlineConditionDoesNotMatchLastPageIdInRootline() {
  472. $this->matchCondition->setRootline($this->rootline);
  473. $this->matchCondition->setPageId(121);
  474. $this->assertFalse($this->matchCondition->match('[PIDupinRootline = 121]'));
  475. }
  476. /**
  477. * Tests whether a page Id is found in the previous rootline entries.
  478. * @test
  479. */
  480. public function PIDupinRootlineConditionMatchesCurrentPageIdWhileEditingNewPage() {
  481. $GLOBALS['SOBE'] = $this->getMock('SC_alt_doc', array());
  482. $GLOBALS['SOBE']->elementsData = array(
  483. array(
  484. 'table' => 'pages',
  485. 'uid' => 'NEW4adc6021e37e7',
  486. 'pid' => 121,
  487. 'cmd' => 'new',
  488. 'deleteAccess' => 0,
  489. ),
  490. );
  491. $GLOBALS['SOBE']->data = array();
  492. $this->matchCondition->setRootline($this->rootline);
  493. $this->matchCondition->setPageId(121);
  494. $this->assertTrue($this->matchCondition->match('[PIDupinRootline = 121]'));
  495. }
  496. /**
  497. * Tests whether a page Id is found in the previous rootline entries.
  498. * @test
  499. */
  500. public function PIDupinRootlineConditionMatchesCurrentPageIdWhileSavingNewPage() {
  501. $GLOBALS['SOBE'] = $this->getMock('SC_alt_doc', array());
  502. $GLOBALS['SOBE']->elementsData = array(
  503. array(
  504. 'table' => 'pages',
  505. /// 999 is the uid of the page that was just created
  506. 'uid' => 999,
  507. 'pid' => 121,
  508. 'cmd' => 'edit',
  509. 'deleteAccess' => 1,
  510. ),
  511. );
  512. $GLOBALS['SOBE']->data = array(
  513. 'pages' => array(
  514. 'NEW4adc6021e37e7' => array(
  515. 'pid' => 121,
  516. ),
  517. ),
  518. );
  519. $this->matchCondition->setRootline($this->rootline);
  520. $this->matchCondition->setPageId(121);
  521. $this->assertTrue($this->matchCondition->match('[PIDupinRootline = 121]'));
  522. }
  523. /**
  524. * Tests whether a page Id is found in all rootline entries.
  525. * @test
  526. */
  527. public function PIDinRootlineConditionMatchesSinglePageIdInRootline() {
  528. $this->matchCondition->setRootline($this->rootline);
  529. $this->matchCondition->setPageId(121);
  530. $this->assertTrue($this->matchCondition->match('[PIDinRootline = 111]'));
  531. }
  532. /**
  533. * Tests whether a page Id is found in all rootline entries.
  534. * @test
  535. */
  536. public function PIDinRootlineConditionMatchesMultiplePageIdsInRootline() {
  537. $this->matchCondition->setRootline($this->rootline);
  538. $this->matchCondition->setPageId(121);
  539. $this->assertTrue($this->matchCondition->match('[PIDinRootline = 999,111,101]'));
  540. }
  541. /**
  542. * Tests whether a page Id is found in all rootline entries.
  543. * @test
  544. */
  545. public function PIDinRootlineConditionMatchesLastPageIdInRootline() {
  546. $this->matchCondition->setRootline($this->rootline);
  547. $this->matchCondition->setPageId(121);
  548. $this->assertTrue($this->matchCondition->match('[PIDinRootline = 121]'));
  549. }
  550. /**
  551. * Tests whether a page Id is found in all rootline entries.
  552. * @test
  553. */
  554. public function PIDinRootlineConditionDoesNotMatchPageIdNotInRootline() {
  555. $this->matchCondition->setRootline($this->rootline);
  556. $this->matchCondition->setPageId(121);
  557. $this->assertFalse($this->matchCondition->match('[PIDinRootline = 999]'));
  558. }
  559. /**
  560. * Tests whether the compatibility version can be evaluated.
  561. * (e.g. 4.9 is compatible to 4.0 but not to 5.0)
  562. * @test
  563. */
  564. public function compatVersionConditionMatchesOlderRelease() {
  565. $GLOBALS['TYPO3_CONF_VARS']['SYS']['compat_version'] = '4.9';
  566. $this->assertTrue($this->matchCondition->match('[compatVersion = 4.0]'));
  567. }
  568. /**
  569. * Tests whether the compatibility version can be evaluated.
  570. * (e.g. 4.9 is compatible to 4.0 but not to 5.0)
  571. * @test
  572. */
  573. public function compatVersionConditionMatchesSameRelease() {
  574. $GLOBALS['TYPO3_CONF_VARS']['SYS']['compat_version'] = '4.9';
  575. $this->assertTrue($this->matchCondition->match('[compatVersion = 4.9]'));
  576. }
  577. /**
  578. * Tests whether the compatibility version can be evaluated.
  579. * (e.g. 4.9 is compatible to 4.0 but not to 5.0)
  580. * @test
  581. */
  582. public function compatVersionConditionDoesNotMatchNewerRelease() {
  583. $GLOBALS['TYPO3_CONF_VARS']['SYS']['compat_version'] = '4.9';
  584. $this->assertFalse($this->matchCondition->match('[compatVersion = 5.0]'));
  585. }
  586. /**
  587. * Tests whether the generic fetching of variables works with the namespace 'GP'.
  588. * @test
  589. */
  590. public function genericGetVariablesSucceedsWithNamespaceGP() {
  591. $_GET = array('testGet' => 'getTest');
  592. $_POST = array('testPost' => 'postTest');
  593. $this->assertTrue($this->matchCondition->match('[globalString = GP:testGet = getTest]'));
  594. $this->assertTrue($this->matchCondition->match('[globalString = GP:testPost = postTest]'));
  595. }
  596. /**
  597. * Tests whether the generic fetching of variables does not work with the namespace 'TSFE',
  598. * since we are in the backend context here.
  599. * @test
  600. */
  601. public function genericGetVariablesFailsWithNamespaceTSFE() {
  602. $GLOBALS['TSFE'] = new stdClass();
  603. $GLOBALS['TSFE']->id = 1234567;
  604. $this->assertFalse($this->matchCondition->match('[globalString = TSFE:id = 1234567]'));
  605. }
  606. /**
  607. * Tests whether the generic fetching of variables works with the namespace 'ENV'.
  608. * @test
  609. */
  610. public function genericGetVariablesSucceedsWithNamespaceENV() {
  611. $testKey = uniqid('test');
  612. putenv($testKey .'=testValue');
  613. $this->assertTrue($this->matchCondition->match('[globalString = ENV:' . $testKey . ' = testValue]'));
  614. }
  615. /**
  616. * Tests whether the generic fetching of variables works with the namespace 'IENV'.
  617. * @test
  618. */
  619. public function genericGetVariablesSucceedsWithNamespaceIENV() {
  620. $_SERVER['HTTP_HOST'] = t3lib_div::getIndpEnv('TYPO3_HOST_ONLY') . ':1234567';
  621. $this->assertTrue($this->matchCondition->match('[globalString = IENV:TYPO3_PORT = 1234567]'));
  622. }
  623. /**
  624. * Tests whether the generic fetching of variables works with any global namespace.
  625. * @test
  626. */
  627. public function genericGetVariablesSucceedsWithAnyGlobalNamespace() {
  628. $GLOBALS[$this->testGlobalNamespace] = array(
  629. 'first' => 'testFirst',
  630. 'second' => array('third' => 'testThird'),
  631. );
  632. $this->assertTrue($this->matchCondition->match(
  633. '[globalString = ' . $this->testGlobalNamespace . '|first = testFirst]'
  634. ));
  635. $this->assertTrue($this->matchCondition->match(
  636. '[globalString = ' . $this->testGlobalNamespace . '|second|third = testThird]'
  637. ));
  638. }
  639. /**
  640. * Tests whether determining a pageId works.
  641. * @test
  642. */
  643. public function pageIdCanBeDeterminedWhileCallingModuleWithPageTree() {
  644. $_GET['id'] = 999;
  645. $this->matchCondition->match('[globalVar = LIT:10 = 10]');
  646. $this->assertEquals(999, $this->matchCondition->getPageId());
  647. }
  648. /**
  649. * Tests whether determining a pageId works.
  650. * @test
  651. */
  652. public function pageIdCanBeDeterminedWhileEditingAPageRecord() {
  653. $_GET['edit']['pages'][999] = 'edit';
  654. $this->matchCondition->match('[globalVar = LIT:10 = 10]');
  655. $this->assertEquals(999, $this->matchCondition->getPageId());
  656. }
  657. /**
  658. * Tests whether determining a pageId works.
  659. * @test
  660. */
  661. public function pageIdCanBeDeterminedWhileEditingARegularRecord() {
  662. $this->setUpDatabaseMockForDeterminePageId();
  663. $_GET['edit'][$this->testTableName][13] = 'edit';
  664. $this->matchCondition->match('[globalVar = LIT:10 = 10]');
  665. $this->assertEquals(999, $this->matchCondition->getPageId());
  666. }
  667. /**
  668. * Tests whether determining a pageId works.
  669. * @test
  670. */
  671. public function pageIdCanBeDeterminedWhileCreatingARecord() {
  672. $_GET['edit']['pages'][999] = 'new';
  673. $this->matchCondition->match('[globalVar = LIT:10 = 10]');
  674. $this->assertEquals(999, $this->matchCondition->getPageId());
  675. }
  676. /**
  677. * Tests whether determining a pageId works.
  678. * @test
  679. */
  680. public function pageIdCanBeDeterminedWhileCreatingARecordAfterAnExistingRecord() {
  681. $this->setUpDatabaseMockForDeterminePageId();
  682. $_GET['edit'][$this->testTableName][-13] = 'new';
  683. $this->matchCondition->match('[globalVar = LIT:10 = 10]');
  684. $this->assertEquals(999, $this->matchCondition->getPageId());
  685. }
  686. /**
  687. * Tests whether determining a pageId works.
  688. * @test
  689. */
  690. public function pageIdCanBeDeterminedWhileDeletingAPageRecord() {
  691. $_GET['cmd']['pages'][999]['delete'] = 1;
  692. $this->matchCondition->match('[globalVar = LIT:10 = 10]');
  693. $this->assertEquals(999, $this->matchCondition->getPageId());
  694. }
  695. /**
  696. * Tests whether determining a pageId works.
  697. * @test
  698. */
  699. public function pageIdCanBeDeterminedWhileCopyingARecordToAnotherPage() {
  700. $_GET['cmd']['pages'][121]['copy'] = 999;
  701. $this->matchCondition->match('[globalVar = LIT:10 = 10]');
  702. $this->assertEquals(999, $this->matchCondition->getPageId());
  703. }
  704. /**
  705. * Tests whether determining a pageId works.
  706. * @test
  707. */
  708. public function pageIdCanBeDeterminedWhileCopyingARecordAfterAnExistingRecord() {
  709. $this->setUpDatabaseMockForDeterminePageId();
  710. $_GET['cmd'][$this->testTableName][121]['copy'] = -13;
  711. $this->matchCondition->match('[globalVar = LIT:10 = 10]');
  712. $this->assertEquals(999, $this->matchCondition->getPageId());
  713. }
  714. /**
  715. * Tests whether determining a pageId works.
  716. * @test
  717. */
  718. public function pageIdCanBeDeterminedWhileMovingARecordToAnotherPage() {
  719. $_GET['cmd']['pages'][121]['move'] = 999;
  720. $this->matchCondition->match('[globalVar = LIT:10 = 10]');
  721. $this->assertEquals(999, $this->matchCondition->getPageId());
  722. }
  723. /**
  724. * Callback method for pageIdCanBeDetermined test cases.
  725. * Simulates TYPO3_DB->exec_SELECTquery().
  726. *
  727. * @param string $fields
  728. * @param string $table
  729. * @param string $where
  730. * @return mixed
  731. */
  732. public function determinePageIdByRecordDatabaseExecuteCallback($fields, $table, $where) {
  733. if ($table === $this->testTableName) {
  734. return array(
  735. 'scope' => $this->testTableName,
  736. 'processed' => false,
  737. 'data' => array(
  738. 'pid' => 999,
  739. ),
  740. );
  741. } else {
  742. return FALSE;
  743. }
  744. }
  745. /**
  746. * Callback method for pageIdCanBeDetermined test cases.
  747. * Simulates TYPO3_DB->sql_fetch_assoc().
  748. *
  749. * @param mixed $resource
  750. * @return mixed
  751. */
  752. public function determinePageIdByRecordDatabaseFetchCallback(&$resource) {
  753. if (is_array($resource) && !$resource['processed'] && $resource['scope'] === $this->testTableName) {
  754. $resource['processed'] = true;
  755. return $resource['data'];
  756. } else {
  757. return FALSE;
  758. }
  759. }
  760. }
  761. ?>