-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathMigrateSettingsTest.php
326 lines (271 loc) · 7.81 KB
/
MigrateSettingsTest.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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
<?php
namespace Tests;
use Illuminate\Support\Facades\File;
class MigrateSettingsTest extends TestCase
{
protected function paths($key = null)
{
$paths = [
'routesFile' => base_path('routes/web.php'),
];
return $key ? $paths[$key] : $paths;
}
public function setUp(): void
{
parent::setUp();
$this->files->copy(__DIR__.'/Fixtures/routes/web.php', $this->paths('routesFile'));
}
/** @test */
public function it_migrates_assets_settings()
{
$this->assertConfigFileContains('assets.php', <<<'EOT'
'presets' => [
// 'small' => ['w' => 200, 'h' => 200, 'q' => 75, 'fit' => 'crop'],
],
EOT
);
$this->artisan('statamic:migrate:settings', ['handle' => 'assets']);
$this->assertConfigFileContains('assets.php', <<<'EOT'
'presets' => [
'sml' => [
'w' => 200,
'h' => 200,
'q' => 75,
'fit' => 'crop',
],
'tall' => [
'w' => 200,
'h' => 600,
'q' => 75,
'fit' => 'contain',
],
],
EOT
);
}
/** @test */
public function it_doesnt_touch_assets_config_if_empty()
{
$this->files->put($this->sitePath('settings/assets.yaml'), '');
$this->artisan('statamic:migrate:settings', ['handle' => 'assets']);
$this->assertConfigFileContains('assets.php', <<<'EOT'
'presets' => [
// 'small' => ['w' => 200, 'h' => 200, 'q' => 75, 'fit' => 'crop'],
],
EOT
);
}
/** @test */
public function it_migrates_cp_settings()
{
$this->assertConfigFileContains('cp.php', <<<'EOT'
'getting_started',
EOT
);
$this->artisan('statamic:migrate:settings', ['handle' => 'cp']);
$this->assertConfigFileContains('cp.php', <<<'EOT'
'start_page' => 'collections',
EOT
);
$this->assertConfigFileContains('cp.php', <<<'EOT'
'date_format' => 'Y-m-d',
EOT
);
$this->assertConfigFileContains('cp.php', <<<'EOT'
'widgets' => [
'getting_started',
[
'type' => 'collection',
'collection' => 'blog',
'limit' => 5,
],
[
'type' => 'collection',
'collection' => 'things',
'limit' => 5,
],
[
'type' => 'form',
'form' => 'contact',
'limit' => 5,
'title' => 'Recent Submissions',
'width' => 'full',
'fields' => [
'name',
'email',
],
],
],
EOT
);
$this->assertConfigFileContains('cp.php', <<<'EOT'
'pagination_size' => 12,
EOT
);
}
/** @test */
public function it_migrates_cp_start_page_to_pages()
{
$this->files->put($this->sitePath('settings/cp.yaml'), 'start_page: pages');
$this->artisan('statamic:migrate:settings', ['handle' => 'cp']);
$this->assertConfigFileContains('cp.php', <<<'EOT'
'start_page' => 'collections/pages',
EOT
);
}
/** @test */
public function it_migrates_routes()
{
$this->artisan('statamic:migrate:settings', ['handle' => 'routes']);
$this->assertRoutesFileContains(<<<'EOT'
Route::statamic('search', 'search');
Route::statamic('blog/tags', 'blog.taxonomies');
Route::statamic('blog/feed', 'feeds.blog', [
'layout' => 'feed',
'content_type' => 'atom',
]);
Route::statamic('complicated/stuff', 'ComplicatedController@stuff');
Route::redirect('products', 'products-old');
Route::permanentRedirect('articles', '/');
Route::permanentRedirect('blog/posts', 'blog');
EOT
);
}
/** @test */
public function it_migrates_system_settings()
{
$this->artisan('statamic:migrate:settings', ['handle' => 'system']);
$this->assertSameWithNormalizedLineEndings(File::get(resource_path('sites.yaml')),
'default:
name: English
locale: en_US
url: /
');
$this->assertConfigFileContains('system.php', <<<'EOT'
'multisite' => false,
EOT
);
}
/** @test */
public function it_migrates_multiple_locales_with_env_references()
{
$this->files->put($this->sitePath('settings/system.yaml'), <<<'EOT'
locales:
en:
name: English
full: en_US
url: "{env:APP_URL}"
fr:
name: French
full: fr_FR
url: '{env:APP_URL_FR}'
EOT
);
$this->artisan('statamic:migrate:settings', ['handle' => 'system']);
$this->assertSameWithNormalizedLineEndings(File::get(resource_path('sites.yaml')),
"default:
name: English
locale: en_US
url: '{env:APP_URL}'
fr:
name: French
locale: fr_FR
url: '{env:APP_URL_FR}'
");
$this->assertConfigFileContains('system.php', <<<'EOT'
'multisite' => true,
EOT
);
}
/** @test */
public function it_migrates_missing_locales_using_v2_default()
{
$this->files->put($this->sitePath('settings/system.yaml'), '');
$this->artisan('statamic:migrate:settings', ['handle' => 'system']);
$this->assertSameWithNormalizedLineEndings(File::get(resource_path('sites.yaml')),
'default:
name: English
locale: en_US
url: /
');
$this->assertConfigFileContains('system.php', <<<'EOT'
'multisite' => false,
EOT
);
}
/** @test */
public function it_migrates_user_settings()
{
$this->artisan('statamic:migrate:settings', ['handle' => 'users']);
$this->assertConfigFileContains('users.php', <<<'EOT'
'avatars' => 'gravatar',
EOT
);
$this->assertConfigFileContains('users.php', <<<'EOT'
'new_user_roles' => [
'author',
],
EOT
);
}
/** @test */
public function it_migrates_empty_user_settings()
{
$this->files->put($this->sitePath('settings/users.yaml'), <<<'EOT'
nothing_relevant: true
EOT
);
$this->artisan('statamic:migrate:settings', ['handle' => 'users']);
$this->assertConfigFileContains('users.php', <<<'EOT'
'avatars' => 'initials',
EOT
);
$this->assertConfigFileContains('users.php', <<<'EOT'
'new_user_roles' => [
//
],
EOT
);
}
/**
* Assert config file is valid and contains specific content.
*
* @param string $file
* @param string $content
*/
protected function assertConfigFileContains($file, $content)
{
$config = config_path("statamic/{$file}");
$beginning = <<<'EOT'
<?php
return [
EOT;
$end = '];';
// Assert valid PHP array.
$this->assertEquals('array', gettype(include $config));
// Assert begining and end of config is untouched.
$this->assertStringContainsStringWithNormalizedLineEndings($beginning, $this->files->get($config));
$this->assertStringContainsStringWithNormalizedLineEndings($end, $this->files->get($config));
// Assert config file contains specific content.
return $this->assertStringContainsStringWithNormalizedLineEndings($content, $this->files->get($config));
}
/**
* Assert routes file contains specific content.
*
* @param string $content
*/
protected function assertRoutesFileContains($content)
{
$contents = $this->files->get($this->paths('routesFile'));
$beginning = <<<'EOT'
// Route::get('/', function () {
// return view('welcome');
// });
EOT;
$end = '];';
// Assert begining of routes file is untouched.
$this->assertStringContainsStringWithNormalizedLineEndings($beginning, $contents);
// Assert routes file contains specific content.
return $this->assertStringContainsStringWithNormalizedLineEndings($content, $contents);
}
}