TaskCollectionTest.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. /**
  3. * TaskCollectionTest file
  4. *
  5. * PHP 5
  6. *
  7. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  8. * Copyright 2005-2010, 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-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
  14. * @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
  15. * @package cake.tests.cases.libs
  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. function setup() {
  28. $shell = $this->getMock('Shell', array(), array(), '', false);
  29. $dispatcher = $this->getMock('ShellDispatcher', array(), array(), '', false);
  30. $this->Tasks = new TaskCollection($shell, $dispatcher);
  31. }
  32. /**
  33. * teardown
  34. *
  35. * @return void
  36. */
  37. function teardown() {
  38. unset($this->Tasks);
  39. }
  40. /**
  41. * test triggering callbacks on loaded tasks
  42. *
  43. * @return void
  44. */
  45. function testLoad() {
  46. $result = $this->Tasks->load('DbConfig');
  47. $this->assertInstanceOf('DbConfigTask', $result);
  48. $this->assertInstanceOf('DbConfigTask', $this->Tasks->DbConfig);
  49. $result = $this->Tasks->attached();
  50. $this->assertEquals(array('DbConfig'), $result, 'attached() results are wrong.');
  51. $this->assertTrue($this->Tasks->enabled('DbConfig'));
  52. }
  53. /**
  54. * test load and enable = false
  55. *
  56. * @return void
  57. */
  58. function testLoadWithEnableFalse() {
  59. $result = $this->Tasks->load('DbConfig', array('enabled' => false));
  60. $this->assertInstanceOf('DbConfigTask', $result);
  61. $this->assertInstanceOf('DbConfigTask', $this->Tasks->DbConfig);
  62. $this->assertFalse($this->Tasks->enabled('DbConfig'), 'DbConfigTask should be disabled');
  63. }
  64. /**
  65. * test missinghelper exception
  66. *
  67. * @expectedException MissingTaskClassException
  68. * @return void
  69. */
  70. function testLoadMissingTaskFile() {
  71. $result = $this->Tasks->load('ThisTaskShouldAlwaysBeMissing');
  72. }
  73. /**
  74. * test loading a plugin helper.
  75. *
  76. * @return void
  77. */
  78. function testLoadPluginTask() {
  79. $dispatcher = $this->getMock('ShellDispatcher', array(), array(), '', false);
  80. $shell = $this->getMock('Shell', array(), array(), '', false);
  81. App::build(array(
  82. 'plugins' => array(LIBS . 'tests' . DS . 'test_app' . DS . 'plugins' . DS)
  83. ));
  84. CakePlugin::load('TestPlugin');
  85. $this->Tasks = new TaskCollection($shell, $dispatcher);
  86. $result = $this->Tasks->load('TestPlugin.OtherTask');
  87. $this->assertInstanceOf('OtherTaskTask', $result, 'Task class is wrong.');
  88. $this->assertInstanceOf('OtherTaskTask', $this->Tasks->OtherTask, 'Class is wrong');
  89. CakePlugin::unload();
  90. }
  91. /**
  92. * test unload()
  93. *
  94. * @return void
  95. */
  96. function testUnload() {
  97. $this->Tasks->load('Extract');
  98. $this->Tasks->load('DbConfig');
  99. $result = $this->Tasks->attached();
  100. $this->assertEquals(array('Extract', 'DbConfig'), $result, 'loaded tasks is wrong');
  101. $this->Tasks->unload('DbConfig');
  102. $this->assertFalse(isset($this->Tasks->DbConfig));
  103. $this->assertTrue(isset($this->Tasks->Extract));
  104. $result = $this->Tasks->attached();
  105. $this->assertEquals(array('Extract'), $result, 'loaded tasks is wrong');
  106. }
  107. }