Cleanup: Updated copyright comments
[Packages/TYPO3.CMS.git] / tests / t3lib / matchcondition / t3lib_matchcondition_backendTest.php
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
26 /**
27 * Testcase for class t3lib_matchCondition_frontend.
28 *
29 * @author Oliver Hader <oliver@typo3.org>
30 * @package TYPO3
31 * @subpackage t3lib
32 */
33 class t3lib_matchCondition_backendTest extends tx_phpunit_testcase {
34 /**
35 * @var array
36 */
37 private $backupGlobalVariables;
38
39 /**
40 * @var array
41 */
42 private $rootline;
43
44 /**
45 * @var t3lib_matchCondition_backend
46 */
47 private $matchCondition;
48
49 /**
50 * @var string
51 */
52 private $testTableName;
53
54 public function setUp() {
55 $this->backupGlobalVariables = array(
56 '_ENV' => $_ENV,
57 '_GET' => $_GET,
58 '_POST' => $_POST,
59 '_SERVER' => $_SERVER,
60 'TCA' => $GLOBALS['TCA'],
61 'TYPO3_DB' => $GLOBALS['TYPO3_DB'],
62 'TYPO3_CONF_VARS' => $GLOBALS['TYPO3_CONF_VARS'],
63 'T3_VAR' => $GLOBALS['T3_VAR'],
64 'BE_USER' => $GLOBALS['BE_USER'],
65 'SOBE' => $GLOBALS['SOBE'],
66 );
67
68 $this->testTableName = 't3lib_matchCondition_backend_testTable';
69 $this->testGlobalNamespace = uniqid('TEST');
70
71 $GLOBALS['TCA'][$this->testTableName] = array('ctrl' => array());
72 $GLOBALS[$this->testGlobalNamespace] = array();
73
74 $this->setUpBackend();
75
76 $this->matchCondition = t3lib_div::makeInstance('t3lib_matchCondition_backend');
77 }
78
79 public function tearDown() {
80 foreach ($this->backupGlobalVariables as $key => $data) {
81 $GLOBALS[$key] = $data;
82 }
83
84 unset($this->matchCondition);
85 unset($this->backupGlobalVariables);
86 unset($GLOBALS[$this->testGlobalNamespace]);
87 }
88
89 private function setUpBackend() {
90 $this->rootline = array(
91 2 => array('uid' => 121, 'pid' => 111),
92 1 => array('uid' => 111, 'pid' => 101,),
93 0 => array('uid' => 101, 'pid' => 0,),
94 );
95
96 $GLOBALS['BE_USER'] = $this->getMock('beUserAuth', array(), array(), '', FALSE);
97 }
98
99 private function setUpDatabaseMockForDeterminePageId() {
100 $GLOBALS['TYPO3_DB'] = $this->getMock('t3lib_DB', array('exec_SELECTquery', 'sql_fetch_assoc', 'sql_free_result'));
101 $GLOBALS['TYPO3_DB']->expects($this->any())->method('exec_SELECTquery')->will(
102 $this->returnCallback(array($this, 'determinePageIdByRecordDatabaseExecuteCallback'))
103 );
104 $GLOBALS['TYPO3_DB']->expects($this->any())->method('sql_fetch_assoc')->will(
105 $this->returnCallback(array($this, 'determinePageIdByRecordDatabaseFetchCallback'))
106 );
107 }
108
109 /**
110 * Tests whether a faulty expression fails.
111 * @test
112 */
113 public function simulateDisabledMatchAllConditionsFailsOnFaultyExpression() {
114 $this->matchCondition->matchAll = false;
115 $this->assertFalse($this->matchCondition->match('[nullCondition = This expression would return false in general]'));
116 }
117
118 /**
119 * Tests whether simulating positive matches for all conditions succeeds.
120 * @test
121 */
122 public function simulateEnabledMatchAllConditionsSucceeds() {
123 $this->matchCondition->setSimulateMatchResult(true);
124 $this->assertTrue($this->matchCondition->match('[nullCondition = This expression would return false in general]'));
125 }
126
127 /**
128 * Tests whether simulating positive matches for specific conditions succeeds.
129 * @test
130 */
131 public function simulateEnabledMatchSpecificConditionsSucceeds() {
132 $testCondition = '[' . uniqid('test') . ' = Any condition to simulate a positive match]';
133 $this->matchCondition->setSimulateMatchConditions(array($testCondition));
134 $this->assertTrue($this->matchCondition->match($testCondition));
135 }
136
137 /**
138 * Tests whether a condition matches Internet Explorer 7 on Windows.
139 *
140 * @return void
141 * @test
142 */
143 public function conditionMatchesInternetExplorer7Windows() {
144 $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)';
145 $result = $this->matchCondition->match('[browser = msie] && [version = 7] && [system = winNT]');
146 $this->assertTrue($result);
147 }
148
149 /**
150 * Tests whether a condition does not match Internet Explorer 7 on Windows.
151 *
152 * @return void
153 * @test
154 */
155 public function conditionDoesNotMatchInternetExplorer7Windows() {
156 $_SERVER['HTTP_USER_AGENT'] = 'Opera/9.25 (Windows NT 6.0; U; en)';
157 $result = $this->matchCondition->match('[browser = msie] && [version = 7] && [system = winNT]');
158 $this->assertFalse($result);
159 }
160
161 /**
162 * Tests whether a device type condition matches a crawler.
163 * @test
164 */
165 public function deviceConditionMatchesRobot() {
166 $_SERVER['HTTP_USER_AGENT'] = 'Googlebot/2.1 (+http://www.google.com/bot.html)';
167 $result = $this->matchCondition->match('[device = robot]');
168 $this->assertTrue($result);
169 }
170
171 /**
172 * Tests whether a device type condition does not match a crawler.
173 * @test
174 */
175 public function deviceConditionDoesNotMatchRobot() {
176 $_SERVER['HTTP_USER_AGENT'] = md5('Some strange user agent');
177 $result = $this->matchCondition->match('[device = robot]');
178 $this->assertFalse($result);
179 }
180
181 /**
182 * Tests whether the language comparison matches.
183 * @test
184 */
185 public function languageConditionMatchesSingleLanguageExpression() {
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 = *de*]'));
188 $this->assertTrue($this->matchCondition->match('[language = *de-de*]'));
189 }
190
191 /**
192 * Tests whether the language comparison matches.
193 * @test
194 */
195 public function languageConditionMatchesMultipleLanguagesExpression() {
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 = *en*,*de*]'));
198 $this->assertTrue($this->matchCondition->match('[language = *en-us*,*de-de*]'));
199 }
200
201 /**
202 * Tests whether the language comparison matches.
203 * @test
204 */
205 public function languageConditionMatchesCompleteLanguagesExpression() {
206 $this->markTestSkipped('This comparison seems to be incomplete in t3lib_matchCondition.');
207
208 $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'de-de,de;q=0.8,en-us;q=0.5,en;q=0.3';
209 $this->assertTrue($this->matchCondition->match('[language = de-de,de;q=0.8]'));
210 }
211
212 /**
213 * Tests whether usergroup comparison matches.
214 * @test
215 */
216 public function usergroupConditionMatchesSingleGroupId() {
217 $GLOBALS['BE_USER']->groupList = '13,14,15';
218 $this->assertTrue($this->matchCondition->match('[usergroup = 13]'));
219 }
220
221 /**
222 * Tests whether usergroup comparison matches.
223 * @test
224 */
225 public function usergroupConditionMatchesMultipleUserGroupId() {
226 $GLOBALS['BE_USER']->groupList = '13,14,15';
227 $this->assertTrue($this->matchCondition->match('[usergroup = 999,15,14,13]'));
228 }
229
230 /**
231 * Tests whether user comparison matches.
232 * @test
233 */
234 public function loginUserConditionMatchesAnyLoggedInUser() {
235 $GLOBALS['BE_USER']->user['uid'] = 13;
236 $this->assertTrue($this->matchCondition->match('[loginUser = *]'));
237 }
238
239 /**
240 * Tests whether user comparison matches.
241 * @test
242 */
243 public function loginUserConditionMatchesSingleLoggedInUser() {
244 $GLOBALS['BE_USER']->user['uid'] = 13;
245 $this->assertTrue($this->matchCondition->match('[loginUser = 13]'));
246 }
247
248 /**
249 * Tests whether user comparison matches.
250 * @test
251 */
252 public function loginUserConditionDoesNotMatchSingleLoggedInUser() {
253 $GLOBALS['BE_USER']->user['uid'] = 13;
254 $this->assertFalse($this->matchCondition->match('[loginUser = 999]'));
255 }
256
257 /**
258 * Tests whether user comparison matches.
259 * @test
260 */
261 public function loginUserConditionMatchesMultipleLoggedInUsers() {
262 $GLOBALS['BE_USER']->user['uid'] = 13;
263 $this->assertTrue($this->matchCondition->match('[loginUser = 999,13]'));
264 }
265
266 /**
267 * Tests whether checkinf for an admin user matches
268 * @test
269 */
270 public function adminUserConditionMatchesAdminUser() {
271 $GLOBALS['BE_USER']->user['uid'] = 13;
272 $GLOBALS['BE_USER']->user['admin'] = 1;
273 $this->assertTrue($this->matchCondition->match('[adminUser = 1]'));
274 }
275
276 /**
277 * Tests whether checkinf for an admin user matches
278 * @test
279 */
280 public function adminUserConditionMatchesRegularUser() {
281 $GLOBALS['BE_USER']->user['uid'] = 14;
282 $GLOBALS['BE_USER']->user['admin'] = 0;
283 $this->assertTrue($this->matchCondition->match('[adminUser = 0]'));
284 }
285
286 /**
287 * Tests whether checkinf for an admin user matches
288 * @test
289 */
290 public function adminUserConditionDoesNotMatchRegularUser() {
291 $GLOBALS['BE_USER']->user['uid'] = 14;
292 $GLOBALS['BE_USER']->user['admin'] = 0;
293 $this->assertFalse($this->matchCondition->match('[adminUser = 1]'));
294 }
295
296 /**
297 * Tests whether numerical comparison matches.
298 * @test
299 */
300 public function globalVarConditionMatchesOnEqualExpression() {
301 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 = 10]'));
302 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 = 10.1]'));
303
304 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 == 10]'));
305 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 == 10.1]'));
306 }
307
308 /**
309 * Tests whether numerical comparison matches.
310 * @test
311 */
312 public function globalVarConditionMatchesOnNotEqualExpression() {
313 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 != 20]'));
314 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 != 10.2]'));
315 }
316
317 /**
318 * Tests whether numerical comparison matches.
319 * @test
320 */
321 public function globalVarConditionMatchesOnLowerThanExpression() {
322 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 < 20]'));
323 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 < 10.2]'));
324 }
325
326 /**
327 * Tests whether numerical comparison matches.
328 * @test
329 */
330 public function globalVarConditionMatchesOnLowerThanOrEqualExpression() {
331 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 <= 10]'));
332 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 <= 20]'));
333
334 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 <= 10.1]'));
335 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 <= 10.2]'));
336 }
337
338 /**
339 * Tests whether numerical comparison matches.
340 * @test
341 */
342 public function globalVarConditionMatchesOnGreaterThanExpression() {
343 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:20 > 10]'));
344 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.2 > 10.1]'));
345 }
346
347 /**
348 * Tests whether numerical comparison matches.
349 * @test
350 */
351 public function globalVarConditionMatchesOnGreaterThanOrEqualExpression() {
352 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 >= 10]'));
353 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:20 >= 10]'));
354
355 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 >= 10.1]'));
356 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.2 >= 10.1]'));
357 }
358
359 /**
360 * Tests whether numerical comparison matches.
361 * @test
362 */
363 public function globalVarConditionMatchesOnEmptyExpressionWithNoValueSet() {
364 $testKey = uniqid('test');
365 $this->assertTrue($this->matchCondition->match('[globalVar = GP:' . $testKey . '=]'));
366 $this->assertTrue($this->matchCondition->match('[globalVar = GP:' . $testKey . ' = ]'));
367 }
368
369 /**
370 * Tests whether numerical comparison matches.
371 * @test
372 */
373 public function globalVarConditionDoesNotMatchOnEmptyExpressionWithValueSetToZero() {
374 $testKey = uniqid('test');
375
376 $_GET = array();
377 $_POST = array($testKey => 0);
378
379 $this->assertFalse($this->matchCondition->match('[globalVar = GP:' . $testKey . '=]'));
380 $this->assertFalse($this->matchCondition->match('[globalVar = GP:' . $testKey . ' = ]'));
381 }
382
383 /**
384 * Tests whether string comparison matches.
385 * @test
386 */
387 public function globalStringConditionMatchesOnEqualExpression() {
388 $this->assertTrue($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = TYPO3.Test.Condition]'));
389 $this->assertFalse($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = TYPO3]'));
390 }
391
392 /**
393 * Tests whether string comparison matches.
394 * @test
395 */
396 public function globalStringConditionMatchesWildcardExpression() {
397 $this->assertTrue($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = TYPO3?Test?Condition]'));
398 $this->assertTrue($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = TYPO3.T*t.Condition]'));
399 $this->assertTrue($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = TYPO3?T*t?Condition]'));
400 }
401
402 /**
403 * Tests whether string comparison matches.
404 * @test
405 */
406 public function globalStringConditionMatchesRegularExpression() {
407 $this->assertTrue($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = /^[A-Za-z3.]+$/]'));
408 $this->assertTrue($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = /^TYPO3\..+Condition$/]'));
409 $this->assertFalse($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = /^FALSE/]'));
410 }
411
412 /**
413 * Tests whether string comparison matches.
414 * @test
415 */
416 public function globalStringConditionMatchesEmptyRegularExpression() {
417 $testKey = uniqid('test');
418 $_SERVER[$testKey] = '';
419 $this->assertTrue($this->matchCondition->match('[globalString = _SERVER|' . $testKey . ' = /^$/]'));
420 }
421
422 /**
423 * Tests whether treeLevel comparison matches.
424 * @test
425 */
426 public function treeLevelConditionMatchesSingleValue() {
427 $this->matchCondition->setRootline($this->rootline);
428 $this->assertTrue($this->matchCondition->match('[treeLevel = 2]'));
429 }
430
431 /**
432 * Tests whether treeLevel comparison matches.
433 * @test
434 */
435 public function treeLevelConditionMatchesMultipleValues() {
436 $this->matchCondition->setRootline($this->rootline);
437 $this->assertTrue($this->matchCondition->match('[treeLevel = 999,998,2]'));
438 }
439
440 /**
441 * Tests whether treeLevel comparison matches.
442 * @test
443 */
444 public function treeLevelConditionDoesNotMatchFaultyValue() {
445 $this->matchCondition->setRootline($this->rootline);
446 $this->assertFalse($this->matchCondition->match('[treeLevel = 999]'));
447 }
448
449 /**
450 * Tests whether treeLevel comparison matches when creating new pages.
451 * @test
452 */
453 public function treeLevelConditionMatchesCurrentPageIdWhileEditingNewPage() {
454 $GLOBALS['SOBE'] = $this->getMock('SC_alt_doc', array());
455 $GLOBALS['SOBE']->elementsData = array(
456 array(
457 'table' => 'pages',
458 'uid' => 'NEW4adc6021e37e7',
459 'pid' => 121,
460 'cmd' => 'new',
461 'deleteAccess' => 0,
462 ),
463 );
464 $GLOBALS['SOBE']->data = array();
465
466 $this->matchCondition->setRootline($this->rootline);
467 $this->matchCondition->setPageId(121);
468 $this->assertTrue($this->matchCondition->match('[treeLevel = 3]'));
469 }
470
471 /**
472 * Tests whether treeLevel comparison matches when creating new pages.
473 * @test
474 */
475 public function treeLevelConditionMatchesCurrentPageIdWhileSavingNewPage() {
476 $GLOBALS['SOBE'] = $this->getMock('SC_alt_doc', array());
477 $GLOBALS['SOBE']->elementsData = array(
478 array(
479 'table' => 'pages',
480 /// 999 is the uid of the page that was just created
481 'uid' => 999,
482 'pid' => 121,
483 'cmd' => 'edit',
484 'deleteAccess' => 1,
485 ),
486 );
487 $GLOBALS['SOBE']->data = array(
488 'pages' => array(
489 'NEW4adc6021e37e7' => array(
490 'pid' => 121,
491 ),
492 ),
493 );
494
495 $this->matchCondition->setRootline($this->rootline);
496 $this->matchCondition->setPageId(121);
497 $this->assertTrue($this->matchCondition->match('[treeLevel = 3]'));
498 }
499
500 /**
501 * Tests whether a page Id is found in the previous rootline entries.
502 * @test
503 */
504 public function PIDupinRootlineConditionMatchesSinglePageIdInRootline() {
505 $this->matchCondition->setRootline($this->rootline);
506 $this->matchCondition->setPageId(121);
507 $this->assertTrue($this->matchCondition->match('[PIDupinRootline = 111]'));
508 }
509
510 /**
511 * Tests whether a page Id is found in the previous rootline entries.
512 * @test
513 */
514 public function PIDupinRootlineConditionMatchesMultiplePageIdsInRootline() {
515 $this->matchCondition->setRootline($this->rootline);
516 $this->matchCondition->setPageId(121);
517 $this->assertTrue($this->matchCondition->match('[PIDupinRootline = 999,111,101]'));
518 }
519
520 /**
521 * Tests whether a page Id is found in the previous rootline entries.
522 * @test
523 */
524 public function PIDupinRootlineConditionDoesNotMatchPageIdNotInRootline() {
525 $this->matchCondition->setRootline($this->rootline);
526 $this->matchCondition->setPageId(121);
527 $this->assertFalse($this->matchCondition->match('[PIDupinRootline = 999]'));
528 }
529
530 /**
531 * Tests whether a page Id is found in the previous rootline entries.
532 * @test
533 */
534 public function PIDupinRootlineConditionDoesNotMatchLastPageIdInRootline() {
535 $this->matchCondition->setRootline($this->rootline);
536 $this->matchCondition->setPageId(121);
537 $this->assertFalse($this->matchCondition->match('[PIDupinRootline = 121]'));
538 }
539
540 /**
541 * Tests whether a page Id is found in the previous rootline entries.
542 * @test
543 */
544 public function PIDupinRootlineConditionMatchesCurrentPageIdWhileEditingNewPage() {
545 $GLOBALS['SOBE'] = $this->getMock('SC_alt_doc', array());
546 $GLOBALS['SOBE']->elementsData = array(
547 array(
548 'table' => 'pages',
549 'uid' => 'NEW4adc6021e37e7',
550 'pid' => 121,
551 'cmd' => 'new',
552 'deleteAccess' => 0,
553 ),
554 );
555 $GLOBALS['SOBE']->data = array();
556
557 $this->matchCondition->setRootline($this->rootline);
558 $this->matchCondition->setPageId(121);
559 $this->assertTrue($this->matchCondition->match('[PIDupinRootline = 121]'));
560 }
561
562 /**
563 * Tests whether a page Id is found in the previous rootline entries.
564 * @test
565 */
566 public function PIDupinRootlineConditionMatchesCurrentPageIdWhileSavingNewPage() {
567 $GLOBALS['SOBE'] = $this->getMock('SC_alt_doc', array());
568 $GLOBALS['SOBE']->elementsData = array(
569 array(
570 'table' => 'pages',
571 /// 999 is the uid of the page that was just created
572 'uid' => 999,
573 'pid' => 121,
574 'cmd' => 'edit',
575 'deleteAccess' => 1,
576 ),
577 );
578 $GLOBALS['SOBE']->data = array(
579 'pages' => array(
580 'NEW4adc6021e37e7' => array(
581 'pid' => 121,
582 ),
583 ),
584 );
585
586 $this->matchCondition->setRootline($this->rootline);
587 $this->matchCondition->setPageId(121);
588 $this->assertTrue($this->matchCondition->match('[PIDupinRootline = 121]'));
589 }
590
591 /**
592 * Tests whether a page Id is found in all rootline entries.
593 * @test
594 */
595 public function PIDinRootlineConditionMatchesSinglePageIdInRootline() {
596 $this->matchCondition->setRootline($this->rootline);
597 $this->matchCondition->setPageId(121);
598 $this->assertTrue($this->matchCondition->match('[PIDinRootline = 111]'));
599 }
600
601 /**
602 * Tests whether a page Id is found in all rootline entries.
603 * @test
604 */
605 public function PIDinRootlineConditionMatchesMultiplePageIdsInRootline() {
606 $this->matchCondition->setRootline($this->rootline);
607 $this->matchCondition->setPageId(121);
608 $this->assertTrue($this->matchCondition->match('[PIDinRootline = 999,111,101]'));
609 }
610
611 /**
612 * Tests whether a page Id is found in all rootline entries.
613 * @test
614 */
615 public function PIDinRootlineConditionMatchesLastPageIdInRootline() {
616 $this->matchCondition->setRootline($this->rootline);
617 $this->matchCondition->setPageId(121);
618 $this->assertTrue($this->matchCondition->match('[PIDinRootline = 121]'));
619 }
620
621 /**
622 * Tests whether a page Id is found in all rootline entries.
623 * @test
624 */
625 public function PIDinRootlineConditionDoesNotMatchPageIdNotInRootline() {
626 $this->matchCondition->setRootline($this->rootline);
627 $this->matchCondition->setPageId(121);
628 $this->assertFalse($this->matchCondition->match('[PIDinRootline = 999]'));
629 }
630
631 /**
632 * Tests whether the compatibility version can be evaluated.
633 * (e.g. 4.9 is compatible to 4.0 but not to 5.0)
634 * @test
635 */
636 public function compatVersionConditionMatchesOlderRelease() {
637 $GLOBALS['TYPO3_CONF_VARS']['SYS']['compat_version'] = '4.9';
638 $this->assertTrue($this->matchCondition->match('[compatVersion = 4.0]'));
639 }
640
641 /**
642 * Tests whether the compatibility version can be evaluated.
643 * (e.g. 4.9 is compatible to 4.0 but not to 5.0)
644 * @test
645 */
646 public function compatVersionConditionMatchesSameRelease() {
647 $GLOBALS['TYPO3_CONF_VARS']['SYS']['compat_version'] = '4.9';
648 $this->assertTrue($this->matchCondition->match('[compatVersion = 4.9]'));
649 }
650
651 /**
652 * Tests whether the compatibility version can be evaluated.
653 * (e.g. 4.9 is compatible to 4.0 but not to 5.0)
654 * @test
655 */
656 public function compatVersionConditionDoesNotMatchNewerRelease() {
657 $GLOBALS['TYPO3_CONF_VARS']['SYS']['compat_version'] = '4.9';
658 $this->assertFalse($this->matchCondition->match('[compatVersion = 5.0]'));
659 }
660
661 /**
662 * Tests whether the generic fetching of variables works with the namespace 'GP'.
663 * @test
664 */
665 public function genericGetVariablesSucceedsWithNamespaceGP() {
666 $_GET = array('testGet' => 'getTest');
667 $_POST = array('testPost' => 'postTest');
668
669 $this->assertTrue($this->matchCondition->match('[globalString = GP:testGet = getTest]'));
670 $this->assertTrue($this->matchCondition->match('[globalString = GP:testPost = postTest]'));
671 }
672
673 /**
674 * Tests whether the generic fetching of variables does not work with the namespace 'TSFE',
675 * since we are in the backend context here.
676 * @test
677 */
678 public function genericGetVariablesFailsWithNamespaceTSFE() {
679 $GLOBALS['TSFE'] = new stdClass();
680 $GLOBALS['TSFE']->id = 1234567;
681
682 $this->assertFalse($this->matchCondition->match('[globalString = TSFE:id = 1234567]'));
683 }
684
685 /**
686 * Tests whether the generic fetching of variables works with the namespace 'ENV'.
687 * @test
688 */
689 public function genericGetVariablesSucceedsWithNamespaceENV() {
690 $testKey = uniqid('test');
691 putenv($testKey .'=testValue');
692
693 $this->assertTrue($this->matchCondition->match('[globalString = ENV:' . $testKey . ' = testValue]'));
694 }
695
696 /**
697 * Tests whether the generic fetching of variables works with the namespace 'IENV'.
698 * @test
699 */
700 public function genericGetVariablesSucceedsWithNamespaceIENV() {
701 $_SERVER['HTTP_HOST'] = t3lib_div::getIndpEnv('TYPO3_HOST_ONLY') . ':1234567';
702 $this->assertTrue($this->matchCondition->match('[globalString = IENV:TYPO3_PORT = 1234567]'));
703 }
704
705 /**
706 * Tests whether the generic fetching of variables works with any global namespace.
707 * @test
708 */
709 public function genericGetVariablesSucceedsWithAnyGlobalNamespace() {
710 $GLOBALS[$this->testGlobalNamespace] = array(
711 'first' => 'testFirst',
712 'second' => array('third' => 'testThird'),
713 );
714
715 $this->assertTrue($this->matchCondition->match(
716 '[globalString = ' . $this->testGlobalNamespace . '|first = testFirst]'
717 ));
718 $this->assertTrue($this->matchCondition->match(
719 '[globalString = ' . $this->testGlobalNamespace . '|second|third = testThird]'
720 ));
721 }
722
723 /**
724 * Tests whether determining a pageId works.
725 * @test
726 */
727 public function pageIdCanBeDeterminedWhileCallingModuleWithPageTree() {
728 $_GET['id'] = 999;
729
730 $this->matchCondition->match('[globalVar = LIT:10 = 10]');
731 $this->assertEquals(999, $this->matchCondition->getPageId());
732 }
733
734 /**
735 * Tests whether determining a pageId works.
736 * @test
737 */
738 public function pageIdCanBeDeterminedWhileEditingAPageRecord() {
739 $_GET['edit']['pages'][999] = 'edit';
740
741 $this->matchCondition->match('[globalVar = LIT:10 = 10]');
742 $this->assertEquals(999, $this->matchCondition->getPageId());
743 }
744
745 /**
746 * Tests whether determining a pageId works.
747 * @test
748 */
749 public function pageIdCanBeDeterminedWhileEditingARegularRecord() {
750 $this->setUpDatabaseMockForDeterminePageId();
751
752 $_GET['edit'][$this->testTableName][13] = 'edit';
753
754 $this->matchCondition->match('[globalVar = LIT:10 = 10]');
755 $this->assertEquals(999, $this->matchCondition->getPageId());
756 }
757
758 /**
759 * Tests whether determining a pageId works.
760 * @test
761 */
762 public function pageIdCanBeDeterminedWhileCreatingARecord() {
763 $_GET['edit']['pages'][999] = 'new';
764
765 $this->matchCondition->match('[globalVar = LIT:10 = 10]');
766 $this->assertEquals(999, $this->matchCondition->getPageId());
767 }
768
769 /**
770 * Tests whether determining a pageId works.
771 * @test
772 */
773 public function pageIdCanBeDeterminedWhileCreatingARecordAfterAnExistingRecord() {
774 $this->setUpDatabaseMockForDeterminePageId();
775
776 $_GET['edit'][$this->testTableName][-13] = 'new';
777
778 $this->matchCondition->match('[globalVar = LIT:10 = 10]');
779 $this->assertEquals(999, $this->matchCondition->getPageId());
780 }
781
782 /**
783 * Tests whether determining a pageId works.
784 * @test
785 */
786 public function pageIdCanBeDeterminedWhileDeletingAPageRecord() {
787 $_GET['cmd']['pages'][999]['delete'] = 1;
788
789 $this->matchCondition->match('[globalVar = LIT:10 = 10]');
790 $this->assertEquals(999, $this->matchCondition->getPageId());
791 }
792
793 /**
794 * Tests whether determining a pageId works.
795 * @test
796 */
797 public function pageIdCanBeDeterminedWhileCopyingARecordToAnotherPage() {
798 $_GET['cmd']['pages'][121]['copy'] = 999;
799
800 $this->matchCondition->match('[globalVar = LIT:10 = 10]');
801 $this->assertEquals(999, $this->matchCondition->getPageId());
802 }
803
804 /**
805 * Tests whether determining a pageId works.
806 * @test
807 */
808 public function pageIdCanBeDeterminedWhileCopyingARecordAfterAnExistingRecord() {
809 $this->setUpDatabaseMockForDeterminePageId();
810
811 $_GET['cmd'][$this->testTableName][121]['copy'] = -13;
812
813 $this->matchCondition->match('[globalVar = LIT:10 = 10]');
814 $this->assertEquals(999, $this->matchCondition->getPageId());
815 }
816
817 /**
818 * Tests whether determining a pageId works.
819 * @test
820 */
821 public function pageIdCanBeDeterminedWhileMovingARecordToAnotherPage() {
822 $_GET['cmd']['pages'][121]['move'] = 999;
823
824 $this->matchCondition->match('[globalVar = LIT:10 = 10]');
825 $this->assertEquals(999, $this->matchCondition->getPageId());
826 }
827
828 /**
829 * Callback method for pageIdCanBeDetermined test cases.
830 * Simulates TYPO3_DB->exec_SELECTquery().
831 *
832 * @param string $fields
833 * @param string $table
834 * @param string $where
835 * @return mixed
836 */
837 public function determinePageIdByRecordDatabaseExecuteCallback($fields, $table, $where) {
838 if ($table === $this->testTableName) {
839 return array(
840 'scope' => $this->testTableName,
841 'processed' => false,
842 'data' => array(
843 'pid' => 999,
844 ),
845 );
846 } else {
847 return FALSE;
848 }
849 }
850
851 /**
852 * Callback method for pageIdCanBeDetermined test cases.
853 * Simulates TYPO3_DB->sql_fetch_assoc().
854 *
855 * @param mixed $resource
856 * @return mixed
857 */
858 public function determinePageIdByRecordDatabaseFetchCallback(&$resource) {
859 if (is_array($resource) && !$resource['processed'] && $resource['scope'] === $this->testTableName) {
860 $resource['processed'] = true;
861 return $resource['data'];
862 } else {
863 return FALSE;
864 }
865 }
866 }
867 ?>