Skip to content

Commit

Permalink
Updating ProjectTask test case to PHPUnit.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Jun 10, 2010
1 parent bd80135 commit aa8d909
Showing 1 changed file with 37 additions and 39 deletions.
76 changes: 37 additions & 39 deletions cake/tests/cases/console/libs/tasks/project.test.php
Expand Up @@ -20,6 +20,8 @@
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::import('Shell', 'Shell', false);
App::import('Core', 'File');


if (!defined('DISABLE_AUTO_DISPATCH')) {
define('DISABLE_AUTO_DISPATCH', true);
Expand All @@ -34,15 +36,6 @@

require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'project.php';

Mock::generatePartial(
'ShellDispatcher', 'TestProjectTaskMockShellDispatcher',
array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment')
);
Mock::generatePartial(
'ProjectTask', 'MockProjectTask',
array('in', '_stop', 'err', 'out', 'createFile')
);

/**
* ProjectTask Test class
*
Expand All @@ -57,10 +50,14 @@ class ProjectTaskTest extends CakeTestCase {
* @return void
*/
public function startTest() {
$this->Dispatcher =& new TestProjectTaskMockShellDispatcher();
$this->Dispatcher = $this->getMock('ShellDispatcher', array(
'getInput', 'stdout', 'stderr', '_stop', '_initEnvironment'
));
$this->Task = $this->getMock('ProjectTask',
array('in', 'err', 'createFile', '_stop'),
array(&$this->Dispatcher)
);
$this->Dispatcher->shellPaths = App::path('shells');
$this->Task =& new MockProjectTask($this->Dispatcher);
$this->Task->Dispatch =& $this->Dispatcher;
$this->Task->path = TMP . 'tests' . DS;
}

Expand All @@ -72,8 +69,9 @@ public function startTest() {
public function endTest() {
ClassRegistry::flush();

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

/**
Expand All @@ -83,8 +81,8 @@ public function endTest() {
*/
protected function _setupTestProject() {
$skel = CAKE_CORE_INCLUDE_PATH . DS . CAKE . 'console' . DS . 'templates' . DS . 'skel';
$this->Task->setReturnValueAt(0, 'in', 'y');
$this->Task->setReturnValueAt(1, 'in', 'n');
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y'));
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue('n'));
$this->Task->bake($this->Task->path . 'bake_test_app', $skel);
}

Expand Down Expand Up @@ -162,27 +160,27 @@ public function testSecuritySaltGeneration() {
$result = $this->Task->securitySalt($path);
$this->assertTrue($result);

$file =& new File($path . 'config' . DS . 'core.php');
$file = new File($path . 'config' . DS . 'core.php');
$contents = $file->read();
$this->assertNoPattern('/DYhG93b0qyJfIxfs2guVoUubWwvniR2G0FgaC9mi/', $contents, 'Default Salt left behind. %s');
}

/**
* test generation of Security.cipherSeed
*
* @return void
*/
public function testSecurityCipherSeedGeneration() {
$this->_setupTestProject();
/**
* test generation of Security.cipherSeed
*
* @return void
*/
public function testSecurityCipherSeedGeneration() {
$this->_setupTestProject();

$path = $this->Task->path . 'bake_test_app' . DS;
$result = $this->Task->securityCipherSeed($path);
$this->assertTrue($result);
$path = $this->Task->path . 'bake_test_app' . DS;
$result = $this->Task->securityCipherSeed($path);
$this->assertTrue($result);

$file =& new File($path . 'config' . DS . 'core.php');
$contents = $file->read();
$this->assertNoPattern('/76859309657453542496749683645/', $contents, 'Default CipherSeed left behind. %s');
}
$file = new File($path . 'config' . DS . 'core.php');
$contents = $file->read();
$this->assertNoPattern('/76859309657453542496749683645/', $contents, 'Default CipherSeed left behind. %s');
}

/**
* Test that index.php is generated correctly.
Expand All @@ -195,11 +193,11 @@ public function testIndexPhpGeneration() {
$path = $this->Task->path . 'bake_test_app' . DS;
$this->Task->corePath($path);

$file =& new File($path . 'webroot' . DS . 'index.php');
$file = new File($path . 'webroot' . DS . 'index.php');
$contents = $file->read();
$this->assertNoPattern('/define\(\'CAKE_CORE_INCLUDE_PATH\', \'ROOT/', $contents);

$file =& new File($path . 'webroot' . DS . 'test.php');
$file = new File($path . 'webroot' . DS . 'test.php');
$contents = $file->read();
$this->assertNoPattern('/define\(\'CAKE_CORE_INCLUDE_PATH\', \'ROOT/', $contents);
}
Expand All @@ -217,12 +215,12 @@ public function testGetPrefix() {
Configure::write('Routing.prefixes', null);
$this->_setupTestProject();
$this->Task->configPath = $this->Task->path . 'bake_test_app' . DS . 'config' . DS;
$this->Task->setReturnValue('in', 'super_duper_admin');
$this->Task->expects($this->once())->method('in')->will($this->returnValue('super_duper_admin'));

$result = $this->Task->getPrefix();
$this->assertEqual($result, 'super_duper_admin_');

$file =& new File($this->Task->configPath . 'core.php');
$file = new File($this->Task->configPath . 'core.php');
$file->delete();
}

Expand All @@ -232,9 +230,9 @@ public function testGetPrefix() {
* @return void
*/
public function testCakeAdmin() {
$file =& new File(CONFIGS . 'core.php');
$file = new File(CONFIGS . 'core.php');
$contents = $file->read();;
$file =& new File(TMP . 'tests' . DS . 'core.php');
$file = new File(TMP . 'tests' . DS . 'core.php');
$file->write($contents);

Configure::write('Routing.prefixes', null);
Expand All @@ -255,7 +253,7 @@ public function testGetPrefixWithMultiplePrefixes() {
Configure::write('Routing.prefixes', array('admin', 'ninja', 'shinobi'));
$this->_setupTestProject();
$this->Task->configPath = $this->Task->path . 'bake_test_app' . DS . 'config' . DS;
$this->Task->setReturnValue('in', 2);
$this->Task->expects($this->once())->method('in')->will($this->returnValue(2));

$result = $this->Task->getPrefix();
$this->assertEqual($result, 'ninja_');
Expand All @@ -271,8 +269,8 @@ public function testExecute() {
$this->Task->params['working'] = TMP . 'tests' . DS;

$path = $this->Task->path . 'bake_test_app';
$this->Task->setReturnValue('in', 'y');
$this->Task->setReturnValueAt(0, 'in', $path);
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue($path));
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue('y'));

$this->Task->execute();
$this->assertTrue(is_dir($path), 'No project dir %s');
Expand Down

0 comments on commit aa8d909

Please sign in to comment.