|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Hyde\Framework\Testing\Feature; |
|
4
|
|
|
|
|
5
|
|
|
use Hyde\Framework\Helpers\Meta; |
|
6
|
|
|
use Hyde\Testing\TestCase; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* @covers \Hyde\Framework\Helpers\Meta |
|
10
|
|
|
*/ |
|
11
|
|
|
class MetadataHelperTest extends TestCase |
|
12
|
|
|
{ |
|
13
|
|
|
protected function setUp(): void |
|
14
|
|
|
{ |
|
15
|
|
|
parent::setUp(); |
|
16
|
|
|
|
|
17
|
|
|
config(['hyde.meta' => []]); |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
public function test_name_method_returns_a_valid_html_meta_string() |
|
21
|
|
|
{ |
|
22
|
|
|
$this->assertEquals( |
|
23
|
|
|
'<meta name="foo" content="bar">', |
|
24
|
|
|
Meta::name('foo', 'bar') |
|
25
|
|
|
); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function test_property_method_returns_a_valid_html_meta_string() |
|
29
|
|
|
{ |
|
30
|
|
|
$this->assertEquals( |
|
31
|
|
|
'<meta property="og:foo" content="bar">', |
|
32
|
|
|
Meta::property('foo', 'bar') |
|
33
|
|
|
); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function test_property_method_accepts_property_with_og_prefix() |
|
37
|
|
|
{ |
|
38
|
|
|
$this->assertEquals( |
|
39
|
|
|
'<meta property="og:foo" content="bar">', |
|
40
|
|
|
Meta::property('og:foo', 'bar') |
|
41
|
|
|
); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function test_property_method_accepts_property_without_og_prefix() |
|
45
|
|
|
{ |
|
46
|
|
|
$this->assertEquals( |
|
47
|
|
|
'<meta property="og:foo" content="bar">', |
|
48
|
|
|
Meta::property('foo', 'bar') |
|
49
|
|
|
); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function test_render_method_implodes_an_array_of_meta_tags_into_a_formatted_string() |
|
53
|
|
|
{ |
|
54
|
|
|
$this->assertEquals( |
|
55
|
|
|
'<meta name="foo" content="bar">' |
|
56
|
|
|
."\n".'<meta property="og:foo" content="bar">', |
|
57
|
|
|
|
|
58
|
|
|
Meta::render([ |
|
59
|
|
|
Meta::name('foo', 'bar'), |
|
60
|
|
|
Meta::property('og:foo', 'bar'), |
|
61
|
|
|
]) |
|
62
|
|
|
); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function test_render_method_returns_an_empty_string_if_no_meta_tags_are_supplied() |
|
66
|
|
|
{ |
|
67
|
|
|
$this->assertEquals( |
|
68
|
|
|
'', |
|
69
|
|
|
Meta::render([]) |
|
70
|
|
|
); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function test_render_method_returns_config_defined_tags_if_no_meta_tags_are_supplied() |
|
74
|
|
|
{ |
|
75
|
|
|
config(['hyde.meta' => [ |
|
76
|
|
|
Meta::name('foo', 'bar'), |
|
77
|
|
|
Meta::property('og:foo', 'bar'), |
|
78
|
|
|
]]); |
|
79
|
|
|
|
|
80
|
|
|
$this->assertEquals( |
|
81
|
|
|
'<meta name="foo" content="bar">' |
|
82
|
|
|
."\n".'<meta property="og:foo" content="bar">', |
|
83
|
|
|
|
|
84
|
|
|
Meta::render([]) |
|
85
|
|
|
); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
public function test_render_method_merges_config_defined_tags_with_supplied_meta_tags() |
|
89
|
|
|
{ |
|
90
|
|
|
config(['hyde.meta' => [ |
|
91
|
|
|
Meta::name('foo', 'bar'), |
|
92
|
|
|
]]); |
|
93
|
|
|
|
|
94
|
|
|
$this->assertEquals( |
|
95
|
|
|
'<meta name="foo" content="bar">' |
|
96
|
|
|
."\n".'<meta property="og:foo" content="bar">', |
|
97
|
|
|
|
|
98
|
|
|
Meta::render([ |
|
99
|
|
|
Meta::property('foo', 'bar'), |
|
100
|
|
|
]) |
|
101
|
|
|
); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
public function test_render_method_returns_unique_meta_tags() |
|
105
|
|
|
{ |
|
106
|
|
|
config(['hyde.meta' => [ |
|
107
|
|
|
Meta::name('foo', 'bar'), |
|
108
|
|
|
]]); |
|
109
|
|
|
|
|
110
|
|
|
$this->assertEquals( |
|
111
|
|
|
'<meta name="foo" content="bar">', |
|
112
|
|
|
Meta::render([ |
|
113
|
|
|
Meta::name('foo', 'bar'), |
|
114
|
|
|
]) |
|
115
|
|
|
); |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
public function test_render_method_gives_precedence_to_supplied_meta_tags() |
|
119
|
|
|
{ |
|
120
|
|
|
config(['hyde.meta' => [ |
|
121
|
|
|
Meta::name('foo', 'bar'), |
|
122
|
|
|
]]); |
|
123
|
|
|
|
|
124
|
|
|
$this->assertEquals( |
|
125
|
|
|
'<meta name="foo" content="baz">', |
|
126
|
|
|
|
|
127
|
|
|
Meta::render([ |
|
128
|
|
|
Meta::name('foo', 'baz'), |
|
129
|
|
|
]) |
|
130
|
|
|
); |
|
131
|
|
|
} |
|
132
|
|
|
} |
|
133
|
|
|
|