Allow abstract BuildTask subclasses (closes #4538)

This commit is contained in:
Loz Calver 2015-08-25 10:14:15 +01:00
parent 445f1d4ccb
commit df9eb77e2b
2 changed files with 72 additions and 1 deletions

View File

@ -100,7 +100,8 @@ class TaskRunner extends Controller {
array_shift($taskClasses); array_shift($taskClasses);
if($taskClasses) foreach($taskClasses as $class) { if($taskClasses) foreach($taskClasses as $class) {
if(!singleton($class)->isEnabled()) continue; if (!$this->taskEnabled($class)) continue;
$desc = (Director::is_cli()) $desc = (Director::is_cli())
? Convert::html2raw(singleton($class)->getDescription()) ? Convert::html2raw(singleton($class)->getDescription())
: singleton($class)->getDescription(); : singleton($class)->getDescription();
@ -116,6 +117,21 @@ class TaskRunner extends Controller {
return $availableTasks; return $availableTasks;
} }
/**
* @param string $class
* @return boolean
*/
protected function taskEnabled($class) {
$reflectionClass = new ReflectionClass($class);
if ($reflectionClass->isAbstract()) {
return false;
} else if (!singleton($class)->isEnabled()) {
return false;
}
return true;
}
} }

View File

@ -0,0 +1,55 @@
<?php
/**
* @package framework
* @subpackage tests
*/
class TaskRunnerTest extends SapphireTest {
public function testTaskEnabled() {
$runner = new TaskRunner();
$method = new ReflectionMethod($runner, 'taskEnabled');
$method->setAccessible(true);
$this->assertTrue($method->invoke($runner, 'TaskRunnerTest_EnabledTask'),
'Enabled task incorrectly marked as disabled');
$this->assertFalse($method->invoke($runner, 'TaskRunnerTest_DisabledTask'),
'Disabled task incorrectly marked as enabled');
$this->assertFalse($method->invoke($runner, 'TaskRunnerTest_AbstractTask'),
'Disabled task incorrectly marked as enabled');
$this->assertTrue($method->invoke($runner, 'TaskRunnerTest_ChildOfAbstractTask'),
'Enabled task incorrectly marked as disabled');
}
}
class TaskRunnerTest_EnabledTask extends BuildTask {
protected $enabled = true;
public function run($request) {
// NOOP
}
}
class TaskRunnerTest_DisabledTask extends BuildTask {
protected $enabled = false;
public function run($request) {
// NOOP
}
}
abstract class TaskRunnerTest_AbstractTask extends BuildTask {
protected $enabled = true;
public function run($request) {
// NOOP
}
}
class TaskRunnerTest_ChildOfAbstractTask extends TaskRunnerTest_AbstractTask {
protected $enabled = true;
public function run($request) {
// NOOP
}
}