TaskCollectionTest.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. /**
  3. * TaskCollectionTest file
  4. *
  5. * PHP 5
  6. *
  7. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  8. * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
  9. *
  10. * Licensed under The MIT License
  11. * Redistributions of files must retain the above copyright notice.
  12. *
  13. * @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
  14. * @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
  15. * @package Cake.Test.Case.Console
  16. * @since CakePHP(tm) v 2.0
  17. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  18. */
  19. App::uses('TaskCollection', 'Console');
  20. App::uses('Shell', 'Console');
  21. class TaskCollectionTest extends CakeTestCase {
  22. /**
  23. * setUp
  24. *
  25. * @return void
  26. */
  27. public function setUp() {
  28. parent::setUp();
  29. $shell = $this->getMock('Shell', array(), array(), '', false);
  30. $dispatcher = $this->getMock('ShellDispatcher', array(), array(), '', false);
  31. $this->Tasks = new TaskCollection($shell, $dispatcher);
  32. }
  33. /**
  34. * tearDown
  35. *
  36. * @return void
  37. */
  38. public function tearDown() {
  39. unset($this->Tasks);
  40. parent::tearDown();
  41. }
  42. /**
  43. * test triggering callbacks on loaded tasks
  44. *
  45. * @return void
  46. */
  47. public function testLoad() {
  48. $result = $this->Tasks->load('DbConfig');
  49. $this->assertInstanceOf('DbConfigTask', $result);
  50. $this->assertInstanceOf('DbConfigTask', $this->Tasks->DbConfig);
  51. $result = $this->Tasks->loaded();
  52. $this->assertEquals(array('DbConfig'), $result, 'loaded() results are wrong.');
  53. }
  54. /**
  55. * test load and enable = false
  56. *
  57. * @return void
  58. */
  59. public function testLoadWithEnableFalse() {
  60. $result = $this->Tasks->load('DbConfig', array('enabled' => false));
  61. $this->assertInstanceOf('DbConfigTask', $result);
  62. $this->assertInstanceOf('DbConfigTask', $this->Tasks->DbConfig);
  63. $this->assertFalse($this->Tasks->enabled('DbConfig'), 'DbConfigTask should be disabled');
  64. }
  65. /**
  66. * test missingtask exception
  67. *
  68. * @expectedException MissingTaskException
  69. * @return void
  70. */
  71. public function testLoadMissingTask() {
  72. $this->Tasks->load('ThisTaskShouldAlwaysBeMissing');
  73. }
  74. /**
  75. * test loading a plugin helper.
  76. *
  77. * @return void
  78. */
  79. public function testLoadPluginTask() {
  80. $dispatcher = $this->getMock('ShellDispatcher', array(), array(), '', false);
  81. $shell = $this->getMock('Shell', array(), array(), '', false);
  82. App::build(array(
  83. 'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
  84. ));
  85. CakePlugin::load('TestPlugin');
  86. $this->Tasks = new TaskCollection($shell, $dispatcher);
  87. $result = $this->Tasks->load('TestPlugin.OtherTask');
  88. $this->assertInstanceOf('OtherTaskTask', $result, 'Task class is wrong.');
  89. $this->assertInstanceOf('OtherTaskTask', $this->Tasks->OtherTask, 'Class is wrong');
  90. CakePlugin::unload();
  91. }
  92. /**
  93. * test unload()
  94. *
  95. * @return void
  96. */
  97. public function testUnload() {
  98. $this->Tasks->load('Extract');
  99. $this->Tasks->load('DbConfig');
  100. $result = $this->Tasks->loaded();
  101. $this->assertEquals(array('Extract', 'DbConfig'), $result, 'loaded tasks is wrong');
  102. $this->Tasks->unload('DbConfig');
  103. $this->assertFalse(isset($this->Tasks->DbConfig));
  104. $this->assertTrue(isset($this->Tasks->Extract));
  105. $result = $this->Tasks->loaded();
  106. $this->assertEquals(array('Extract'), $result, 'loaded tasks is wrong');
  107. }
  108. }