SonataSeoBundle /Tests/Twig/Extension/SeoExtensionTest.php

Language PHP Lines 135
MD5 Hash 585d543e3d42d8eebd5c315f5d9d5dd3
Repository https://github.com/verdet23/SonataSeoBundle.git View Raw File
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
/*
 * This file is part of the Sonata package.
 *
 * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Sonata\SeoBundle\Tests\Request;

use Sonata\SeoBundle\Twig\Extension\SeoExtension;

class BlockTest extends \PHPUnit_Framework_TestCase
{
    public function testHtmlAttributes()
    {
        $page = $this->getMock('Sonata\SeoBundle\Seo\SeoPageInterface');
        $page->expects($this->once())->method('getHtmlAttributes')->will($this->returnValue(array(
            'xmlns' => 'http://www.w3.org/1999/xhtml',
            'xmlns:og' => 'http://opengraphprotocol.org/schema/',
        )));

        $extension = new SeoExtension($page, 'UTF-8');

        ob_start();
        $extension->renderHtmlAttributes();
        $content = ob_get_contents();
        ob_end_clean();
        $this->assertEquals('xmlns="http://www.w3.org/1999/xhtml" xmlns:og="http://opengraphprotocol.org/schema/" ', $content);
    }

    public function testTitle()
    {
        $page = $this->getMock('Sonata\SeoBundle\Seo\SeoPageInterface');
        $page->expects($this->once())->method('getTitle')->will($this->returnValue('<b>foo bar</b>'));

        $extension = new SeoExtension($page, 'UTF-8');

        ob_start();
        $extension->renderTitle();
        $content = ob_get_contents();
        ob_end_clean();
        $this->assertEquals('<title>foo bar</title>', $content);
    }

    public function testEncoding()
    {
        $page = $this->getMock('Sonata\SeoBundle\Seo\SeoPageInterface');
        $page->expects($this->once())->method('getTitle')->will($this->returnValue('pięć głów zatkniętych na pal'));
        $page->expects($this->once())->method('getMetas')->will($this->returnValue(array(
            'http-equiv' => array(),
            'name'       => array('foo' => array('pięć głów zatkniętych na pal', array())),
            'schema'     => array(),
            'charset'    => array(),
            'property'   => array(),
        )));

        $extension = new SeoExtension($page, 'UTF-8');

        ob_start();
        $extension->renderTitle();
        $content = ob_get_contents();
        ob_end_clean();
        $this->assertEquals('<title>pięć głów zatkniętych na pal</title>', $content);

        ob_start();
        $extension->renderMetadatas();
        $content = ob_get_contents();
        ob_end_clean();
        $this->assertEquals("<meta name=\"foo\" content=\"pięć gł&oacute;w zatkniętych na pal\" />\n", $content);
    }

    public function testMetadatas()
    {
        $page = $this->getMock('Sonata\SeoBundle\Seo\SeoPageInterface');
        $page->expects($this->once())->method('getMetas')->will($this->returnValue(array(
            'http-equiv' => array(),
            'name'       => array('foo' => array('bar "\'"', array())),
            'schema'     => array(),
            'charset'    => array(),
            'property'   => array(),
        )));

        $extension = new SeoExtension($page, 'UTF-8');

        ob_start();
        $extension->renderMetadatas();
        $content = ob_get_contents();
        ob_end_clean();

        $this->assertEquals("<meta name=\"foo\" content=\"bar &quot;'&quot;\" />\n", $content);
    }

    public function testName()
    {
        $page = $this->getMock('Sonata\SeoBundle\Seo\SeoPageInterface');
        $extension = new SeoExtension($page, 'UTF-8');

        $this->assertEquals('sonata_seo', $extension->getName());
    }

    public function testLinkCanonical()
    {
        $page = $this->getMock('Sonata\SeoBundle\Seo\SeoPageInterface');
        $page->expects($this->any())->method('getLinkCanonical')->will($this->returnValue('http://example.com'));

        $extension = new SeoExtension($page, 'UTF-8');
        ob_start();
        $extension->renderLinkCanonical();
        $content = ob_get_contents();
        ob_end_clean();

        $this->assertEquals("<link rel=\"canonical\" href=\"http://example.com\"/>\n", $content);
    }

    public function testLangAlternates()
    {
        $page = $this->getMock('Sonata\SeoBundle\Seo\SeoPageInterface');
        $page->expects($this->once())->method('getLangAlternates')->will($this->returnValue(array(
                    'http://example.com/' => 'x-default',
                )));

        $extension = new SeoExtension($page, 'UTF-8');

        ob_start();
        $extension->renderLangAlternates();
        $content = ob_get_contents();
        ob_end_clean();

        $this->assertEquals("<link rel=\"alternate\" href=\"http://example.com/\" hreflang=\"x-default\"/>\n", $content);
    }
}
Back to Top