[CLEANUP] Move ConditionMatcherTests into one place 55/36355/7
authorMateusz Wojtuła <matw88@gmail.com>
Thu, 29 Jan 2015 13:53:31 +0000 (14:53 +0100)
committerChristian Kuhn <lolli@schwarzbu.ch>
Fri, 30 Jan 2015 10:58:57 +0000 (11:58 +0100)
Moved core ConditionMatcherTest to Backend extension.

Change-Id: I7bd63d728c172046fa808329807d28feb458de87
Resolves: #64324
Releases: master
Reviewed-on: http://review.typo3.org/36355
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Oliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/core/Tests/Unit/Configuration/ConditionMatcherTest.php [deleted file]
typo3/sysext/core/Tests/Unit/Configuration/ConditionMatcherUserFuncs.php [deleted file]
typo3/sysext/core/Tests/Unit/Configuration/TypoScript/ConditionMatching/AbstractConditionMatcherTest.php
typo3/sysext/core/Tests/Unit/Configuration/TypoScript/ConditionMatching/Fixtures/ConditionMatcherUserFuncs.php [new file with mode: 0644]

diff --git a/typo3/sysext/core/Tests/Unit/Configuration/ConditionMatcherTest.php b/typo3/sysext/core/Tests/Unit/Configuration/ConditionMatcherTest.php
deleted file mode 100644 (file)
index c468670..0000000
+++ /dev/null
@@ -1,134 +0,0 @@
-<?php
-namespace TYPO3\CMS\Core\Tests\Unit\Configuration;
-
-use TYPO3\CMS\Backend\Configuration\TypoScript\ConditionMatching\ConditionMatcher;
-use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
-use TYPO3\CMS\Core\Utility\GeneralUtility;
-
-/*
- * This file is part of the TYPO3 CMS project.
- *
- * It is free software; you can redistribute it and/or modify it under
- * the terms of the GNU General Public License, either version 2
- * of the License, or any later version.
- *
- * For the full copyright and license information, please read the
- * LICENSE.txt file that was distributed with this source code.
- *
- * The TYPO3 project - inspiring people to share!
- */
-
-require_once(ExtensionManagementUtility::extPath('core', 'Tests/Unit/Configuration/ConditionMatcherUserFuncs.php'));
-
-/**
- * Test class for ConditionMatcher functions
- *
- * @author Dmitry Dulepov <dmitry.dulepov@gmail.com>
- */
-class ConditionMatcherTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
-
-       /** @var ConditionMatcher */
-       protected $conditionMatcher;
-
-       public function setUp() {
-               $this->conditionMatcher = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Configuration\TypoScript\ConditionMatching\ConditionMatcher::class);
-       }
-
-       /**
-        * @test
-        * @return void
-        */
-       public function testUserFuncIsCalled() {
-               $this->assertTrue($this->conditionMatcher->match('[userFunc = user_testFunction]'));
-       }
-
-       /**
-        * @test
-        * @return void
-        */
-       public function testUserFuncWithSingleArgument() {
-               $this->assertTrue($this->conditionMatcher->match('[userFunc = user_testFunctionWithSingleArgument(x)]'));
-       }
-
-       /**
-        * @test
-        * @return void
-        */
-       public function testUserFuncWithMultipleArguments() {
-               $this->assertTrue($this->conditionMatcher->match('[userFunc = user_testFunctionWithThreeArguments(1,2,3)]'));
-       }
-
-       /**
-        * @test
-        * @return void
-        */
-       public function testUserFuncReturnsFalse() {
-               $this->assertFalse($this->conditionMatcher->match('[userFunc = user_testFunctionFalse]'));
-       }
-
-       /**
-        * @test
-        * @return void
-        */
-       public function testUserFuncWithMultipleArgumentsAndQuotes() {
-               $this->assertTrue($this->conditionMatcher->match('[userFunc = user_testFunctionWithThreeArguments(1,2,"3,4,5,6")]'));
-       }
-
-       /**
-        * @test
-        * @return void
-        */
-       public function testUserFuncWithMultipleArgumentsAndQuotesAndSpaces() {
-               $this->assertTrue($this->conditionMatcher->match('[userFunc = user_testFunctionWithThreeArguments ( 1 , 2, "3, 4, 5, 6" ) ]'));
-       }
-
-       /**
-        * @test
-        * @return void
-        */
-       public function testUserFuncWithMultipleArgumentsAndQuotesAndSpacesStripped() {
-               $this->assertTrue($this->conditionMatcher->match('[userFunc = user_testFunctionWithThreeArgumentsSpaces ( 1 , 2, "3, 4, 5, 6" ) ]'));
-       }
-
-       /**
-        * @test
-        * @return void
-        */
-       public function testUserFuncWithSpacesInQuotes() {
-               $this->assertTrue($this->conditionMatcher->match('[userFunc = user_testFunctionWithSpaces(" 3, 4, 5, 6 ")]'));
-       }
-
-       /**
-        * @test
-        * @return void
-        */
-       public function testUserFuncWithMultipleArgumentsAndQuotesAndSpacesStrippedAndEscapes() {
-               $this->assertTrue($this->conditionMatcher->match('[userFunc = user_testFunctionWithThreeArgumentsSpaces ( 1 , 2, "3, \"4, 5\", 6" ) ]'));
-       }
-
-       /**
-        * @test
-        * @return void
-        */
-       public function testUserFuncWithQuoteMissing() {
-               $this->assertTrue($this->conditionMatcher->match('[userFunc = user_testFunctionWithQuoteMissing ("value \") ]'));
-       }
-
-       /**
-        * @test
-        * @return void
-        */
-       public function testUserFuncWithQuotesInside() {
-               $this->assertTrue($this->conditionMatcher->match('[userFunc = user_testQuotes("1 \" 2") ]'));
-       }
-
-       /**
-        * @test
-        * @return void
-        */
-       public function testUserFuncWithClassMethodCall() {
-               $this->assertTrue($this->conditionMatcher->match('[userFunc = ConditionMatcherUserFunctions::isTrue(1)]'));
-       }
-
-}
-
diff --git a/typo3/sysext/core/Tests/Unit/Configuration/ConditionMatcherUserFuncs.php b/typo3/sysext/core/Tests/Unit/Configuration/ConditionMatcherUserFuncs.php
deleted file mode 100644 (file)
index 67142b5..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-<?php
-/*
- * This file is part of the TYPO3 CMS project.
- *
- * It is free software; you can redistribute it and/or modify it under
- * the terms of the GNU General Public License, either version 2
- * of the License, or any later version.
- *
- * For the full copyright and license information, please read the
- * LICENSE.txt file that was distributed with this source code.
- *
- * The TYPO3 project - inspiring people to share!
- */
-
-namespace {
-       function user_testFunctionWithSingleArgument() {
-               return count(func_get_args()) === 1;
-       }
-
-       function user_testFunctionWithThreeArguments() {
-               return count(func_get_args()) === 3;
-       }
-
-       function user_testFunctionWithThreeArgumentsSpaces() {
-               $result = TRUE;
-               foreach (func_get_args() as $argument) {
-                       $result &= (trim($argument) == $argument);
-               }
-               return $result;
-       }
-
-       function user_testFunctionWithSpaces($value) {
-               return $value === ' 3, 4, 5, 6 ';
-       }
-
-       function user_testFunction() {
-               return TRUE;
-       }
-
-       function user_testFunctionFalse() {
-               return FALSE;
-       }
-
-       function user_testFunctionWithQuoteMissing($value) {
-               return $value === 'value "';
-       }
-
-       function user_testQuotes($value) {
-               return $value === '1 " 2';
-       }
-
-       class ConditionMatcherUserFunctions {
-
-               /**
-                * @param mixed $value
-                * @return bool
-                */
-               static public function isTrue($value) {
-                       return (bool)$value;
-               }
-
-       }
-}
-
index ea4b03f..07057e2 100644 (file)
@@ -16,14 +16,16 @@ namespace TYPO3\CMS\Core\Tests\Unit\Configuration\TypoScript\ConditionMatching;
 
 use TYPO3\CMS\Core\Core\ApplicationContext;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
