[TASK] Add more tests for ConditionMatcher 86/57886/8
authorFrank Naegler <frank.naegler@typo3.org>
Mon, 13 Aug 2018 16:13:25 +0000 (18:13 +0200)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Tue, 14 Aug 2018 17:31:23 +0000 (19:31 +0200)
Resolves: #85835
Releases: master
Change-Id: Ia9c66139b74ac15bcf9b5b693b57b840b706e188
Reviewed-on: https://review.typo3.org/57886
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
typo3/sysext/core/Tests/Unit/Configuration/TypoScript/ConditionMatching/AbstractConditionMatcherTest.php
typo3/sysext/frontend/Tests/Unit/Configuration/TypoScript/ConditionMatching/ConditionMatcherTest.php

index 0b75b62..99992b8 100644 (file)
@@ -65,6 +65,66 @@ class AbstractConditionMatcherTest extends UnitTestCase
     }
 
     /**
+     * @return array
+     */
+    public function datesConditionDataProvider(): array
+    {
+        return [
+            '[dayofmonth = 17]' => ['dayofmonth', 17, true],
+            '[dayofweek = 3]' => ['dayofweek', 3, true],
+            '[dayofyear = 16]' => ['dayofyear', 16, true],
+            '[hour = 11]' => ['hour', 11, true],
+            '[minute = 4]' => ['minute', 4, true],
+            '[month = 1]' => ['month', 1, true],
+            '[year = 1945]' => ['year', 1945, true],
+        ];
+    }
+
+    /**
+     * @test
+     * @dataProvider datesConditionDataProvider
+     * @param string $expressionMethod
+     * @param int $expressionValue
+     * @param bool $expected
+     */
+    public function checkConditionMatcherForDates(string $expressionMethod, int $expressionValue, bool $expected): void
+    {
+        $GLOBALS['SIM_EXEC_TIME'] = mktime(11, 4, 0, 1, 17, 1945);
+        $this->assertSame($expected, $this->evaluateConditionCommonMethod->invokeArgs(
+            $this->conditionMatcher,
+            [$expressionMethod, $expressionValue]
+        ));
+    }
+
+    /**
+     * @return array
+     */
+    public function hostnameDataProvider(): array
+    {
+        return [
+            '[hostname = localhost]' => ['hostname', 'localhost', true],
+            '[hostname = localhost, foo.local]' => ['hostname', 'localhost, foo.local', true],
+            '[hostname = bar.local, foo.local]' => ['hostname', 'bar.local, foo.local', false],
+        ];
+    }
+
+    /**
+     * @test
+     * @dataProvider hostnameDataProvider
+     * @param string $expressionMethod
+     * @param string $expressionValue
+     * @param bool $expected
+     */
+    public function checkConditionMatcherForHostname(string $expressionMethod, string $expressionValue, bool $expected): void
+    {
+        $GLOBALS['_SERVER']['REMOTE_ADDR'] = '127.0.0.1';
+        $this->assertSame($expected, $this->evaluateConditionCommonMethod->invokeArgs(
+            $this->conditionMatcher,
+            [$expressionMethod, $expressionValue]
+        ));
+    }
+
+    /**
      * Data provider with matching applicationContext conditions.
      *
      * @return array
index 27e8a6e..fc997a4 100644 (file)
@@ -511,6 +511,31 @@ class ConditionMatcherTest extends UnitTestCase
     }
 
     /**
+     * @return array
+     */
+    public function pageDataProvider(): array
+    {
+        return [
+            '[page|layout = 0]' => ['[page|layout = 0]', true],
+            '[page|layout = 1]' => ['[page|layout = 1]', false],
+            '[page|title = Foo]' => ['[page|title = Foo]', true],
+        ];
+    }
+
+    /**
+     * @test
+     * @dataProvider pageDataProvider
+     * @param string $expression
+     * @param bool $expected
+     */
+    public function checkConditionMatcherForPage(string $expression, bool $expected): void
+    {
+        $GLOBALS['TSFE']->page = ['title' => 'Foo', 'layout' => 0];
+        $subject = new ConditionMatcher(new Context());
+        $this->assertSame($expected, $subject->match($expression));
+    }
+
+    /**
      * Tests whether a page Id is found in the previous rootline entries.
      *
      * @test