mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Allow abstract BuildTask subclasses (closes #4538)
This commit is contained in:
parent
445f1d4ccb
commit
df9eb77e2b
@ -100,7 +100,8 @@ class TaskRunner extends Controller {
|
||||
array_shift($taskClasses);
|
||||
|
||||
if($taskClasses) foreach($taskClasses as $class) {
|
||||
if(!singleton($class)->isEnabled()) continue;
|
||||
if (!$this->taskEnabled($class)) continue;
|
||||
|
||||
$desc = (Director::is_cli())
|
||||
? Convert::html2raw(singleton($class)->getDescription())
|
||||
: singleton($class)->getDescription();
|
||||
@ -116,6 +117,21 @@ class TaskRunner extends Controller {
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
55
tests/dev/TaskRunnerTest.php
Normal file
55
tests/dev/TaskRunnerTest.php
Normal 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
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user