‪TYPO3CMS  ‪main
YamlFileLoaderTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Psr\Log\AbstractLogger;
21 use Psr\Log\LogLevel;
23 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
24 
25 final class ‪YamlFileLoaderTest extends FunctionalTestCase
26 {
27  protected bool ‪$resetSingletonInstances = true;
28 
34  public function ‪load(): void
35  {
36  $fileName = 'EXT:core/Tests/Functional/Configuration/Loader/Fixtures/Berta.yaml';
37 
38  $expected = [
39  'options' => [
40  'option1',
41  'option2',
42  ],
43  'betterthanbefore' => 1,
44  ];
45  ‪$output = (new ‪YamlFileLoader())->‪load($fileName);
46  self::assertSame($expected, ‪$output);
47  }
48 
54  public function ‪loadWithAnImport(): void
55  {
56  $fileName = 'EXT:core/Tests/Functional/Configuration/Loader/Fixtures/LoadWithAnImport.yaml';
57 
58  $expected = [
59  'options' => [
60  'optionBefore',
61  'option1',
62  'option2',
63  ],
64  'betterthanbefore' => 1,
65  ];
66 
67  ‪$output = (new ‪YamlFileLoader())->‪load($fileName);
68  self::assertSame($expected, ‪$output);
69  }
70 
76  public function ‪loadWithMultipleImports(): void
77  {
78  $fileName = 'EXT:core/Tests/Functional/Configuration/Loader/Fixtures/LoadWithMultipleImports.yaml';
79 
80  $expected = [
81  'options' => [
82  'optionBefore',
83  'optionAfterBefore',
84  'option1',
85  'option2',
86  ],
87  'betterthanbefore' => 1,
88  ];
89 
90  ‪$output = (new ‪YamlFileLoader())->‪load($fileName);
91  self::assertSame($expected, ‪$output);
92  }
93 
99  public function ‪loadWithImportAndRelativePaths(): void
100  {
101  $fileName = 'EXT:core/Tests/Functional/Configuration/Loader/Fixtures/LoadWithImportAndRelativeFiles.yaml';
102  ‪$output = (new ‪YamlFileLoader())->‪load($fileName);
103  self::assertSame(
104  [
105  'enable' => [
106  'frontend' => false,
107  'json.api' => true,
108  'backend' => true,
109  'rest.api' => true,
110  ],
111  ],
112  ‪$output
113  );
114  }
115 
121  public function ‪loadWithPlaceholders(): void
122  {
123  $fileName = 'EXT:core/Tests/Functional/Configuration/Loader/Fixtures/LoadWithPlaceholders.yaml';
124  ‪$output = (new ‪YamlFileLoader())->‪load($fileName);
125 
126  $expected = [
127  'firstset' => [
128  'myinitialversion' => 13,
129  ],
130  'options' => [
131  'option1',
132  'option2',
133  ],
134  'betterthanbefore' => 13,
135  'muchbetterthanbefore' => 'some::option1::option',
136  ];
137 
138  self::assertSame($expected, ‪$output);
139  }
140 
146  public function ‪loadWithNestedPlaceholders(): void
147  {
148  $fileName = 'EXT:core/Tests/Functional/Configuration/Loader/Fixtures/LoadWithNestedPlaceholders.yaml';
149 
150  $expected = [
151  'firstset' => [
152  'myinitialversion' => 13,
153  ],
154  'options' => [
155  'option1',
156  'option2',
157  ],
158  'betterthanbefore' => 13,
159  ];
160 
161  putenv('foo=%firstset.myinitialversion%');
162  ‪$output = (new ‪YamlFileLoader())->‪load($fileName);
163  putenv('foo=');
164  self::assertSame($expected, ‪$output);
165  }
166 
172  public function ‪loadWithImportAndEnvVars(): void
173  {
174  $loader = new ‪YamlFileLoader();
175 
176  putenv('foo=barbaz');
177  ‪$output = $loader->load('EXT:core/Tests/Functional/Configuration/Loader/Fixtures/Env/Berta.yaml');
178  putenv('foo=');
179 
180  $expected = [
181  'loadedWithEnvVars' => 1,
182  'options' => [
183  'optionBefore',
184  'option1',
185  'option2',
186  ],
187  ];
188 
189  self::assertSame($expected, ‪$output);
190  }
191 
198  {
199  ‪$output = (new ‪YamlFileLoader())->‪load('EXT:core/Tests/Functional/Configuration/Loader/Fixtures/Placeholder/Berta.yaml');
200 
201  $expected = [
202  'loadedWithPlaceholder' => 1,
203  'settings' => [
204  'dynamicOption' => 'Foo',
205  ],
206  ];
207 
208  self::assertSame($expected, ‪$output);
209  }
210 
216  public function ‪loadWithGlobbedImports(): void
217  {
218  ‪$output = (new ‪YamlFileLoader())->‪load('EXT:core/Tests/Functional/Configuration/Loader/Fixtures/LoadWithGlobbedImports.yaml');
219 
220  $expected = [
221  'options' => [
222  'optionBefore',
223  'optionAfterBefore',
224  'option1',
225  'option2',
226  ],
227  'betterthanbefore' => 1,
228  ];
229 
230  self::assertSame($expected, ‪$output);
231  }
232 
239  {
240  $logger = new class () extends AbstractLogger {
241  public array $logEntries = [];
242 
243  public function log($level, \Stringable|string $message, array $context = []): void
244  {
245  $this->logEntries[$level][0] = $message;
246  }
247  };
248  $loader = new ‪YamlFileLoader();
249  $loader->setLogger($logger);
250  ‪$output = $loader->load('EXT:core/Tests/Functional/Configuration/Loader/Fixtures/LoadWithGlobbedImportsWithPathTraversal.yaml');
251 
252  self::assertEmpty(‪$output);
253  self::assertSame('Referencing a file which is outside of TYPO3s main folder', $logger->logEntries[LogLevel::ERROR][0] ?? '');
254  }
255 }
‪TYPO3\CMS\Core\Tests\Functional\Configuration\Loader\YamlFileLoaderTest\loadWithGlobbedImports
‪loadWithGlobbedImports()
Definition: YamlFileLoaderTest.php:216
‪TYPO3\CMS\Core\Tests\Functional\Configuration\Loader\YamlFileLoaderTest\$resetSingletonInstances
‪bool $resetSingletonInstances
Definition: YamlFileLoaderTest.php:27
‪TYPO3\CMS\Core\Tests\Functional\Configuration\Loader\YamlFileLoaderTest\loadWithImportAndEnvVars
‪loadWithImportAndEnvVars()
Definition: YamlFileLoaderTest.php:172
‪TYPO3\CMS\Core\Tests\Functional\Configuration\Loader\YamlFileLoaderTest\loadWithNestedPlaceholders
‪loadWithNestedPlaceholders()
Definition: YamlFileLoaderTest.php:146
‪TYPO3\CMS\Core\Tests\Functional\Configuration\Loader\YamlFileLoaderTest\loadWithPlaceholders
‪loadWithPlaceholders()
Definition: YamlFileLoaderTest.php:121
‪TYPO3\CMS\Core\Tests\Functional\Configuration\Loader\YamlFileLoaderTest\loadWithImportAndPlaceholderInFileName
‪loadWithImportAndPlaceholderInFileName()
Definition: YamlFileLoaderTest.php:197
‪TYPO3\CMS\Core\Tests\Functional\Configuration\Loader
Definition: YamlFileLoaderTest.php:18
‪$output
‪$output
Definition: annotationChecker.php:119
‪TYPO3\CMS\Core\Tests\Functional\Configuration\Loader\YamlFileLoaderTest\load
‪load()
Definition: YamlFileLoaderTest.php:34
‪TYPO3\CMS\Core\Configuration\Loader\YamlFileLoader
Definition: YamlFileLoader.php:47
‪TYPO3\CMS\Core\Tests\Functional\Configuration\Loader\YamlFileLoaderTest\loadWithImportAndRelativePaths
‪loadWithImportAndRelativePaths()
Definition: YamlFileLoaderTest.php:99
‪TYPO3\CMS\Core\Tests\Functional\Configuration\Loader\YamlFileLoaderTest
Definition: YamlFileLoaderTest.php:26
‪TYPO3\CMS\Core\Tests\Functional\Configuration\Loader\YamlFileLoaderTest\loadWithMultipleImports
‪loadWithMultipleImports()
Definition: YamlFileLoaderTest.php:76
‪TYPO3\CMS\Core\Tests\Functional\Configuration\Loader\YamlFileLoaderTest\loadWithGlobbedImportsWithPathTraversalShouldFail
‪loadWithGlobbedImportsWithPathTraversalShouldFail()
Definition: YamlFileLoaderTest.php:238
‪TYPO3\CMS\Core\Tests\Functional\Configuration\Loader\YamlFileLoaderTest\loadWithAnImport
‪loadWithAnImport()
Definition: YamlFileLoaderTest.php:54