[FEATURE] Support literal strings in boolean arguments
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Tests / Unit / Core / Parser / SyntaxTree / BooleanNodeTest.php
index 91249a2..fc8f8b3 100644 (file)
@@ -244,6 +244,83 @@ class BooleanNodeTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
                $this->assertFalse($booleanNode->evaluate($this->renderingContext));
        }
 
+       /**
+        * @test
+        */
+       public function notEqualReturnsFalseIfComparingMatchingStrings() {
+               $rootNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\RootNode();
+               $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('\'stringA\' != "stringA"'));
+
+               $booleanNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode($rootNode);
+               $this->assertFalse($booleanNode->evaluate($this->renderingContext));
+       }
+
+       /**
+        * @test
+        */
+       public function notEqualReturnsTrueIfComparingNonMatchingStrings() {
+               $rootNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\RootNode();
+               $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('\'stringA\' != \'stringB\''));
+
+               $booleanNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode($rootNode);
+               $this->assertTrue($booleanNode->evaluate($this->renderingContext));
+       }
+
+       /**
+        * @test
+        */
+       public function equalsReturnsFalseIfComparingNonMatchingStrings() {
+               $rootNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\RootNode();
+               $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('\'stringA\' == \'stringB\''));
+
+               $booleanNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode($rootNode);
+               $this->assertFalse($booleanNode->evaluate($this->renderingContext));
+       }
+
+       /**
+        * @test
+        */
+       public function equalsReturnsTrueIfComparingMatchingStrings() {
+               $rootNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\RootNode();
+               $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('\'stringA\' == "stringA"'));
+
+               $booleanNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode($rootNode);
+               $this->assertTrue($booleanNode->evaluate($this->renderingContext));
+       }
+
+       /**
+        * @test
+        */
+       public function equalsReturnsTrueIfComparingMatchingStringsWithEscapedQuotes() {
+               $rootNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\RootNode();
+               $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('\'\\\'stringA\\\'\' == \'\\\'stringA\\\'\''));
+
+               $booleanNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode($rootNode);
+               $this->assertTrue($booleanNode->evaluate($this->renderingContext));
+       }
+
+       /**
+        * @test
+        */
+       public function equalsReturnsFalseIfComparingStringWithNonZero() {
+               $rootNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\RootNode();
+               $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('\'stringA\' == 42'));
+
+               $booleanNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode($rootNode);
+               $this->assertFalse($booleanNode->evaluate($this->renderingContext));
+       }
+
+       /**
+        * @test
+        */
+       public function equalsReturnsTrueIfComparingStringWithZero() {
+               $rootNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\RootNode();
+               $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('\'stringA\' == 0'));
+
+               $booleanNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode($rootNode);
+               $this->assertTrue($booleanNode->evaluate($this->renderingContext));
+       }
+
        /**
         * @test
         */