Skip to content

Commit

Permalink
Pointing test directory creation to TMP/tests/
Browse files Browse the repository at this point in the history
Adding tests for ProjectTask::bake()
  • Loading branch information
markstory committed Jun 17, 2009
1 parent bf7fcdf commit 8c2a027
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 21 deletions.
17 changes: 6 additions & 11 deletions cake/console/libs/tasks/project.php
Original file line number Original file line Diff line number Diff line change
@@ -1,27 +1,22 @@
<?php <?php
/* SVN FILE: $Id$ */
/** /**
* The Project Task handles creating the base application * The Project Task handles creating the base application
* *
* Long description for file
* *
* PHP versions 4 and 5 * PHP versions 4 and 5
* *
* CakePHP(tm) : Rapid Development Framework (http://www.cakephp.org) * CakePHP(tm) : Rapid Development Framework (http://www.cakephp.org)
* Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org) * Copyright 2005-2009, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
* *
* Licensed under The MIT License * Licensed under The MIT License
* Redistributions of files must retain the above copyright notice. * Redistributions of files must retain the above copyright notice.
* *
* @filesource * @filesource
* @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org) * @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project * @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
* @package cake * @package cake
* @subpackage cake.cake.scripts.bake * @subpackage cake.cake.console.bake
* @since CakePHP(tm) v 1.2 * @since CakePHP(tm) v 1.2
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License * @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/ */


Expand Down Expand Up @@ -142,7 +137,7 @@ function bake($path, $skel = null, $skip = array('empty')) {


$looksGood = $this->in('Look okay?', array('y', 'n', 'q'), 'y'); $looksGood = $this->in('Look okay?', array('y', 'n', 'q'), 'y');


if (low($looksGood) == 'y') { if (strtolower($looksGood) == 'y') {
$verbose = $this->in(__('Do you want verbose output?', true), array('y', 'n'), 'n'); $verbose = $this->in(__('Do you want verbose output?', true), array('y', 'n'), 'n');


$Folder = new Folder($skel); $Folder = new Folder($skel);
Expand All @@ -155,14 +150,14 @@ function bake($path, $skel = null, $skip = array('empty')) {
return false; return false;
} }


if (low($verbose) == 'y') { if (strtolower($verbose) == 'y') {
foreach ($Folder->messages() as $message) { foreach ($Folder->messages() as $message) {
$this->out($message); $this->out($message);
} }
} }


return true; return true;
} elseif (low($looksGood) == 'q') { } elseif (strtolower($looksGood) == 'q') {
$this->out('Bake Aborted.'); $this->out('Bake Aborted.');
} else { } else {
$this->execute(false); $this->execute(false);
Expand Down
14 changes: 7 additions & 7 deletions cake/tests/cases/console/libs/tasks/plugin.test.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function startTest() {
$this->Dispatcher->shellPaths = Configure::read('shellPaths'); $this->Dispatcher->shellPaths = Configure::read('shellPaths');
$this->Task =& new MockPluginTask($this->Dispatcher); $this->Task =& new MockPluginTask($this->Dispatcher);
$this->Task->Dispatch =& $this->Dispatcher; $this->Task->Dispatch =& $this->Dispatcher;
$this->Task->path = TMP; $this->Task->path = TMP . 'tests' . DS;
} }


/** /**
Expand All @@ -79,7 +79,7 @@ function startTest() {
**/ **/
function startCase() { function startCase() {
$this->_paths = $paths = Configure::read('pluginPaths'); $this->_paths = $paths = Configure::read('pluginPaths');
$this->_testPath = array_push($paths, TMP); $this->_testPath = array_push($paths, TMP . 'tests' . DS);
Configure::write('pluginPaths', $paths); Configure::write('pluginPaths', $paths);
} }


Expand Down Expand Up @@ -112,7 +112,7 @@ function testBakeFoldersAndFiles() {
$this->Task->setReturnValueAt(1, 'in', 'y'); $this->Task->setReturnValueAt(1, 'in', 'y');
$this->Task->bake('BakeTestPlugin'); $this->Task->bake('BakeTestPlugin');


$path = TMP . 'bake_test_plugin'; $path = $this->Task->path . 'bake_test_plugin';
$this->assertTrue(is_dir($path), 'No plugin dir %s'); $this->assertTrue(is_dir($path), 'No plugin dir %s');
$this->assertTrue(is_dir($path . DS . 'controllers'), 'No controllers dir %s'); $this->assertTrue(is_dir($path . DS . 'controllers'), 'No controllers dir %s');
$this->assertTrue(is_dir($path . DS . 'controllers' . DS .'components'), 'No components dir %s'); $this->assertTrue(is_dir($path . DS . 'controllers' . DS .'components'), 'No components dir %s');
Expand All @@ -130,7 +130,7 @@ function testBakeFoldersAndFiles() {
$file = $path . DS . 'bake_test_plugin_app_model.php'; $file = $path . DS . 'bake_test_plugin_app_model.php';
$this->Task->expectAt(1, 'createFile', array($file, '*'), 'No AppModel %s'); $this->Task->expectAt(1, 'createFile', array($file, '*'), 'No AppModel %s');


$Folder =& new Folder(TMP . 'bake_test_plugin'); $Folder =& new Folder($this->Task->path . 'bake_test_plugin');
$Folder->delete(); $Folder->delete();
} }


Expand All @@ -145,15 +145,15 @@ function testExecuteWithOneArg() {
$this->Task->Dispatch->args = array('BakeTestPlugin'); $this->Task->Dispatch->args = array('BakeTestPlugin');
$this->Task->args =& $this->Task->Dispatch->args; $this->Task->args =& $this->Task->Dispatch->args;


$path = TMP . 'bake_test_plugin'; $path = $this->Task->path . 'bake_test_plugin';
$file = $path . DS . 'bake_test_plugin_app_controller.php'; $file = $path . DS . 'bake_test_plugin_app_controller.php';
$this->Task->expectAt(0, 'createFile', array($file, '*'), 'No AppController %s'); $this->Task->expectAt(0, 'createFile', array($file, '*'), 'No AppController %s');


$file = $path . DS . 'bake_test_plugin_app_model.php'; $file = $path . DS . 'bake_test_plugin_app_model.php';
$this->Task->expectAt(1, 'createFile', array($file, '*'), 'No AppModel %s'); $this->Task->expectAt(1, 'createFile', array($file, '*'), 'No AppModel %s');


$this->Task->execute(); $this->Task->execute();
$Folder =& new Folder(TMP . 'bake_test_plugin'); $Folder =& new Folder($this->Task->path . 'bake_test_plugin');
$Folder->delete(); $Folder->delete();
} }


