1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SMT\Tests; |
4
|
|
|
|
5
|
|
|
use SMT\OutputPageHtmlTagsInserter; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @covers \SMT\OutputPageHtmlTagsInserter |
9
|
|
|
* @group semantic-meta-tags |
10
|
|
|
* |
11
|
|
|
* @license GNU GPL v2+ |
12
|
|
|
* @since 1.0 |
13
|
|
|
* |
14
|
|
|
* @author mwjames |
15
|
|
|
*/ |
16
|
|
|
class OutputPageHtmlTagsInserterTest extends \PHPUnit_Framework_TestCase { |
17
|
|
|
|
18
|
|
|
public function testCanConstruct() { |
19
|
|
|
|
20
|
|
|
$outputPage = $this->getMockBuilder( '\OutputPage' ) |
21
|
|
|
->disableOriginalConstructor() |
22
|
|
|
->getMock(); |
23
|
|
|
|
24
|
|
|
$this->assertInstanceOf( |
25
|
|
|
'\SMT\OutputPageHtmlTagsInserter', |
26
|
|
|
new OutputPageHtmlTagsInserter( $outputPage ) |
27
|
|
|
); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function testTryToUseOutputPageForSpecialPage() { |
31
|
|
|
|
32
|
|
|
$title = $this->getMockBuilder( '\Title' ) |
33
|
|
|
->disableOriginalConstructor() |
34
|
|
|
->getMock(); |
35
|
|
|
|
36
|
|
|
$title->expects( $this->any() ) |
37
|
|
|
->method( 'isSpecialPage' ) |
38
|
|
|
->will( $this->returnValue( true ) ); |
39
|
|
|
|
40
|
|
|
$outputPage = $this->getMockBuilder( '\OutputPage' ) |
41
|
|
|
->disableOriginalConstructor() |
42
|
|
|
->getMock(); |
43
|
|
|
|
44
|
|
|
$outputPage->expects( $this->never() ) |
45
|
|
|
->method( 'addMeta' ); |
46
|
|
|
|
47
|
|
|
$outputPage->expects( $this->atLeastOnce() ) |
48
|
|
|
->method( 'getTitle' ) |
49
|
|
|
->will( $this->returnValue( $title ) ); |
50
|
|
|
|
51
|
|
|
$instance = new OutputPageHtmlTagsInserter( $outputPage ); |
52
|
|
|
|
53
|
|
|
$this->assertFalse( |
54
|
|
|
$instance->canUseOutputPage() |
55
|
|
|
); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function testTryToUseOutputPageForNonViewAction() { |
59
|
|
|
|
60
|
|
|
$title = $this->getMockBuilder( '\Title' ) |
61
|
|
|
->disableOriginalConstructor() |
62
|
|
|
->getMock(); |
63
|
|
|
|
64
|
|
|
$title->expects( $this->any() ) |
65
|
|
|
->method( 'isSpecialPage' ) |
66
|
|
|
->will( $this->returnValue( false ) ); |
67
|
|
|
|
68
|
|
|
$outputPage = $this->getMockBuilder( '\OutputPage' ) |
69
|
|
|
->disableOriginalConstructor() |
70
|
|
|
->getMock(); |
71
|
|
|
|
72
|
|
|
$outputPage->expects( $this->never() ) |
73
|
|
|
->method( 'addMeta' ); |
74
|
|
|
|
75
|
|
|
$outputPage->expects( $this->atLeastOnce() ) |
76
|
|
|
->method( 'getTitle' ) |
77
|
|
|
->will( $this->returnValue( $title ) ); |
78
|
|
|
|
79
|
|
|
$instance = new OutputPageHtmlTagsInserter( $outputPage ); |
80
|
|
|
$instance->setActionName( 'foo' ); |
81
|
|
|
|
82
|
|
|
$this->assertFalse( |
83
|
|
|
$instance->canUseOutputPage() |
84
|
|
|
); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function testTryToAddContentForBlacklistedTag() { |
88
|
|
|
|
89
|
|
|
$outputPage = $this->getMockBuilder( '\OutputPage' ) |
90
|
|
|
->disableOriginalConstructor() |
91
|
|
|
->getMock(); |
92
|
|
|
|
93
|
|
|
$outputPage->expects( $this->never() ) |
94
|
|
|
->method( 'addMeta' ); |
95
|
|
|
|
96
|
|
|
$instance = new OutputPageHtmlTagsInserter( $outputPage ); |
97
|
|
|
$instance->setMetaTagsBlacklist( array( 'foo' ) ); |
98
|
|
|
|
99
|
|
|
$instance->addTagContentToOutputPage( 'FOO', 'bar' ); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @dataProvider nonOgTagProvider |
104
|
|
|
*/ |
105
|
|
|
public function testAddTagForNonOgContent( $tag, $content, $expected ) { |
106
|
|
|
|
107
|
|
|
$outputPage = $this->getMockBuilder( '\OutputPage' ) |
108
|
|
|
->disableOriginalConstructor() |
109
|
|
|
->getMock(); |
110
|
|
|
|
111
|
|
|
$outputPage->expects( $this->once() ) |
112
|
|
|
->method( 'addMeta' ) |
113
|
|
|
->with( |
114
|
|
|
$this->equalTo( $expected['tag'] ), |
115
|
|
|
$this->equalTo( $expected['content'] ) ); |
116
|
|
|
|
117
|
|
|
$instance = new OutputPageHtmlTagsInserter( $outputPage ); |
118
|
|
|
$instance->addTagContentToOutputPage( $tag, $content ); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @dataProvider propertyTagProvider |
123
|
|
|
*/ |
124
|
|
|
public function testAddTagOnMetaPropertyPrefixContent( $prefixes, $tag, $content, $expected ) { |
125
|
|
|
|
126
|
|
|
$outputPage = $this->getMockBuilder( '\OutputPage' ) |
127
|
|
|
->disableOriginalConstructor() |
128
|
|
|
->getMock(); |
129
|
|
|
|
130
|
|
|
$outputPage->expects( $this->once() ) |
131
|
|
|
->method( 'addHeadItem' ) |
132
|
|
|
->with( |
133
|
|
|
$this->equalTo( $expected['tag'] ), |
134
|
|
|
$this->stringContains( $expected['item'] ) ); |
135
|
|
|
|
136
|
|
|
$instance = new OutputPageHtmlTagsInserter( $outputPage ); |
137
|
|
|
|
138
|
|
|
$instance->setMetaPropertyPrefixes( |
139
|
|
|
$prefixes |
140
|
|
|
); |
141
|
|
|
|
142
|
|
|
$instance->addTagContentToOutputPage( $tag, $content ); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
public function nonOgTagProvider() { |
146
|
|
|
|
147
|
|
|
$provider = array(); |
148
|
|
|
|
149
|
|
|
$provider[] = array( |
150
|
|
|
'foo', |
151
|
|
|
'foobar', |
152
|
|
|
array( 'tag' => 'foo', 'content' => 'foobar' ) |
153
|
|
|
); |
154
|
|
|
|
155
|
|
|
$provider[] = array( |
156
|
|
|
'FOO', |
157
|
|
|
'"foobar"', |
158
|
|
|
array( 'tag' => 'foo', 'content' => '"foobar"' ) |
159
|
|
|
); |
160
|
|
|
|
161
|
|
|
$provider[] = array( |
162
|
|
|
' foo ', |
163
|
|
|
' foobar ', |
164
|
|
|
array( 'tag' => 'foo', 'content' => ' foobar ' ) |
165
|
|
|
); |
166
|
|
|
|
167
|
|
|
$provider[] = array( |
168
|
|
|
'FO"O', |
169
|
|
|
'foobar', |
170
|
|
|
array( 'tag' => 'fo"o', 'content' => 'foobar' ) |
171
|
|
|
); |
172
|
|
|
|
173
|
|
|
$provider[] = array( |
174
|
|
|
'twitter:card', |
175
|
|
|
'FOO', |
176
|
|
|
array( 'tag' => 'twitter:card', 'content' => 'FOO' ) |
177
|
|
|
); |
178
|
|
|
|
179
|
|
|
return $provider; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
public function propertyTagProvider() { |
183
|
|
|
|
184
|
|
|
$provider = array(); |
185
|
|
|
|
186
|
|
|
$provider[] = array( |
187
|
|
|
array( |
188
|
|
|
'og:' |
189
|
|
|
), |
190
|
|
|
'og:bar', |
191
|
|
|
'foobar', |
192
|
|
|
array( |
193
|
|
|
'tag' => 'meta:property:og:bar', |
194
|
|
|
'item' => '<!-- Semantic MetaTags -->' . "\n" . '<meta property="og:bar" content="foobar"' |
195
|
|
|
) |
196
|
|
|
); |
197
|
|
|
|
198
|
|
|
return $provider; |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
} |
202
|
|
|
|