[FEATURE] Integrate preliminary PackageManager API
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Configuration / TypoScript / ConditionMatching / AbstractConditionMatcherTest.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Unit\Configuration\TypoScript\ConditionMatching;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2013 Steffen Müller <typo3@t3node.com>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26
27 use TYPO3\CMS\Core\Core\ApplicationContext;
28 use TYPO3\CMS\Core\Utility\GeneralUtility;
29
30 /**
31 * Testcases for
32 * TYPO3\CMS\Core\Configuration\TypoScript\ConditionMatching\AbstractConditionMatcher
33 *
34 * @author Steffen Müller <typo3@t3node.com>
35 */
36 class AbstractConditionMatcherTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
37
38 /**
39 * @var \TYPO3\CMS\Core\Core\ApplicationContext
40 */
41 protected $backupApplicationContext = NULL;
42
43 /**
44 *
45 */
46 public function setUp() {
47 $this->backupApplicationContext = GeneralUtility::getApplicationContext();
48 }
49
50 /**
51 *
52 */
53 public function tearDown() {
54 Fixtures\GeneralUtilityFixture::setApplicationContext($this->backupApplicationContext);
55 unset($this->backupApplicationContext);
56 }
57
58 /**
59 * Data provider with matching applicationContext conditions.
60 *
61 * @return array
62 */
63 public function matchingApplicationContextConditions() {
64 return array(
65 array('Production*'),
66 array('Production/Staging/*'),
67 array('Production/Staging/Server2'),
68 array('/^Production.*$/'),
69 array('/^Production\/.+\/Server\d+$/'),
70 );
71 }
72
73 /**
74 * @test
75 * @dataProvider matchingApplicationContextConditions
76 */
77 public function evaluateConditionCommonReturnsTrueForMatchingContexts($matchingContextCondition) {
78
79 /** @var \TYPO3\CMS\Core\Core\ApplicationContext $applicationContext */
80 $applicationContext = new ApplicationContext('Production/Staging/Server2');
81 Fixtures\GeneralUtilityFixture::setApplicationContext($applicationContext);
82
83 /** @var \TYPO3\CMS\Core\Configuration\TypoScript\ConditionMatching\AbstractConditionMatcher|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface $abstractConditionMatcherMock */
84 $abstractConditionMatcherMock = $this->getMockForAbstractClass(
85 'TYPO3\\CMS\\Core\\Configuration\\TypoScript\\ConditionMatching\\AbstractConditionMatcher',
86 array(),
87 '',
88 TRUE,
89 TRUE,
90 TRUE,
91 array('evaluateConditionCommon')
92 );
93
94 $method = new \ReflectionMethod(
95 'TYPO3\\CMS\\Core\\Configuration\\TypoScript\\ConditionMatching\\AbstractConditionMatcher',
96 'evaluateConditionCommon'
97 );
98 $method->setAccessible(TRUE);
99
100 $this->assertTrue(
101 $method->invokeArgs($abstractConditionMatcherMock, array('applicationContext', $matchingContextCondition))
102 );
103 }
104
105 /**
106 * Data provider with not matching applicationContext conditions.
107 *
108 * @return array
109 */
110 public function notMatchingApplicationContextConditions() {
111 return array(
112 array('Production'),
113 array('Testing*'),
114 array('Development/Profiling, Testing/Unit'),
115 array('Testing/Staging/Server2'),
116 array('/^Testing.*$/'),
117 array('/^Production\/.+\/Host\d+$/'),
118 );
119 }
120
121 /**
122 * @test
123 * @dataProvider notMatchingApplicationContextConditions
124 */
125 public function evaluateConditionCommonReturnsNullForNotMatchingApplicationContexts($notMatchingApplicationContextCondition) {
126
127 /** @var \TYPO3\CMS\Core\Core\ApplicationContext $applicationContext */
128 $applicationContext = new ApplicationContext('Production/Staging/Server2');
129 Fixtures\GeneralUtilityFixture::setApplicationContext($applicationContext);
130
131 /** @var \TYPO3\CMS\Core\Configuration\TypoScript\ConditionMatching\AbstractConditionMatcher|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface $abstractConditionMatcherMock */
132 $abstractConditionMatcherMock = $this->getMockForAbstractClass(
133 'TYPO3\\CMS\\Core\\Configuration\\TypoScript\\ConditionMatching\\AbstractConditionMatcher',
134 array(),
135 '',
136 TRUE,
137 TRUE,
138 TRUE,
139 array('evaluateConditionCommon')
140 );
141
142 $method = new \ReflectionMethod(
143 'TYPO3\\CMS\\Core\\Configuration\\TypoScript\\ConditionMatching\\AbstractConditionMatcher',
144 'evaluateConditionCommon'
145 );
146 $method->setAccessible(TRUE);
147
148 $this->assertNull(
149 $method->invokeArgs($abstractConditionMatcherMock, array('applicationContext', $notMatchingApplicationContextCondition))
150 );
151 }
152 }