1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Sonata package. |
5
|
|
|
* |
6
|
|
|
* (c) Thomas Rabaix <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Sonata\SeoBundle\Tests\Seo; |
13
|
|
|
|
14
|
|
|
use Sonata\SeoBundle\Seo\SeoPage; |
15
|
|
|
|
16
|
|
|
class SeoPageTest extends \PHPUnit_Framework_TestCase |
17
|
|
|
{ |
18
|
|
|
public function testAddMeta() |
19
|
|
|
{ |
20
|
|
|
$page = new SeoPage(); |
21
|
|
|
$page->addMeta('property', 'foo', 'bar'); |
22
|
|
|
|
23
|
|
|
$expected = array( |
24
|
|
|
'http-equiv' => array(), |
25
|
|
|
'name' => array(), |
26
|
|
|
'schema' => array(), |
27
|
|
|
'charset' => array(), |
28
|
|
|
'property' => array('foo' => array('bar', array())), |
29
|
|
|
); |
30
|
|
|
|
31
|
|
|
$this->assertEquals($expected, $page->getMetas()); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function testOverrideMetas() |
35
|
|
|
{ |
36
|
|
|
$page = new SeoPage(); |
37
|
|
|
$page->setMetas(array('property' => array('foo' => 'bar', 'foo2' => array('bar2', array())))); |
38
|
|
|
|
39
|
|
|
$expected = array( |
40
|
|
|
'property' => array('foo' => array('bar', array()), 'foo2' => array('bar2', array())), |
41
|
|
|
); |
42
|
|
|
|
43
|
|
|
$this->assertEquals($expected, $page->getMetas()); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function testAcceptedMetaContent() |
47
|
|
|
{ |
48
|
|
|
$page = new SeoPage(); |
49
|
|
|
$page->setMetas(array('property' => array('int' => 123, 'string' => 'i am a string', 'float' => 55.22))); |
50
|
|
|
|
51
|
|
|
$expected = array( |
52
|
|
|
'property' => array('int' => array(123, array()), 'string' => array('i am a string', array()), 'float' => array(55.22, array())), |
53
|
|
|
); |
54
|
|
|
|
55
|
|
|
$this->assertEquals($expected, $page->getMetas()); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function testRemoveMeta() |
59
|
|
|
{ |
60
|
|
|
$page = new SeoPage(); |
61
|
|
|
$page->setMetas(array('property' => array('foo' => 'bar', 'foo2' => array('bar2', array())))); |
62
|
|
|
$page->removeMeta('property', 'foo'); |
63
|
|
|
|
64
|
|
|
$this->assertFalse($page->hasMeta('property', 'foo')); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @expectedException RuntimeException |
69
|
|
|
*/ |
70
|
|
|
public function testInvalidMetas() |
71
|
|
|
{ |
72
|
|
|
$page = new SeoPage(); |
73
|
|
|
$page->setMetas(array( |
74
|
|
|
'type' => 'not an array', |
75
|
|
|
)); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function testHtmlAttributes() |
79
|
|
|
{ |
80
|
|
|
$page = new SeoPage(); |
81
|
|
|
$page->setHtmlAttributes(array('key1' => 'value1')); |
82
|
|
|
$page->addHtmlAttributes('key2', 'value2'); |
83
|
|
|
|
84
|
|
|
$expected = array( |
85
|
|
|
'key1' => 'value1', |
86
|
|
|
'key2' => 'value2', |
87
|
|
|
); |
88
|
|
|
|
89
|
|
|
$this->assertEquals($expected, $page->getHtmlAttributes()); |
90
|
|
|
|
91
|
|
|
$this->assertTrue($page->hasHtmlAttribute('key2')); |
92
|
|
|
$page->removeHtmlAttributes('key2'); |
93
|
|
|
$this->assertFalse($page->hasHtmlAttribute('key2')); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function testHeadAttributes() |
97
|
|
|
{ |
98
|
|
|
$page = new SeoPage(); |
99
|
|
|
$page->setHeadAttributes(array('head1' => 'value1')); |
100
|
|
|
$page->addHeadAttribute('head2', 'value2'); |
101
|
|
|
|
102
|
|
|
$expected = array( |
103
|
|
|
'head1' => 'value1', |
104
|
|
|
'head2' => 'value2', |
105
|
|
|
); |
106
|
|
|
|
107
|
|
|
$this->assertEquals($expected, $page->getHeadAttributes()); |
108
|
|
|
|
109
|
|
|
$this->assertTrue($page->hasHeadAttribute('head1')); |
110
|
|
|
$page->removeHeadAttribute('head1'); |
111
|
|
|
$this->assertFalse($page->hasHeadAttribute('head1')); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
public function testSetTitle() |
115
|
|
|
{ |
116
|
|
|
$page = new SeoPage(); |
117
|
|
|
$page->setTitle('My title'); |
118
|
|
|
|
119
|
|
|
$this->assertEquals('My title', $page->getTitle()); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
public function testAddTitle() |
123
|
|
|
{ |
124
|
|
|
$page = new SeoPage(); |
125
|
|
|
$page->setTitle('My title'); |
126
|
|
|
$page->setSeparator(' - '); |
127
|
|
|
$page->addTitle('Additional title'); |
128
|
|
|
|
129
|
|
|
$this->assertEquals('Additional title - My title', $page->getTitle()); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
public function testLinkCanonical() |
133
|
|
|
{ |
134
|
|
|
$page = new SeoPage(); |
135
|
|
|
$page->setLinkCanonical('http://example.com'); |
136
|
|
|
|
137
|
|
|
$this->assertEquals('http://example.com', $page->getLinkCanonical()); |
138
|
|
|
|
139
|
|
|
$page->removeLinkCanonical(); |
140
|
|
|
$this->assertEquals('', $page->getLinkCanonical()); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
public function testLangAlternates() |
144
|
|
|
{ |
145
|
|
|
$page = new SeoPage(); |
146
|
|
|
$page->setLangAlternates(array('http://example.com/' => 'x-default')); |
147
|
|
|
$page->addLangAlternate('http://example.com/en-us', 'en-us'); |
148
|
|
|
|
149
|
|
|
$expected = array( |
150
|
|
|
'http://example.com/' => 'x-default', |
151
|
|
|
'http://example.com/en-us' => 'en-us', |
152
|
|
|
); |
153
|
|
|
|
154
|
|
|
$this->assertEquals($expected, $page->getLangAlternates()); |
155
|
|
|
|
156
|
|
|
$this->assertTrue($page->hasLangAlternate('http://example.com/')); |
157
|
|
|
$page->removeLangAlternate('http://example.com/'); |
158
|
|
|
$this->assertFalse($page->hasLangAlternate('http://example.com/')); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* The hasMeta() should return true for a defined meta, false otherwise. |
163
|
|
|
*/ |
164
|
|
|
public function testHasMeta() |
165
|
|
|
{ |
166
|
|
|
$page = new SeoPage(); |
167
|
|
|
$page->addMeta('property', 'test', array()); |
|
|
|
|
168
|
|
|
|
169
|
|
|
$this->assertTrue($page->hasMeta('property', 'test')); |
170
|
|
|
$this->assertFalse($page->hasMeta('property', 'fake')); |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
public function testSetSeparator() |
174
|
|
|
{ |
175
|
|
|
$page = new SeoPage(); |
176
|
|
|
|
177
|
|
|
$this->assertInstanceOf('Sonata\SeoBundle\Seo\SeoPage', $page->setSeparator('-')); |
178
|
|
|
} |
179
|
|
|
} |
180
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: