-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathMigrateGlobalSetTest.php
107 lines (85 loc) · 3.1 KB
/
MigrateGlobalSetTest.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
<?php
namespace Tests;
use Statamic\Facades\Path;
use Statamic\Migrator\YAML;
class MigrateGlobalSetTest extends TestCase
{
protected function paths()
{
return [
base_path('content/globals/main.yaml'),
resource_path('blueprints'),
];
}
protected function originalPath()
{
return Path::tidy(base_path('site/content/globals/main.yaml'));
}
protected function newPath()
{
return Path::tidy(base_path('content/globals/main.yaml'));
}
protected function blueprintPath()
{
return Path::tidy(resource_path('blueprints/globals/main.yaml'));
}
private function migrateGlobalSet($globalSet)
{
$this->assertFileNotExists($this->newPath());
$this->files->put($this->originalPath(), YAML::dump($globalSet));
$this->artisan('statamic:migrate:global-set', ['handle' => 'main']);
$this->assertFileExists($this->newPath());
return YAML::parse($this->files->get($this->newPath()));
}
/** @test */
public function it_can_migrate_a_global_set()
{
$this->assertFileNotExists($this->newPath());
$this->assertFileNotExists($this->blueprintPath());
$set = $this->migrateGlobalSet([
'id' => '547c5873-ce9a-4b92-b6b8-a9c785f92fb4',
'title' => 'Global',
'fieldset' => 'globals',
'site_title' => 'Frederick\'s Swap Shop',
'author' => 'Frederick Schwap',
'fav_colour' => 'colours/red', // this is a taxonomy field, with a value that needs to be migrated
]);
$this->assertEquals($set, [
'title' => 'Global',
'data' => [
'site_title' => 'Frederick\'s Swap Shop',
'author' => 'Frederick Schwap',
'fav_colour' => 'red',
],
]);
$this->assertFileExists($this->newPath());
$this->assertFileExists($this->blueprintPath());
}
/** @test */
public function it_can_implicitly_migrate_globals_blueprint()
{
$this->assertFileNotExists($this->blueprintPath());
$set = $this->migrateGlobalSet([
'id' => '547c5873-ce9a-4b92-b6b8-a9c785f92fb4',
'title' => 'Global',
'site_title' => 'Frederick\'s Swap Shop',
'author' => 'Frederick Schwap',
// 'fieldset' => 'globals', // If this is not explicitly set, fall back to migrating `globals` fieldset
]);
$this->assertFileExists($this->blueprintPath());
}
/** @test */
public function it_migrates_without_fieldset_when_one_does_not_exist()
{
$this->files->delete(base_path('site/settings/fieldsets/globals.yaml'));
$this->assertFileNotExists($this->newPath());
$this->assertFileNotExists($this->blueprintPath());
$set = $this->migrateGlobalSet([
'title' => 'Global',
'site_title' => 'Frederick\'s Swap Shop',
'author' => 'Frederick Schwap',
]);
$this->assertFileExists($this->newPath());
$this->assertFileNotExists($this->blueprintPath());
}
}