-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathMigrateThemeTest.php
125 lines (94 loc) · 4.15 KB
/
MigrateThemeTest.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
<?php
namespace Tests;
use Statamic\Facades\Path;
class MigrateThemeTest extends TestCase
{
protected function paths($key = null)
{
$paths = [
'macros' => resource_path('macros.yaml'),
'views' => resource_path('views'),
];
return $key ? $paths[$key] : $paths;
}
protected function viewsPath($append = null)
{
return Path::tidy(collect([resource_path('views'), $append])->filter()->implode('/'));
}
protected function redwoodPath($append)
{
return Path::tidy($this->sitePath("themes/redwood/{$append}"));
}
/** @test */
public function it_migrates_views()
{
$this->assertCount(0, $this->files->allFiles($this->viewsPath()));
$this->artisan('statamic:migrate:theme', ['handle' => 'redwood']);
$this->assertCount(33, $this->files->allFiles($this->viewsPath()));
$this->assertCount(7, $this->files->directories($this->viewsPath()));
$this->assertCount(10, $this->files->files($this->viewsPath()));
$this->assertCount(2, $this->files->files($this->viewsPath('layouts')));
$this->assertCount(4, $this->files->files($this->viewsPath('partials')));
$this->assertCount(1, $this->files->files($this->viewsPath('partials/articles')));
$expectedUserViews = [
'account.antlers.html',
'index.antlers.html',
'profile.antlers.html',
];
$migratedUserViews = collect($this->files->files($this->viewsPath('user')))
->map
->getFilename()
->all();
$this->assertEquals($expectedUserViews, $migratedUserViews);
}
/** @test */
public function it_migrates_default_layout()
{
$this->assertCount(0, $this->files->allFiles($this->viewsPath()));
$this->artisan('statamic:migrate:theme', ['handle' => 'redwood']);
$this->assertFileNotExists($this->viewsPath('layouts/default.antlers.html'));
$this->assertFileExists($this->viewsPath('layouts/layout.antlers.html'));
}
/** @test */
public function it_migrates_custom_default_layout()
{
$this->files->put($this->sitePath('settings/theming.yaml'), 'default_layout: custom');
$this->files->move(
$this->sitePath('themes/redwood/layouts/default.html'),
$this->sitePath('themes/redwood/layouts/custom.html')
);
$this->assertCount(0, $this->files->allFiles($this->viewsPath()));
$this->artisan('statamic:migrate:theme', ['handle' => 'redwood']);
$this->assertFileNotExists($this->viewsPath('layouts/default.antlers.html'));
$this->assertFileNotExists($this->viewsPath('layouts/custom.antlers.html'));
$this->assertFileExists($this->viewsPath('layouts/layout.antlers.html'));
}
/** @test */
public function it_leaves_blade_extension_alone()
{
$this->artisan('statamic:migrate:theme', ['handle' => 'redwood']);
$this->assertFileExists($this->viewsPath('not-antlers.blade.php'));
}
/** @test */
public function it_migrates_theme_partial_tags()
{
$this->assertFileHasContent('{{ theme:partial src="nav" }}', $this->redwoodPath('layouts/default.html'));
$this->artisan('statamic:migrate:theme', ['handle' => 'redwood']);
$this->assertFileHasContent('{{ partial:nav }}', $this->viewsPath('layouts/layout.antlers.html'));
}
/** @test */
public function it_migrates_blade_global_modify_calls()
{
$this->assertFileHasContent('{{ modify($content)->striptags() }}', $this->redwoodPath('templates/not-antlers.blade.php'));
$this->artisan('statamic:migrate:theme', ['handle' => 'redwood']);
$this->assertFileHasContent('{{ \Statamic\Modifiers\Modify::value($content)->striptags() }}', $this->viewsPath('not-antlers.blade.php'));
}
/** @test */
public function it_migrates_macros()
{
$this->assertFileNotExists($this->paths('macros'));
$this->artisan('statamic:migrate:theme', ['handle' => 'redwood']);
$this->assertFileExists($this->paths('macros'));
$this->assertParsedYamlHasKey('jake', $this->paths('macros'));
}
}