PageRenderTime 47ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/Blocks/Test/Case/Controller/BlocksControllerTest.php

https://github.com/kareypowell/croogo
PHP | 402 lines | 310 code | 21 blank | 71 comment | 0 complexity | c376179c3ecdfcf0f6d2ec23b427d13b MD5 | raw file
  1. <?php
  2. App::uses('BlocksController', 'Blocks.Controller');
  3. App::uses('CroogoControllerTestCase', 'Croogo.TestSuite');
  4. class BlocksControllerTest 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.meta.meta',
  18. 'plugin.nodes.node',
  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('Blocks') . 'View' . DS)
  39. ), App::APPEND);
  40. $this->BlocksController = $this->generate('Blocks.Blocks', array(
  41. 'methods' => array(
  42. 'redirect',
  43. ),
  44. 'components' => array(
  45. 'Auth' => array('user'),
  46. 'Session',
  47. ),
  48. ));
  49. $this->BlocksController->Auth
  50. ->staticExpects($this->any())
  51. ->method('user')
  52. ->will($this->returnCallback(array($this, 'authUserCallback')));
  53. }
  54. /**
  55. * tearDown
  56. *
  57. * @return void
  58. */
  59. public function tearDown() {
  60. parent::tearDown();
  61. unset($this->BlocksController);
  62. }
  63. /**
  64. * testAdminIndex
  65. *
  66. * @return void
  67. */
  68. public function testAdminIndex() {
  69. $this->testAction('/admin/blocks/blocks/index');
  70. $this->assertNotEmpty($this->vars['blocks']);
  71. }
  72. /**
  73. * testAdminIndexSearch
  74. *
  75. * @return void
  76. */
  77. public function testAdminIndexSearch() {
  78. $this->testAction('/admin/blocks/blocks/index?title=Recent');
  79. $this->assertNotEmpty($this->vars['blocks']);
  80. $this->assertEquals(1, count($this->vars['blocks']));
  81. $this->assertEquals(9, $this->vars['blocks'][0]['Block']['id']);
  82. }
  83. /**
  84. * testAdminAdd
  85. *
  86. * @return void
  87. */
  88. public function testAdminAdd() {
  89. $this->expectFlashAndRedirect('The Block has been saved');
  90. $this->testAction('/admin/blocks/blocks/add', array(
  91. 'data' => array(
  92. 'Block' => array(
  93. 'title' => 'Test block',
  94. 'alias' => 'test_block',
  95. 'class' => 'test-block',
  96. 'show_title' => 'test_block',
  97. 'region_id' => 4, // right
  98. 'body' => 'text here',
  99. 'visibility_paths' => '',
  100. 'status' => 1,
  101. ),
  102. 'Role' => array(
  103. 'Role' => array(),
  104. ),
  105. ),
  106. ));
  107. $result = $this->BlocksController->Block->findByAlias('test_block');
  108. $this->assertEqual($result['Block']['title'], 'Test block');
  109. }
  110. /**
  111. * testAdminEdit
  112. *
  113. * @return void
  114. */
  115. public function testAdminEdit() {
  116. $this->expectFlashAndRedirect('The Block has been saved');
  117. $this->testAction('/admin/blocks/blocks/edit/1', array(
  118. 'data' => array(
  119. 'Block' => array(
  120. 'id' => 3, // About
  121. 'title' => 'About [modified]',
  122. 'visibility_paths' => '',
  123. ),
  124. 'Role' => array(
  125. 'Role' => array(),
  126. ),
  127. ),
  128. ));
  129. $result = $this->BlocksController->Block->findByAlias('about');
  130. $this->assertEquals('About [modified]', $result['Block']['title']);
  131. }
  132. /**
  133. * testAdminDelete
  134. *
  135. * @return void
  136. */
  137. public function testAdminDelete() {
  138. $this->expectFlashAndRedirect('Block deleted');
  139. $this->testAction('/admin/blocks/blocks/delete/8');
  140. $hasAny = $this->BlocksController->Block->hasAny(array(
  141. 'Block.alias' => 'search',
  142. ));
  143. $this->assertFalse($hasAny);
  144. }
  145. /**
  146. * testAdminMoveUp
  147. *
  148. * @return void
  149. */
  150. public function testAdminMoveUp() {
  151. $this->expectFlashAndRedirect('Moved up successfully');
  152. $this->testAction('/admin/blocks/blocks/moveup/3');
  153. $list = $this->BlocksController->Block->find('list', array(
  154. 'fields' => array(
  155. 'id',
  156. 'alias',
  157. ),
  158. 'order' => 'Block.weight ASC',
  159. ));
  160. $blockAliases = array_values($list);
  161. $this->assertEqual($blockAliases, array(
  162. 'about',
  163. 'search',
  164. 'categories',
  165. 'blogroll',
  166. 'recent_posts',
  167. 'meta',
  168. 'block-visible-by-public',
  169. 'block-visible-by-admin-or-registered',
  170. ));
  171. }
  172. /**
  173. * testAdminMoveUpWithSteps
  174. *
  175. * @return void
  176. */
  177. public function testAdminMoveUpWithSteps() {
  178. $this->expectFlashAndRedirect('Moved up successfully');
  179. $this->testAction('/admin/blocks/blocks/moveup/6/3');
  180. $list = $this->BlocksController->Block->find('list', array(
  181. 'fields' => array(
  182. 'id',
  183. 'alias',
  184. ),
  185. 'order' => 'Block.weight ASC',
  186. ));
  187. $blockAliases = array_values($list);
  188. $this->assertEqual($blockAliases, array(
  189. 'blogroll',
  190. 'search',
  191. 'about',
  192. 'categories',
  193. 'recent_posts',
  194. 'meta',
  195. 'block-visible-by-public',
  196. 'block-visible-by-admin-or-registered',
  197. ));
  198. }
  199. /**
  200. * testAdminMoveDown
  201. *
  202. * @return void
  203. */
  204. public function testAdminMoveDown() {
  205. $this->expectFlashAndRedirect('Moved down successfully');
  206. $this->testAction('/admin/blocks/blocks/movedown/3');
  207. $list = $this->BlocksController->Block->find('list', array(
  208. 'fields' => array(
  209. 'id',
  210. 'alias',
  211. ),
  212. 'order' => 'Block.weight ASC',
  213. ));
  214. $blockAliases = array_values($list);
  215. $this->assertEqual($blockAliases, array(
  216. 'search',
  217. 'categories',
  218. 'about',
  219. 'blogroll',
  220. 'recent_posts',
  221. 'meta',
  222. 'block-visible-by-public',
  223. 'block-visible-by-admin-or-registered',
  224. ));
  225. }
  226. /**
  227. * testAdminMoveDownWithSteps
  228. *
  229. * @return void
  230. */
  231. public function testAdminMoveDownWithSteps() {
  232. $this->expectFlashAndRedirect('Moved down successfully');
  233. $this->testAction('/admin/blocks/blocks/movedown/8/3');
  234. $list = $this->BlocksController->Block->find('list', array(
  235. 'fields' => array(
  236. 'id',
  237. 'alias',
  238. ),
  239. 'order' => 'Block.weight ASC',
  240. ));
  241. $blockAliases = array_values($list);
  242. $this->assertEqual($blockAliases, array(
  243. 'about',
  244. 'categories',
  245. 'blogroll',
  246. 'search',
  247. 'recent_posts',
  248. 'meta',
  249. 'block-visible-by-public',
  250. 'block-visible-by-admin-or-registered',
  251. ));
  252. }
  253. /**
  254. * testAdminProcessDelete
  255. *
  256. * @return void
  257. */
  258. public function testAdminProcessDelete() {
  259. $this->expectFlashAndRedirect('Blocks deleted');
  260. $this->testAction('/admin/blocks/blocks/process', array(
  261. 'data' => array(
  262. 'Block' => array(
  263. 'action' => 'delete',
  264. '8' => array('id' => 0), // Search
  265. '3' => array('id' => 1), // About
  266. '7' => array('id' => 0), // Categories
  267. '6' => array('id' => 1), // Blogroll
  268. '9' => array('id' => 0), // Recent Posts
  269. '5' => array('id' => 1), // Meta
  270. ),
  271. ),
  272. ));
  273. $list = $this->BlocksController->Block->find('list', array(
  274. 'fields' => array(
  275. 'id',
  276. 'alias',
  277. ),
  278. 'order' => 'Block.weight ASC',
  279. ));
  280. $blockAliases = array_values($list);
  281. $this->assertEqual($blockAliases, array(
  282. 'search',
  283. 'categories',
  284. 'recent_posts',
  285. 'block-visible-by-public',
  286. 'block-visible-by-admin-or-registered',
  287. ));
  288. }
  289. /**
  290. * testAdminProcessPublish
  291. *
  292. * @return void
  293. */
  294. public function testAdminProcessPublish() {
  295. // unpublish a Block for testing
  296. $this->BlocksController->Block->id = 3; // About
  297. $this->BlocksController->Block->save(array(
  298. 'id' => 3,
  299. 'status' => CroogoStatus::UNPUBLISHED,
  300. ));
  301. $this->BlocksController->Block->id = false;
  302. $about = $this->BlocksController->Block->hasAny(array(
  303. 'id' => 3,
  304. 'status' => 0,
  305. ));
  306. $this->assertTrue($about);
  307. $this->expectFlashAndRedirect('Blocks published');
  308. $this->testAction('/admin/blocks/blocks/process', array(
  309. 'data' => array(
  310. 'Block' => array(
  311. 'action' => 'publish',
  312. '8' => array('id' => 1), // Search
  313. '3' => array('id' => 1), // About
  314. '7' => array('id' => 1), // Categories
  315. '6' => array('id' => 1), // Blogroll
  316. '9' => array('id' => 1), // Recent Posts
  317. '5' => array('id' => 1), // Meta
  318. ),
  319. ),
  320. ));
  321. $list = $this->BlocksController->Block->find('list', array(
  322. 'conditions' => array(
  323. 'Block.status' => true,
  324. ),
  325. 'fields' => array(
  326. 'id',
  327. 'alias',
  328. ),
  329. 'order' => 'Block.weight ASC',
  330. ));
  331. $blockAliases = array_values($list);
  332. $this->assertEqual($blockAliases, array(
  333. 'search',
  334. 'about',
  335. 'categories',
  336. 'blogroll',
  337. 'recent_posts',
  338. 'meta',
  339. 'block-visible-by-public',
  340. 'block-visible-by-admin-or-registered',
  341. ));
  342. }
  343. /**
  344. * testAdminProcessUnpublish
  345. *
  346. * @return void
  347. */
  348. public function testAdminProcessUnpublish() {
  349. $this->expectFlashAndRedirect('Blocks unpublished');
  350. $this->testAction('/admin/blocks/blocks/process', array(
  351. 'data' => array(
  352. 'Block' => array(
  353. 'action' => 'unpublish',
  354. '8' => array('id' => 1), // Search
  355. '3' => array('id' => 1), // About
  356. '7' => array('id' => 0), // Categories
  357. '6' => array('id' => 1), // Blogroll
  358. '9' => array('id' => 0), // Recent Posts
  359. '5' => array('id' => 1), // Meta
  360. ),
  361. ),
  362. ));
  363. $list = $this->BlocksController->Block->find('list', array(
  364. 'conditions' => array(
  365. 'Block.status' => 1,
  366. ),
  367. 'fields' => array(
  368. 'id',
  369. 'alias',
  370. ),
  371. 'order' => 'Block.weight ASC',
  372. ));
  373. $blockAliases = array_values($list);
  374. $this->assertEqual($blockAliases, array(
  375. 'categories',
  376. 'recent_posts',
  377. 'block-visible-by-public',
  378. 'block-visible-by-admin-or-registered',
  379. ));
  380. }
  381. }