Skip to content
Snippets Groups Projects
Unverified Commit 5cdf79ea authored by Tobias Reischmann's avatar Tobias Reischmann Committed by GitHub
Browse files

Merge pull request #75 from learnweb/bug/copydisplaytitle

Copy the displaytitle upon duplicate
parents 0696e4f7 6530fff5
Branches
No related tags found
No related merge requests found
...@@ -353,14 +353,19 @@ class workflow_manager { ...@@ -353,14 +353,19 @@ class workflow_manager {
} }
/** /**
* Creates a workflow with a specific title. Is used to create preset workflows for trigger plugins. * Creates a workflow with a specific title. Is used to create preset workflows for trigger plugins or for
* duplication of workflows.
* *
* @param $title string title of the workflow. Usually the pluginname of the trigger. * @param $title string title of the workflow.
* @param $displaytitle string display title of the workflow.
* @return workflow the created workflow. * @return workflow the created workflow.
*/ */
public static function create_workflow($title) { public static function create_workflow($title, $displaytitle = null) {
$record = new \stdClass(); $record = new \stdClass();
$record->title = $title; $record->title = $title;
if (!is_null($displaytitle)) {
$record->displaytitle = $displaytitle;
}
$workflow = workflow::from_record($record); $workflow = workflow::from_record($record);
self::insert_or_update($workflow); self::insert_or_update($workflow);
return $workflow; return $workflow;
...@@ -379,7 +384,7 @@ class workflow_manager { ...@@ -379,7 +384,7 @@ class workflow_manager {
} catch (\coding_exception $e) { } catch (\coding_exception $e) {
$newtitle = $oldworkflow->title; $newtitle = $oldworkflow->title;
} }
$newworkflow = self::create_workflow($newtitle); $newworkflow = self::create_workflow($newtitle, $oldworkflow->displaytitle);
$newworkflow->rollbackdelay = $oldworkflow->rollbackdelay; $newworkflow->rollbackdelay = $oldworkflow->rollbackdelay;
$newworkflow->finishdelay = $oldworkflow->finishdelay; $newworkflow->finishdelay = $oldworkflow->finishdelay;
$newworkflow->delayforallworkflows = $oldworkflow->delayforallworkflows; $newworkflow->delayforallworkflows = $oldworkflow->delayforallworkflows;
......
...@@ -74,6 +74,7 @@ class tool_lifecycle_generator extends testing_module_generator { ...@@ -74,6 +74,7 @@ class tool_lifecycle_generator extends testing_module_generator {
$record = new stdClass(); $record = new stdClass();
$record->id = null; $record->id = null;
$record->title = 'myworkflow'; $record->title = 'myworkflow';
$record->displaytitle = 'random displaystring:' . random_string(10);
$workflow = workflow::from_record($record); $workflow = workflow::from_record($record);
workflow_manager::insert_or_update($workflow); workflow_manager::insert_or_update($workflow);
foreach ($stepnames as $subpluginname) { foreach ($stepnames as $subpluginname) {
......
...@@ -74,7 +74,31 @@ class tool_lifecycle_workflow_activate_disable_duplicate_testcase extends workfl ...@@ -74,7 +74,31 @@ class tool_lifecycle_workflow_activate_disable_duplicate_testcase extends workfl
* Test to deactivate the first workflow. * Test to deactivate the first workflow.
*/ */
public function test_deactivate_first() { public function test_deactivate_first() {
// TODO to be implemented. workflow_manager::handle_action(action::WORKFLOW_ABORTDISABLE, $this->workflow1->id);
$this->assertFalse(workflow_manager::is_active($this->workflow1->id));
}
/**
* Test to duplicate the first workflow.
*/
public function test_duplicate_first() {
workflow_manager::handle_action(action::WORKFLOW_DUPLICATE, $this->workflow1->id);
$workflows = workflow_manager::get_workflows();
$this->assertCount(4, $workflows);
// Retrieve the duplicated workflow.
$duplicate = null;
$existingworkflowids = [$this->workflow1->id, $this->workflow2->id, $this->workflow3->id];
foreach ($workflows as $workflow) {
if (!array_search($workflow->id, $existingworkflowids)) {
$duplicate = $workflow;
break;
}
}
$this->assertEquals($this->workflow1->displaytitle, $duplicate->displaytitle);
$workflow1stepcount = count(\tool_lifecycle\manager\step_manager::get_step_instances($this->workflow1->id));
$duplicatestepcount = count(\tool_lifecycle\manager\step_manager::get_step_instances($duplicate->id));
$this->assertEquals($workflow1stepcount, $duplicatestepcount);
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment