CommonHelperTest.php 5.0 KB

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