From 8e08f2d0435386f1139a047bf89f635d30ce14c4 Mon Sep 17 00:00:00 2001 From: Nina Herrmann Date: Fri, 7 Jul 2023 12:19:58 +0200 Subject: [PATCH] fix upload workflow (#185) * fix upload workflow * inserting feedback * finally --- .../local/backup/restore_lifecycle_workflow.php | 2 +- classes/local/manager/workflow_manager.php | 1 + tests/behat/manual_trigger.feature | 2 +- tests/behat/upload_workflow.feature | 11 +++++++++++ tests/fixtures/simpleworkflow.xml | 15 +++++++++++++++ uploadworkflow.php | 10 +++------- 6 files changed, 32 insertions(+), 9 deletions(-) create mode 100644 tests/behat/upload_workflow.feature create mode 100644 tests/fixtures/simpleworkflow.xml diff --git a/classes/local/backup/restore_lifecycle_workflow.php b/classes/local/backup/restore_lifecycle_workflow.php index 1cb3ff1c..4fdf1640 100644 --- a/classes/local/backup/restore_lifecycle_workflow.php +++ b/classes/local/backup/restore_lifecycle_workflow.php @@ -59,7 +59,6 @@ class restore_lifecycle_workflow { public function __construct($xmldata) { $this->reader = new \XMLReader(); $this->reader->XML($xmldata); - } /** @@ -102,6 +101,7 @@ private function load_workflow() { $this->workflow->timeactive = null; $this->workflow->timedeactive = null; $this->workflow->sortindex = null; + workflow_manager::insert_or_update($this->workflow); } /** diff --git a/classes/local/manager/workflow_manager.php b/classes/local/manager/workflow_manager.php index 9a107aa1..13d5cae6 100644 --- a/classes/local/manager/workflow_manager.php +++ b/classes/local/manager/workflow_manager.php @@ -55,6 +55,7 @@ public static function insert_or_update(workflow &$workflow) { $workflow->id = $DB->insert_record('tool_lifecycle_workflow', $workflow); } $transaction->allow_commit(); + return $workflow->id; } /** diff --git a/tests/behat/manual_trigger.feature b/tests/behat/manual_trigger.feature index 164d4088..e667c0cb 100644 --- a/tests/behat/manual_trigger.feature +++ b/tests/behat/manual_trigger.feature @@ -1,4 +1,4 @@ -@tool @tool_lifecycle +@tool @tool_lifecycle @manual_trigger Feature: Add a manual trigger and test view and actions as a teacher Background: diff --git a/tests/behat/upload_workflow.feature b/tests/behat/upload_workflow.feature new file mode 100644 index 00000000..2ea1a1c3 --- /dev/null +++ b/tests/behat/upload_workflow.feature @@ -0,0 +1,11 @@ +@tool @tool_lifecycle @_file_upload @upload_workflow +Feature: Upload a workflow definition + + @javascript + Scenario: Upload a new workflow + Given I log in as "admin" + And I navigate to "Plugins > Admin tools > Life Cycle > Workflow drafts" in site administration + And I click on "Upload workflow" "link" + And I upload "admin/tool/lifecycle/tests/fixtures/simpleworkflow.xml" file to "File" filemanager + And I press "Upload" + Then I should see "A Workflow" diff --git a/tests/fixtures/simpleworkflow.xml b/tests/fixtures/simpleworkflow.xml new file mode 100644 index 00000000..3e570689 --- /dev/null +++ b/tests/fixtures/simpleworkflow.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/uploadworkflow.php b/uploadworkflow.php index 7fd08dfb..06161e1a 100644 --- a/uploadworkflow.php +++ b/uploadworkflow.php @@ -22,13 +22,9 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -use tool_lifecycle\action; use tool_lifecycle\local\backup\restore_lifecycle_workflow; -use tool_lifecycle\local\entity\workflow; use tool_lifecycle\local\form\form_upload_workflow; -use tool_lifecycle\local\form\form_workflow_instance; -use tool_lifecycle\local\manager\workflow_manager; -use tool_lifecycle\local\table\workflow_definition_table; +use tool_lifecycle\permission_and_navigation; use tool_lifecycle\urls; require_once(__DIR__ . '/../../../config.php'); @@ -36,7 +32,7 @@ require_login(); global $OUTPUT, $PAGE, $DB; -\tool_lifecycle\permission_and_navigation::setup_draft(); +permission_and_navigation::setup_draft(); $PAGE->set_url(new \moodle_url(urls::UPLOAD_WORKFLOW)); $title = get_string('upload_workflow', 'tool_lifecycle'); @@ -63,7 +59,7 @@ die(); } else { // Redirect to workflow page. - redirect(urls::WORKFLOW_DETAILS, ['wf' => $restore->get_workflow()->id]); + redirect(new moodle_url(urls::WORKFLOW_DETAILS, ['wf' => $restore->get_workflow()->id])); } }