+use TYPO3\CMS\Core\Configuration\TypoScript\ConditionMatching\AbstractConditionMatcher;
+use TYPO3\CMS\Core\Tests\UnitTestCase;
 
 /**
- * Testcases for
- * TYPO3\CMS\Core\Configuration\TypoScript\ConditionMatching\AbstractConditionMatcher
+ * Test cases
  *
  * @author Steffen Müller <typo3@t3node.com>
  */
-class AbstractConditionMatcherTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
+class AbstractConditionMatcherTest extends UnitTestCase {
 
        /**
         * @var \TYPO3\CMS\Core\Core\ApplicationContext
@@ -31,16 +33,31 @@ class AbstractConditionMatcherTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
        protected $backupApplicationContext = NULL;
 
        /**
-        *
+        * @var AbstractConditionMatcher|\PHPUnit_Framework_MockObject_MockObject
+        */
+       protected $conditionMatcher;
+
+       /**
+        * @var \ReflectionMethod
+        */
+       protected $evaluateConditionCommonMethod;
+
+       /**
+        * Set up
         */
-       public function setUp() {
+       protected function setUp() {
+               require_once('Fixtures/ConditionMatcherUserFuncs.php');
+
                $this->backupApplicationContext = GeneralUtility::getApplicationContext();
+               $this->conditionMatcher = $this->getMockForAbstractClass(AbstractConditionMatcher::class);
+               $this->evaluateConditionCommonMethod = new \ReflectionMethod(AbstractConditionMatcher::class, 'evaluateConditionCommon');
+               $this->evaluateConditionCommonMethod->setAccessible(TRUE);
        }
 
        /**
-        *
+        * Tear down
         */
-       public function tearDown() {
+       protected function tearDown() {
                Fixtures\GeneralUtilityFixture::setApplicationContext($this->backupApplicationContext);
                parent::tearDown();
        }
@@ -48,7 +65,7 @@ class AbstractConditionMatcherTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
        /**
         * Data provider with matching applicationContext conditions.
         *
-        * @return array
+        * @return array[]
         */
        public function matchingApplicationContextConditionsDataProvider() {
                return array(
@@ -56,7 +73,7 @@ class AbstractConditionMatcherTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                        array('Production/Staging/*'),
                        array('Production/Staging/Server2'),
                        array('/^Production.*$/'),
-                       array('/^Production\/.+\/Server\d+$/'),
+                       array('/^Production\\/.+\\/Server\\d+$/'),
                );
        }
 
@@ -69,26 +86,15 @@ class AbstractConditionMatcherTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                $applicationContext = new ApplicationContext('Production/Staging/Server2');
                Fixtures\GeneralUtilityFixture::setApplicationContext($applicationContext);
 
-               /** @var \TYPO3\CMS\Core\Configuration\TypoScript\ConditionMatching\AbstractConditionMatcher|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface $abstractConditionMatcherMock */
-               $abstractConditionMatcherMock = $this->getMockForAbstractClass(
-                       \TYPO3\CMS\Core\Configuration\TypoScript\ConditionMatching\AbstractConditionMatcher::class
-               );
-
-               $method = new \ReflectionMethod(
-                       \TYPO3\CMS\Core\Configuration\TypoScript\ConditionMatching\AbstractConditionMatcher::class,
-                       'evaluateConditionCommon'
-               );
-               $method->setAccessible(TRUE);
-
                $this->assertTrue(
-                       $method->invokeArgs($abstractConditionMatcherMock, array('applicationContext', $matchingContextCondition))
+                       $this->evaluateConditionCommonMethod->invokeArgs($this->conditionMatcher, array('applicationContext', $matchingContextCondition))
                );
        }
 
        /**
         * Data provider with not matching applicationContext conditions.
         *
-        * @return array
+        * @return array[]
         */
        public function notMatchingApplicationContextConditionsDataProvider() {
                return array(
@@ -97,7 +103,7 @@ class AbstractConditionMatcherTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                        array('Development/Profiling, Testing/Unit'),
                        array('Testing/Staging/Server2'),
                        array('/^Testing.*$/'),
-                       array('/^Production\/.+\/Host\d+$/'),
+                       array('/^Production\\/.+\\/Host\\d+$/'),
                );
        }
 
@@ -110,26 +116,15 @@ class AbstractConditionMatcherTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                $applicationContext = new ApplicationContext('Production/Staging/Server2');
                Fixtures\GeneralUtilityFixture::setApplicationContext($applicationContext);
 
-               /** @var \TYPO3\CMS\Core\Configuration\TypoScript\ConditionMatching\AbstractConditionMatcher|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface $abstractConditionMatcherMock */
-               $abstractConditionMatcherMock = $this->getMockForAbstractClass(
-                       \TYPO3\CMS\Core\Configuration\TypoScript\ConditionMatching\AbstractConditionMatcher::class
-               );
-
-               $method = new \ReflectionMethod(
-                       \TYPO3\CMS\Core\Configuration\TypoScript\ConditionMatching\AbstractConditionMatcher::class,
-                       'evaluateConditionCommon'
-               );
-               $method->setAccessible(TRUE);
-
                $this->assertFalse(
-                       $method->invokeArgs($abstractConditionMatcherMock, array('applicationContext', $notMatchingApplicationContextCondition))
+                       $this->evaluateConditionCommonMethod->invokeArgs($this->conditionMatcher, array('applicationContext', $notMatchingApplicationContextCondition))
                );
        }
 
        /**
         * Data provider for evaluateConditionCommonEvaluatesIpAddressesCorrectly
         *
-        * @return array
+        * @return array[]
         */
        public function evaluateConditionCommonDevIpMaskDataProvider() {
                return array(
@@ -139,32 +134,32 @@ class AbstractConditionMatcherTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                        'IP matches' => array(
                                '127.0.0.1',
                                '127.0.0.1',
-                               TRUE
+                               TRUE,
                        ),
                        'ipv4 wildcard subnet' => array(
                                '127.0.0.1/24',
                                '127.0.0.2',
-                               TRUE
+                               TRUE,
                        ),
                        'ipv6 wildcard subnet' => array(
                                '0:0::1/128',
                                '::1',
-                               TRUE
+                               TRUE,
                        ),
                        'List of addresses matches' => array(
                                '1.2.3.4, 5.6.7.8',
                                '5.6.7.8',
-                               TRUE
+                               TRUE,
                        ),
                        'IP does not match' => array(
                                '127.0.0.1',
                                '127.0.0.2',
-                               FALSE
+                               FALSE,
                        ),
                        'ipv4 subnet does not match' => array(
                                '127.0.0.1/8',
                                '126.0.0.1',
-                               FALSE
+                               FALSE,
                        ),
                        'ipv6 subnet does not match' => array(
                                '::1/127',
@@ -174,7 +169,7 @@ class AbstractConditionMatcherTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                        'List of addresses does not match' => array(
                                '127.0.0.1, ::1',
                                '::2',
-                               FALSE
+                               FALSE,
                        ),
                );
        }
@@ -184,24 +179,157 @@ class AbstractConditionMatcherTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @dataProvider evaluateConditionCommonDevIpMaskDataProvider
         */
        public function evaluateConditionCommonEvaluatesIpAddressesCorrectly($devIpMask, $actualIp, $expectedResult) {
-               /** @var \TYPO3\CMS\Core\Configuration\TypoScript\ConditionMatching\AbstractConditionMatcher|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface $abstractConditionMatcherMock */
-               $abstractConditionMatcherMock = $this->getMockForAbstractClass(
-                       \TYPO3\CMS\Core\Configuration\TypoScript\ConditionMatching\AbstractConditionMatcher::class
-               );
-               $method = new \ReflectionMethod(
-                       \TYPO3\CMS\Core\Configuration\TypoScript\ConditionMatching\AbstractConditionMatcher::class,
-                       'evaluateConditionCommon'
-               );
-               $method->setAccessible(TRUE);
-
                // Do not trigger proxy stuff of GeneralUtility::getIndPEnv
                unset($GLOBALS['TYPO3_CONF_VARS']['SYS']['reverseProxyIP']);
 
                $_SERVER['REMOTE_ADDR'] = $actualIp;
                $GLOBALS['TYPO3_CONF_VARS']['SYS']['devIPmask'] = $devIpMask;
 
-               $actualResult = $method->invokeArgs($abstractConditionMatcherMock, array('IP', 'devIP'));
+               $actualResult = $this->evaluateConditionCommonMethod->invokeArgs($this->conditionMatcher, array('IP', 'devIP'));
                $this->assertSame($expectedResult, $actualResult);
        }
 
+       /**
+        * @test
+        */
+       public function testUserFuncIsCalled() {
+               $this->assertTrue(
+                       $this->evaluateConditionCommonMethod->invokeArgs(
+                               $this->conditionMatcher,
+                               array('userFunc','user_testFunction')
+                       )
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function testUserFuncWithSingleArgument() {
+               $this->assertTrue(
+                       $this->evaluateConditionCommonMethod->invokeArgs(
+                               $this->conditionMatcher,
+                               array('userFunc', 'user_testFunctionWithSingleArgument(x)')
+                       )
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function testUserFuncWithMultipleArguments() {
+               $this->assertTrue(
+                       $this->evaluateConditionCommonMethod->invokeArgs(
+                               $this->conditionMatcher,
+                               array('userFunc', 'user_testFunctionWithThreeArguments(1,2,3)')
+                       )
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function testUserFuncReturnsFalse() {
+               $this->assertFalse(
+                       $this->evaluateConditionCommonMethod->invokeArgs(
+                               $this->conditionMatcher,
+                               array('userFunc', 'user_testFunctionFalse')
+                       )
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function testUserFuncWithMultipleArgumentsAndQuotes() {
+               $this->assertTrue(
+                       $this->evaluateConditionCommonMethod->invokeArgs(
+                               $this->conditionMatcher,
+                               array('userFunc', 'user_testFunctionWithThreeArguments(1,2,"3,4,5,6")')
+                       )
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function testUserFuncWithMultipleArgumentsAndQuotesAndSpaces() {
+               $this->assertTrue(
+                       $this->evaluateConditionCommonMethod->invokeArgs(
+                               $this->conditionMatcher,
+                               array('userFunc', 'user_testFunctionWithThreeArguments ( 1 , 2, "3, 4, 5, 6" )')
+                       )
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function testUserFuncWithMultipleArgumentsAndQuotesAndSpacesStripped() {
+               $this->assertTrue(
+                       $this->evaluateConditionCommonMethod->invokeArgs(
+                               $this->conditionMatcher,
+                               array('userFunc', 'user_testFunctionWithThreeArgumentsSpaces ( 1 , 2, "3, 4, 5, 6" )')
+                       )
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function testUserFuncWithSpacesInQuotes() {
+               $this->assertTrue(
+                       $this->evaluateConditionCommonMethod->invokeArgs(
+                               $this->conditionMatcher,
+                               array('userFunc', 'user_testFunctionWithSpaces(" 3, 4, 5, 6 ")')
+                       )
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function testUserFuncWithMultipleArgumentsAndQuotesAndSpacesStrippedAndEscapes() {
+               $this->assertTrue(
+                       $this->evaluateConditionCommonMethod->invokeArgs(
+                               $this->conditionMatcher,
+                               array('userFunc', 'user_testFunctionWithThreeArgumentsSpaces ( 1 , 2, "3, \"4, 5\", 6" )')
+                       )
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function testUserFuncWithQuoteMissing() {
+               $this->assertTrue(
+                       $this->evaluateConditionCommonMethod->invokeArgs(
+                               $this->conditionMatcher,
+                               array('userFunc', 'user_testFunctionWithQuoteMissing ("value \")')
+                       )
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function testUserFuncWithQuotesInside() {
+               $this->assertTrue(
+                       $this->evaluateConditionCommonMethod->invokeArgs(
+                               $this->conditionMatcher,
+                               array('userFunc', 'user_testQuotes("1 \" 2")')
+                       )
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function testUserFuncWithClassMethodCall() {
+               $this->assertTrue(
+                       $this->evaluateConditionCommonMethod->invokeArgs(
+                               $this->conditionMatcher,
+                               array('userFunc', 'ConditionMatcherUserFunctions::isTrue(1)')
+                       )
+               );
+       }
 }
\ No newline at end of file
diff --git a/typo3/sysext/core/Tests/Unit/Configuration/TypoScript/ConditionMatching/Fixtures/ConditionMatcherUserFuncs.php b/typo3/sysext/core/Tests/Unit/Configuration/TypoScript/ConditionMatching/Fixtures/ConditionMatcherUserFuncs.php
new file mode 100644 (file)
index 0000000..67142b5
--- /dev/null
@@ -0,0 +1,64 @@
+<?php
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+namespace {
+       function user_testFunctionWithSingleArgument() {
+               return count(func_get_args()) === 1;
+       }
+
+       function user_testFunctionWithThreeArguments() {
+               return count(func_get_args()) === 3;
+       }
+
+       function user_testFunctionWithThreeArgumentsSpaces() {
+               $result = TRUE;
+               foreach (func_get_args() as $argument) {
+                       $result &= (trim($argument) == $argument);
+               }
+               return $result;
+       }
+
+       function user_testFunctionWithSpaces($value) {
+               return $value === ' 3, 4, 5, 6 ';
+       }
+
+       function user_testFunction() {
+               return TRUE;
+       }
+
+       function user_testFunctionFalse() {
+               return FALSE;
+       }
+
+       function user_testFunctionWithQuoteMissing($value) {
+               return $value === 'value "';
+       }
+
+       function user_testQuotes($value) {
+               return $value === '1 " 2';
+       }
+
+       class ConditionMatcherUserFunctions {
+
+               /**
+                * @param mixed $value
+                * @return bool
+                */
+               static public function isTrue($value) {
+                       return (bool)$value;
+               }
+
+       }
+}
+