pictcode / lib / Cake / Test / Case / Console / TaskCollectionTest.php @ 48ae03cf
履歴 | 表示 | アノテート | ダウンロード (4.257 KB)
| 1 | 635eef61 | spyder1211 | <?php
|
|---|---|---|---|
| 2 | /**
|
||
| 3 | * TaskCollectionTest file
|
||
| 4 | *
|
||
| 5 | * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||
| 6 | * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||
| 7 | *
|
||
| 8 | * Licensed under The MIT License
|
||
| 9 | * For full copyright and license information, please see the LICENSE.txt
|
||
| 10 | * Redistributions of files must retain the above copyright notice.
|
||
| 11 | *
|
||
| 12 | * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||
| 13 | * @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
|
||
| 14 | * @package Cake.Test.Case.Console
|
||
| 15 | * @since CakePHP(tm) v 2.0
|
||
| 16 | * @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||
| 17 | */
|
||
| 18 | |||
| 19 | App::uses('TaskCollection', 'Console'); |
||
| 20 | App::uses('Shell', 'Console'); |
||
| 21 | |||
| 22 | /**
|
||
| 23 | * Extended Task
|
||
| 24 | */
|
||
| 25 | class DbConfigAliasedTask extends Shell { |
||
| 26 | } |
||
| 27 | |||
| 28 | /**
|
||
| 29 | * Class TaskCollectionTest
|
||
| 30 | *
|
||
| 31 | * @package Cake.Test.Case.Console
|
||
| 32 | */
|
||
| 33 | class TaskCollectionTest extends CakeTestCase { |
||
| 34 | |||
| 35 | /**
|
||
| 36 | * setUp
|
||
| 37 | *
|
||
| 38 | * @return void
|
||
| 39 | */
|
||
| 40 | public function setUp() { |
||
| 41 | parent::setUp();
|
||
| 42 | $shell = $this->getMock('Shell', array(), array(), '', false); |
||
| 43 | $dispatcher = $this->getMock('ShellDispatcher', array(), array(), '', false); |
||
| 44 | $this->Tasks = new TaskCollection($shell, $dispatcher); |
||
| 45 | } |
||
| 46 | |||
| 47 | /**
|
||
| 48 | * tearDown
|
||
| 49 | *
|
||
| 50 | * @return void
|
||
| 51 | */
|
||
| 52 | public function tearDown() { |
||
| 53 | unset($this->Tasks); |
||
| 54 | parent::tearDown();
|
||
| 55 | } |
||
| 56 | |||
| 57 | /**
|
||
| 58 | * test triggering callbacks on loaded tasks
|
||
| 59 | *
|
||
| 60 | * @return void
|
||
| 61 | */
|
||
| 62 | public function testLoad() { |
||
| 63 | $result = $this->Tasks->load('DbConfig'); |
||
| 64 | $this->assertInstanceOf('DbConfigTask', $result); |
||
| 65 | $this->assertInstanceOf('DbConfigTask', $this->Tasks->DbConfig); |
||
| 66 | |||
| 67 | $result = $this->Tasks->loaded(); |
||
| 68 | $this->assertEquals(array('DbConfig'), $result, 'loaded() results are wrong.'); |
||
| 69 | } |
||
| 70 | |||
| 71 | /**
|
||
| 72 | * test load and enable = false
|
||
| 73 | *
|
||
| 74 | * @return void
|
||
| 75 | */
|
||
| 76 | public function testLoadWithEnableFalse() { |
||
| 77 | $result = $this->Tasks->load('DbConfig', array('enabled' => false)); |
||
| 78 | $this->assertInstanceOf('DbConfigTask', $result); |
||
| 79 | $this->assertInstanceOf('DbConfigTask', $this->Tasks->DbConfig); |
||
| 80 | |||
| 81 | $this->assertFalse($this->Tasks->enabled('DbConfig'), 'DbConfigTask should be disabled'); |
||
| 82 | } |
||
| 83 | |||
| 84 | /**
|
||
| 85 | * test missingtask exception
|
||
| 86 | *
|
||
| 87 | * @expectedException MissingTaskException
|
||
| 88 | * @return void
|
||
| 89 | */
|
||
| 90 | public function testLoadMissingTask() { |
||
| 91 | $this->Tasks->load('ThisTaskShouldAlwaysBeMissing'); |
||
| 92 | } |
||
| 93 | |||
| 94 | /**
|
||
| 95 | * test loading a plugin helper.
|
||
| 96 | *
|
||
| 97 | * @return void
|
||
| 98 | */
|
||
| 99 | public function testLoadPluginTask() { |
||
| 100 | $dispatcher = $this->getMock('ShellDispatcher', array(), array(), '', false); |
||
| 101 | $shell = $this->getMock('Shell', array(), array(), '', false); |
||
| 102 | App::build(array( |
||
| 103 | 'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS) |
||
| 104 | )); |
||
| 105 | CakePlugin::load('TestPlugin'); |
||
| 106 | $this->Tasks = new TaskCollection($shell, $dispatcher); |
||
| 107 | |||
| 108 | $result = $this->Tasks->load('TestPlugin.OtherTask'); |
||
| 109 | $this->assertInstanceOf('OtherTaskTask', $result, 'Task class is wrong.'); |
||
| 110 | $this->assertInstanceOf('OtherTaskTask', $this->Tasks->OtherTask, 'Class is wrong'); |
||
| 111 | CakePlugin::unload();
|
||
| 112 | } |
||
| 113 | |||
| 114 | /**
|
||
| 115 | * test unload()
|
||
| 116 | *
|
||
| 117 | * @return void
|
||
| 118 | */
|
||
| 119 | public function testUnload() { |
||
| 120 | $this->Tasks->load('Extract'); |
||
| 121 | $this->Tasks->load('DbConfig'); |
||
| 122 | |||
| 123 | $result = $this->Tasks->loaded(); |
||
| 124 | $this->assertEquals(array('Extract', 'DbConfig'), $result, 'loaded tasks is wrong'); |
||
| 125 | |||
| 126 | $this->Tasks->unload('DbConfig'); |
||
| 127 | $this->assertFalse(isset($this->Tasks->DbConfig)); |
||
| 128 | $this->assertTrue(isset($this->Tasks->Extract)); |
||
| 129 | |||
| 130 | $result = $this->Tasks->loaded(); |
||
| 131 | $this->assertEquals(array('Extract'), $result, 'loaded tasks is wrong'); |
||
| 132 | } |
||
| 133 | |||
| 134 | /**
|
||
| 135 | * Tests loading as an alias
|
||
| 136 | *
|
||
| 137 | * @return void
|
||
| 138 | */
|
||
| 139 | public function testLoadWithAlias() { |
||
| 140 | $result = $this->Tasks->load('DbConfig', array('className' => 'DbConfigAliased')); |
||
| 141 | $this->assertInstanceOf('DbConfigAliasedTask', $result); |
||
| 142 | $this->assertInstanceOf('DbConfigAliasedTask', $this->Tasks->DbConfig); |
||
| 143 | |||
| 144 | $result = $this->Tasks->loaded(); |
||
| 145 | $this->assertEquals(array('DbConfig'), $result, 'loaded() results are wrong.'); |
||
| 146 | |||
| 147 | $result = $this->Tasks->load('SomeTask', array('className' => 'TestPlugin.OtherTask')); |
||
| 148 | $this->assertInstanceOf('OtherTaskTask', $result); |
||
| 149 | $this->assertInstanceOf('OtherTaskTask', $this->Tasks->SomeTask); |
||
| 150 | |||
| 151 | $result = $this->Tasks->loaded(); |
||
| 152 | $this->assertEquals(array('DbConfig', 'SomeTask'), $result, 'loaded() results are wrong.'); |
||
| 153 | } |
||
| 154 | |||
| 155 | } |