[TASK] Re-work/simplify copyright header in PHP files - Part 4
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Core / ApplicationContextTest.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Unit\Core;
3
4 /* *
5 * This script belongs to the TYPO3 Flow framework. *
6 * *
7 * It is free software; you can redistribute it and/or modify it under *
8 * the terms of the GNU Lesser General Public License, either version 3 *
9 * of the License, or (at your option) any later version. *
10 * *
11 * The TYPO3 project - inspiring people to share! *
12 * */
13
14 use TYPO3\CMS\Core\Core\ApplicationContext;
15
16 /**
17 * Testcase for the ApplicationContext class
18 */
19 class ApplicationContextTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
20
21 /**
22 * Data provider with allowed contexts.
23 *
24 * @return array
25 */
26 public function allowedContexts() {
27 return array(
28 array('Production'),
29 array('Testing'),
30 array('Development'),
31
32 array('Development/MyLocalComputer'),
33 array('Development/MyLocalComputer/Foo'),
34 array('Production/SpecialDeployment/LiveSystem'),
35 );
36 }
37
38 /**
39 * @test
40 * @dataProvider allowedContexts
41 */
42 public function contextStringCanBeSetInConstructorAndReadByCallingToString($allowedContext) {
43 $context = new ApplicationContext($allowedContext);
44 $this->assertSame($allowedContext, (string)$context);
45 }
46
47 /**
48 * Data provider with forbidden contexts.
49 *
50 * @return array
51 */
52 public function forbiddenContexts() {
53 return array(
54 array('MySpecialContexz'),
55 array('Testing123'),
56 array('DevelopmentStuff'),
57 array('DevelopmentStuff/FooBar'),
58 );
59 }
60
61 /**
62 * @test
63 * @dataProvider forbiddenContexts
64 * @expectedException \TYPO3\CMS\Core\Exception
65 */
66 public function constructorThrowsExceptionIfMainContextIsForbidden($forbiddenContext) {
67 new ApplicationContext($forbiddenContext);
68 }
69
70 /**
71 * Data provider with expected is*() values for various contexts.
72 *
73 * @return array
74 */
75 public function isMethods() {
76 return array(
77 'Development' => array(
78 'contextName' => 'Development',
79 'isDevelopment' => TRUE,
80 'isProduction' => FALSE,
81 'isTesting' => FALSE,
82 'parentContext' => NULL
83 ),
84 'Development/YourSpecialContext' => array(
85 'contextName' => 'Development/YourSpecialContext',
86 'isDevelopment' => TRUE,
87 'isProduction' => FALSE,
88 'isTesting' => FALSE,
89 'parentContext' => 'Development'
90 ),
91
92 'Production' => array(
93 'contextName' => 'Production',
94 'isDevelopment' => FALSE,
95 'isProduction' => TRUE,
96 'isTesting' => FALSE,
97 'parentContext' => NULL
98 ),
99 'Production/MySpecialContext' => array(
100 'contextName' => 'Production/MySpecialContext',
101 'isDevelopment' => FALSE,
102 'isProduction' => TRUE,
103 'isTesting' => FALSE,
104 'parentContext' => 'Production'
105 ),
106
107 'Testing' => array(
108 'contextName' => 'Testing',
109 'isDevelopment' => FALSE,
110 'isProduction' => FALSE,
111 'isTesting' => TRUE,
112 'parentContext' => NULL
113 ),
114 'Testing/MySpecialContext' => array(
115 'contextName' => 'Testing/MySpecialContext',
116 'isDevelopment' => FALSE,
117 'isProduction' => FALSE,
118 'isTesting' => TRUE,
119 'parentContext' => 'Testing'
120 )
121 );
122 }
123
124 /**
125 * @test
126 * @dataProvider isMethods
127 */
128 public function contextMethodsReturnTheCorrectValues($contextName, $isDevelopment, $isProduction, $isTesting, $parentContext) {
129 $context = new ApplicationContext($contextName);
130 $this->assertSame($isDevelopment, $context->isDevelopment());
131 $this->assertSame($isProduction, $context->isProduction());
132 $this->assertSame($isTesting, $context->isTesting());
133 $this->assertSame((string)$parentContext, (string)$context->getParent());
134 }
135
136 /**
137 * @test
138 */
139 public function parentContextIsConnectedRecursively() {
140 $context = new ApplicationContext('Production/Foo/Bar');
141 $parentContext = $context->getParent();
142 $this->assertSame('Production/Foo', (string) $parentContext);
143
144 $rootContext = $parentContext->getParent();
145 $this->assertSame('Production', (string) $rootContext);
146 }
147 }