2010-07-07 03:30:24 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* TaskCollectionTest file
|
|
|
|
*
|
2017-06-10 21:33:55 +00:00
|
|
|
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
|
2017-06-10 22:10:52 +00:00
|
|
|
* Copyright (c) Cake Software Foundation, Inc. (https://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.
|
|
|
|
*
|
2017-06-10 22:10:52 +00:00
|
|
|
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
|
2017-06-10 22:15:34 +00:00
|
|
|
* @link https://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
|
2017-06-10 22:23:14 +00:00
|
|
|
* @license https://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');
|
2013-11-18 10:56:00 +00:00
|
|
|
|
2013-05-03 05:07:33 +00:00
|
|
|
/**
|
|
|
|
* Extended Task
|
|
|
|
*/
|
|
|
|
class DbConfigAliasedTask extends Shell {
|
|
|
|
}
|
2010-07-07 03:30:24 +00:00
|
|
|
|
2013-05-30 22:11:14 +00:00
|
|
|
/**
|
2016-08-10 10:22:09 +00:00
|
|
|
* TaskCollectionTest
|
2013-05-30 22:11:14 +00:00
|
|
|
*
|
|
|
|
* @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
|
|
|
|
*/
|
2022-12-28 07:03:39 +00:00
|
|
|
public function setUp() : void {
|
2011-12-04 21:27:51 +00:00
|
|
|
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
|
|
|
|
*/
|
2022-12-28 07:03:39 +00:00
|
|
|
public function tearDown() : void {
|
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
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-10-15 18:06:31 +00:00
|
|
|
public function testLoadMissingTask() {
|
2022-12-31 04:13:42 +00:00
|
|
|
$this->expectException(MissingTaskException::class);
|
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');
|
|
|
|
}
|
|
|
|
|
2013-05-03 05:07:33 +00:00
|
|
|
/**
|
|
|
|
* Tests loading as an alias
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testLoadWithAlias() {
|
|
|
|
$result = $this->Tasks->load('DbConfig', array('className' => 'DbConfigAliased'));
|
|
|
|
$this->assertInstanceOf('DbConfigAliasedTask', $result);
|
|
|
|
$this->assertInstanceOf('DbConfigAliasedTask', $this->Tasks->DbConfig);
|
|
|
|
|
|
|
|
$result = $this->Tasks->loaded();
|
|
|
|
$this->assertEquals(array('DbConfig'), $result, 'loaded() results are wrong.');
|
|
|
|
|
|
|
|
$result = $this->Tasks->load('SomeTask', array('className' => 'TestPlugin.OtherTask'));
|
|
|
|
$this->assertInstanceOf('OtherTaskTask', $result);
|
|
|
|
$this->assertInstanceOf('OtherTaskTask', $this->Tasks->SomeTask);
|
|
|
|
|
|
|
|
$result = $this->Tasks->loaded();
|
|
|
|
$this->assertEquals(array('DbConfig', 'SomeTask'), $result, 'loaded() results are wrong.');
|
|
|
|
}
|
|
|
|
|
2011-04-17 10:35:21 +00:00
|
|
|
}
|