CommonHelperTest.php 5.0 KB

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