PageRenderTime 100ms CodeModel.GetById 19ms RepoModel.GetById 2ms app.codeStats 0ms

/Croogo/Test/Case/Console/Command/ExtShellTest.php

https://github.com/kareypowell/croogo
PHP | 175 lines | 113 code | 21 blank | 41 comment | 0 complexity | 679b9ebe0825785152776716a68c5aba MD5 | raw file
  1. <?php
  2. App::uses('ShellDispatcher', 'Console');
  3. App::uses('AppShell', 'Console/Command');
  4. App::uses('Shell', 'Console');
  5. App::uses('ExtShell', 'Croogo.Console/Command');
  6. App::uses('Folder', 'Utility');
  7. App::uses('CroogoTestCase', 'Croogo.TestSuite');
  8. /**
  9. * Ext Shell Test
  10. *
  11. * @category Test
  12. * @package Croogo
  13. * @version 1.4
  14. * @author Fahad Ibnay Heylaal <contact@fahad19.com>
  15. * @license http://www.opensource.org/licenses/mit-license.php The MIT License
  16. * @link http://www.croogo.org
  17. */
  18. class ExtShellTest extends CroogoTestCase {
  19. /**
  20. * fixtures
  21. *
  22. * @var array
  23. */
  24. public $fixtures = array(
  25. 'plugin.comments.comment',
  26. 'plugin.menus.menu',
  27. 'plugin.blocks.block',
  28. 'plugin.menus.link',
  29. 'plugin.meta.meta',
  30. 'plugin.nodes.node',
  31. 'plugin.taxonomy.model_taxonomy',
  32. 'plugin.blocks.region',
  33. 'plugin.users.role',
  34. 'plugin.settings.setting',
  35. 'plugin.taxonomy.taxonomy',
  36. 'plugin.taxonomy.term',
  37. 'plugin.taxonomy.type',
  38. 'plugin.taxonomy.types_vocabulary',
  39. 'plugin.users.user',
  40. 'plugin.taxonomy.vocabulary',
  41. 'plugin.users.aro',
  42. 'plugin.users.aco',
  43. 'plugin.users.aros_aco',
  44. );
  45. /**
  46. * setUp method
  47. *
  48. * @return void
  49. */
  50. public function setUp() {
  51. parent::setUp();
  52. $Folder = new Folder(APP . 'Plugin' . DS . 'Example');
  53. $Folder->copy(CakePlugin::path('Croogo') . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS . 'Example');
  54. $this->Setting = ClassRegistry::init('Settings.Setting');
  55. }
  56. /**
  57. * tearDown
  58. *
  59. * @return void
  60. */
  61. public function tearDown() {
  62. parent::tearDown();
  63. $Folder = new Folder(CakePlugin::path('Croogo') . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS . 'Example');
  64. $Folder->delete();
  65. }
  66. /**
  67. * testPlugin
  68. *
  69. * @return void
  70. */
  71. public function testPlugin() {
  72. $Link = ClassRegistry::init('Menus.Link');
  73. $Shell = $this->getMock('ExtShell', array('out', 'err'));
  74. $Shell->args = array('deactivate', 'plugin', 'Example');
  75. $Shell->params = array('force' => false);
  76. $Shell->main();
  77. $result = $this->Setting->findByKey('Hook.bootstraps');
  78. $this->assertFalse(in_array('Example', explode(',', $result['Setting']['value'])));
  79. $result = $Link->findByTitle('Example');
  80. $this->assertFalse(!empty($result));
  81. $Shell->args = array('activate', 'plugin', 'Example');
  82. $Shell->main();
  83. $result = $this->Setting->findByKey('Hook.bootstraps');
  84. $this->assertTrue(in_array('Example', explode(',', $result['Setting']['value'])));
  85. $result = $Link->findByTitle('Example');
  86. $this->assertTrue(!empty($result));
  87. $bogusPlugin = 'Bogus';
  88. $Shell->args = array('activate', 'plugin', $bogusPlugin);
  89. $Shell->main();
  90. $result = $this->Setting->findByKey('Hook.bootstraps');
  91. $this->assertFalse(in_array($bogusPlugin, explode(',', $result['Setting']['value'])));
  92. }
  93. /**
  94. * testForceActivation
  95. */
  96. public function testForceActivation() {
  97. $Shell = $this->getMock('ExtShell', array('out', 'err'));
  98. $Shell->args = array('activate', 'plugin', 'TestPlugin');
  99. $Shell->main();
  100. $result = $this->Setting->findByKey('Hook.bootstraps');
  101. $this->assertFalse(in_array('TestPlugin', explode(',', $result['Setting']['value'])));
  102. $Shell->args = array('activate', 'plugin', 'TestPlugin');
  103. $Shell->params = array('force' => true);
  104. $Shell->main();
  105. $result = $this->Setting->findByKey('Hook.bootstraps');
  106. $this->assertTrue(in_array('TestPlugin', explode(',', $result['Setting']['value'])));
  107. }
  108. /**
  109. * testForceDeactivation
  110. */
  111. public function testForceDeactivation() {
  112. $Shell = $this->getMock('ExtShell', array('out', 'err'));
  113. $result = $this->Setting->findByKey('Hook.bootstraps');
  114. $bogus = $result['Setting']['value'] . ',Bogus';
  115. $this->Setting->write('Hook.bootstraps', $bogus);
  116. $Shell->args = array('deactivate', 'plugin', 'Bogus');
  117. $Shell->params['force'] = true;
  118. $Shell->main();
  119. $result = $this->Setting->findByKey('Hook.bootstraps');
  120. $this->assertFalse(in_array('Bogus', explode(',', $result['Setting']['value'])));
  121. }
  122. /**
  123. * testTheme
  124. *
  125. * @return void
  126. */
  127. public function testTheme() {
  128. $Shell = $this->getMock('ExtShell', array('out', 'err'));
  129. $Shell->args = array('activate', 'theme', 'Mytheme');
  130. $Shell->main();
  131. $result = $this->Setting->findByKey('Site.theme');
  132. $this->assertEquals('Mytheme', $result['Setting']['value']);
  133. $this->assertEquals('Mytheme', Configure::read('Site.theme'));
  134. $Shell->args = array('activate', 'theme', 'Bogus');
  135. $Shell->main();
  136. $result = $this->Setting->findByKey('Site.theme');
  137. $this->assertEquals('Mytheme', $result['Setting']['value']);
  138. $this->assertEquals('Mytheme', Configure::read('Site.theme'));
  139. $Shell->args = array('deactivate', 'theme');
  140. $Shell->main();
  141. $result = $this->Setting->findByKey('Site.theme');
  142. $this->assertEquals('Mytheme', $result['Setting']['value']);
  143. $Shell->args = array('deactivate', 'theme', 'Mytheme');
  144. $Shell->main();
  145. $result = $this->Setting->findByKey('Site.theme');
  146. $this->assertEquals('Mytheme', $result['Setting']['value']);
  147. $Shell->args = array('activate', 'theme', 'Mytheme');
  148. $Shell->main();
  149. $Shell->args = array('activate', 'theme', 'default');
  150. $Shell->main();
  151. $result = $this->Setting->findByKey('Site.theme');
  152. $this->assertEquals('', $result['Setting']['value']);
  153. }
  154. }