CommonHelperTest.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <?php
  2. namespace Tools\TestCase\View\Helper;
  3. use Cake\Core\Configure;
  4. use Cake\Routing\Router;
  5. use Cake\View\View;
  6. use Tools\TestSuite\TestCase;
  7. use Tools\View\Helper\CommonHelper;
  8. /**
  9. * CommonHelper tests
  10. */
  11. class CommonHelperTest extends TestCase {
  12. public $Common;
  13. public function setUp() {
  14. parent::setUp();
  15. Router::reload();
  16. $View = new View(null);
  17. $this->Common = new CommonHelper($View);
  18. }
  19. /**
  20. * CommonHelperTest::testMetaRobots()
  21. *
  22. * @return void
  23. */
  24. public function testMetaRobots() {
  25. $result = $this->Common->metaRobots();
  26. $this->assertContains('<meta name="robots" content="', $result);
  27. }
  28. /**
  29. * CommonHelperTest::testMetaName()
  30. *
  31. * @return void
  32. */
  33. public function testMetaName() {
  34. $result = $this->Common->metaName('foo', [1, 2, 3]);
  35. $expected = '<meta name="foo" content="1, 2, 3" />';
  36. $this->assertEquals($expected, $result);
  37. }
  38. /**
  39. * CommonHelperTest::testMetaDescription()
  40. *
  41. * @return void
  42. */
  43. public function testMetaDescription() {
  44. $result = $this->Common->metaDescription('foo', 'deu');
  45. $expected = '<meta lang="deu" name="description" content="foo"/>';
  46. $this->assertEquals($expected, $result);
  47. }
  48. /**
  49. * CommonHelperTest::testMetaKeywords()
  50. *
  51. * @return void
  52. */
  53. public function testMetaKeywords() {
  54. $result = $this->Common->metaKeywords('foo bar', 'deu');
  55. $expected = '<meta lang="deu" name="keywords" content="foo bar"/>';
  56. $this->assertEquals($expected, $result);
  57. }
  58. /**
  59. * CommonHelperTest::testMetaRss()
  60. *
  61. * @return void
  62. */
  63. public function testMetaRss() {
  64. $result = $this->Common->metaRss('/some/url', 'some title');
  65. $expected = '<link rel="alternate" type="application/rss+xml" title="some title" href="/some/url" />';
  66. $this->assertEquals($expected, $result);
  67. }
  68. /**
  69. * CommonHelperTest::testMetaEquiv()
  70. *
  71. * @return void
  72. */
  73. public function testMetaEquiv() {
  74. $result = $this->Common->metaEquiv('type', 'value');
  75. $expected = '<meta http-equiv="type" content="value" />';
  76. $this->assertEquals($expected, $result);
  77. }
  78. /**
  79. * @return void
  80. */
  81. public function testMetaCanonical() {
  82. $is = $this->Common->metaCanonical('/some/url/param1');
  83. $this->assertEquals('<link href="' . $this->Common->Url->build('/some/url/param1') . '" rel="canonical"/>', trim($is));
  84. $is = $this->Common->metaCanonical('/some/url/param1', true);
  85. $this->assertEquals('<link href="' . $this->Common->Url->build('/some/url/param1', true) . '" rel="canonical"/>', trim($is));
  86. }
  87. /**
  88. * @return void
  89. */
  90. public function testMetaAlternate() {
  91. $is = $this->Common->metaAlternate('/some/url/param1', 'de-de', true);
  92. $this->assertEquals('<link href="' . $this->Common->Url->build('/some/url/param1', true) . '" rel="alternate" hreflang="de-de"/>', trim($is));
  93. $is = $this->Common->metaAlternate(['controller' => 'some', 'action' => 'url'], 'de', true);
  94. $this->assertEquals('<link href="' . $this->Common->Url->build('/some/url', true) . '" rel="alternate" hreflang="de"/>', trim($is));
  95. $is = $this->Common->metaAlternate(['controller' => 'some', 'action' => 'url'], ['de', 'de-ch'], true);
  96. $this->assertEquals('<link href="' . $this->Common->Url->build('/some/url', true) . '" rel="alternate" hreflang="de"/>' . PHP_EOL . '<link href="' . $this->Common->Url->build('/some/url', true) . '" rel="alternate" hreflang="de-ch"/>', trim($is));
  97. $is = $this->Common->metaAlternate(['controller' => 'some', 'action' => 'url'], ['de' => ['ch', 'at'], 'en' => ['gb', 'us']], true);
  98. $this->assertEquals('<link href="' . $this->Common->Url->build('/some/url', true) . '" rel="alternate" hreflang="de-ch"/>' . PHP_EOL .
  99. '<link href="' . $this->Common->Url->build('/some/url', true) . '" rel="alternate" hreflang="de-at"/>' . PHP_EOL .
  100. '<link href="' . $this->Common->Url->build('/some/url', true) . '" rel="alternate" hreflang="en-gb"/>' . PHP_EOL .
  101. '<link href="' . $this->Common->Url->build('/some/url', true) . '" rel="alternate" hreflang="en-us"/>', trim($is));
  102. }
  103. /**
  104. * CommonHelperTest::testAsp()
  105. *
  106. * @return void
  107. */
  108. public function testAsp() {
  109. $res = $this->Common->asp('House', 2, true);
  110. $expected = __d('tools', 'Houses');
  111. $this->assertEquals($expected, $res);
  112. $res = $this->Common->asp('House', 1, true);
  113. $expected = __d('tools', 'House');
  114. $this->assertEquals($expected, $res);
  115. }
  116. /**
  117. * CommonHelperTest::testSp()
  118. *
  119. * @return void
  120. */
  121. public function testSp() {
  122. $res = $this->Common->sp('House', 'Houses', 0, true);
  123. $expected = __d('tools', 'Houses');
  124. $this->assertEquals($expected, $res);
  125. $res = $this->Common->sp('House', 'Houses', 2, true);
  126. $this->assertEquals($expected, $res);
  127. $res = $this->Common->sp('House', 'Houses', 1, true);
  128. $expected = __d('tools', 'House');
  129. $this->assertEquals($expected, $res);
  130. $res = $this->Common->sp('House', 'Houses', 1);
  131. $expected = 'House';
  132. $this->assertEquals($expected, $res);
  133. }
  134. /**
  135. * TearDown method
  136. *
  137. * @return void
  138. */
  139. public function tearDown() {
  140. parent::tearDown();
  141. unset($this->Common);
  142. }
  143. }