[BUGFIX] language condition does not match exact string
[Packages/TYPO3.CMS.git] / typo3 / sysext / frontend / Tests / Unit / Configuration / TypoScript / ConditionMatching / ConditionMatcherTest.php
index 3ba0fea..2282727 100644 (file)
@@ -4,7 +4,7 @@ namespace TYPO3\CMS\Frontend\Tests\Unit\Configuration\TypoScript\ConditionMatchi
 /***************************************************************
  *  Copyright notice
  *
- *  (c) 2009-2011 Oliver Hader <oliver@typo3.org>
+ *  (c) 2009-2013 Oliver Hader <oliver@typo3.org>
  *  All rights reserved
  *
  *  This script is part of the TYPO3 project. The TYPO3 project is
@@ -28,56 +28,30 @@ namespace TYPO3\CMS\Frontend\Tests\Unit\Configuration\TypoScript\ConditionMatchi
  * Testcase for class \TYPO3\CMS\Frontend\Configuration\TypoScript\ConditionMatching\ConditionMatcher.
  *
  * @author     Oliver Hader <oliver@typo3.org>
- * @package TYPO3
- * @subpackage t3lib
  */
-class ConditionMatcherTest extends \tx_phpunit_testcase {
+class ConditionMatcherTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
 
        /**
-        * @var array
+        * @var string Name of a key in $GLOBALS for this test
         */
-       private $backupGlobalVariables;
+       protected $testGlobalNamespace;
 
        /**
-        * @var array
+        * @var \TYPO3\CMS\Frontend\Configuration\TypoScript\ConditionMatching\ConditionMatcher Class under test
         */
-       private $rootline;
-
-       /**
-        * @var \TYPO3\CMS\Frontend\Configuration\TypoScript\ConditionMatching\ConditionMatcher
-        */
-       private $matchCondition;
+       protected $matchCondition;
 
        public function setUp() {
-               $this->backupGlobalVariables = array(
-                       '_ENV' => $_ENV,
-                       '_GET' => $_GET,
-                       '_POST' => $_POST,
-                       '_SERVER' => $_SERVER,
-                       'TYPO3_CONF_VARS' => $GLOBALS['TYPO3_CONF_VARS'],
-                       'T3_VAR' => $GLOBALS['T3_VAR']
-               );
                $this->testGlobalNamespace = uniqid('TEST');
                $GLOBALS[$this->testGlobalNamespace] = array();
-               $this->setUpTSFE();
-               $this->matchCondition = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Configuration\\TypoScript\\ConditionMatching\\ConditionMatcher');
-       }
-
-       public function tearDown() {
-               foreach ($this->backupGlobalVariables as $key => $data) {
-                       $GLOBALS[$key] = $data;
-               }
-               unset($this->matchCondition);
-               unset($this->backupGlobalVariables);
-               unset($GLOBALS[$this->testGlobalNamespace]);
-       }
-
-       private function setUpTSFE() {
-               $this->rootline = array(
+               $GLOBALS['TSFE'] = new \stdClass();
+               $GLOBALS['TSFE']->tmpl = new \stdClass();
+               $GLOBALS['TSFE']->tmpl->rootLine = array(
                        2 => array('uid' => 121, 'pid' => 111),
                        1 => array('uid' => 111, 'pid' => 101),
                        0 => array('uid' => 101, 'pid' => 0)
                );
+               $this->matchCondition = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Configuration\\TypoScript\\ConditionMatching\\ConditionMatcher');
        }
 
        /**
@@ -262,9 +236,8 @@ class ConditionMatcherTest extends \tx_phpunit_testcase {
         * @test
         */
        public function languageConditionMatchesCompleteLanguagesExpression() {
-               $this->markTestSkipped('This comparison seems to be incomplete in \TYPO3\CMS\Frontend\Configuration\TypoScript\ConditionMatching\ConditionMatcher.');
                $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'de-de,de;q=0.8,en-us;q=0.5,en;q=0.3';
-               $this->assertTrue($this->matchCondition->match('[language = de-de,de;q=0.8]'));
+               $this->assertTrue($this->matchCondition->match('[language = de-de,de;q=0.8,en-us;q=0.5,en;q=0.3]'));
        }
 
        /**
@@ -391,6 +364,15 @@ class ConditionMatcherTest extends \tx_phpunit_testcase {
        }
 
        /**
+        * Tests whether numerical comparison does not match.
+        *
+        * @test
+        */
+       public function globalVarConditionDoesNotMatchOnNotEqualExpression() {
+               $this->assertFalse($this->matchCondition->match('[globalVar = LIT:10 != 10]'));
+       }
+
+       /**
         * Tests whether numerical comparison matches.
         *
         * @test
@@ -483,6 +465,19 @@ class ConditionMatcherTest extends \tx_phpunit_testcase {
         *
         * @test
         */
+       public function globalStringConditionMatchesOnEmptyExpressionWithValueSetToEmptyString() {
+               $testKey = uniqid('test');
+               $_GET = array();
+               $_POST = array($testKey => '');
+               $this->assertTrue($this->matchCondition->match('[globalString = GP:' . $testKey . '=]'));
+               $this->assertTrue($this->matchCondition->match('[globalString = GP:' . $testKey . ' = ]'));
+       }
+
+       /**
+        * Tests whether string comparison matches.
+        *
+        * @test
+        */
        public function globalStringConditionMatchesWildcardExpression() {
                $this->assertTrue($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = TYPO3?Test?Condition]'));
                $this->assertTrue($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = TYPO3.T*t.Condition]'));
@@ -517,7 +512,6 @@ class ConditionMatcherTest extends \tx_phpunit_testcase {
         * @test
         */
        public function treeLevelConditionMatchesSingleValue() {
-               $GLOBALS['TSFE']->tmpl->rootLine = $this->rootline;
                $this->assertTrue($this->matchCondition->match('[treeLevel = 2]'));
        }
 
@@ -527,7 +521,6 @@ class ConditionMatcherTest extends \tx_phpunit_testcase {
         * @test
         */
        public function treeLevelConditionMatchesMultipleValues() {
-               $GLOBALS['TSFE']->tmpl->rootLine = $this->rootline;
                $this->assertTrue($this->matchCondition->match('[treeLevel = 999,998,2]'));
        }
 
@@ -537,7 +530,6 @@ class ConditionMatcherTest extends \tx_phpunit_testcase {
         * @test
         */
        public function treeLevelConditionDoesNotMatchFaultyValue() {
-               $GLOBALS['TSFE']->tmpl->rootLine = $this->rootline;
                $this->assertFalse($this->matchCondition->match('[treeLevel = 999]'));
        }
 
@@ -547,7 +539,6 @@ class ConditionMatcherTest extends \tx_phpunit_testcase {
         * @test
         */
        public function PIDupinRootlineConditionMatchesSinglePageIdInRootline() {
-               $GLOBALS['TSFE']->tmpl->rootLine = $this->rootline;
                $GLOBALS['TSFE']->id = 121;
                $this->assertTrue($this->matchCondition->match('[PIDupinRootline = 111]'));
        }
@@ -558,7 +549,6 @@ class ConditionMatcherTest extends \tx_phpunit_testcase {
         * @test
         */
        public function PIDupinRootlineConditionMatchesMultiplePageIdsInRootline() {
-               $GLOBALS['TSFE']->tmpl->rootLine = $this->rootline;
                $GLOBALS['TSFE']->id = 121;
                $this->assertTrue($this->matchCondition->match('[PIDupinRootline = 999,111,101]'));
        }
@@ -569,7 +559,6 @@ class ConditionMatcherTest extends \tx_phpunit_testcase {
         * @test
         */
        public function PIDupinRootlineConditionDoesNotMatchPageIdNotInRootline() {
-               $GLOBALS['TSFE']->tmpl->rootLine = $this->rootline;
                $GLOBALS['TSFE']->id = 121;
                $this->assertFalse($this->matchCondition->match('[PIDupinRootline = 999]'));
        }
@@ -580,7 +569,6 @@ class ConditionMatcherTest extends \tx_phpunit_testcase {
         * @test
         */
        public function PIDupinRootlineConditionDoesNotMatchLastPageIdInRootline() {
-               $GLOBALS['TSFE']->tmpl->rootLine = $this->rootline;
                $GLOBALS['TSFE']->id = 121;
                $this->assertFalse($this->matchCondition->match('[PIDupinRootline = 121]'));
        }
@@ -591,7 +579,6 @@ class ConditionMatcherTest extends \tx_phpunit_testcase {
         * @test
         */
        public function PIDinRootlineConditionMatchesSinglePageIdInRootline() {
-               $GLOBALS['TSFE']->tmpl->rootLine = $this->rootline;
                $GLOBALS['TSFE']->id = 121;
                $this->assertTrue($this->matchCondition->match('[PIDinRootline = 111]'));
        }
@@ -602,7 +589,6 @@ class ConditionMatcherTest extends \tx_phpunit_testcase {
         * @test
         */
        public function PIDinRootlineConditionMatchesMultiplePageIdsInRootline() {
-               $GLOBALS['TSFE']->tmpl->rootLine = $this->rootline;
                $GLOBALS['TSFE']->id = 121;
                $this->assertTrue($this->matchCondition->match('[PIDinRootline = 999,111,101]'));
        }
@@ -613,7 +599,6 @@ class ConditionMatcherTest extends \tx_phpunit_testcase {
         * @test
         */
        public function PIDinRootlineConditionMatchesLastPageIdInRootline() {
-               $GLOBALS['TSFE']->tmpl->rootLine = $this->rootline;
                $GLOBALS['TSFE']->id = 121;
                $this->assertTrue($this->matchCondition->match('[PIDinRootline = 121]'));
        }
@@ -624,7 +609,6 @@ class ConditionMatcherTest extends \tx_phpunit_testcase {
         * @test
         */
        public function PIDinRootlineConditionDoesNotMatchPageIdNotInRootline() {
-               $GLOBALS['TSFE']->tmpl->rootLine = $this->rootline;
                $GLOBALS['TSFE']->id = 121;
                $this->assertFalse($this->matchCondition->match('[PIDinRootline = 999]'));
        }
@@ -723,5 +707,3 @@ class ConditionMatcherTest extends \tx_phpunit_testcase {
        }
 
 }
-
-?>
\ No newline at end of file