921cf40ddbaf1d65d8ea2615798e31e60b84b1fe
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Configuration / ConditionMatcherTest.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Unit\Configuration;
3
4 use TYPO3\CMS\Backend\Configuration\TypoScript\ConditionMatching\ConditionMatcher;
5 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
6 use TYPO3\CMS\Core\Utility\GeneralUtility;
7
8 /**
9 * This file is part of the TYPO3 CMS project.
10 *
11 * It is free software; you can redistribute it and/or modify it under
12 * the terms of the GNU General Public License, either version 2
13 * of the License, or any later version.
14 *
15 * For the full copyright and license information, please read the
16 * LICENSE.txt file that was distributed with this source code.
17 *
18 * The TYPO3 project - inspiring people to share!
19 */
20
21 require_once(ExtensionManagementUtility::extPath('core', 'Tests/Unit/Configuration/ConditionMatcherUserFuncs.php'));
22
23 /**
24 * Test class for ConditionMatcher functions
25 *
26 * @author Dmitry Dulepov <dmitry.dulepov@gmail.com>
27 */
28 class ConditionMatcherTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
29
30 /** @var ConditionMatcher */
31 protected $conditionMatcher;
32
33 public function setUp() {
34 $this->conditionMatcher = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Configuration\\TypoScript\\ConditionMatching\\ConditionMatcher');
35 }
36
37 /**
38 * @test
39 * @return void
40 */
41 public function testUserFuncIsCalled() {
42 $this->assertTrue($this->conditionMatcher->match('[userFunc = user_testFunction]'));
43 }
44
45 /**
46 * @test
47 * @return void
48 */
49 public function testUserFuncWithSingleArgument() {
50 $this->assertTrue($this->conditionMatcher->match('[userFunc = user_testFunctionWithSingleArgument(x)]'));
51 }
52
53 /**
54 * @test
55 * @return void
56 */
57 public function testUserFuncWithMultipleArguments() {
58 $this->assertTrue($this->conditionMatcher->match('[userFunc = user_testFunctionWithThreeArguments(1,2,3)]'));
59 }
60
61 /**
62 * @test
63 * @return void
64 */
65 public function testUserFuncReturnsFalse() {
66 $this->assertFalse($this->conditionMatcher->match('[userFunc = user_testFunctionFalse]'));
67 }
68
69 /**
70 * @test
71 * @return void
72 */
73 public function testUserFuncWithMultipleArgumentsAndQuotes() {
74 $this->assertTrue($this->conditionMatcher->match('[userFunc = user_testFunctionWithThreeArguments(1,2,"3,4,5,6")]'));
75 }
76
77 /**
78 * @test
79 * @return void
80 */
81 public function testUserFuncWithMultipleArgumentsAndQuotesAndSpaces() {
82 $this->assertTrue($this->conditionMatcher->match('[userFunc = user_testFunctionWithThreeArguments ( 1 , 2, "3, 4, 5, 6" ) ]'));
83 }
84
85 /**
86 * @test
87 * @return void
88 */
89 public function testUserFuncWithMultipleArgumentsAndQuotesAndSpacesStripped() {
90 $this->assertTrue($this->conditionMatcher->match('[userFunc = user_testFunctionWithThreeArgumentsSpaces ( 1 , 2, "3, 4, 5, 6" ) ]'));
91 }
92
93 /**
94 * @test
95 * @return void
96 */
97 public function testUserFuncWithSpacesInQuotes() {
98 $this->assertTrue($this->conditionMatcher->match('[userFunc = user_testFunctionWithSpaces(" 3, 4, 5, 6 ")]'));
99 }
100
101 /**
102 * @test
103 * @return void
104 */
105 public function testUserFuncWithMultipleArgumentsAndQuotesAndSpacesStrippedAndEscapes() {
106 $this->assertTrue($this->conditionMatcher->match('[userFunc = user_testFunctionWithThreeArgumentsSpaces ( 1 , 2, "3, \"4, 5\", 6" ) ]'));
107 }
108
109 /**
110 * @test
111 * @return void
112 */
113 public function testUserFuncWithQuoteMissing() {
114 $this->assertTrue($this->conditionMatcher->match('[userFunc = user_testFunctionWithQuoteMissing ("value \") ]'));
115 }
116
117 /**
118 * @test
119 * @return void
120 */
121 public function testUserFuncWithQuotesInside() {
122 $this->assertTrue($this->conditionMatcher->match('[userFunc = user_testQuotes("1 \" 2") ]'));
123 }
124
125 }
126
127 ?>