1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Sonata Project 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\Request; |
13
|
|
|
|
14
|
|
|
use Sonata\SeoBundle\Twig\Extension\SeoExtension; |
15
|
|
|
|
16
|
|
|
class SeoExtensionTest extends \PHPUnit_Framework_TestCase |
17
|
|
|
{ |
18
|
|
|
public function testHtmlAttributes() |
19
|
|
|
{ |
20
|
|
|
$page = $this->getMock('Sonata\SeoBundle\Seo\SeoPageInterface'); |
21
|
|
|
$page->expects($this->once())->method('getHtmlAttributes')->will($this->returnValue(array( |
22
|
|
|
'xmlns' => 'http://www.w3.org/1999/xhtml', |
23
|
|
|
'xmlns:og' => 'http://opengraphprotocol.org/schema/', |
24
|
|
|
))); |
25
|
|
|
|
26
|
|
|
$extension = new SeoExtension($page, 'UTF-8'); |
27
|
|
|
|
28
|
|
|
$this->assertEquals('xmlns="http://www.w3.org/1999/xhtml" xmlns:og="http://opengraphprotocol.org/schema/"', $extension->getHtmlAttributes()); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function testHeadAttributes() |
32
|
|
|
{ |
33
|
|
|
$page = $this->getMock('Sonata\SeoBundle\Seo\SeoPageInterface'); |
34
|
|
|
$page->expects($this->once())->method('getHeadAttributes')->will($this->returnValue(array())); |
35
|
|
|
|
36
|
|
|
$extension = new SeoExtension($page, 'UTF-8'); |
37
|
|
|
|
38
|
|
|
$this->assertEquals('', $extension->getHeadAttributes()); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function testTitle() |
42
|
|
|
{ |
43
|
|
|
$page = $this->getMock('Sonata\SeoBundle\Seo\SeoPageInterface'); |
44
|
|
|
$page->expects($this->once())->method('getTitle')->will($this->returnValue('<b>foo bar</b>')); |
45
|
|
|
|
46
|
|
|
$extension = new SeoExtension($page, 'UTF-8'); |
47
|
|
|
|
48
|
|
|
$this->assertEquals('<title>foo bar</title>', $extension->getTitle()); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function testEncoding() |
52
|
|
|
{ |
53
|
|
|
$page = $this->getMock('Sonata\SeoBundle\Seo\SeoPageInterface'); |
54
|
|
|
$page->expects($this->once())->method('getTitle')->will($this->returnValue('pięć głów zatkniętych na pal')); |
55
|
|
|
$page->expects($this->once())->method('getMetas')->will($this->returnValue(array( |
56
|
|
|
'http-equiv' => array(), |
57
|
|
|
'name' => array('foo' => array('pięć głów zatkniętych na pal', array())), |
58
|
|
|
'schema' => array(), |
59
|
|
|
'charset' => array(), |
60
|
|
|
'property' => array(), |
61
|
|
|
))); |
62
|
|
|
|
63
|
|
|
$extension = new SeoExtension($page, 'UTF-8'); |
64
|
|
|
|
65
|
|
|
$this->assertEquals('<title>pięć głów zatkniętych na pal</title>', $extension->getTitle()); |
66
|
|
|
|
67
|
|
|
$this->assertEquals("<meta name=\"foo\" content=\"pięć głów zatkniętych na pal\" />\n", $extension->getMetadatas()); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function testMetadatas() |
71
|
|
|
{ |
72
|
|
|
$page = $this->getMock('Sonata\SeoBundle\Seo\SeoPageInterface'); |
73
|
|
|
$page->expects($this->once())->method('getMetas')->will($this->returnValue(array( |
74
|
|
|
'http-equiv' => array(), |
75
|
|
|
'name' => array('foo' => array('bar "\'"', array())), |
76
|
|
|
'schema' => array(), |
77
|
|
|
'charset' => array('UTF-8' => array('', array())), |
78
|
|
|
'property' => array(), |
79
|
|
|
))); |
80
|
|
|
|
81
|
|
|
$extension = new SeoExtension($page, 'UTF-8'); |
82
|
|
|
|
83
|
|
|
$this->assertEquals("<meta name=\"foo\" content=\"bar "'"\" />\n<meta charset=\"UTF-8\" />\n", $extension->getMetadatas()); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function testName() |
87
|
|
|
{ |
88
|
|
|
$page = $this->getMock('Sonata\SeoBundle\Seo\SeoPageInterface'); |
89
|
|
|
$extension = new SeoExtension($page, 'UTF-8'); |
90
|
|
|
|
91
|
|
|
$this->assertEquals('sonata_seo', $extension->getName()); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function testLinkCanonical() |
95
|
|
|
{ |
96
|
|
|
$page = $this->getMock('Sonata\SeoBundle\Seo\SeoPageInterface'); |
97
|
|
|
$page->expects($this->any())->method('getLinkCanonical')->will($this->returnValue('http://example.com')); |
98
|
|
|
|
99
|
|
|
$extension = new SeoExtension($page, 'UTF-8'); |
100
|
|
|
|
101
|
|
|
$this->assertEquals("<link rel=\"canonical\" href=\"http://example.com\"/>\n", $extension->getLinkCanonical()); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
public function testLangAlternates() |
105
|
|
|
{ |
106
|
|
|
$page = $this->getMock('Sonata\SeoBundle\Seo\SeoPageInterface'); |
107
|
|
|
$page->expects($this->once())->method('getLangAlternates')->will($this->returnValue(array( |
108
|
|
|
'http://example.com/' => 'x-default', |
109
|
|
|
))); |
110
|
|
|
|
111
|
|
|
$extension = new SeoExtension($page, 'UTF-8'); |
112
|
|
|
|
113
|
|
|
$this->assertEquals("<link rel=\"alternate\" href=\"http://example.com/\" hreflang=\"x-default\"/>\n", $extension->getLangAlternates()); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
public function testOEmbedLinks() |
117
|
|
|
{ |
118
|
|
|
$page = $this->getMock('Sonata\SeoBundle\Seo\SeoPageInterface'); |
119
|
|
|
$page->expects($this->once())->method('getOembedLinks')->will($this->returnValue(array( |
120
|
|
|
'Foo' => 'http://example.com/', |
121
|
|
|
))); |
122
|
|
|
|
123
|
|
|
$extension = new SeoExtension($page, 'UTF-8'); |
124
|
|
|
|
125
|
|
|
$this->assertEquals("<link rel=\"alternate\" type=\"application/json+oembed\" href=\"http://example.com/\" title=\"Foo\" />\n", $extension->getOembedLinks()); |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|