‪TYPO3CMS  10.4
ApplicationContextTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
20 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
21 
25 class ‪ApplicationContextTest extends UnitTestCase
26 {
32  public function ‪allowedContexts()
33  {
34  return [
35  ['Production'],
36  ['Testing'],
37  ['Development'],
38 
39  ['Development/MyLocalComputer'],
40  ['Development/MyLocalComputer/Foo'],
41  ['Production/SpecialDeployment/LiveSystem'],
42  ];
43  }
44 
50  {
51  $context = new ‪ApplicationContext($allowedContext);
52  self::assertSame($allowedContext, (string)$context);
53  }
54 
60  public function ‪forbiddenContexts()
61  {
62  return [
63  ['MySpecialContext'],
64  ['Testing123'],
65  ['DevelopmentStuff'],
66  ['DevelopmentStuff/FooBar'],
67  ];
68  }
69 
74  public function ‪constructorThrowsExceptionIfMainContextIsForbidden($forbiddenContext)
75  {
76  $this->expectException(Exception::class);
77  $this->expectExceptionCode(1335436551);
78 
79  new ‪ApplicationContext($forbiddenContext);
80  }
81 
87  public function ‪isMethods()
88  {
89  return [
90  'Development' => [
91  'contextName' => 'Development',
92  'isDevelopment' => true,
93  'isProduction' => false,
94  'isTesting' => false,
95  'parentContext' => null
96  ],
97  'Development/YourSpecialContext' => [
98  'contextName' => 'Development/YourSpecialContext',
99  'isDevelopment' => true,
100  'isProduction' => false,
101  'isTesting' => false,
102  'parentContext' => 'Development'
103  ],
104 
105  'Production' => [
106  'contextName' => 'Production',
107  'isDevelopment' => false,
108  'isProduction' => true,
109  'isTesting' => false,
110  'parentContext' => null
111  ],
112  'Production/MySpecialContext' => [
113  'contextName' => 'Production/MySpecialContext',
114  'isDevelopment' => false,
115  'isProduction' => true,
116  'isTesting' => false,
117  'parentContext' => 'Production'
118  ],
119 
120  'Testing' => [
121  'contextName' => 'Testing',
122  'isDevelopment' => false,
123  'isProduction' => false,
124  'isTesting' => true,
125  'parentContext' => null
126  ],
127  'Testing/MySpecialContext' => [
128  'contextName' => 'Testing/MySpecialContext',
129  'isDevelopment' => false,
130  'isProduction' => false,
131  'isTesting' => true,
132  'parentContext' => 'Testing'
133  ]
134  ];
135  }
136 
141  public function ‪contextMethodsReturnTheCorrectValues($contextName, $isDevelopment, $isProduction, $isTesting, $parentContext)
142  {
143  $context = new ‪ApplicationContext($contextName);
144  self::assertSame($isDevelopment, $context->isDevelopment());
145  self::assertSame($isProduction, $context->isProduction());
146  self::assertSame($isTesting, $context->isTesting());
147  self::assertSame((string)$parentContext, (string)$context->getParent());
148  }
149 
154  {
155  $context = new ‪ApplicationContext('Production/Foo/Bar');
156  $parentContext = $context->getParent();
157  self::assertSame('Production/Foo', (string)$parentContext);
158 
159  $rootContext = $parentContext->getParent();
160  self::assertSame('Production', (string)$rootContext);
161  }
162 }
‪TYPO3\CMS\Core\Core\ApplicationContext
Definition: ApplicationContext.php:37
‪TYPO3\CMS\Core\Exception
‪TYPO3\CMS\Core\Tests\Unit\Core\ApplicationContextTest\parentContextIsConnectedRecursively
‪parentContextIsConnectedRecursively()
Definition: ApplicationContextTest.php:153
‪TYPO3\CMS\Core\Tests\Unit\Core\ApplicationContextTest\constructorThrowsExceptionIfMainContextIsForbidden
‪constructorThrowsExceptionIfMainContextIsForbidden($forbiddenContext)
Definition: ApplicationContextTest.php:74
‪TYPO3\CMS\Core\Tests\Unit\Core
Definition: ApplicationContextTest.php:16
‪TYPO3\CMS\Core\Tests\Unit\Core\ApplicationContextTest\isMethods
‪array isMethods()
Definition: ApplicationContextTest.php:87
‪TYPO3\CMS\Core\Tests\Unit\Core\ApplicationContextTest\forbiddenContexts
‪array forbiddenContexts()
Definition: ApplicationContextTest.php:60
‪TYPO3\CMS\Core\Tests\Unit\Core\ApplicationContextTest\allowedContexts
‪array allowedContexts()
Definition: ApplicationContextTest.php:32
‪TYPO3\CMS\Core\Tests\Unit\Core\ApplicationContextTest
Definition: ApplicationContextTest.php:26
‪TYPO3\CMS\Core\Tests\Unit\Core\ApplicationContextTest\contextMethodsReturnTheCorrectValues
‪contextMethodsReturnTheCorrectValues($contextName, $isDevelopment, $isProduction, $isTesting, $parentContext)
Definition: ApplicationContextTest.php:141
‪TYPO3\CMS\Core\Tests\Unit\Core\ApplicationContextTest\contextStringCanBeSetInConstructorAndReadByCallingToString
‪contextStringCanBeSetInConstructorAndReadByCallingToString($allowedContext)
Definition: ApplicationContextTest.php:49