TYPO3 CMS  TYPO3_7-6
AbstractConditionMatcherTest.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
21 
26 {
30  protected $backupApplicationContext = null;
31 
35  protected $conditionMatcher;
36 
41 
45  protected function setUp()
46  {
47  require_once('Fixtures/ConditionMatcherUserFuncs.php');
48 
50 
51  $this->backupApplicationContext = GeneralUtility::getApplicationContext();
52  $this->conditionMatcher = $this->getMockForAbstractClass(AbstractConditionMatcher::class);
53  $this->evaluateConditionCommonMethod = new \ReflectionMethod(AbstractConditionMatcher::class, 'evaluateConditionCommon');
54  $this->evaluateConditionCommonMethod->setAccessible(true);
55  }
56 
60  protected function tearDown()
61  {
62  Fixtures\GeneralUtilityFixture::setApplicationContext($this->backupApplicationContext);
63  parent::tearDown();
64  }
65 
72  {
73  return [
74  ['Production*'],
75  ['Production/Staging/*'],
76  ['Production/Staging/Server2'],
77  ['/^Production.*$/'],
78  ['/^Production\\/.+\\/Server\\d+$/'],
79  ];
80  }
81 
86  public function evaluateConditionCommonReturnsTrueForMatchingContexts($matchingContextCondition)
87  {
89  $applicationContext = new ApplicationContext('Production/Staging/Server2');
91 
92  $this->assertTrue(
93  $this->evaluateConditionCommonMethod->invokeArgs($this->conditionMatcher, ['applicationContext', $matchingContextCondition])
94  );
95  }
96 
103  {
104  return [
105  ['Production'],
106  ['Testing*'],
107  ['Development/Profiling, Testing/Unit'],
108  ['Testing/Staging/Server2'],
109  ['/^Testing.*$/'],
110  ['/^Production\\/.+\\/Host\\d+$/'],
111  ];
112  }
113 
118  public function evaluateConditionCommonReturnsNullForNotMatchingApplicationContexts($notMatchingApplicationContextCondition)
119  {
121  $applicationContext = new ApplicationContext('Production/Staging/Server2');
123 
124  $this->assertFalse(
125  $this->evaluateConditionCommonMethod->invokeArgs($this->conditionMatcher, ['applicationContext', $notMatchingApplicationContextCondition])
126  );
127  }
128 
135  {
136  return [
137  // [0] $GLOBALS['TYPO3_CONF_VARS']['SYS']['devIPmask']
138  // [1] Actual IP
139  // [2] Expected condition result
140  'IP matches' => [
141  '127.0.0.1',
142  '127.0.0.1',
143  true,
144  ],
145  'ipv4 wildcard subnet' => [
146  '127.0.0.1/24',
147  '127.0.0.2',
148  true,
149  ],
150  'ipv6 wildcard subnet' => [
151  '0:0::1/128',
152  '::1',
153  true,
154  ],
155  'List of addresses matches' => [
156  '1.2.3.4, 5.6.7.8',
157  '5.6.7.8',
158  true,
159  ],
160  'IP does not match' => [
161  '127.0.0.1',
162  '127.0.0.2',
163  false,
164  ],
165  'ipv4 subnet does not match' => [
166  '127.0.0.1/8',
167  '126.0.0.1',
168  false,
169  ],
170  'ipv6 subnet does not match' => [
171  '::1/127',
172  '::2',
173  false
174  ],
175  'List of addresses does not match' => [
176  '127.0.0.1, ::1',
177  '::2',
178  false,
179  ],
180  ];
181  }
182 
187  public function evaluateConditionCommonEvaluatesIpAddressesCorrectly($devIpMask, $actualIp, $expectedResult)
188  {
189  // Do not trigger proxy stuff of GeneralUtility::getIndPEnv
190  unset($GLOBALS['TYPO3_CONF_VARS']['SYS']['reverseProxyIP']);
191 
192  $_SERVER['REMOTE_ADDR'] = $actualIp;
193  $GLOBALS['TYPO3_CONF_VARS']['SYS']['devIPmask'] = $devIpMask;
194 
195  $actualResult = $this->evaluateConditionCommonMethod->invokeArgs($this->conditionMatcher, ['IP', 'devIP']);
196  $this->assertSame($expectedResult, $actualResult);
197  }
198 
202  public function testUserFuncIsCalled()
203  {
204  $this->assertTrue(
205  $this->evaluateConditionCommonMethod->invokeArgs(
206  $this->conditionMatcher,
207  ['userFunc', 'user_testFunction']
208  )
209  );
210  }
211 
216  {
217  $this->assertTrue(
218  $this->evaluateConditionCommonMethod->invokeArgs(
219  $this->conditionMatcher,
220  ['userFunc', 'user_testFunctionWithSingleArgument(x)']
221  )
222  );
223  }
224 
229  {
230  $this->assertTrue(
231  $this->evaluateConditionCommonMethod->invokeArgs(
232  $this->conditionMatcher,
233  ['userFunc', 'user_testFunctionWithSingleArgument(0)']
234  )
235  );
236  }
237 
242  {
243  $this->assertTrue(
244  $this->evaluateConditionCommonMethod->invokeArgs(
245  $this->conditionMatcher,
246  ['userFunc', 'user_testFunctionWithNoArgument( )']
247  )
248  );
249  }
250 
255  {
256  $this->assertTrue(
257  $this->evaluateConditionCommonMethod->invokeArgs(
258  $this->conditionMatcher,
259  ['userFunc', 'user_testFunctionWithThreeArguments(1,2,3)']
260  )
261  );
262  }
263 
268  {
269  $this->assertTrue(
270  $this->evaluateConditionCommonMethod->invokeArgs(
271  $this->conditionMatcher,
272  ['userFunc', 'user_testFunctionWithThreeArguments(0,true,"foo")']
273  )
274  );
275  }
276 
281  {
282  $this->assertTrue(
283  $this->evaluateConditionCommonMethod->invokeArgs(
284  $this->conditionMatcher,
285  ['userFunc', 'user_testFunctionWithThreeArguments(0,"foo",true)']
286  )
287  );
288  }
289 
294  {
295  $this->assertTrue(
296  $this->evaluateConditionCommonMethod->invokeArgs(
297  $this->conditionMatcher,
298  ['userFunc', 'user_testFunctionWithThreeArguments("foo",true,0)']
299  )
300  );
301  }
302 
307  {
308  $this->assertTrue(
309  $this->evaluateConditionCommonMethod->invokeArgs(
310  $this->conditionMatcher,
311  ['userFunc', 'user_testFunctionWithThreeArguments("foo",0,true)']
312  )
313  );
314  }
315 
320  {
321  $this->assertTrue(
322  $this->evaluateConditionCommonMethod->invokeArgs(
323  $this->conditionMatcher,
324  ['userFunc', 'user_testFunctionWithThreeArguments(true,0,"foo")']
325  )
326  );
327  }
328 
333  {
334  $this->assertTrue(
335  $this->evaluateConditionCommonMethod->invokeArgs(
336  $this->conditionMatcher,
337  ['userFunc', 'user_testFunctionWithThreeArguments(true,"foo",0)']
338  )
339  );
340  }
341 
346  {
347  $this->assertTrue(
348  $this->evaluateConditionCommonMethod->invokeArgs(
349  $this->conditionMatcher,
350  ['userFunc', "user_testFunctionWithThreeArguments(0,true,'foo')"]
351  )
352  );
353  }
354 
359  {
360  $this->assertTrue(
361  $this->evaluateConditionCommonMethod->invokeArgs(
362  $this->conditionMatcher,
363  ['userFunc', "user_testFunctionWithThreeArguments(0,'foo',true)"]
364  )
365  );
366  }
367 
372  {
373  $this->assertTrue(
374  $this->evaluateConditionCommonMethod->invokeArgs(
375  $this->conditionMatcher,
376  ['userFunc', "user_testFunctionWithThreeArguments('foo',true,0)"]
377  )
378  );
379  }
380 
385  {
386  $this->assertTrue(
387  $this->evaluateConditionCommonMethod->invokeArgs(
388  $this->conditionMatcher,
389  ['userFunc', "user_testFunctionWithThreeArguments('foo',0,true)"]
390  )
391  );
392  }
393 
398  {
399  $this->assertTrue(
400  $this->evaluateConditionCommonMethod->invokeArgs(
401  $this->conditionMatcher,
402  ['userFunc', "user_testFunctionWithThreeArguments(true,0,'foo')"]
403  )
404  );
405  }
406 
411  {
412  $this->assertTrue(
413  $this->evaluateConditionCommonMethod->invokeArgs(
414  $this->conditionMatcher,
415  ['userFunc', "user_testFunctionWithThreeArguments(true,'foo',0)"]
416  )
417  );
418  }
419 
424  {
425  $this->assertTrue(
426  $this->evaluateConditionCommonMethod->invokeArgs(
427  $this->conditionMatcher,
428  ['userFunc', "user_testFunctionWithThreeArguments('foo','bar', 'baz')"]
429  )
430  );
431  }
432 
437  {
438  $this->assertTrue(
439  $this->evaluateConditionCommonMethod->invokeArgs(
440  $this->conditionMatcher,
441  ['userFunc', 'user_testFunctionWithThreeArguments("foo","bar","baz")']
442  )
443  );
444  }
445 
449  public function testUserFuncReturnsFalse()
450  {
451  $this->assertFalse(
452  $this->evaluateConditionCommonMethod->invokeArgs(
453  $this->conditionMatcher,
454  ['userFunc', 'user_testFunctionFalse']
455  )
456  );
457  }
458 
463  {
464  $this->assertTrue(
465  $this->evaluateConditionCommonMethod->invokeArgs(
466  $this->conditionMatcher,
467  ['userFunc', 'user_testFunctionWithThreeArguments(1,2,"3,4,5,6")']
468  )
469  );
470  }
471 
476  {
477  $this->assertTrue(
478  $this->evaluateConditionCommonMethod->invokeArgs(
479  $this->conditionMatcher,
480  ['userFunc', 'user_testFunctionWithThreeArguments ( 1 , 2, "3, 4, 5, 6" )']
481  )
482  );
483  }
484 
489  {
490  $this->assertTrue(
491  $this->evaluateConditionCommonMethod->invokeArgs(
492  $this->conditionMatcher,
493  ['userFunc', 'user_testFunctionWithThreeArgumentsSpaces ( 1 , 2, "3, 4, 5, 6" )']
494  )
495  );
496  }
497 
502  {
503  $this->assertTrue(
504  $this->evaluateConditionCommonMethod->invokeArgs(
505  $this->conditionMatcher,
506  ['userFunc', 'user_testFunctionWithSpaces(" 3, 4, 5, 6 ")']
507  )
508  );
509  }
510 
515  {
516  $this->assertTrue(
517  $this->evaluateConditionCommonMethod->invokeArgs(
518  $this->conditionMatcher,
519  ['userFunc', 'user_testFunctionWithThreeArgumentsSpaces ( 1 , 2, "3, \"4, 5\", 6" )']
520  )
521  );
522  }
523 
528  {
529  $this->assertTrue(
530  $this->evaluateConditionCommonMethod->invokeArgs(
531  $this->conditionMatcher,
532  ['userFunc', 'user_testFunctionWithQuoteMissing ("value \")']
533  )
534  );
535  }
536 
541  {
542  $this->assertTrue(
543  $this->evaluateConditionCommonMethod->invokeArgs(
544  $this->conditionMatcher,
545  ['userFunc', 'user_testQuotes("1 \" 2")']
546  )
547  );
548  }
549 
554  {
555  $this->assertTrue(
556  $this->evaluateConditionCommonMethod->invokeArgs(
557  $this->conditionMatcher,
558  ['userFunc', 'ConditionMatcherUserFunctions::isTrue(1)']
559  )
560  );
561  }
562 }
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']