‪TYPO3CMS  9.5
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 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
19 
23 class ‪ApplicationContextTest extends UnitTestCase
24 {
30  public function ‪allowedContexts()
31  {
32  return [
33  ['Production'],
34  ['Testing'],
35  ['Development'],
36 
37  ['Development/MyLocalComputer'],
38  ['Development/MyLocalComputer/Foo'],
39  ['Production/SpecialDeployment/LiveSystem'],
40  ];
41  }
42 
48  {
49  $context = new ‪ApplicationContext($allowedContext);
50  $this->assertSame($allowedContext, (string)$context);
51  }
52 
58  public function ‪forbiddenContexts()
59  {
60  return [
61  ['MySpecialContexz'],
62  ['Testing123'],
63  ['DevelopmentStuff'],
64  ['DevelopmentStuff/FooBar'],
65  ];
66  }
67 
72  public function ‪constructorThrowsExceptionIfMainContextIsForbidden($forbiddenContext)
73  {
74  $this->expectException(\‪TYPO3\CMS\Core\Exception::class);
75  $this->expectExceptionCode(1335436551);
76 
77  new ‪ApplicationContext($forbiddenContext);
78  }
79 
85  public function ‪isMethods()
86  {
87  return [
88  'Development' => [
89  'contextName' => 'Development',
90  'isDevelopment' => true,
91  'isProduction' => false,
92  'isTesting' => false,
93  'parentContext' => null
94  ],
95  'Development/YourSpecialContext' => [
96  'contextName' => 'Development/YourSpecialContext',
97  'isDevelopment' => true,
98  'isProduction' => false,
99  'isTesting' => false,
100  'parentContext' => 'Development'
101  ],
102 
103  'Production' => [
104  'contextName' => 'Production',
105  'isDevelopment' => false,
106  'isProduction' => true,
107  'isTesting' => false,
108  'parentContext' => null
109  ],
110  'Production/MySpecialContext' => [
111  'contextName' => 'Production/MySpecialContext',
112  'isDevelopment' => false,
113  'isProduction' => true,
114  'isTesting' => false,
115  'parentContext' => 'Production'
116  ],
117 
118  'Testing' => [
119  'contextName' => 'Testing',
120  'isDevelopment' => false,
121  'isProduction' => false,
122  'isTesting' => true,
123  'parentContext' => null
124  ],
125  'Testing/MySpecialContext' => [
126  'contextName' => 'Testing/MySpecialContext',
127  'isDevelopment' => false,
128  'isProduction' => false,
129  'isTesting' => true,
130  'parentContext' => 'Testing'
131  ]
132  ];
133  }
134 
139  public function ‪contextMethodsReturnTheCorrectValues($contextName, $isDevelopment, $isProduction, $isTesting, $parentContext)
140  {
141  $context = new ‪ApplicationContext($contextName);
142  $this->assertSame($isDevelopment, $context->isDevelopment());
143  $this->assertSame($isProduction, $context->isProduction());
144  $this->assertSame($isTesting, $context->isTesting());
145  $this->assertSame((string)$parentContext, (string)$context->getParent());
146  }
147 
152  {
153  $context = new ‪ApplicationContext('Production/Foo/Bar');
154  $parentContext = $context->getParent();
155  $this->assertSame('Production/Foo', (string)$parentContext);
156 
157  $rootContext = $parentContext->getParent();
158  $this->assertSame('Production', (string)$rootContext);
159  }
160 }
‪TYPO3\CMS\Core\Core\ApplicationContext
Definition: ApplicationContext.php:36
‪TYPO3
‪TYPO3\CMS\Core\Tests\Unit\Core\ApplicationContextTest\parentContextIsConnectedRecursively
‪parentContextIsConnectedRecursively()
Definition: ApplicationContextTest.php:151
‪TYPO3\CMS\Core\Tests\Unit\Core\ApplicationContextTest\constructorThrowsExceptionIfMainContextIsForbidden
‪constructorThrowsExceptionIfMainContextIsForbidden($forbiddenContext)
Definition: ApplicationContextTest.php:72
‪TYPO3\CMS\Core\Tests\Unit\Core
Definition: ApplicationContextTest.php:2
‪TYPO3\CMS\Core\Tests\Unit\Core\ApplicationContextTest\isMethods
‪array isMethods()
Definition: ApplicationContextTest.php:85
‪TYPO3\CMS\Core\Tests\Unit\Core\ApplicationContextTest\forbiddenContexts
‪array forbiddenContexts()
Definition: ApplicationContextTest.php:58
‪TYPO3\CMS\Core\Tests\Unit\Core\ApplicationContextTest\allowedContexts
‪array allowedContexts()
Definition: ApplicationContextTest.php:30
‪TYPO3\CMS\Core\Tests\Unit\Core\ApplicationContextTest
Definition: ApplicationContextTest.php:24
‪TYPO3\CMS\Core\Tests\Unit\Core\ApplicationContextTest\contextMethodsReturnTheCorrectValues
‪contextMethodsReturnTheCorrectValues($contextName, $isDevelopment, $isProduction, $isTesting, $parentContext)
Definition: ApplicationContextTest.php:139
‪TYPO3\CMS\Core\Tests\Unit\Core\ApplicationContextTest\contextStringCanBeSetInConstructorAndReadByCallingToString
‪contextStringCanBeSetInConstructorAndReadByCallingToString($allowedContext)
Definition: ApplicationContextTest.php:47