TYPO3 CMS  TYPO3_6-2
AbstractConditionMatcherTest.php
Go to the documentation of this file.
1 <?php
3 
22 
23 require_once(ExtensionManagementUtility::extPath('core', 'Tests/Unit/Configuration/ConditionMatcherUserFuncs.php'));
24 
32 
36  protected $backupApplicationContext = NULL;
37 
41  protected $conditionMatcher;
42 
47 
51  public function setUp() {
52  $this->backupApplicationContext = GeneralUtility::getApplicationContext();
53  $this->conditionMatcher = $this->getMockForAbstractClass('TYPO3\\CMS\\Core\\Configuration\\TypoScript\\ConditionMatching\\AbstractConditionMatcher');
54  $this->evaluateConditionCommonMethod = new \ReflectionMethod('TYPO3\\CMS\\Core\\Configuration\\TypoScript\\ConditionMatching\\AbstractConditionMatcher', 'evaluateConditionCommon');
55  $this->evaluateConditionCommonMethod->setAccessible(true);
56  }
57 
61  public function tearDown() {
62  Fixtures\GeneralUtilityFixture::setApplicationContext($this->backupApplicationContext);
63  parent::tearDown();
64  }
65 
72  return array(
73  array('Production*'),
74  array('Production/Staging/*'),
75  array('Production/Staging/Server2'),
76  array('/^Production.*$/'),
77  array('/^Production\/.+\/Server\d+$/'),
78  );
79  }
80 
85  public function evaluateConditionCommonReturnsTrueForMatchingContexts($matchingContextCondition) {
87  $applicationContext = new ApplicationContext('Production/Staging/Server2');
89 
91  $abstractConditionMatcherMock = $this->getMockForAbstractClass(
92  'TYPO3\\CMS\\Core\\Configuration\\TypoScript\\ConditionMatching\\AbstractConditionMatcher',
93  array(),
94  '',
95  TRUE,
96  TRUE,
97  TRUE,
98  array('evaluateConditionCommon')
99  );
100 
101  $method = new \ReflectionMethod(
102  'TYPO3\\CMS\\Core\\Configuration\\TypoScript\\ConditionMatching\\AbstractConditionMatcher',
103  'evaluateConditionCommon'
104  );
105  $method->setAccessible(TRUE);
106 
107  $this->assertTrue(
108  $method->invokeArgs($abstractConditionMatcherMock, array('applicationContext', $matchingContextCondition))
109  );
110  }
111 
118  return array(
119  array('Production'),
120  array('Testing*'),
121  array('Development/Profiling, Testing/Unit'),
122  array('Testing/Staging/Server2'),
123  array('/^Testing.*$/'),
124  array('/^Production\/.+\/Host\d+$/'),
125  );
126  }
127 
132  public function evaluateConditionCommonReturnsNullForNotMatchingApplicationContexts($notMatchingApplicationContextCondition) {
134  $applicationContext = new ApplicationContext('Production/Staging/Server2');
136 
138  $abstractConditionMatcherMock = $this->getMockForAbstractClass(
139  'TYPO3\\CMS\\Core\\Configuration\\TypoScript\\ConditionMatching\\AbstractConditionMatcher',
140  array(),
141  '',
142  TRUE,
143  TRUE,
144  TRUE,
145  array('evaluateConditionCommon')
146  );
147 
148  $method = new \ReflectionMethod(
149  'TYPO3\\CMS\\Core\\Configuration\\TypoScript\\ConditionMatching\\AbstractConditionMatcher',
150  'evaluateConditionCommon'
151  );
152  $method->setAccessible(TRUE);
153 
154  $this->assertNull(
155  $method->invokeArgs($abstractConditionMatcherMock, array('applicationContext', $notMatchingApplicationContextCondition))
156  );
157  }
158 
165  return array(
166  // [0] $GLOBALS['TYPO3_CONF_VARS']['SYS']['devIPmask']
167  // [1] Actual IP
168  // [2] Expected condition result
169  'IP matches' => array(
170  '127.0.0.1',
171  '127.0.0.1',
172  TRUE
173  ),
174  'ipv4 wildcard subnet' => array(
175  '127.0.0.1/24',
176  '127.0.0.2',
177  TRUE
178  ),
179  'ipv6 wildcard subnet' => array(
180  '0:0::1/128',
181  '::1',
182  TRUE
183  ),
184  'List of addresses matches' => array(
185  '1.2.3.4, 5.6.7.8',
186  '5.6.7.8',
187  TRUE
188  ),
189  'IP does not match' => array(
190  '127.0.0.1',
191  '127.0.0.2',
192  NULL
193  ),
194  'ipv4 subnet does not match' => array(
195  '127.0.0.1/8',
196  '126.0.0.1',
197  NULL
198  ),
199  'ipv6 subnet does not match' => array(
200  '::1/127',
201  '::2',
202  NULL
203  ),
204  'List of addresses does not match' => array(
205  '127.0.0.1, ::1',
206  '::2',
207  NULL
208  ),
209  );
210  }
211 
216  public function evaluateConditionCommonEvaluatesIpAddressesCorrectly($devIpMask, $actualIp, $expectedResult) {
218  $abstractConditionMatcherMock = $this->getMockForAbstractClass(
219  'TYPO3\\CMS\\Core\\Configuration\\TypoScript\\ConditionMatching\\AbstractConditionMatcher',
220  array(),
221  '',
222  TRUE,
223  TRUE,
224  TRUE,
225  array('evaluateConditionCommon')
226  );
227  $method = new \ReflectionMethod(
228  'TYPO3\\CMS\\Core\\Configuration\\TypoScript\\ConditionMatching\\AbstractConditionMatcher',
229  'evaluateConditionCommon'
230  );
231  $method->setAccessible(TRUE);
232 
233  // Do not trigger proxy stuff of GeneralUtility::getIndPEnv
234  unset($GLOBALS['TYPO3_CONF_VARS']['SYS']['reverseProxyIP']);
235 
236  $_SERVER['REMOTE_ADDR'] = $actualIp;
237  $GLOBALS['TYPO3_CONF_VARS']['SYS']['devIPmask'] = $devIpMask;
238 
239  $actualResult = $method->invokeArgs($abstractConditionMatcherMock, array('IP', 'devIP'));
240  $this->assertSame($expectedResult, $actualResult);
241  }
242 
246  public function testUserFuncIsCalled() {
247  $this->assertTrue(
248  $this->evaluateConditionCommonMethod->invokeArgs(
249  $this->conditionMatcher,
250  array('userFunc', 'user_testFunction')
251  )
252  );
253  }
254 
258  public function testUserFuncWithSingleArgument() {
259  $this->assertTrue(
260  $this->evaluateConditionCommonMethod->invokeArgs(
261  $this->conditionMatcher,
262  array('userFunc', 'user_testFunctionWithSingleArgument(x)')
263  )
264  );
265  }
266 
271  $this->assertTrue(
272  $this->evaluateConditionCommonMethod->invokeArgs(
273  $this->conditionMatcher,
274  array('userFunc', 'user_testFunctionWithSingleArgument(0)')
275  )
276  );
277  }
278 
283  $this->assertTrue(
284  $this->evaluateConditionCommonMethod->invokeArgs(
285  $this->conditionMatcher,
286  array('userFunc', 'user_testFunctionWithNoArgument( )')
287  )
288  );
289  }
290 
295  $this->assertTrue(
296  $this->evaluateConditionCommonMethod->invokeArgs(
297  $this->conditionMatcher,
298  array('userFunc', 'user_testFunctionWithThreeArguments(1,2,3)')
299  )
300  );
301  }
302 
307  $this->assertTrue(
308  $this->evaluateConditionCommonMethod->invokeArgs(
309  $this->conditionMatcher,
310  array('userFunc', 'user_testFunctionWithThreeArguments(0,true,"foo")')
311  )
312  );
313  }
314 
319  $this->assertTrue(
320  $this->evaluateConditionCommonMethod->invokeArgs(
321  $this->conditionMatcher,
322  array('userFunc', 'user_testFunctionWithThreeArguments(0,"foo",true)')
323  )
324  );
325  }
326 
331  $this->assertTrue(
332  $this->evaluateConditionCommonMethod->invokeArgs(
333  $this->conditionMatcher,
334  array('userFunc', 'user_testFunctionWithThreeArguments("foo",true,0)')
335  )
336  );
337  }
338 
343  $this->assertTrue(
344  $this->evaluateConditionCommonMethod->invokeArgs(
345  $this->conditionMatcher,
346  array('userFunc', 'user_testFunctionWithThreeArguments("foo",0,true)')
347  )
348  );
349  }
350 
355  $this->assertTrue(
356  $this->evaluateConditionCommonMethod->invokeArgs(
357  $this->conditionMatcher,
358  array('userFunc', 'user_testFunctionWithThreeArguments(true,0,"foo")')
359  )
360  );
361  }
362 
367  $this->assertTrue(
368  $this->evaluateConditionCommonMethod->invokeArgs(
369  $this->conditionMatcher,
370  array('userFunc', 'user_testFunctionWithThreeArguments(true,"foo",0)')
371  )
372  );
373  }
374 
379  $this->assertTrue(
380  $this->evaluateConditionCommonMethod->invokeArgs(
381  $this->conditionMatcher,
382  array('userFunc', "user_testFunctionWithThreeArguments(0,true,'foo')")
383  )
384  );
385  }
386 
391  $this->assertTrue(
392  $this->evaluateConditionCommonMethod->invokeArgs(
393  $this->conditionMatcher,
394  array('userFunc', "user_testFunctionWithThreeArguments(0,'foo',true)")
395  )
396  );
397  }
398 
403  $this->assertTrue(
404  $this->evaluateConditionCommonMethod->invokeArgs(
405  $this->conditionMatcher,
406  array('userFunc', "user_testFunctionWithThreeArguments('foo',true,0)")
407  )
408  );
409  }
410 
415  $this->assertTrue(
416  $this->evaluateConditionCommonMethod->invokeArgs(
417  $this->conditionMatcher,
418  array('userFunc', "user_testFunctionWithThreeArguments('foo',0,true)")
419  )
420  );
421  }
422 
427  $this->assertTrue(
428  $this->evaluateConditionCommonMethod->invokeArgs(
429  $this->conditionMatcher,
430  array('userFunc', "user_testFunctionWithThreeArguments(true,0,'foo')")
431  )
432  );
433  }
434 
439  $this->assertTrue(
440  $this->evaluateConditionCommonMethod->invokeArgs(
441  $this->conditionMatcher,
442  array('userFunc', "user_testFunctionWithThreeArguments(true,'foo',0)")
443  )
444  );
445  }
446 
451  $this->assertTrue(
452  $this->evaluateConditionCommonMethod->invokeArgs(
453  $this->conditionMatcher,
454  array('userFunc', "user_testFunctionWithThreeArguments('foo','bar', 'baz')")
455  )
456  );
457  }
458 
463  $this->assertTrue(
464  $this->evaluateConditionCommonMethod->invokeArgs(
465  $this->conditionMatcher,
466  array('userFunc', 'user_testFunctionWithThreeArguments("foo","bar","baz")')
467  )
468  );
469  }
470 }
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]