PluginTaskTest.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <?php
  2. /**
  3. * PluginTask Test file
  4. *
  5. * Test Case for plugin generation shell task
  6. *
  7. * PHP 5
  8. *
  9. * CakePHP : Rapid Development Framework (http://cakephp.org)
  10. * Copyright 2006-2009, Cake Software Foundation, Inc.
  11. *
  12. * Licensed under The MIT License
  13. * Redistributions of files must retain the above copyright notice.
  14. *
  15. * @copyright Copyright 2006-2009, Cake Software Foundation, Inc.
  16. * @link http://cakephp.org CakePHP Project
  17. * @package cake.tests.cases.console.libs.tasks
  18. * @since CakePHP v 1.3.0
  19. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  20. */
  21. App::uses('ShellDispatcher', 'Console');
  22. App::uses('ConsoleOutput', 'Console');
  23. App::uses('ConsoleInput', 'Console');
  24. App::uses('Shell', 'Console');
  25. App::uses('PluginTask', 'Console/Command/Task');
  26. App::uses('ModelTask', 'Console/Command/Task');
  27. App::uses('Folder', 'Utility');
  28. App::uses('File', 'Utility');
  29. /**
  30. * PluginTaskPlugin class
  31. *
  32. * @package cake.tests.cases.console.libs.tasks
  33. */
  34. class PluginTaskTest extends CakeTestCase {
  35. /**
  36. * setup method
  37. *
  38. * @return void
  39. */
  40. public function setUp() {
  41. parent::setUp();
  42. $out = $this->getMock('ConsoleOutput', array(), array(), '', false);
  43. $in = $this->getMock('ConsoleInput', array(), array(), '', false);
  44. $this->Task = $this->getMock('PluginTask',
  45. array('in', 'err', 'createFile', '_stop', 'clear'),
  46. array($out, $out, $in)
  47. );
  48. $this->Task->path = TMP . 'tests' . DS;
  49. $this->_paths = $paths = App::path('plugins');
  50. $this->_testPath = array_push($paths, TMP . 'tests' . DS);
  51. App::build(array('plugins' => $paths));
  52. }
  53. /**
  54. * test bake()
  55. *
  56. * @return void
  57. */
  58. public function testBakeFoldersAndFiles() {
  59. $this->Task->expects($this->at(0))->method('in')->will($this->returnValue($this->_testPath));
  60. $this->Task->expects($this->at(1))->method('in')->will($this->returnValue('y'));
  61. $path = $this->Task->path . 'bake_test_plugin';
  62. $file = $path . DS . 'bake_test_plugin_app_controller.php';
  63. $this->Task->expects($this->at(2))->method('createFile')
  64. ->with($file, new PHPUnit_Framework_Constraint_IsAnything());
  65. $file = $path . DS . 'bake_test_plugin_app_model.php';
  66. $this->Task->expects($this->at(3))->method('createFile')
  67. ->with($file, new PHPUnit_Framework_Constraint_IsAnything());
  68. $this->Task->bake('BakeTestPlugin');
  69. $path = $this->Task->path . 'bake_test_plugin';
  70. $this->assertTrue(is_dir($path), 'No plugin dir %s');
  71. $directories = array(
  72. 'config' . DS . 'schema',
  73. 'models' . DS . 'behaviors',
  74. 'models' . DS . 'datasources',
  75. 'console' . DS . 'shells' . DS . 'tasks',
  76. 'controllers' . DS . 'components',
  77. 'libs',
  78. 'views' . DS . 'helpers',
  79. 'tests' . DS . 'cases' . DS . 'components',
  80. 'tests' . DS . 'cases' . DS . 'helpers',
  81. 'tests' . DS . 'cases' . DS . 'behaviors',
  82. 'tests' . DS . 'cases' . DS . 'controllers',
  83. 'tests' . DS . 'cases' . DS . 'models',
  84. 'tests' . DS . 'groups',
  85. 'tests' . DS . 'fixtures',
  86. 'vendors',
  87. 'webroot'
  88. );
  89. foreach ($directories as $dir) {
  90. $this->assertTrue(is_dir($path . DS . $dir), 'Missing directory for ' . $dir);
  91. }
  92. $Folder = new Folder($this->Task->path . 'bake_test_plugin');
  93. $Folder->delete();
  94. }
  95. /**
  96. * test execute with no args, flowing into interactive,
  97. *
  98. * @return void
  99. */
  100. public function testExecuteWithNoArgs() {
  101. $this->Task->expects($this->at(0))->method('in')->will($this->returnValue('TestPlugin'));
  102. $this->Task->expects($this->at(1))->method('in')->will($this->returnValue('3'));
  103. $this->Task->expects($this->at(2))->method('in')->will($this->returnValue('y'));
  104. $path = $this->Task->path . 'test_plugin';
  105. $file = $path . DS . 'test_plugin_app_controller.php';
  106. $this->Task->expects($this->at(3))->method('createFile')
  107. ->with($file, new PHPUnit_Framework_Constraint_IsAnything());
  108. $file = $path . DS . 'test_plugin_app_model.php';
  109. $this->Task->expects($this->at(4))->method('createFile')
  110. ->with($file, new PHPUnit_Framework_Constraint_IsAnything());
  111. $this->Task->args = array();
  112. $this->Task->execute();
  113. $Folder = new Folder($path);
  114. $Folder->delete();
  115. }
  116. /**
  117. * Test Execute
  118. *
  119. * @return void
  120. */
  121. public function testExecuteWithOneArg() {
  122. $this->Task->expects($this->at(0))->method('in')
  123. ->will($this->returnValue($this->_testPath));
  124. $this->Task->expects($this->at(1))->method('in')
  125. ->will($this->returnValue('y'));
  126. $path = $this->Task->path . 'bake_test_plugin';
  127. $file = $path . DS . 'bake_test_plugin_app_controller.php';
  128. $this->Task->expects($this->at(2))->method('createFile')
  129. ->with($file, new PHPUnit_Framework_Constraint_IsAnything());
  130. $path = $this->Task->path . 'bake_test_plugin';
  131. $file = $path . DS . 'bake_test_plugin_app_model.php';
  132. $this->Task->expects($this->at(3))->method('createFile')
  133. ->with($file, new PHPUnit_Framework_Constraint_IsAnything());
  134. $this->Task->args = array('BakeTestPlugin');
  135. $this->Task->execute();
  136. $Folder = new Folder($this->Task->path . 'bake_test_plugin');
  137. $Folder->delete();
  138. }
  139. }