PageRenderTime 36ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 0ms

/Tests/Twig/Extension/SeoExtensionTest.php

https://github.com/verdet23/SonataSeoBundle
PHP | 134 lines | 101 code | 25 blank | 8 comment | 0 complexity | 585d543e3d42d8eebd5c315f5d9d5dd3 MD5 | raw file
Possible License(s): JSON
  1. <?php
  2. /*
  3. * This file is part of the Sonata package.
  4. *
  5. * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Sonata\SeoBundle\Tests\Request;
  11. use Sonata\SeoBundle\Twig\Extension\SeoExtension;
  12. class BlockTest extends \PHPUnit_Framework_TestCase
  13. {
  14. public function testHtmlAttributes()
  15. {
  16. $page = $this->getMock('Sonata\SeoBundle\Seo\SeoPageInterface');
  17. $page->expects($this->once())->method('getHtmlAttributes')->will($this->returnValue(array(
  18. 'xmlns' => 'http://www.w3.org/1999/xhtml',
  19. 'xmlns:og' => 'http://opengraphprotocol.org/schema/',
  20. )));
  21. $extension = new SeoExtension($page, 'UTF-8');
  22. ob_start();
  23. $extension->renderHtmlAttributes();
  24. $content = ob_get_contents();
  25. ob_end_clean();
  26. $this->assertEquals('xmlns="http://www.w3.org/1999/xhtml" xmlns:og="http://opengraphprotocol.org/schema/" ', $content);
  27. }
  28. public function testTitle()
  29. {
  30. $page = $this->getMock('Sonata\SeoBundle\Seo\SeoPageInterface');
  31. $page->expects($this->once())->method('getTitle')->will($this->returnValue('<b>foo bar</b>'));
  32. $extension = new SeoExtension($page, 'UTF-8');
  33. ob_start();
  34. $extension->renderTitle();
  35. $content = ob_get_contents();
  36. ob_end_clean();
  37. $this->assertEquals('<title>foo bar</title>', $content);
  38. }
  39. public function testEncoding()
  40. {
  41. $page = $this->getMock('Sonata\SeoBundle\Seo\SeoPageInterface');
  42. $page->expects($this->once())->method('getTitle')->will($this->returnValue('pięć głów zatkniętych na pal'));
  43. $page->expects($this->once())->method('getMetas')->will($this->returnValue(array(
  44. 'http-equiv' => array(),
  45. 'name' => array('foo' => array('pięć głów zatkniętych na pal', array())),
  46. 'schema' => array(),
  47. 'charset' => array(),
  48. 'property' => array(),
  49. )));
  50. $extension = new SeoExtension($page, 'UTF-8');
  51. ob_start();
  52. $extension->renderTitle();
  53. $content = ob_get_contents();
  54. ob_end_clean();
  55. $this->assertEquals('<title>pięć głów zatkniętych na pal</title>', $content);
  56. ob_start();
  57. $extension->renderMetadatas();
  58. $content = ob_get_contents();
  59. ob_end_clean();
  60. $this->assertEquals("<meta name=\"foo\" content=\"pięć gł&oacute;w zatkniętych na pal\" />\n", $content);
  61. }
  62. public function testMetadatas()
  63. {
  64. $page = $this->getMock('Sonata\SeoBundle\Seo\SeoPageInterface');
  65. $page->expects($this->once())->method('getMetas')->will($this->returnValue(array(
  66. 'http-equiv' => array(),
  67. 'name' => array('foo' => array('bar "\'"', array())),
  68. 'schema' => array(),
  69. 'charset' => array(),
  70. 'property' => array(),
  71. )));
  72. $extension = new SeoExtension($page, 'UTF-8');
  73. ob_start();
  74. $extension->renderMetadatas();
  75. $content = ob_get_contents();
  76. ob_end_clean();
  77. $this->assertEquals("<meta name=\"foo\" content=\"bar &quot;'&quot;\" />\n", $content);
  78. }
  79. public function testName()
  80. {
  81. $page = $this->getMock('Sonata\SeoBundle\Seo\SeoPageInterface');
  82. $extension = new SeoExtension($page, 'UTF-8');
  83. $this->assertEquals('sonata_seo', $extension->getName());
  84. }
  85. public function testLinkCanonical()
  86. {
  87. $page = $this->getMock('Sonata\SeoBundle\Seo\SeoPageInterface');
  88. $page->expects($this->any())->method('getLinkCanonical')->will($this->returnValue('http://example.com'));
  89. $extension = new SeoExtension($page, 'UTF-8');
  90. ob_start();
  91. $extension->renderLinkCanonical();
  92. $content = ob_get_contents();
  93. ob_end_clean();
  94. $this->assertEquals("<link rel=\"canonical\" href=\"http://example.com\"/>\n", $content);
  95. }
  96. public function testLangAlternates()
  97. {
  98. $page = $this->getMock('Sonata\SeoBundle\Seo\SeoPageInterface');
  99. $page->expects($this->once())->method('getLangAlternates')->will($this->returnValue(array(
  100. 'http://example.com/' => 'x-default',
  101. )));
  102. $extension = new SeoExtension($page, 'UTF-8');
  103. ob_start();
  104. $extension->renderLangAlternates();
  105. $content = ob_get_contents();
  106. ob_end_clean();
  107. $this->assertEquals("<link rel=\"alternate\" href=\"http://example.com/\" hreflang=\"x-default\"/>\n", $content);
  108. }
  109. }