PageRenderTime 51ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/Croogo/Test/Case/View/Helper/CroogoHtmlHelperTest.php

https://github.com/kareypowell/croogo
PHP | 183 lines | 158 code | 19 blank | 6 comment | 0 complexity | 05b7852e9593679a91331d225dc39429 MD5 | raw file
  1. <?php
  2. App::uses('CroogoHelper', 'Croogo.View/Helper');
  3. App::uses('CroogoHtmlHelper', 'Croogo.View/Helper');
  4. App::uses('Controller', 'Controller');
  5. App::uses('CroogoTestCase', 'Croogo.TestSuite');
  6. App::uses('View', 'View');
  7. App::uses('HtmlHelper', 'View/Helper');
  8. class CroogoHtmlHelperTest extends CroogoTestCase {
  9. public $fixtures = array(
  10. 'plugin.taxonomy.type',
  11. );
  12. public function setUp() {
  13. $controller = null;
  14. $this->View = new View($controller);
  15. $this->CroogoHtml = new CroogoHtmlHelper($this->View);
  16. }
  17. public function tearDown() {
  18. unset($this->View);
  19. unset($this->CroogoHtml);
  20. }
  21. public function testIcon() {
  22. $result = $this->CroogoHtml->icon('remove');
  23. $this->assertContains('<i class="icon-remove"></i>', $result);
  24. }
  25. public function testStatusOk() {
  26. $result = $this->CroogoHtml->status(1);
  27. $this->assertContains('<i class="icon-ok green"></i>', $result);
  28. }
  29. public function testStatusOkWithUrl() {
  30. $result = $this->CroogoHtml->status(1, array(
  31. 'admin' => true,
  32. 'plugin' => 'nodes',
  33. 'controller' => 'nodes',
  34. 'action' => 'toggle',
  35. ));
  36. $expected = array(
  37. 'a' => array(
  38. 'href',
  39. 'data-url' => '/admin/nodes/nodes/toggle',
  40. 'class' => 'icon-ok green ajax-toggle',
  41. ),
  42. '/a',
  43. );
  44. $this->assertTags($result, $expected);
  45. }
  46. public function testStatusRemove() {
  47. $result = $this->CroogoHtml->status(0);
  48. $this->assertContains('<i class="icon-remove red"></i>', $result);
  49. }
  50. public function testStatusRemoveWithUrl() {
  51. $result = $this->CroogoHtml->status(0, array(
  52. 'admin' => true,
  53. 'plugin' => 'nodes',
  54. 'controller' => 'nodes',
  55. 'action' => 'delete',
  56. ));
  57. $expected = array(
  58. 'a' => array(
  59. 'href',
  60. 'data-url' => '/admin/nodes/nodes/delete',
  61. 'class' => 'icon-remove red ajax-toggle',
  62. ),
  63. '/a',
  64. );
  65. $this->assertTags($result, $expected);
  66. }
  67. public function testLink() {
  68. $result = $this->CroogoHtml->link('', '/remove', array('icon' => 'remove', 'button' => 'danger'));
  69. $this->assertContains('class="btn btn-danger"', $result);
  70. $this->assertContains('<i class="icon-remove icon-large"></i>', $result);
  71. }
  72. /**
  73. * testLinkWithSmallIcon
  74. */
  75. public function testLinkWithSmallIcon() {
  76. $result = $this->CroogoHtml->link('', '/remove', array(
  77. 'icon' => 'remove',
  78. 'iconSize' => 'small',
  79. 'button' => 'danger'
  80. ));
  81. $this->assertContains('class="btn btn-danger"', $result);
  82. $this->assertContains('<i class="icon-remove"></i>', $result);
  83. }
  84. /**
  85. * testLinkWithInlineIcon
  86. */
  87. public function testLinkWithInlineIcon() {
  88. $result = $this->CroogoHtml->link('', '/remove', array(
  89. 'icon' => 'remove',
  90. 'iconSize' => 'small',
  91. 'iconInline' => true,
  92. 'button' => 'danger'
  93. ));
  94. $expected = array(
  95. 'a' => array(
  96. 'href',
  97. 'class' => 'btn btn-danger icon-remove',
  98. ),
  99. );
  100. $this->assertTags($result, $expected);
  101. $result = $this->CroogoHtml->link('', '/remove', array(
  102. 'icon' => 'remove',
  103. 'iconInline' => true,
  104. 'button' => 'danger'
  105. ));
  106. $expected = array(
  107. 'a' => array(
  108. 'href',
  109. 'class' => 'btn btn-danger icon-large icon-remove',
  110. ),
  111. );
  112. $this->assertTags($result, $expected);
  113. }
  114. public function testLinkDefaultButton() {
  115. $result = $this->CroogoHtml->link('Remove', '/remove', array('button' => 'default'));
  116. $this->assertContains('<a href="/remove" class="btn">Remove</a>', $result);
  117. }
  118. public function testLinkOptionsIsNull() {
  119. $result = $this->CroogoHtml->link('Remove', '/remove', null);
  120. }
  121. public function testLinkTooltip() {
  122. $result = $this->CroogoHtml->link('', '/remove', array('tooltip' => 'remove it'));
  123. $expected = array(
  124. 'a' => array(
  125. 'href',
  126. 'rel' => 'tooltip',
  127. 'data-placement',
  128. 'data-trigger',
  129. 'data-title' => 'remove it',
  130. ),
  131. '/a',
  132. );
  133. $this->assertTags($result, $expected);
  134. }
  135. public function testLinkButtonTooltipWithArrayOptions() {
  136. $result = $this->CroogoHtml->link('', '/remove', array(
  137. 'button' => array('success'),
  138. 'tooltip' => array(
  139. 'data-title' => 'remove it',
  140. 'data-placement' => 'left',
  141. 'data-trigger' => 'focus',
  142. ),
  143. ));
  144. $expected = array(
  145. 'a' => array(
  146. 'href',
  147. 'class' => 'btn btn-success',
  148. 'rel' => 'tooltip',
  149. 'data-placement' => 'left',
  150. 'data-trigger' => 'focus',
  151. 'data-title' => 'remove it',
  152. ),
  153. '/a',
  154. );
  155. $this->assertTags($result, $expected);
  156. }
  157. public function testAddPathAndGetCrumbList() {
  158. $this->CroogoHtml->addPath('/yes/we/can', '/');
  159. $result = $this->CroogoHtml->getCrumbList();
  160. $this->assertContains('<a href="/yes/">yes</a>', $result);
  161. $this->assertContains('<a href="/yes/we/">we</a>', $result);
  162. $this->assertContains('<a href="/yes/we/can/">can</a>', $result);
  163. }
  164. }