[TASK] Remove $db property in UserAuthentication classes
[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 {
28 return array(
29 array('Production'),
30 array('Testing'),
31 array('Development'),
32
33 array('Development/MyLocalComputer'),
34 array('Development/MyLocalComputer/Foo'),
35 array('Production/SpecialDeployment/LiveSystem'),
36 );
37 }
38
39 /**
40 * @test
41 * @dataProvider allowedContexts
42 */
43 public function contextStringCanBeSetInConstructorAndReadByCallingToString($allowedContext)
44 {
45 $context = new ApplicationContext($allowedContext);
46 $this->assertSame($allowedContext, (string)$context);
47 }
48
49 /**
50 * Data provider with forbidden contexts.
51 *
52 * @return array
53 */
54 public function forbiddenContexts()
55 {
56 return array(
57 array('MySpecialContexz'),
58 array('Testing123'),
59 array('DevelopmentStuff'),
60 array('DevelopmentStuff/FooBar'),
61 );
62 }
63
64 /**
65 * @test
66 * @dataProvider forbiddenContexts
67 * @expectedException \TYPO3\CMS\Core\Exception
68 */
69 public function constructorThrowsExceptionIfMainContextIsForbidden($forbiddenContext)
70 {
71 new ApplicationContext($forbiddenContext);
72 }
73
74 /**
75 * Data provider with expected is*() values for various contexts.
76 *
77 * @return array
78 */
79 public function isMethods()
80 {
81 return array(
82 'Development' => array(
83 'contextName' => 'Development',
84 'isDevelopment' => true,
85 'isProduction' => false,
86 'isTesting' => false,
87 'parentContext' => null
88 ),
89 'Development/YourSpecialContext' => array(
90 'contextName' => 'Development/YourSpecialContext',
91 'isDevelopment' => true,
92 'isProduction' => false,
93 'isTesting' => false,
94 'parentContext' => 'Development'
95 ),
96
97 'Production' => array(
98 'contextName' => 'Production',
99 'isDevelopment' => false,
100 'isProduction' => true,
101 'isTesting' => false,
102 'parentContext' => null
103 ),
104 'Production/MySpecialContext' => array(
105 'contextName' => 'Production/MySpecialContext',
106 'isDevelopment' => false,
107 'isProduction' => true,
108 'isTesting' => false,
109 'parentContext' => 'Production'
110 ),
111
112 'Testing' => array(
113 'contextName' => 'Testing',
114 'isDevelopment' => false,
115 'isProduction' => false,
116 'isTesting' => true,
117 'parentContext' => null
118 ),
119 'Testing/MySpecialContext' => array(
120 'contextName' => 'Testing/MySpecialContext',
121 'isDevelopment' => false,
122 'isProduction' => false,
123 'isTesting' => true,
124 'parentContext' => 'Testing'
125 )
126 );
127 }
128
129 /**
130 * @test
131 * @dataProvider isMethods
132 */
133 public function contextMethodsReturnTheCorrectValues($contextName, $isDevelopment, $isProduction, $isTesting, $parentContext)
134 {
135 $context = new ApplicationContext($contextName);
136 $this->assertSame($isDevelopment, $context->isDevelopment());
137 $this->assertSame($isProduction, $context->isProduction());
138 $this->assertSame($isTesting, $context->isTesting());
139 $this->assertSame((string)$parentContext, (string)$context->getParent());
140 }
141
142 /**
143 * @test
144 */
145 public function parentContextIsConnectedRecursively()
146 {
147 $context = new ApplicationContext('Production/Foo/Bar');
148 $parentContext = $context->getParent();
149 $this->assertSame('Production/Foo', (string)$parentContext);
150
151 $rootContext = $parentContext->getParent();
152 $this->assertSame('Production', (string)$rootContext);
153 }
154 }