-
Notifications
You must be signed in to change notification settings - Fork 638
/
YamlFileLoaderTest.php
193 lines (177 loc) · 5.25 KB
/
YamlFileLoaderTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<?php
declare(strict_types = 1);
namespace TYPO3\CMS\Core\Tests\Unit\Configuration\Loader;
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
use TYPO3\CMS\Core\Configuration\Loader\YamlFileLoader;
/**
* Test case for the YAML file loader class
*/
class YamlFileLoaderTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
{
/**
* Generic method to check if the load method returns an array from a YAML file
* @test
*/
public function load()
{
$fileName = 'Berta.yml';
$fileContents = '
options:
- option1
- option2
betterthanbefore: 1
';
$expected = [
'options' => [
'option1',
'option2'
],
'betterthanbefore' => 1
];
// Accessible mock to $subject since getFileContents calls GeneralUtility methods
$subject = $this->getAccessibleMock(YamlFileLoader::class, ['getFileContents']);
$subject->expects($this->once())->method('getFileContents')->with($fileName)->willReturn($fileContents);
$output = $subject->load($fileName);
$this->assertSame($expected, $output);
}
/**
* Method checking for imports that they have been processed properly
* @test
*/
public function loadWithAnImport()
{
$fileName = 'Berta.yml';
$fileContents = '
imports:
- { resource: Secondfile.yml }
options:
- option1
- option2
betterthanbefore: 1
';
$importFileName = 'Secondfile.yml';
$importFileContents = '
options:
- optionBefore
betterthanbefore: 2
';
$expected = [
'options' => [
'optionBefore',
'option1',
'option2'
],
'betterthanbefore' => 1
];
// Accessible mock to $subject since getFileContents calls GeneralUtility methods
$subject = $this->getAccessibleMock(YamlFileLoader::class, ['getFileContents']);
$subject->expects($this->at(0))->method('getFileContents')->with($fileName)->willReturn($fileContents);
$subject->expects($this->at(1))->method('getFileContents')->with($importFileName)->willReturn($importFileContents);
$output = $subject->load($fileName);
$this->assertSame($expected, $output);
}
/**
* Method checking for placeholders
* @test
*/
public function loadWithPlacholders()
{
$fileName = 'Berta.yml';
$fileContents = '
firstset:
myinitialversion: 13
options:
- option1
- option2
betterthanbefore: \'%firstset.myinitialversion%\'
';
$expected = [
'firstset' => [
'myinitialversion' => 13
],
'options' => [
'option1',
'option2'
],
'betterthanbefore' => 13
];
// Accessible mock to $subject since getFileContents calls GeneralUtility methods
$subject = $this->getAccessibleMock(YamlFileLoader::class, ['getFileContents']);
$subject->expects($this->once())->method('getFileContents')->with($fileName)->willReturn($fileContents);
$output = $subject->load($fileName);
$this->assertSame($expected, $output);
}
/**
* dataprovider for tests isPlaceholderTest
* @return array
*/
public function isPlaceholderDataProvider()
{
return [
'regular string' => [
'berta13',
false
],
'regular array' => [
['berta13'],
false
],
'regular float' => [
13.131313,
false
],
'regular int' => [
13,
false
],
'invalid placeholder with only % at the beginning' => [
'%cool',
false
],
'invalid placeholder with only % at the end' => [
'cool%',
false
],
'invalid placeholder with two % but not at the end' => [
'%cool%again',
false
],
'invalid placeholder with two % but not at the beginning nor end' => [
'did%you%know',
false
],
'valid placeholder with just numbers' => [
'%13%',
true
],
'valid placeholder' => [
'%foo%baracks%',
true
],
];
}
/**
* @dataProvider isPlaceholderDataProvider
* @test
* @param mixed $placeholderValue
* @param bool $expected
* @skip
*/
public function isPlaceholderTest($placeholderValue, bool $expected)
{
$subject = $this->getAccessibleMock(YamlFileLoader::class, ['dummy']);
$output = $subject->_call('isPlaceholder', $placeholderValue);
$this->assertSame($expected, $output);
}
}