2010-07-07 03:30:24 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* TaskCollectionTest file
|
|
|
|
*
|
|
|
|
* PHP 5
|
|
|
|
*
|
|
|
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
|
|
|
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
|
|
|
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
|
|
|
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.tests.cases.libs
|
2010-07-07 03:30:24 +00:00
|
|
|
* @since CakePHP(tm) v 2.0
|
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
|
|
|
*/
|
2010-10-03 05:53:42 +00:00
|
|
|
|
2010-07-07 03:30:24 +00:00
|
|
|
App::import('Shell', 'TaskCollection', false);
|
|
|
|
App::import('Shell', 'Shell', false);
|
|
|
|
|
|
|
|
class TaskCollectionTest extends CakeTestCase {
|
|
|
|
/**
|
|
|
|
* setup
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function setup() {
|
2010-10-04 04:23:54 +00:00
|
|
|
$shell = $this->getMock('Shell', array(), array(), '', false);
|
2010-10-10 00:55:00 +00:00
|
|
|
$dispatcher = $this->getMock('ShellDispatcher', array(), array(), '', false);
|
|
|
|
$this->Tasks = new TaskCollection($shell, $dispatcher);
|
2010-07-07 03:30:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* teardown
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function teardown() {
|
|
|
|
unset($this->Tasks);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test triggering callbacks on loaded tasks
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testLoad() {
|
|
|
|
$result = $this->Tasks->load('DbConfig');
|
2010-12-24 17:54:04 +00:00
|
|
|
$this->assertInstanceOf('DbConfigTask', $result);
|
|
|
|
$this->assertInstanceOf('DbConfigTask', $this->Tasks->DbConfig);
|
2010-07-07 03:30:24 +00:00
|
|
|
|
|
|
|
$result = $this->Tasks->attached();
|
|
|
|
$this->assertEquals(array('DbConfig'), $result, 'attached() results are wrong.');
|
|
|
|
|
|
|
|
$this->assertTrue($this->Tasks->enabled('DbConfig'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test load and enable = false
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testLoadWithEnableFalse() {
|
2011-01-19 00:33:05 +00:00
|
|
|
$result = $this->Tasks->load('DbConfig', array('enabled' => false));
|
2010-12-24 17:54:04 +00:00
|
|
|
$this->assertInstanceOf('DbConfigTask', $result);
|
|
|
|
$this->assertInstanceOf('DbConfigTask', $this->Tasks->DbConfig);
|
2010-07-07 03:30:24 +00:00
|
|
|
|
|
|
|
$this->assertFalse($this->Tasks->enabled('DbConfig'), 'DbConfigTask should be disabled');
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* test missinghelper exception
|
|
|
|
*
|
|
|
|
* @expectedException MissingTaskFileException
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testLoadMissingTaskFile() {
|
|
|
|
$result = $this->Tasks->load('ThisTaskShouldAlwaysBeMissing');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test loading a plugin helper.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testLoadPluginTask() {
|
2010-10-10 00:55:00 +00:00
|
|
|
$dispatcher = $this->getMock('ShellDispatcher', array(), array(), '', false);
|
2010-10-04 04:23:54 +00:00
|
|
|
$shell = $this->getMock('Shell', array(), array(), '', false);
|
2010-10-17 19:58:44 +00:00
|
|
|
App::build(array(
|
|
|
|
'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS)
|
|
|
|
));
|
2010-10-10 00:55:00 +00:00
|
|
|
$this->Tasks = new TaskCollection($shell, $dispatcher);
|
2010-07-08 00:49:59 +00:00
|
|
|
|
2010-07-07 03:30:24 +00:00
|
|
|
$result = $this->Tasks->load('TestPlugin.OtherTask');
|
2010-12-24 17:54:04 +00:00
|
|
|
$this->assertInstanceOf('OtherTaskTask', $result, 'Task class is wrong.');
|
|
|
|
$this->assertInstanceOf('OtherTaskTask', $this->Tasks->OtherTask, 'Class is wrong');
|
2010-07-07 03:30:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test unload()
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testUnload() {
|
|
|
|
$this->Tasks->load('Extract');
|
2010-07-08 00:49:59 +00:00
|
|
|
$this->Tasks->load('DbConfig');
|
2010-07-07 03:30:24 +00:00
|
|
|
|
|
|
|
$result = $this->Tasks->attached();
|
2010-07-08 00:49:59 +00:00
|
|
|
$this->assertEquals(array('Extract', 'DbConfig'), $result, 'loaded tasks is wrong');
|
2010-07-07 03:30:24 +00:00
|
|
|
|
2010-07-08 00:49:59 +00:00
|
|
|
$this->Tasks->unload('DbConfig');
|
|
|
|
$this->assertFalse(isset($this->Tasks->DbConfig));
|
2010-07-07 03:30:24 +00:00
|
|
|
$this->assertTrue(isset($this->Tasks->Extract));
|
|
|
|
|
|
|
|
$result = $this->Tasks->attached();
|
|
|
|
$this->assertEquals(array('Extract'), $result, 'loaded tasks is wrong');
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|