-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathYamlTest.php
76 lines (57 loc) · 2.06 KB
/
YamlTest.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
<?php
namespace Tests;
use Exception;
use Statamic\Facades\Path;
use Statamic\Migrator\YAML;
class YamlTest extends TestCase
{
public function path()
{
return Path::tidy(base_path('site/settings/system.yaml'));
}
/** @test */
public function it_detects_parser()
{
$this->files->delete($this->path());
$this->assertFileNotExists($this->path());
$this->assertEquals(null, YAML::detect());
$this->files->put($this->path(), "yaml_parser: spyc\n");
$this->assertEquals('spyc', YAML::detect());
$this->files->put($this->path(), "yaml_parser: symfony\n");
$this->assertEquals('symfony', YAML::detect());
}
/** @test */
public function it_parses_symfonic_yaml()
{
$yaml = "description: '@seo:pro'\n";
$this->files->put($this->path(), "yaml_parser: symfony\n");
$this->assertEquals(['description' => '@seo:pro'], Yaml::parse($yaml));
}
/** @test */
public function it_parses_spicey_yaml()
{
$yaml = "description: @seo:pro\n";
$this->files->put($this->path(), "yaml_parser: spyc\n");
$this->assertEquals(['description' => '@seo:pro'], Yaml::parse($yaml));
}
/** @test */
public function it_cannot_parse_spicey_yaml_if_site_settings_explicitly_set_to_symfony()
{
$yaml = "description: @seo:pro\n";
$this->files->put($this->path(), "yaml_parser: symfony\n");
$this->expectException(Exception::class);
YAML::parse($yaml);
}
/** @test */
public function it_falls_back_to_spicey_parsing_if_necesary_when_it_cannot_detect_site_settings()
{
$this->assertEquals(['description' => '@seo:pro'], Yaml::parse("description: '@seo:pro'\n"));
$this->assertEquals(['description' => '@seo:pro'], Yaml::parse("description: @seo:pro\n"));
}
/** @test */
public function it_defers_to_statamic_yaml_facade_when_dumping()
{
$data = ['description' => '@seo:pro'];
$this->assertEquals("description: '@seo:pro'\n", Yaml::dump($data));
}
}