Expand All @@ -167,7 +167,7 @@ function testExecuteWithTwoArgs() {
$this->Task->setReturnValueAt(0, 'in', $this->_testPath); $this->Task->setReturnValueAt(0, 'in', $this->_testPath);
$this->Task->setReturnValueAt(1, 'in', 'y'); $this->Task->setReturnValueAt(1, 'in', 'y');


$Folder =& new Folder(TMP . 'bake_test_plugin', true); $Folder =& new Folder($this->Task->path . 'bake_test_plugin', true);


$this->Task->Dispatch->args = array('BakeTestPlugin', 'model'); $this->Task->Dispatch->args = array('BakeTestPlugin', 'model');
$this->Task->args =& $this->Task->Dispatch->args; $this->Task->args =& $this->Task->Dispatch->args;
Expand Down
31 changes: 28 additions & 3 deletions cake/tests/cases/console/libs/tasks/project.test.php
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php <?php
/* SVN FILE: $Id$ */
/** /**
* ProjectTask Test file * ProjectTask Test file
* *
Expand Down Expand Up @@ -34,7 +33,7 @@
ob_end_clean(); ob_end_clean();
} }


if (!class_exists('PluginTask')) { if (!class_exists('ProjectTask')) {
require CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'project.php'; require CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'project.php';
} }


Expand Down Expand Up @@ -66,7 +65,7 @@ function startTest() {
$this->Dispatcher->shellPaths = Configure::read('shellPaths'); $this->Dispatcher->shellPaths = Configure::read('shellPaths');
$this->Task =& new MockProjectTask($this->Dispatcher); $this->Task =& new MockProjectTask($this->Dispatcher);
$this->Task->Dispatch =& $this->Dispatcher; $this->Task->Dispatch =& $this->Dispatcher;
$this->Task->path = TMP; $this->Task->path = TMP . 'tests' . DS;
} }


/** /**
Expand All @@ -79,6 +78,32 @@ function endTest() {
ClassRegistry::flush(); ClassRegistry::flush();
} }


/**
* test bake() method and directory creation.
*
* @return void
**/
function testBake() {
$skel = CAKE_CORE_INCLUDE_PATH . DS . CONSOLE_LIBS . 'templates' . DS . 'skel';
$this->Task->setReturnValueAt(0, 'in', 'y');
$this->Task->setReturnValueAt(1, 'in', 'n');
$this->Task->bake($this->Task->path . 'bake_test_app', $skel);

$path = $this->Task->path . 'bake_test_app';
$this->assertTrue(is_dir($path), 'No project dir %s');
$this->assertTrue(is_dir($path . DS . 'controllers'), 'No controllers dir %s');
$this->assertTrue(is_dir($path . DS . 'controllers' . DS .'components'), 'No components dir %s');
$this->assertTrue(is_dir($path . DS . 'models'), 'No models dir %s');
$this->assertTrue(is_dir($path . DS . 'views'), 'No views dir %s');
$this->assertTrue(is_dir($path . DS . 'views' . DS . 'helpers'), 'No helpers dir %s');
$this->assertTrue(is_dir($path . DS . 'tests'), 'No tests dir %s');
$this->assertTrue(is_dir($path . DS . 'tests' . DS . 'cases'), 'No cases dir %s');
$this->assertTrue(is_dir($path . DS . 'tests' . DS . 'groups'), 'No groups dir %s');
$this->assertTrue(is_dir($path . DS . 'tests' . DS . 'fixtures'), 'No fixtures dir %s');

$Folder =& new Folder($this->Task->path . 'bake_test_app');
$Folder->delete();
}


} }
?> ?>

0 comments on commit 8c2a027

Please sign in to comment.