PluginTaskTest.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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 . 'BakeTestPlugin';
  62. $file = $path . DS . 'Controller' . DS .'BakeTestPluginAppController.php';
  63. $this->Task->expects($this->at(2))->method('createFile')
  64. ->with($file, new PHPUnit_Framework_Constraint_IsAnything());
  65. $file = $path . DS . 'Model' . DS . 'BakeTestPluginAppModel.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 . 'BakeTestPlugin';
  70. $this->assertTrue(is_dir($path), 'No plugin dir %s');
  71. $directories = array(
  72. 'config' . DS . 'schema',
  73. 'Model' . DS . 'Behavior',
  74. 'Model' . DS . 'Datasource',
  75. 'Console' . DS . 'Command' . DS . 'Task',
  76. 'Controller' . DS . 'Component',
  77. 'Lib',
  78. 'View' . DS . 'Helper',
  79. 'tests' . DS . 'Case' . DS . 'Controller' . DS . 'Component',
  80. 'tests' . DS . 'Case' . DS . 'View' . DS . 'Helper',
  81. 'tests' . DS . 'Case' . DS . 'Model' . DS . 'Behavior',
  82. 'tests' . DS . 'Fixture',
  83. 'vendors',
  84. 'webroot'
  85. );
  86. foreach ($directories as $dir) {
  87. $this->assertTrue(is_dir($path . DS . $dir), 'Missing directory for ' . $dir);
  88. }
  89. $Folder = new Folder($this->Task->path . 'BakeTestPlugin');
  90. $Folder->delete();
  91. }
  92. /**
  93. * test execute with no args, flowing into interactive,
  94. *
  95. * @return void
  96. */
  97. public function testExecuteWithNoArgs() {
  98. $this->Task->expects($this->at(0))->method('in')->will($this->returnValue('TestPlugin'));
  99. $this->Task->expects($this->at(1))->method('in')->will($this->returnValue('3'));
  100. $this->Task->expects($this->at(2))->method('in')->will($this->returnValue('y'));
  101. $path = $this->Task->path . 'TestPlugin';
  102. $file = $path . DS . 'Controller' . DS . 'TestPluginAppController.php';
  103. $this->Task->expects($this->at(3))->method('createFile')
  104. ->with($file, new PHPUnit_Framework_Constraint_IsAnything());
  105. $file = $path . DS . 'Model' . DS . 'TestPluginAppModel.php';
  106. $this->Task->expects($this->at(4))->method('createFile')
  107. ->with($file, new PHPUnit_Framework_Constraint_IsAnything());
  108. $this->Task->args = array();
  109. $this->Task->execute();
  110. $Folder = new Folder($path);
  111. $Folder->delete();
  112. }
  113. /**
  114. * Test Execute
  115. *
  116. * @return void
  117. */
  118. public function testExecuteWithOneArg() {
  119. $this->Task->expects($this->at(0))->method('in')
  120. ->will($this->returnValue($this->_testPath));
  121. $this->Task->expects($this->at(1))->method('in')
  122. ->will($this->returnValue('y'));
  123. $path = $this->Task->path . 'BakeTestPlugin';
  124. $file = $path . DS . 'Controller' . DS . 'BakeTestPluginAppController.php';
  125. $this->Task->expects($this->at(2))->method('createFile')
  126. ->with($file, new PHPUnit_Framework_Constraint_IsAnything());
  127. $path = $this->Task->path . 'BakeTestPlugin';
  128. $file = $path . DS . 'Model' . DS . 'BakeTestPluginAppModel.php';
  129. $this->Task->expects($this->at(3))->method('createFile')
  130. ->with($file, new PHPUnit_Framework_Constraint_IsAnything());
  131. $this->Task->args = array('BakeTestPlugin');
  132. $this->Task->execute();
  133. $Folder = new Folder($this->Task->path . 'BakeTestPlugin');
  134. $Folder->delete();
  135. }
  136. }