PageRenderTime 57ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/Taxonomy/Test/Case/Controller/VocabulariesControllerTest.php

https://github.com/kareypowell/croogo
PHP | 180 lines | 123 code | 11 blank | 46 comment | 0 complexity | 2e06c118593b14bc124fb1f5ee73477b MD5 | raw file
  1. <?php
  2. App::uses('VocabulariesController', 'Taxonomy.Controller');
  3. App::uses('CroogoControllerTestCase', 'Croogo.TestSuite');
  4. /**
  5. * VocabulariesController Test
  6. */
  7. class VocabulariesControllerTest extends CroogoControllerTestCase {
  8. /**
  9. * fixtures
  10. */
  11. public $fixtures = array(
  12. 'plugin.users.aco',
  13. 'plugin.users.aro',
  14. 'plugin.users.aros_aco',
  15. 'plugin.blocks.block',
  16. 'plugin.comments.comment',
  17. 'plugin.contacts.contact',
  18. 'plugin.translate.i18n',
  19. 'plugin.settings.language',
  20. 'plugin.menus.link',
  21. 'plugin.menus.menu',
  22. 'plugin.contacts.message',
  23. 'plugin.nodes.node',
  24. 'plugin.meta.meta',
  25. 'plugin.taxonomy.model_taxonomy',
  26. 'plugin.blocks.region',
  27. 'plugin.users.role',
  28. 'plugin.settings.setting',
  29. 'plugin.taxonomy.taxonomy',
  30. 'plugin.taxonomy.term',
  31. 'plugin.taxonomy.type',
  32. 'plugin.taxonomy.types_vocabulary',
  33. 'plugin.users.user',
  34. 'plugin.taxonomy.vocabulary',
  35. );
  36. /**
  37. * setUp
  38. *
  39. * @return void
  40. */
  41. public function setUp() {
  42. parent::setUp();
  43. App::build(array(
  44. 'View' => array(CakePlugin::path('Taxonomy') . 'View' . DS)
  45. ), App::APPEND);
  46. $this->VocabulariesController = $this->generate('Taxonomy.Vocabularies', array(
  47. 'methods' => array(
  48. 'redirect',
  49. ),
  50. 'components' => array(
  51. 'Auth' => array('user'),
  52. 'Session',
  53. ),
  54. ));
  55. $this->VocabulariesController->Auth
  56. ->staticExpects($this->any())
  57. ->method('user')
  58. ->will($this->returnCallback(array($this, 'authUserCallback')));
  59. }
  60. /**
  61. * tearDown
  62. *
  63. * @return void
  64. */
  65. public function tearDown() {
  66. parent::tearDown();
  67. unset($this->VocabulariesController);
  68. }
  69. /**
  70. * testAdminIndex
  71. *
  72. * @return void
  73. */
  74. public function testAdminIndex() {
  75. $this->testAction('/admin/taxonomy/vocabularies/index');
  76. $this->assertNotEmpty($this->vars['vocabularies']);
  77. }
  78. /**
  79. * testAdminAdd
  80. *
  81. * @return void
  82. */
  83. public function testAdminAdd() {
  84. $this->expectFlashAndRedirect('The Vocabulary has been saved');
  85. $this->testAction('admin/taxonomy/vocabularies/add', array(
  86. 'data' => array(
  87. 'Vocabulary' => array(
  88. 'title' => 'New Vocabulary',
  89. 'alias' => 'new_vocabulary',
  90. ),
  91. ),
  92. ));
  93. $newVocabulary = $this->VocabulariesController->Vocabulary->findByAlias('new_vocabulary');
  94. $this->assertEqual($newVocabulary['Vocabulary']['title'], 'New Vocabulary');
  95. }
  96. /**
  97. * testAdminEdit
  98. *
  99. * @return void
  100. */
  101. public function testAdminEdit() {
  102. $this->expectFlashAndRedirect('The Vocabulary has been saved');
  103. $this->testAction('/admin/taxonomy/vocabularies/edit/1', array(
  104. 'data' => array(
  105. 'Vocabulary' => array(
  106. 'id' => 1, // categories
  107. 'title' => 'Categories [modified]',
  108. ),
  109. ),
  110. ));
  111. $categories = $this->VocabulariesController->Vocabulary->findByAlias('categories');
  112. $this->assertEquals('Categories [modified]', $categories['Vocabulary']['title']);
  113. }
  114. /**
  115. * testAdminDelete
  116. *
  117. * @return void
  118. */
  119. public function testAdminDelete() {
  120. $this->expectFlashAndRedirect('Vocabulary deleted');
  121. $this->testAction('admin/taxonomy/vocabularies/delete/1'); // ID of categories
  122. $hasAny = $this->VocabulariesController->Vocabulary->hasAny(array(
  123. 'Vocabulary.alias' => 'categories',
  124. ));
  125. $this->assertFalse($hasAny);
  126. }
  127. /**
  128. * testAdminMoveup
  129. *
  130. * @return void
  131. */
  132. public function testAdminMoveup() {
  133. $this->expectFlashAndRedirect('Moved up successfully');
  134. $this->testAction('admin/taxonomy/vocabularies/moveup/2'); // ID of tags
  135. $vocabularies = $this->VocabulariesController->Vocabulary->find('list', array(
  136. 'fields' => array(
  137. 'id',
  138. 'alias',
  139. ),
  140. 'order' => 'Vocabulary.weight ASC',
  141. ));
  142. $expected = array(
  143. '2' => 'tags',
  144. '1' => 'categories',
  145. );
  146. $this->assertEqual($vocabularies, $expected);
  147. }
  148. /**
  149. * testAdminMovedown
  150. *
  151. * @return void
  152. */
  153. public function testAdminMovedown() {
  154. $this->expectFlashAndRedirect('Moved down successfully');
  155. $this->testAction('admin/taxonomy/vocabularies/movedown/1'); // ID of categories
  156. $vocabularies = $this->VocabulariesController->Vocabulary->find('list', array(
  157. 'fields' => array(
  158. 'id',
  159. 'alias',
  160. ),
  161. 'order' => 'Vocabulary.weight ASC',
  162. ));
  163. $expected = array(
  164. '2' => 'tags',
  165. '1' => 'categories',
  166. );
  167. $this->assertEqual($vocabularies, $expected);
  168. }
  169. }