Completed
Pull Request — master (#116)
by
unknown
02:33
created

SeoExtensionTest::testLinks()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 11
rs 9.4285
cc 1
eloc 7
nc 1
nop 0
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\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ł&oacute;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 &quot;'&quot;\" />\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
    /**
117
     * Test SeoExtension::getLinks method.
118
     */
119
    public function testLinks()
120
    {
121
        $page = $this->getMock('Sonata\SeoBundle\Seo\SeoPageInterface');
122
        $page->expects($this->once())->method('getLinks')->will($this->returnValue(array(
123
            'prev'      => array('href' => 'http://example.com'),
124
            'alternate' => array('rel' => 'http://example.com', 'hreflang' => 'x-default'),
125
        )));
126
127
        $extension = new SeoExtension($page, 'UTF-8');
128
        $this->assertEquals("<link rel=\"prev\" href=\"http://example.com\" />\n", $extension->getLinks());
129
    }
130
131
    public function testOEmbedLinks()
132
    {
133
        $page = $this->getMock('Sonata\SeoBundle\Seo\SeoPageInterface');
134
        $page->expects($this->once())->method('getOembedLinks')->will($this->returnValue(array(
135
            'Foo' => 'http://example.com/',
136
        )));
137
138
        $extension = new SeoExtension($page, 'UTF-8');
139
140
        $this->assertEquals("<link rel=\"alternate\" type=\"application/json+oembed\" href=\"http://example.com/\" title=\"Foo\" />\n", $extension->getOembedLinks());
141
    }
142
}
143