From a025cb2e016973a562f5b7bdc1e975460de34cf1 Mon Sep 17 00:00:00 2001 From: Ceeram Date: Wed, 13 Jul 2011 23:54:24 +0200 Subject: [PATCH] Adding option to ProjectTask, for setting CAKE_CORE_INCLUDE_PATH. Tests added. --- lib/Cake/Console/Command/Task/ProjectTask.php | 24 ++++++++----- .../Console/Command/Task/ProjectTaskTest.php | 35 ++++++++++++++++--- 2 files changed, 47 insertions(+), 12 deletions(-) diff --git a/lib/Cake/Console/Command/Task/ProjectTask.php b/lib/Cake/Console/Command/Task/ProjectTask.php index bd7afcd3e..4e705d843 100644 --- a/lib/Cake/Console/Command/Task/ProjectTask.php +++ b/lib/Cake/Console/Command/Task/ProjectTask.php @@ -91,14 +91,6 @@ class ProjectTask extends Shell { $success = false; } - if ($this->corePath($path) === true) { - $this->out(__d('cake_console', ' * CAKE_CORE_INCLUDE_PATH set to %s in webroot/index.php', CAKE_CORE_INCLUDE_PATH)); - $this->out(__d('cake_console', ' * CAKE_CORE_INCLUDE_PATH set to %s in webroot/test.php', CAKE_CORE_INCLUDE_PATH)); - $this->out(__d('cake_console', ' * Remember to check these value after moving to production server')); - } else { - $this->err(__d('cake_console', 'Unable to set CAKE_CORE_INCLUDE_PATH, you should change it in %s', $path . 'webroot' .DS .'index.php')); - $success = false; - } if ($this->consolePath($path) === true) { $this->out(__d('cake_console', ' * app/Console/cake.php path set.')); } else { @@ -106,6 +98,22 @@ class ProjectTask extends Shell { $success = false; } + $this->out(__d('cake_console', 'The value for CAKE_CORE_INCLUDE_PATH can be hardcoded set to %s in webroot/index.php', CAKE_CORE_INCLUDE_PATH)); + $this->out(__d('cake_console', 'If you hard code it, the project will possibly run only in your computer.')); + $setConstants = $this->in(__d('cake_console', 'Do you want to set CAKE_CORE_INCLUDE_PATH in webroot/index.php?'), array('y', 'n'), 'n'); + if (strtolower($setConstants) === 'y') { + if ($this->corePath($path) === true) { + $this->out(__d('cake_console', ' * CAKE_CORE_INCLUDE_PATH set to %s in webroot/index.php', CAKE_CORE_INCLUDE_PATH)); + $this->out(__d('cake_console', ' * CAKE_CORE_INCLUDE_PATH set to %s in webroot/test.php', CAKE_CORE_INCLUDE_PATH)); + $this->out(__d('cake_console', ' * Remember to check these values after moving to production server')); + } else { + $this->err(__d('cake_console', 'Unable to set CAKE_CORE_INCLUDE_PATH, you should change it in %s', $path . 'webroot' .DS .'index.php')); + $success = false; + } + } else { + $this->out(__d('cake_console', 'Please make sure your cake core is accessible, if you have problems edit CAKE_CORE_INCLUDE_PATH in webroot/index.php')); + } + $Folder = new Folder($path); if (!$Folder->chmod($path . 'tmp', 0777)) { $this->err(__d('cake_console', 'Could not set permissions on %s', $path . DS .'tmp')); diff --git a/lib/Cake/Test/Case/Console/Command/Task/ProjectTaskTest.php b/lib/Cake/Test/Case/Console/Command/Task/ProjectTaskTest.php index fc7714f2e..88afc92ca 100644 --- a/lib/Cake/Test/Case/Console/Command/Task/ProjectTaskTest.php +++ b/lib/Cake/Test/Case/Console/Command/Task/ProjectTaskTest.php @@ -115,12 +115,40 @@ class ProjectTaskTest extends CakeTestCase { * @return void */ public function testExecuteWithAbsolutePath() { - $this->Task->args[0] = TMP . 'tests' . DS . 'bake_test_app'; + $path = $this->Task->args[0] = TMP . 'tests' . DS . 'bake_test_app'; $this->Task->params['skel'] = CAKE . 'Console' . DS . 'Templates' . DS . 'skel'; $this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y')); + $this->Task->expects($this->at(3))->method('in')->will($this->returnValue('n')); $this->Task->execute(); $this->assertTrue(is_dir($this->Task->args[0]), 'No project dir'); + $file = new File($path . DS . 'webroot' . DS . 'index.php'); + $contents = $file->read(); + $this->assertPattern('/define\(\'CAKE_CORE_INCLUDE_PATH\', ROOT/', $contents); + $file = new File($path . DS . 'webroot' . DS . 'test.php'); + $contents = $file->read(); + $this->assertPattern('/define\(\'CAKE_CORE_INCLUDE_PATH\', ROOT/', $contents); + } + +/** + * test bake with setting CAKE_CORE_INCLUDE_PATH in webroot/index.php + * + * @return void + */ + public function testExecuteWithSettingIncludePath() { + $path = $this->Task->args[0] = TMP . 'tests' . DS . 'bake_test_app'; + $this->Task->params['skel'] = CAKE . 'Console' . DS . 'Templates' . DS . 'skel'; + $this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y')); + $this->Task->expects($this->at(3))->method('in')->will($this->returnValue('y')); + $this->Task->execute(); + + $this->assertTrue(is_dir($this->Task->args[0]), 'No project dir'); + $file = new File($path . DS . 'webroot' . DS . 'index.php'); + $contents = $file->read(); + $this->assertNoPattern('/define\(\'CAKE_CORE_INCLUDE_PATH\', ROOT/', $contents); + $file = new File($path . DS . 'webroot' . DS . 'test.php'); + $contents = $file->read(); + $this->assertNoPattern('/define\(\'CAKE_CORE_INCLUDE_PATH\', ROOT/', $contents); } /** @@ -199,11 +227,10 @@ class ProjectTaskTest extends CakeTestCase { $file = new File($path . 'webroot' . DS . 'index.php'); $contents = $file->read(); - $this->assertNoPattern('/define\(\'CAKE_CORE_INCLUDE_PATH\', \'ROOT/', $contents); - + $this->assertNoPattern('/define\(\'CAKE_CORE_INCLUDE_PATH\', ROOT/', $contents); $file = new File($path . 'webroot' . DS . 'test.php'); $contents = $file->read(); - $this->assertNoPattern('/define\(\'CAKE_CORE_INCLUDE_PATH\', \'ROOT/', $contents); + $this->assertNoPattern('/define\(\'CAKE_CORE_INCLUDE_PATH\', ROOT/', $contents); } /**