ProjectTaskTest.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?php
  2. /**
  3. * CakePHP : Rapid Development Framework (http://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * For full copyright and license information, please see the LICENSE.txt
  8. * Redistributions of files must retain the above copyright notice.
  9. *
  10. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  11. * @link http://cakephp.org CakePHP Project
  12. * @since 1.3.0
  13. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  14. */
  15. namespace Cake\Test\TestCase\Console\Command\Task;
  16. use Cake\Console\Command\Task\ProjectTask;
  17. use Cake\Core\Configure;
  18. use Cake\TestSuite\TestCase;
  19. use Cake\Utility\File;
  20. use Cake\Utility\Folder;
  21. /**
  22. * ProjectTask Test class
  23. *
  24. */
  25. class ProjectTaskTest extends TestCase {
  26. /**
  27. * setUp method
  28. *
  29. * @return void
  30. */
  31. public function setUp() {
  32. parent::setUp();
  33. $out = $this->getMock('Cake\Console\ConsoleOutput', array(), array(), '', false);
  34. $in = $this->getMock('Cake\Console\ConsoleInput', array(), array(), '', false);
  35. $this->Task = $this->getMock('Cake\Console\Command\Task\ProjectTask',
  36. array('in', 'err', 'createFile', '_stop'),
  37. array($out, $out, $in)
  38. );
  39. $this->Task->path = TMP;
  40. }
  41. /**
  42. * tearDown method
  43. *
  44. * @return void
  45. */
  46. public function tearDown() {
  47. parent::tearDown();
  48. $Folder = new Folder($this->Task->path . 'BakeTestApp');
  49. $Folder->delete();
  50. unset($this->Task);
  51. }
  52. /**
  53. * creates a test project that is used for testing project task.
  54. *
  55. * @return void
  56. */
  57. protected function _setupTestProject() {
  58. $this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y'));
  59. $this->Task->bake($this->Task->path . 'BakeTestApp');
  60. }
  61. /**
  62. * test bake with an absolute path.
  63. *
  64. * @return void
  65. */
  66. public function testExecuteWithAbsolutePath() {
  67. $this->markTestIncomplete('Need to figure this out');
  68. $path = $this->Task->args[0] = TMP . 'BakeTestApp';
  69. $this->Task->params['skel'] = CAKE . 'Console/Templates/skel';
  70. $this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y'));
  71. $this->Task->execute();
  72. $this->assertTrue(is_dir($this->Task->args[0]), 'No project dir');
  73. $File = new File($path . DS . 'Config/paths.php');
  74. $contents = $File->read();
  75. $this->assertRegExp('/define\(\'CAKE_CORE_INCLUDE_PATH\', .*?DS/', $contents);
  76. }
  77. /**
  78. * Copy the TestApp route file so it can be modified.
  79. *
  80. * @return void
  81. */
  82. protected function _cloneRoutes() {
  83. $File = new File(TEST_APP . 'TestApp/Config/routes.php');
  84. $contents = $File->read();
  85. mkdir(TMP . 'BakeTestApp/Config/', 0777, true);
  86. $File = new File(TMP . 'BakeTestApp/Config/routes.php');
  87. $File->write($contents);
  88. }
  89. /**
  90. * test getPrefix method, and that it returns Routing.prefix or writes to config file.
  91. *
  92. * @return void
  93. */
  94. public function testGetPrefix() {
  95. Configure::write('Routing.prefixes', array('admin'));
  96. $result = $this->Task->getPrefix();
  97. $this->assertEquals('admin_', $result);
  98. $this->_cloneRoutes();
  99. Configure::write('Routing.prefixes', null);
  100. $this->Task->appPath = TMP . 'BakeTestApp/';
  101. Configure::write('Routing.prefixes', null);
  102. $this->Task->expects($this->once())->method('in')->will($this->returnValue('super_duper_admin'));
  103. $result = $this->Task->getPrefix();
  104. $this->assertEquals('super_duper_admin_', $result);
  105. }
  106. /**
  107. * test cakeAdmin() writing routes.php
  108. *
  109. * @return void
  110. */
  111. public function testCakeAdmin() {
  112. $this->_cloneRoutes();
  113. Configure::write('Routing.prefixes', null);
  114. $this->Task->appPath = TMP . 'BakeTestApp/';
  115. $result = $this->Task->cakeAdmin('my_prefix');
  116. $this->assertTrue($result);
  117. $this->assertEquals(Configure::read('Routing.prefixes'), array('my_prefix'));
  118. }
  119. /**
  120. * test getting the prefix with more than one prefix setup
  121. *
  122. * @return void
  123. */
  124. public function testGetPrefixWithMultiplePrefixes() {
  125. Configure::write('Routing.prefixes', array('admin', 'ninja', 'shinobi'));
  126. $this->Task->appPath = $this->Task->path . 'BakeTestApp/';
  127. $this->Task->expects($this->once())->method('in')->will($this->returnValue(2));
  128. $result = $this->Task->getPrefix();
  129. $this->assertEquals('ninja_', $result);
  130. }
  131. }