2010-07-07 03:30:24 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* TaskCollectionTest file
|
|
|
|
*
|
|
|
|
* PHP 5
|
|
|
|
*
|
|
|
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
2013-02-08 11:59:49 +00:00
|
|
|
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2010-07-07 03:30:24 +00:00
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
2013-02-08 12:22:51 +00:00
|
|
|
* For full copyright and license information, please see the LICENSE.txt
|
2010-07-07 03:30:24 +00:00
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
2013-02-08 11:59:49 +00:00
|
|
|
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2012-04-27 02:49:18 +00:00
|
|
|
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Console
|
2010-07-07 03:30:24 +00:00
|
|
|
* @since CakePHP(tm) v 2.0
|
2013-05-30 22:11:14 +00:00
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
2010-07-07 03:30:24 +00:00
|
|
|
*/
|
2010-10-03 05:53:42 +00:00
|
|
|
|
2010-12-09 03:45:18 +00:00
|
|
|
App::uses('TaskCollection', 'Console');
|
|
|
|
App::uses('Shell', 'Console');
|
2010-07-07 03:30:24 +00:00
|
|
|
|
2013-05-30 22:11:14 +00:00
|
|
|
/**
|
|
|
|
* Class TaskCollectionTest
|
|
|
|
*
|
|
|
|
* @package Cake.Test.Case.Console
|
|
|
|
*/
|
2010-07-07 03:30:24 +00:00
|
|
|
class TaskCollectionTest extends CakeTestCase {
|
2012-03-11 04:32:02 +00:00
|
|
|
|
2010-07-07 03:30:24 +00:00
|
|
|
/**
|
2011-12-04 21:27:51 +00:00
|
|
|
* setUp
|
2010-07-07 03:30:24 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-12-04 21:27:51 +00:00
|
|
|
public function setUp() {
|
|
|
|
parent::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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-12-04 21:27:51 +00:00
|
|
|
* tearDown
|
2010-07-07 03:30:24 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-12-04 21:27:51 +00:00
|
|
|
public function tearDown() {
|
2010-07-07 03:30:24 +00:00
|
|
|
unset($this->Tasks);
|
2011-12-04 21:27:51 +00:00
|
|
|
parent::tearDown();
|
2010-07-07 03:30:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test triggering callbacks on loaded tasks
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testLoad() {
|
2010-07-07 03:30:24 +00:00
|
|
|
$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
|
|
|
|
2012-11-16 11:14:28 +00:00
|
|
|
$result = $this->Tasks->loaded();
|
|
|
|
$this->assertEquals(array('DbConfig'), $result, 'loaded() results are wrong.');
|
2010-07-07 03:30:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test load and enable = false
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public 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');
|
|
|
|
}
|
2011-12-06 20:52:48 +00:00
|
|
|
|
2010-07-07 03:30:24 +00:00
|
|
|
/**
|
2011-10-15 18:06:31 +00:00
|
|
|
* test missingtask exception
|
2010-07-07 03:30:24 +00:00
|
|
|
*
|
2011-10-15 18:06:31 +00:00
|
|
|
* @expectedException MissingTaskException
|
2010-07-07 03:30:24 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-10-15 18:06:31 +00:00
|
|
|
public function testLoadMissingTask() {
|
2013-01-23 12:45:50 +00:00
|
|
|
$this->Tasks->load('ThisTaskShouldAlwaysBeMissing');
|
2010-07-07 03:30:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test loading a plugin helper.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public 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(
|
2011-11-13 21:48:52 +00:00
|
|
|
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
|
2010-10-17 19:58:44 +00:00
|
|
|
));
|
2011-05-12 04:58:39 +00:00
|
|
|
CakePlugin::load('TestPlugin');
|
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');
|
2011-05-12 04:58:39 +00:00
|
|
|
CakePlugin::unload();
|
2010-07-07 03:30:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test unload()
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testUnload() {
|
2010-07-07 03:30:24 +00:00
|
|
|
$this->Tasks->load('Extract');
|
2010-07-08 00:49:59 +00:00
|
|
|
$this->Tasks->load('DbConfig');
|
2010-07-07 03:30:24 +00:00
|
|
|
|
2012-11-16 11:14:28 +00:00
|
|
|
$result = $this->Tasks->loaded();
|
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));
|
|
|
|
|
2012-11-16 11:14:28 +00:00
|
|
|
$result = $this->Tasks->loaded();
|
2010-07-07 03:30:24 +00:00
|
|
|
$this->assertEquals(array('Extract'), $result, 'loaded tasks is wrong');
|
|
|
|
}
|
|
|
|
|
2011-04-17 10:35:21 +00:00
|
|
|
}
|