PageRenderTime 42ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/Croogo/Test/Case/Controller/Component/CroogoComponentTest.php

https://github.com/kareypowell/croogo
PHP | 107 lines | 78 code | 18 blank | 11 comment | 0 complexity | 75ac6933e702e7c2229d6bf3f3fd4e7a MD5 | raw file
  1. <?php
  2. App::uses('AppController', 'Controller');
  3. App::uses('Component', 'Controller');
  4. App::uses('ComponentCollection', 'Controller');
  5. App::uses('CroogoTestCase', 'Croogo.TestSuite');
  6. App::uses('CroogoComponent', 'Croogo.Controller/Component');
  7. class MockCroogoComponent extends CroogoComponent {
  8. public function startup(Controller $controller) {
  9. $this->_controller = $controller;
  10. }
  11. }
  12. class CroogoTestController extends AppController {
  13. }
  14. class CroogoComponentTest extends CroogoTestCase {
  15. public $fixtures = array(
  16. 'plugin.users.aco',
  17. 'plugin.users.aro',
  18. 'plugin.users.aros_aco',
  19. 'plugin.settings.setting',
  20. 'plugin.menus.menu',
  21. 'plugin.menus.link',
  22. 'plugin.users.role',
  23. 'plugin.taxonomy.type',
  24. 'plugin.taxonomy.vocabulary',
  25. 'plugin.taxonomy.types_vocabulary',
  26. 'plugin.nodes.node',
  27. );
  28. public function setUp() {
  29. parent::setUp();
  30. $this->Controller = new CroogoTestController(new CakeRequest(), new CakeResponse());
  31. $this->Controller->constructClasses();
  32. $this->Controller->Croogo = new MockCroogoComponent($this->Controller->Components);
  33. $this->Controller->Components->unload('Blocks');
  34. $this->Controller->Components->unload('Menus');
  35. $this->Controller->Components->set('Croogo', $this->Controller->Croogo);
  36. $this->Controller->startupProcess();
  37. }
  38. public function testAddRemoveAcos() {
  39. $Aco = ClassRegistry::init('Aco');
  40. $this->Controller->Croogo->addAco('CroogoTestController');
  41. $parent = $Aco->findByAlias('CroogoTestController');
  42. $this->assertNotEmpty($parent);
  43. $this->Controller->Croogo->addAco('CroogoTestController/index');
  44. $child = $Aco->findByParentId($parent['Aco']['id']);
  45. $this->assertNotEmpty($child);
  46. $this->Controller->Croogo->removeAco('CroogoTestController/index');
  47. $child = $Aco->findByParentId($parent['Aco']['id']);
  48. $this->assertEmpty($child);
  49. $this->Controller->Croogo->removeAco('CroogoTestController');
  50. $parent = $Aco->findByAlias('CroogoTestController');
  51. $this->assertEmpty($parent);
  52. }
  53. public function testPluginIsActive() {
  54. $result = $this->Controller->Croogo->pluginIsActive('Example');
  55. $this->assertTrue($result);
  56. $result = $this->Controller->Croogo->pluginIsActive('example');
  57. $this->assertTrue($result);
  58. $result = $this->Controller->Croogo->pluginIsActive('Shops');
  59. $this->assertFalse($result);
  60. }
  61. /**
  62. * testRedirect
  63. *
  64. * @return void
  65. * @dataProvider redirectData
  66. */
  67. public function testRedirect($expected, $url, $data = array()) {
  68. $Controller = $this->getMock('CroogoTestController', array('redirect'), array(new CakeRequest(), new CakeResponse()));
  69. $Controller->request->data = $data;
  70. $Controller->expects($this->once())
  71. ->method('redirect')
  72. ->with($this->equalTo($expected));
  73. $CroogoComponent = new CroogoComponent(new ComponentCollection());
  74. $CroogoComponent->startup($Controller);
  75. $CroogoComponent->redirect($url);
  76. }
  77. /**
  78. * redirectData
  79. *
  80. * @return array
  81. */
  82. public function redirectData() {
  83. return array(
  84. array('croogo.org', 'croogo.org'),
  85. array(array('action' => 'index'), array('action' => 'edit', 1)),
  86. array(array('action' => 'edit', 1), array('action' => 'edit', 1), array('apply' => 'Apply')),
  87. );
  88. }
  89. }