|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Hyde\Framework\Testing\Unit; |
|
4
|
|
|
|
|
5
|
|
|
use Hyde\Framework\Models\FrontMatter; |
|
6
|
|
|
use Hyde\Testing\TestCase; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* @covers \Hyde\Framework\Models\FrontMatter |
|
10
|
|
|
*/ |
|
11
|
|
|
class FrontMatterModelTest extends TestCase |
|
12
|
|
|
{ |
|
13
|
|
|
public function test_constructor_creates_new_front_matter_model() |
|
14
|
|
|
{ |
|
15
|
|
|
$matter = new FrontMatter([]); |
|
16
|
|
|
$this->assertInstanceOf(FrontMatter::class, $matter); |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
public function test_constructor_arguments_are_optional() |
|
20
|
|
|
{ |
|
21
|
|
|
$matter = new FrontMatter(); |
|
22
|
|
|
$this->assertInstanceOf(FrontMatter::class, $matter); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
public function test_constructor_arguments_are_assigned() |
|
26
|
|
|
{ |
|
27
|
|
|
$matter = new FrontMatter(['foo' => 'bar']); |
|
28
|
|
|
$this->assertEquals(['foo' => 'bar'], $matter->matter); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function test_static_from_array_method_creates_new_front_matter_model() |
|
32
|
|
|
{ |
|
33
|
|
|
$matter = FrontMatter::fromArray(['foo' => 'bar']); |
|
34
|
|
|
$this->assertInstanceOf(FrontMatter::class, $matter); |
|
35
|
|
|
$this->assertEquals(['foo' => 'bar'], $matter->matter); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function test_to_string_magic_method_converts_model_array_into_yaml_front_matter() |
|
39
|
|
|
{ |
|
40
|
|
|
$matter = new FrontMatter(['foo' => 'bar']); |
|
41
|
|
|
$this->assertEquals("---\nfoo: bar\n---\n", (string) $matter); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function test_magic_get_method_returns_front_matter_property() |
|
45
|
|
|
{ |
|
46
|
|
|
$matter = new FrontMatter(['foo' => 'bar']); |
|
47
|
|
|
$this->assertEquals('bar', $matter->foo); |
|
|
|
|
|
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function test_magic_get_method_returns_null_if_property_does_not_exist() |
|
51
|
|
|
{ |
|
52
|
|
|
$matter = new FrontMatter(); |
|
53
|
|
|
$this->assertNull($matter->foo); |
|
|
|
|
|
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function test_get_method_returns_empty_array_if_document_has_no_matter() |
|
57
|
|
|
{ |
|
58
|
|
|
$matter = new FrontMatter(); |
|
59
|
|
|
$this->assertEquals([], $matter->get()); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function test_get_method_returns_document_front_matter_array_if_no_arguments_are_specified() |
|
63
|
|
|
{ |
|
64
|
|
|
$matter = new FrontMatter(['foo' => 'bar']); |
|
65
|
|
|
$this->assertEquals(['foo' => 'bar'], $matter->get()); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function test_get_method_returns_null_if_specified_front_matter_key_does_not_exist() |
|
69
|
|
|
{ |
|
70
|
|
|
$matter = new FrontMatter(); |
|
71
|
|
|
$this->assertNull($matter->get('bar')); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function test_get_method_returns_specified_default_value_if_property_does_not_exist() |
|
75
|
|
|
{ |
|
76
|
|
|
$matter = new FrontMatter(); |
|
77
|
|
|
$this->assertEquals('default', $matter->get('bar', 'default')); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
public function test_get_method_returns_specified_front_matter_value_if_key_is_specified() |
|
81
|
|
|
{ |
|
82
|
|
|
$matter = new FrontMatter(['foo' => 'bar']); |
|
83
|
|
|
$this->assertEquals('bar', $matter->get('foo')); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
public function test_to_array_returns_front_matter_array() |
|
87
|
|
|
{ |
|
88
|
|
|
$matter = new FrontMatter(['foo' => 'bar']); |
|
89
|
|
|
$this->assertEquals(['foo' => 'bar'], $matter->toArray()); |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|