TYPO3 CMS  TYPO3_8-7
ApplicationContextTest.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
18 
22 class ApplicationContextTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
23 {
29  public function allowedContexts()
30  {
31  return [
32  ['Production'],
33  ['Testing'],
34  ['Development'],
35 
36  ['Development/MyLocalComputer'],
37  ['Development/MyLocalComputer/Foo'],
38  ['Production/SpecialDeployment/LiveSystem'],
39  ];
40  }
41 
47  {
48  $context = new ApplicationContext($allowedContext);
49  $this->assertSame($allowedContext, (string)$context);
50  }
51 
57  public function forbiddenContexts()
58  {
59  return [
60  ['MySpecialContexz'],
61  ['Testing123'],
62  ['DevelopmentStuff'],
63  ['DevelopmentStuff/FooBar'],
64  ];
65  }
66 
71  public function constructorThrowsExceptionIfMainContextIsForbidden($forbiddenContext)
72  {
73  $this->expectException(\TYPO3\CMS\Core\Exception::class);
74  $this->expectExceptionCode(1335436551);
75 
76  new ApplicationContext($forbiddenContext);
77  }
78 
84  public function isMethods()
85  {
86  return [
87  'Development' => [
88  'contextName' => 'Development',
89  'isDevelopment' => true,
90  'isProduction' => false,
91  'isTesting' => false,
92  'parentContext' => null
93  ],
94  'Development/YourSpecialContext' => [
95  'contextName' => 'Development/YourSpecialContext',
96  'isDevelopment' => true,
97  'isProduction' => false,
98  'isTesting' => false,
99  'parentContext' => 'Development'
100  ],
101 
102  'Production' => [
103  'contextName' => 'Production',
104  'isDevelopment' => false,
105  'isProduction' => true,
106  'isTesting' => false,
107  'parentContext' => null
108  ],
109  'Production/MySpecialContext' => [
110  'contextName' => 'Production/MySpecialContext',
111  'isDevelopment' => false,
112  'isProduction' => true,
113  'isTesting' => false,
114  'parentContext' => 'Production'
115  ],
116 
117  'Testing' => [
118  'contextName' => 'Testing',
119  'isDevelopment' => false,
120  'isProduction' => false,
121  'isTesting' => true,
122  'parentContext' => null
123  ],
124  'Testing/MySpecialContext' => [
125  'contextName' => 'Testing/MySpecialContext',
126  'isDevelopment' => false,
127  'isProduction' => false,
128  'isTesting' => true,
129  'parentContext' => 'Testing'
130  ]
131  ];
132  }
133 
138  public function contextMethodsReturnTheCorrectValues($contextName, $isDevelopment, $isProduction, $isTesting, $parentContext)
139  {
140  $context = new ApplicationContext($contextName);
141  $this->assertSame($isDevelopment, $context->isDevelopment());
142  $this->assertSame($isProduction, $context->isProduction());
143  $this->assertSame($isTesting, $context->isTesting());
144  $this->assertSame((string)$parentContext, (string)$context->getParent());
145  }
146 
151  {
152  $context = new ApplicationContext('Production/Foo/Bar');
153  $parentContext = $context->getParent();
154  $this->assertSame('Production/Foo', (string)$parentContext);
155 
156  $rootContext = $parentContext->getParent();
157  $this->assertSame('Production', (string)$rootContext);
158  }
159 }
contextMethodsReturnTheCorrectValues($contextName, $isDevelopment, $isProduction, $isTesting, $parentContext)