2 declare(strict_types
=1);
3 namespace TYPO3\CMS\Core\Tests\Unit\Configuration\Loader
;
6 * This file is part of the TYPO3 CMS project.
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.
12 * For the full copyright and license information, please read the
13 * LICENSE.txt file that was distributed with this source code.
15 * The TYPO3 project - inspiring people to share!
18 use TYPO3\CMS\Core\Configuration\Loader\YamlFileLoader
;
21 * Test case for the YAML file loader class
23 class YamlFileLoaderTest
extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
26 * Generic method to check if the load method returns an array from a YAML file
29 public function load()
31 $fileName = 'Berta.yml';
44 'betterthanbefore' => 1
47 // Accessible mock to $subject since getFileContents calls GeneralUtility methods
48 $subject = $this->getAccessibleMock(YamlFileLoader
::class, ['getFileContents']);
49 $subject->expects($this->once())->method('getFileContents')->with($fileName)->willReturn($fileContents);
50 $output = $subject->load($fileName);
51 $this->assertSame($expected, $output);
55 * Method checking for imports that they have been processed properly
58 public function loadWithAnImport()
60 $fileName = 'Berta.yml';
63 - { resource: Secondfile.yml }
71 $importFileName = 'Secondfile.yml';
72 $importFileContents = '
84 'betterthanbefore' => 1
87 // Accessible mock to $subject since getFileContents calls GeneralUtility methods
88 $subject = $this->getAccessibleMock(YamlFileLoader
::class, ['getFileContents']);
89 $subject->expects($this->at(0))->method('getFileContents')->with($fileName)->willReturn($fileContents);
90 $subject->expects($this->at(1))->method('getFileContents')->with($importFileName)->willReturn($importFileContents);
91 $output = $subject->load($fileName);
92 $this->assertSame($expected, $output);
96 * Method checking for placeholders
99 public function loadWithPlacholders()
101 $fileName = 'Berta.yml';
109 betterthanbefore: %firstset.myinitialversion%
114 'myinitialversion' => 13
120 'betterthanbefore' => 13
123 // Accessible mock to $subject since getFileContents calls GeneralUtility methods
124 $subject = $this->getAccessibleMock(YamlFileLoader
::class, ['getFileContents']);
125 $subject->expects($this->once())->method('getFileContents')->with($fileName)->willReturn($fileContents);
126 $output = $subject->load($fileName);
127 $this->assertSame($expected, $output);
131 * dataprovider for tests isPlaceholderTest
134 public function isPlaceholderDataProvider()
137 'regular string' => [
153 'invalid placeholder with only % at the beginning' => [
157 'invalid placeholder with only % at the end' => [
161 'invalid placeholder with two % but not at the end' => [
165 'invalid placeholder with two % but not at the beginning nor end' => [
169 'valid placeholder with just numbers' => [
173 'valid placeholder' => [
181 * @dataProvider isPlaceholderDataProvider
183 * @param mixed $placeholderValue
184 * @param bool $expected
187 public function isPlaceholderTest($placeholderValue, bool $expected)
189 $subject = $this->getAccessibleMock(YamlFileLoader
::class, ['dummy']);
190 $output = $subject->_call('isPlaceholder', $placeholderValue);
191 $this->assertSame($expected, $output);