2080ed3a63022b39dbbe2d13edc89bf573a81083
[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 * Copyright notice
10 *
11 * (c) 2013 Dmitry Dulepov <dmitry.dulepov@gmail.com>
12 * All rights reserved
13 *
14 * This script is part of the TYPO3 project. The TYPO3 project is
15 * free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
19 *
20 * The GNU General Public License can be found at
21 * http://www.gnu.org/copyleft/gpl.html.
22 *
23 * This script is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * This copyright notice MUST APPEAR in all copies of the script!
29 ***************************************************************/
30
31 require_once(ExtensionManagementUtility::extPath('core', 'Tests/Unit/Configuration/ConditionMatcherUserFuncs.php'));
32
33 /**
34 * Test class for ConditionMatcher functions
35 *
36 * @author Dmitry Dulepov <dmitry.dulepov@gmail.com>
37 */
38 class ConditionMatcherTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
39
40 /** @var ConditionMatcher */
41 protected $conditionMatcher;
42
43 public function setUp() {
44 $this->conditionMatcher = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Configuration\\TypoScript\\ConditionMatching\\ConditionMatcher');
45 }
46
47 /**
48 * @test
49 * @return void
50 */
51 public function testUserFuncIsCalled() {
52 $this->assertTrue($this->conditionMatcher->match('[userFunc = user_testFunction]'));
53 }
54
55 /**
56 * @test
57 * @return void
58 */
59 public function testUserFuncWithSingleArgument() {
60 $this->assertTrue($this->conditionMatcher->match('[userFunc = user_testFunctionWithSingleArgument(x)]'));
61 }
62
63 /**
64 * @test
65 * @return void
66 */
67 public function testUserFuncWithMultipleArguments() {
68 $this->assertTrue($this->conditionMatcher->match('[userFunc = user_testFunctionWithThreeArguments(1,2,3)]'));
69 }
70
71 /**
72 * @test
73 * @return void
74 */
75 public function testUserFuncReturnsFalse() {
76 $this->assertFalse($this->conditionMatcher->match('[userFunc = user_testFunctionFalse]'));
77 }
78
79 /**
80 * @test
81 * @return void
82 */
83 public function testUserFuncWithMultipleArgumentsAndQuotes() {
84 $this->assertTrue($this->conditionMatcher->match('[userFunc = user_testFunctionWithThreeArguments(1,2,"3,4,5,6")]'));
85 }
86
87 /**
88 * @test
89 * @return void
90 */
91 public function testUserFuncWithMultipleArgumentsAndQuotesAndSpaces() {
92 $this->assertTrue($this->conditionMatcher->match('[userFunc = user_testFunctionWithThreeArguments ( 1 , 2, "3, 4, 5, 6" ) ]'));
93 }
94
95 /**
96 * @test
97 * @return void
98 */
99 public function testUserFuncWithMultipleArgumentsAndQuotesAndSpacesStripped() {
100 $this->assertTrue($this->conditionMatcher->match('[userFunc = user_testFunctionWithThreeArgumentsSpaces ( 1 , 2, "3, 4, 5, 6" ) ]'));
101 }
102
103 /**
104 * @test
105 * @return void
106 */
107 public function testUserFuncWithSpacesInQuotes() {
108 $this->assertTrue($this->conditionMatcher->match('[userFunc = user_testFunctionWithSpaces(" 3, 4, 5, 6 ")]'));
109 }
110
111 /**
112 * @test
113 * @return void
114 */
115 public function testUserFuncWithMultipleArgumentsAndQuotesAndSpacesStrippedAndEscapes() {
116 $this->assertTrue($this->conditionMatcher->match('[userFunc = user_testFunctionWithThreeArgumentsSpaces ( 1 , 2, "3, \"4, 5\", 6" ) ]'));
117 }
118
119 /**
120 * @test
121 * @return void
122 */
123 public function testUserFuncWithQuoteMissing() {
124 $this->assertTrue($this->conditionMatcher->match('[userFunc = user_testFunctionWithQuoteMissing ("value \") ]'));
125 }
126
127 /**
128 * @test
129 * @return void
130 */
131 public function testUserFuncWithQuotesInside() {
132 $this->assertTrue($this->conditionMatcher->match('[userFunc = user_testQuotes("1 \" 2") ]'));
133 }
134
135 }
136
137 ?>