TYPO3 CMS  TYPO3_7-6
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 
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 
72  public function constructorThrowsExceptionIfMainContextIsForbidden($forbiddenContext)
73  {
74  new ApplicationContext($forbiddenContext);
75  }
76 
82  public function isMethods()
83  {
84  return [
85  'Development' => [
86  'contextName' => 'Development',
87  'isDevelopment' => true,
88  'isProduction' => false,
89  'isTesting' => false,
90  'parentContext' => null
91  ],
92  'Development/YourSpecialContext' => [
93  'contextName' => 'Development/YourSpecialContext',
94  'isDevelopment' => true,
95  'isProduction' => false,
96  'isTesting' => false,
97  'parentContext' => 'Development'
98  ],
99 
100  'Production' => [
101  'contextName' => 'Production',
102  'isDevelopment' => false,
103  'isProduction' => true,
104  'isTesting' => false,
105  'parentContext' => null
106  ],
107  'Production/MySpecialContext' => [
108  'contextName' => 'Production/MySpecialContext',
109  'isDevelopment' => false,
110  'isProduction' => true,
111  'isTesting' => false,
112  'parentContext' => 'Production'
113  ],
114 
115  'Testing' => [
116  'contextName' => 'Testing',
117  'isDevelopment' => false,
118  'isProduction' => false,
119  'isTesting' => true,
120  'parentContext' => null
121  ],
122  'Testing/MySpecialContext' => [
123  'contextName' => 'Testing/MySpecialContext',
124  'isDevelopment' => false,
125  'isProduction' => false,
126  'isTesting' => true,
127  'parentContext' => 'Testing'
128  ]
129  ];
130  }
131 
136  public function contextMethodsReturnTheCorrectValues($contextName, $isDevelopment, $isProduction, $isTesting, $parentContext)
137  {
138  $context = new ApplicationContext($contextName);
139  $this->assertSame($isDevelopment, $context->isDevelopment());
140  $this->assertSame($isProduction, $context->isProduction());
141  $this->assertSame($isTesting, $context->isTesting());
142  $this->assertSame((string)$parentContext, (string)$context->getParent());
143  }
144 
149  {
150  $context = new ApplicationContext('Production/Foo/Bar');
151  $parentContext = $context->getParent();
152  $this->assertSame('Production/Foo', (string)$parentContext);
153 
154  $rootContext = $parentContext->getParent();
155  $this->assertSame('Production', (string)$rootContext);
156  }
157 }
contextMethodsReturnTheCorrectValues($contextName, $isDevelopment, $isProduction, $isTesting, $parentContext)