PageRenderTime 48ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/Taxonomy/Test/Case/Controller/TermsControllerTest.php

https://github.com/kareypowell/croogo
PHP | 231 lines | 170 code | 15 blank | 46 comment | 0 complexity | 95e0ed93156f1ad7e9ae0fdc877e20f3 MD5 | raw file
  1. <?php
  2. App::uses('TermsController', 'Taxonomy.Controller');
  3. App::uses('CroogoControllerTestCase', 'Croogo.TestSuite');
  4. class TermsControllerTest extends CroogoControllerTestCase {
  5. public $fixtures = array(
  6. 'plugin.users.aco',
  7. 'plugin.users.aro',
  8. 'plugin.users.aros_aco',
  9. 'plugin.blocks.block',
  10. 'plugin.comments.comment',
  11. 'plugin.contacts.contact',
  12. 'plugin.translate.i18n',
  13. 'plugin.settings.language',
  14. 'plugin.menus.link',
  15. 'plugin.menus.menu',
  16. 'plugin.contacts.message',
  17. 'plugin.nodes.node',
  18. 'plugin.meta.meta',
  19. 'plugin.taxonomy.model_taxonomy',
  20. 'plugin.blocks.region',
  21. 'plugin.users.role',
  22. 'plugin.settings.setting',
  23. 'plugin.taxonomy.taxonomy',
  24. 'plugin.taxonomy.term',
  25. 'plugin.taxonomy.type',
  26. 'plugin.taxonomy.types_vocabulary',
  27. 'plugin.users.user',
  28. 'plugin.taxonomy.vocabulary',
  29. );
  30. /**
  31. * setUp
  32. *
  33. * @return void
  34. */
  35. public function setUp() {
  36. parent::setUp();
  37. App::build(array(
  38. 'View' => array(CakePlugin::path('Taxonomy') . 'View' . DS)
  39. ), App::APPEND);
  40. $this->TermsController = $this->generate('Taxonomy.Terms', array(
  41. 'methods' => array(
  42. 'redirect',
  43. ),
  44. 'components' => array(
  45. 'Auth' => array('user'),
  46. 'Session',
  47. 'Menus.Menus',
  48. ),
  49. ));
  50. $this->TermsController->Auth
  51. ->staticExpects($this->any())
  52. ->method('user')
  53. ->will($this->returnCallback(array($this, 'authUserCallback')));
  54. }
  55. /**
  56. * tearDown
  57. *
  58. * @return void
  59. */
  60. public function tearDown() {
  61. parent::tearDown();
  62. unset($this->TermsController);
  63. }
  64. /**
  65. * testAdminIndex
  66. *
  67. * @return void
  68. */
  69. public function testAdminIndex() {
  70. $this->testAction('/admin/taxonomy/terms/index/1');
  71. $this->assertNotEmpty($this->vars['terms']);
  72. $expected = array(
  73. '1' => 'Uncategorized',
  74. '2' => 'Announcements',
  75. );
  76. $termsTree = Hash::combine($this->vars['terms'], '{n}.Term.id', '{n}.Term.title');
  77. $this->assertEquals($expected, $termsTree);
  78. }
  79. /**
  80. * testAdminAdd
  81. *
  82. * @return void
  83. */
  84. public function testAdminAdd() {
  85. $this->expectFlashAndRedirect('Term saved successfuly.');
  86. $this->testAction('admin/taxonomy/terms/add/1', array(
  87. 'data' => array(
  88. 'Taxonomy' => array(
  89. 'parent_id' => null,
  90. ),
  91. 'Term' => array(
  92. 'title' => 'New Category',
  93. 'slug' => 'new-category',
  94. 'description' => 'category description here',
  95. ),
  96. ),
  97. ));
  98. $termsTree = $this->TermsController->Term->Taxonomy->getTree('categories');
  99. $termsTreeSlugs = array_keys($termsTree);
  100. $expected = array(
  101. 'uncategorized',
  102. 'announcements',
  103. 'new-category',
  104. );
  105. $this->assertEqual($termsTreeSlugs, $expected);
  106. }
  107. /**
  108. * testAdminAddWithParent
  109. *
  110. * @return void
  111. */
  112. public function testAdminAddWithParent() {
  113. $this->expectFlashAndRedirect('Term saved successfuly.');
  114. $this->testAction('admin/taxonomy/terms/add/1', array(
  115. 'data' => array(
  116. 'Taxonomy' => array(
  117. 'parent_id' => 1, // Uncategorized
  118. ),
  119. 'Term' => array(
  120. 'title' => 'New Category',
  121. 'slug' => 'new-category',
  122. 'description' => 'category description here',
  123. ),
  124. ),
  125. ));
  126. $termsTree = $this->TermsController->Term->Taxonomy->getTree('categories');
  127. $termsTreeTitles = array_values($termsTree);
  128. $expected = array(
  129. 'Uncategorized',
  130. '_New Category',
  131. 'Announcements',
  132. );
  133. $this->assertEqual($termsTreeTitles, $expected);
  134. }
  135. /**
  136. * testAdminEdit
  137. *
  138. * @return void
  139. */
  140. public function testAdminEdit() {
  141. $this->expectFlashAndRedirect('Term saved successfuly.');
  142. // ID of Uncategorized and Categories
  143. $this->testAction('/admin/taxonomy/terms/edit/1/1', array(
  144. 'data' => array(
  145. 'Taxonomy' => array(
  146. 'id' => 1,
  147. 'parent_id' => null,
  148. ),
  149. 'Term' => array(
  150. 'id' => 1,
  151. 'title' => 'New Category',
  152. 'slug' => 'new-category',
  153. 'description' => 'category description here',
  154. ),
  155. ),
  156. ));
  157. $termsTree = $this->TermsController->Term->Taxonomy->getTree('categories');
  158. $expected = array(
  159. 'new-category' => 'New Category',
  160. 'announcements' => 'Announcements',
  161. );
  162. $this->assertEquals($expected, $termsTree);
  163. }
  164. /**
  165. * testAdminDelete
  166. *
  167. * @return void
  168. */
  169. public function testAdminDelete() {
  170. $ModelTaxonomy = ClassRegistry::init('Taxonomy.ModelTaxonomy');
  171. $options = array('conditions' => array(
  172. 'taxonomy_id' => 1,
  173. ));
  174. $count = $ModelTaxonomy->find('count', $options);
  175. $this->assertEquals(1, $count);
  176. $this->expectFlashAndRedirect('Term deleted');
  177. $this->testAction('admin/taxonomy/terms/delete/1/1'); // ID of Uncategorized and Categories
  178. $termsTree = $this->TermsController->Term->Taxonomy->getTree('categories');
  179. $count = $ModelTaxonomy->find('count', $options);
  180. $this->assertEquals(0, $count);
  181. $expected = array(
  182. 'announcements' => 'Announcements',
  183. );
  184. $this->assertEqual($termsTree, $expected);
  185. }
  186. /**
  187. * testAdminMoveup
  188. *
  189. * @return void
  190. */
  191. public function testAdminMoveup() {
  192. $this->expectFlashAndRedirect('Moved up successfully');
  193. $this->testAction('admin/taxonomy/terms/moveup/2/1'); // ID of Announcements and Categories
  194. $termsTree = $this->TermsController->Term->Taxonomy->getTree('categories');
  195. $expected = array(
  196. 'announcements' => 'Announcements',
  197. 'uncategorized' => 'Uncategorized',
  198. );
  199. $this->assertEqual($termsTree, $expected);
  200. }
  201. /**
  202. * testAdminMovedown
  203. *
  204. * @return void
  205. */
  206. public function testAdminMovedown() {
  207. $this->expectFlashAndRedirect('Moved down successfully');
  208. $this->testAction('admin/taxonomy/terms/movedown/1/1'); // ID of Uncategorized and Categories
  209. $termsTree = $this->TermsController->Term->Taxonomy->getTree('categories');
  210. $expected = array(
  211. 'announcements' => 'Announcements',
  212. 'uncategorized' => 'Uncategorized',
  213. );
  214. $this->assertEqual($termsTree, $expected);
  215. }
  216. }