TYPO3 CMS  TYPO3_6-2
ConditionMatcherTest.php
Go to the documentation of this file.
1 <?php
3 
23 
28 
32  protected $matchCondition;
33 
34  public function setUp() {
35  $this->testGlobalNamespace = $this->getUniqueId('TEST');
37  $GLOBALS['TSFE'] = new \stdClass();
38  $GLOBALS['TSFE']->tmpl = new \stdClass();
39  $GLOBALS['TSFE']->tmpl->rootLine = array(
40  2 => array('uid' => 121, 'pid' => 111),
41  1 => array('uid' => 111, 'pid' => 101),
42  0 => array('uid' => 101, 'pid' => 0)
43  );
44  $this->matchCondition = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Configuration\\TypoScript\\ConditionMatching\\ConditionMatcher');
45  }
46 
53  $this->matchCondition->matchAll = FALSE;
54  $this->assertFalse($this->matchCondition->match('[nullCondition = This expression would return FALSE in general]'));
55  }
56 
63  $this->matchCondition->setSimulateMatchResult(TRUE);
64  $this->assertTrue($this->matchCondition->match('[nullCondition = This expression would return FALSE in general]'));
65  }
66 
73  $testCondition = '[' . $this->getUniqueId('test') . ' = Any condition to simulate a positive match]';
74  $this->matchCondition->setSimulateMatchConditions(array($testCondition));
75  $this->assertTrue($this->matchCondition->match($testCondition));
76  }
77 
85  $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)';
86  $result = $this->matchCondition->match('[browser = msie] && [version = 7] && [system = winNT]');
87  $this->assertTrue($result);
88  }
89 
97  $_SERVER['HTTP_USER_AGENT'] = 'Opera/9.25 (Windows NT 6.0; U; en)';
98  $result = $this->matchCondition->match('[browser = msie] && [version = 7] && [system = winNT]');
99  $this->assertFalse($result);
100  }
101 
108  $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7W367a Safari/531.21.10';
109  $result = $this->matchCondition->match('[system = iOS]');
110  $this->assertTrue($result);
111  }
112 
119  $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7W367a Safari/531.21.10';
120  $result = $this->matchCondition->match('[system = mac]');
121  $this->assertTrue($result);
122  }
123 
130  $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; SV1)';
131  $result = $this->matchCondition->match('[system = win2k]');
132  $this->assertTrue($result);
133  }
134 
141  $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; SV1)';
142  $result = $this->matchCondition->match('[system = winNT]');
143  $this->assertTrue($result);
144  }
145 
152  $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 4.0)';
153  $result = $this->matchCondition->match('[system = winNT]');
154  $this->assertTrue($result);
155  }
156 
163  $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Linux; U; Android 2.3; en-US; sdk Build/GRH55) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1';
164  $result = $this->matchCondition->match('[system = android]');
165  $this->assertTrue($result);
166  }
167 
174  $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Linux; U; Android 2.3; en-US; sdk Build/GRH55) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1';
175  $result = $this->matchCondition->match('[system = linux]');
176  $this->assertTrue($result);
177  }
178 
184  public function deviceConditionMatchesRobot() {
185  $_SERVER['HTTP_USER_AGENT'] = 'Googlebot/2.1 (+http://www.google.com/bot.html)';
186  $result = $this->matchCondition->match('[device = robot]');
187  $this->assertTrue($result);
188  }
189 
196  $_SERVER['HTTP_USER_AGENT'] = md5('Some strange user agent');
197  $result = $this->matchCondition->match('[device = robot]');
198  $this->assertFalse($result);
199  }
200 
207  $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'de-de,de;q=0.8,en-us;q=0.5,en;q=0.3';
208  $this->assertTrue($this->matchCondition->match('[language = *de*]'));
209  $this->assertTrue($this->matchCondition->match('[language = *de-de*]'));
210  }
211 
218  $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'de-de,de;q=0.8,en-us;q=0.5,en;q=0.3';
219  $this->assertTrue($this->matchCondition->match('[language = *en*,*de*]'));
220  $this->assertTrue($this->matchCondition->match('[language = *en-us*,*de-de*]'));
221  }
222 
229  $this->markTestSkipped('This comparison seems to be incomplete in \TYPO3\CMS\Frontend\Configuration\TypoScript\ConditionMatching\ConditionMatcher.');
230  $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'de-de,de;q=0.8,en-us;q=0.5,en;q=0.3';
231  $this->assertTrue($this->matchCondition->match('[language = de-de,de;q=0.8]'));
232  }
233 
240  $GLOBALS['TSFE']->gr_list = '13,14,15';
241  $this->assertTrue($this->matchCondition->match('[usergroup = 13]'));
242  }
243 
250  $GLOBALS['TSFE']->gr_list = '13,14,15';
251  $this->assertTrue($this->matchCondition->match('[usergroup = 999,15,14,13]'));
252  }
253 
260  $GLOBALS['TSFE']->gr_list = '0,-1';
261  $this->assertFalse($this->matchCondition->match('[usergroup = 0,-1]'));
262  }
263 
270  $GLOBALS['TSFE']->loginUser = TRUE;
271  $GLOBALS['TSFE']->fe_user->user['uid'] = 13;
272  $this->assertTrue($this->matchCondition->match('[loginUser = *]'));
273  }
274 
281  $GLOBALS['TSFE']->loginUser = TRUE;
282  $GLOBALS['TSFE']->fe_user->user['uid'] = 13;
283  $this->assertTrue($this->matchCondition->match('[loginUser = 13]'));
284  }
285 
292  $GLOBALS['TSFE']->loginUser = TRUE;
293  $GLOBALS['TSFE']->fe_user->user['uid'] = 13;
294  $this->assertTrue($this->matchCondition->match('[loginUser = 999,13]'));
295  }
296 
303  $GLOBALS['TSFE']->loginUser = FALSE;
304  $GLOBALS['TSFE']->fe_user->user['uid'] = 13;
305  $this->assertFalse($this->matchCondition->match('[loginUser = *]'));
306  $this->assertFalse($this->matchCondition->match('[loginUser = 13]'));
307  }
308 
315  $GLOBALS['TSFE']->loginUser = FALSE;
316  $this->assertTrue($this->matchCondition->match('[loginUser = ]'));
317  }
318 
325  $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 = 10]'));
326  $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 = 10.1]'));
327  $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 == 10]'));
328  $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 == 10.1]'));
329  }
330 
337  $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 = 10|20|30]'));
338  $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 = 10.1|20.2|30.3]'));
339  $this->assertTrue($this->matchCondition->match('[globalVar = LIT:20 = 10|20|30]'));
340  $this->assertTrue($this->matchCondition->match('[globalVar = LIT:20.2 = 10.1|20.2|30.3]'));
341  $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 == 10|20|30]'));
342  $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 == 10.1|20.2|30.3]'));
343  $this->assertTrue($this->matchCondition->match('[globalVar = LIT:20 == 10|20|30]'));
344  $this->assertTrue($this->matchCondition->match('[globalVar = LIT:20.2 == 10.1|20.2|30.3]'));
345  }
346 
353  $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 != 20]'));
354  $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 != 10.2]'));
355  }
356 
363  $this->assertFalse($this->matchCondition->match('[globalVar = LIT:10 != 10]'));
364  }
365 
372  $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 != 20|30]'));
373  $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 != 10.2|20.3]'));
374  }
375 
382  $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 < 20]'));
383  $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 < 10.2]'));
384  }
385 
392  $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 <= 10]'));
393  $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 <= 20]'));
394  $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 <= 10.1]'));
395  $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 <= 10.2]'));
396  }
397 
404  $this->assertTrue($this->matchCondition->match('[globalVar = LIT:20 > 10]'));
405  $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.2 > 10.1]'));
406  }
407 
414  $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 >= 10]'));
415  $this->assertTrue($this->matchCondition->match('[globalVar = LIT:20 >= 10]'));
416  $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 >= 10.1]'));
417  $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.2 >= 10.1]'));
418  }
419 
426  $testKey = $this->getUniqueId('test');
427  $this->assertTrue($this->matchCondition->match('[globalVar = GP:' . $testKey . '=]'));
428  $this->assertTrue($this->matchCondition->match('[globalVar = GP:' . $testKey . ' = ]'));
429  }
430 
437  $testKey = $this->getUniqueId('test');
438  $_GET = array();
439  $_POST = array($testKey => 0);
440  $this->assertFalse($this->matchCondition->match('[globalVar = GP:' . $testKey . '=]'));
441  $this->assertFalse($this->matchCondition->match('[globalVar = GP:' . $testKey . ' = ]'));
442  }
443 
450  $testKey = $this->getUniqueId('test');
451  $testValue = '1';
452  $_GET = array();
453  $_POST = array($testKey => array('0' => $testValue));
454  $this->assertTrue($this->matchCondition->match('[globalVar = GP:' . $testKey . '|0=' . $testValue . ']'));
455  }
456 
463  $this->assertTrue($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = TYPO3.Test.Condition]'));
464  $this->assertFalse($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = TYPO3]'));
465  }
466 
473  $testKey = $this->getUniqueId('test');
474  $_GET = array();
475  $_POST = array($testKey => '');
476  $this->assertTrue($this->matchCondition->match('[globalString = GP:' . $testKey . '=]'));
477  $this->assertTrue($this->matchCondition->match('[globalString = GP:' . $testKey . ' = ]'));
478  }
479 
486  $this->assertTrue($this->matchCondition->match('[globalString = LIT:=]'));
487  $this->assertTrue($this->matchCondition->match('[globalString = LIT: = ]'));
488  }
489 
496  $this->assertTrue($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = TYPO3?Test?Condition]'));
497  $this->assertTrue($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = TYPO3.T*t.Condition]'));
498  $this->assertTrue($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = TYPO3?T*t?Condition]'));
499  }
500 
507  $this->assertTrue($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = /^[A-Za-z3.]+$/]'));
508  $this->assertTrue($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = /^TYPO3\\..+Condition$/]'));
509  $this->assertFalse($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = /^FALSE/]'));
510  }
511 
518  $testKey = $this->getUniqueId('test');
519  $_SERVER[$testKey] = '';
520  $this->assertTrue($this->matchCondition->match('[globalString = _SERVER|' . $testKey . ' = /^$/]'));
521  }
522 
529  $this->assertTrue($this->matchCondition->match('[treeLevel = 2]'));
530  }
531 
538  $this->assertTrue($this->matchCondition->match('[treeLevel = 999,998,2]'));
539  }
540 
547  $this->assertFalse($this->matchCondition->match('[treeLevel = 999]'));
548  }
549 
556  $GLOBALS['TSFE']->id = 121;
557  $this->assertTrue($this->matchCondition->match('[PIDupinRootline = 111]'));
558  }
559 
566  $GLOBALS['TSFE']->id = 121;
567  $this->assertTrue($this->matchCondition->match('[PIDupinRootline = 999,111,101]'));
568  }
569 
576  $GLOBALS['TSFE']->id = 121;
577  $this->assertFalse($this->matchCondition->match('[PIDupinRootline = 999]'));
578  }
579 
586  $GLOBALS['TSFE']->id = 121;
587  $this->assertFalse($this->matchCondition->match('[PIDupinRootline = 121]'));
588  }
589 
596  $GLOBALS['TSFE']->id = 121;
597  $this->assertTrue($this->matchCondition->match('[PIDinRootline = 111]'));
598  }
599 
606  $GLOBALS['TSFE']->id = 121;
607  $this->assertTrue($this->matchCondition->match('[PIDinRootline = 999,111,101]'));
608  }
609 
616  $GLOBALS['TSFE']->id = 121;
617  $this->assertTrue($this->matchCondition->match('[PIDinRootline = 121]'));
618  }
619 
626  $GLOBALS['TSFE']->id = 121;
627  $this->assertFalse($this->matchCondition->match('[PIDinRootline = 999]'));
628  }
629 
637  $GLOBALS['TYPO3_CONF_VARS']['SYS']['compat_version'] = '4.9';
638  $this->assertTrue($this->matchCondition->match('[compatVersion = 4.0]'));
639  }
640 
648  $GLOBALS['TYPO3_CONF_VARS']['SYS']['compat_version'] = '4.9';
649  $this->assertTrue($this->matchCondition->match('[compatVersion = 4.9]'));
650  }
651 
659  $GLOBALS['TYPO3_CONF_VARS']['SYS']['compat_version'] = '4.9';
660  $this->assertFalse($this->matchCondition->match('[compatVersion = 5.0]'));
661  }
662 
669  $_GET = array('testGet' => 'getTest');
670  $_POST = array('testPost' => 'postTest');
671  $this->assertTrue($this->matchCondition->match('[globalString = GP:testGet = getTest]'));
672  $this->assertTrue($this->matchCondition->match('[globalString = GP:testPost = postTest]'));
673  }
674 
681  $GLOBALS['TSFE']->id = 1234567;
682  $GLOBALS['TSFE']->testSimpleObject = new \stdClass();
683  $GLOBALS['TSFE']->testSimpleObject->testSimpleVariable = 'testValue';
684  $this->assertTrue($this->matchCondition->match('[globalString = TSFE:id = 1234567]'));
685  $this->assertTrue($this->matchCondition->match('[globalString = TSFE:testSimpleObject|testSimpleVariable = testValue]'));
686  }
687 
694  $testKey = $this->getUniqueId('test');
695  putenv($testKey . '=testValue');
696  $this->assertTrue($this->matchCondition->match('[globalString = ENV:' . $testKey . ' = testValue]'));
697  }
698 
705  $_SERVER['HTTP_HOST'] = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_HOST_ONLY') . ':1234567';
706  $this->assertTrue($this->matchCondition->match('[globalString = IENV:TYPO3_PORT = 1234567]'));
707  }
708 
716  'first' => 'testFirst',
717  'second' => array('third' => 'testThird')
718  );
719  $this->assertTrue($this->matchCondition->match('[globalString = ' . $this->testGlobalNamespace . '|first = testFirst]'));
720  $this->assertTrue($this->matchCondition->match('[globalString = ' . $this->testGlobalNamespace . '|second|third = testThird]'));
721  }
722 
723 }
if($list_of_literals) if(!empty($literals)) if(!empty($literals)) $result
Analyse literals to prepend the N char to them if their contents aren&#39;t numeric.
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]