ProjectTaskTest.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. $io = $this->getMock('Cake\Console\ConsoleIo', [], [], '', false);
  34. $this->Task = $this->getMock('Cake\Console\Command\Task\ProjectTask',
  35. array('in', 'err', 'createFile', '_stop'),
  36. array($io)
  37. );
  38. $this->Task->path = TMP;
  39. }
  40. /**
  41. * tearDown method
  42. *
  43. * @return void
  44. */
  45. public function tearDown() {
  46. parent::tearDown();
  47. $Folder = new Folder($this->Task->path . 'BakeTestApp');
  48. $Folder->delete();
  49. unset($this->Task);
  50. }
  51. /**
  52. * creates a test project that is used for testing project task.
  53. *
  54. * @return void
  55. */
  56. protected function _setupTestProject() {
  57. $this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y'));
  58. $this->Task->bake($this->Task->path . 'BakeTestApp');
  59. }
  60. /**
  61. * test bake with an absolute path.
  62. *
  63. * @return void
  64. */
  65. public function testExecuteWithAbsolutePath() {
  66. $this->markTestIncomplete('Need to figure this out');
  67. $this->Task->params['skel'] = CAKE . 'Console/Templates/skel';
  68. $this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y'));
  69. $this->Task->execute(TMP . 'BakeTestApp');
  70. $this->assertTrue(is_dir(TMP . 'BakeTestApp'), 'No project dir');
  71. $File = new File($path . DS . 'Config/paths.php');
  72. $contents = $File->read();
  73. $this->assertRegExp('/define\(\'CAKE_CORE_INCLUDE_PATH\', .*?DS/', $contents);
  74. }
  75. /**
  76. * Copy the TestApp route file so it can be modified.
  77. *
  78. * @return void
  79. */
  80. protected function _cloneRoutes() {
  81. $File = new File(TEST_APP . 'TestApp/Config/routes.php');
  82. $contents = $File->read();
  83. mkdir(TMP . 'BakeTestApp/Config/', 0777, true);
  84. $File = new File(TMP . 'BakeTestApp/Config/routes.php');
  85. $File->write($contents);
  86. }
  87. /**
  88. * test getPrefix method, and that it returns Routing.prefix or writes to config file.
  89. *
  90. * @return void
  91. */
  92. public function testGetPrefix() {
  93. Configure::write('Routing.prefixes', array('admin'));
  94. $result = $this->Task->getPrefix();
  95. $this->assertEquals('admin_', $result);
  96. $this->_cloneRoutes();
  97. Configure::write('Routing.prefixes', null);
  98. $this->Task->appPath = TMP . 'BakeTestApp/';
  99. Configure::write('Routing.prefixes', null);
  100. $this->Task->expects($this->once())->method('in')->will($this->returnValue('super_duper_admin'));
  101. $result = $this->Task->getPrefix();
  102. $this->assertEquals('super_duper_admin_', $result);
  103. }
  104. /**
  105. * test cakeAdmin() writing routes.php
  106. *
  107. * @return void
  108. */
  109. public function testCakeAdmin() {
  110. $this->_cloneRoutes();
  111. Configure::write('Routing.prefixes', null);
  112. $this->Task->appPath = TMP . 'BakeTestApp/';
  113. $result = $this->Task->cakeAdmin('my_prefix');
  114. $this->assertTrue($result);
  115. $this->assertEquals(Configure::read('Routing.prefixes'), array('my_prefix'));
  116. }
  117. /**
  118. * test getting the prefix with more than one prefix setup
  119. *
  120. * @return void
  121. */
  122. public function testGetPrefixWithMultiplePrefixes() {
  123. Configure::write('Routing.prefixes', array('admin', 'ninja', 'shinobi'));
  124. $this->Task->appPath = $this->Task->path . 'BakeTestApp/';
  125. $this->Task->expects($this->once())->method('in')->will($this->returnValue(2));
  126. $result = $this->Task->getPrefix();
  127. $this->assertEquals('ninja_', $result);
  128. }
  129. }