Skip to content
Snippets Groups Projects
Commit 43b664ef authored by Tobias Reischmann's avatar Tobias Reischmann
Browse files

Fix proc_data test for new workflow definition

parent 1ea9805c
Branches
No related tags found
No related merge requests found
...@@ -59,7 +59,7 @@ class cleanup_processor { ...@@ -59,7 +59,7 @@ class cleanup_processor {
break; break;
} }
if ($response == trigger_response::trigger()) { if ($response == trigger_response::trigger()) {
process_manager::create_process($course->id, trigger_subplugin::from_record($trigger)); process_manager::create_process($course->id, $trigger->workflowid);
break; break;
} }
} }
......
...@@ -74,16 +74,13 @@ class process { ...@@ -74,16 +74,13 @@ class process {
if (!object_property_exists($record, 'courseid')) { if (!object_property_exists($record, 'courseid')) {
return null; return null;
} }
if (!object_property_exists($record, 'timestepchanged')) {
return null;
}
if (object_property_exists($record, 'waiting') && $record->waiting) { if (object_property_exists($record, 'waiting') && $record->waiting) {
$waiting = true; $waiting = true;
} else { } else {
$waiting = false; $waiting = false;
} }
if (!object_property_exists($record, 'stepindex') && $record->stepindex) { if (object_property_exists($record, 'stepindex') && $record->stepindex) {
$stepindex = $record->stepindex; $stepindex = $record->stepindex;
} else { } else {
$stepindex = 1; $stepindex = 1;
......
...@@ -32,18 +32,18 @@ defined('MOODLE_INTERNAL') || die(); ...@@ -32,18 +32,18 @@ defined('MOODLE_INTERNAL') || die();
class process_manager { class process_manager {
/** /**
* Creates a process for the course which is at the respective step the trigger is followed by. * Creates a process for the course for a certain workflow.
* @param int $courseid id of the course * @param int $courseid id of the course
* @param trigger_subplugin $trigger * @param int $workflowid id of the workflow
* @return process|null * @return process|null
*/ */
public static function create_process($courseid, $trigger) { public static function create_process($courseid, $workflowid) {
global $DB; global $DB;
if ($trigger->worflowid !== null) { if ($workflowid !== null) {
$record = new \stdClass(); $record = new \stdClass();
$record->id = null; $record->id = null;
$record->courseid = $courseid; $record->courseid = $courseid;
$record->worflowid = $trigger->worflowid; $record->workflowid = $workflowid;
$record->timestepchanged = time(); $record->timestepchanged = time();
$process = process::from_record($record); $process = process::from_record($record);
$process->id = $DB->insert_record('tool_cleanupcourses_process', $process); $process->id = $DB->insert_record('tool_cleanupcourses_process', $process);
......
...@@ -48,7 +48,7 @@ class tool_cleanupcourses_generator extends testing_module_generator { ...@@ -48,7 +48,7 @@ class tool_cleanupcourses_generator extends testing_module_generator {
} }
/** /**
* Creates an artificial workflow with two steps. * Creates an artificial workflow without steps.
*/ */
public static function create_active_workflow() { public static function create_active_workflow() {
// Create Workflow // Create Workflow
...@@ -74,6 +74,17 @@ class tool_cleanupcourses_generator extends testing_module_generator { ...@@ -74,6 +74,17 @@ class tool_cleanupcourses_generator extends testing_module_generator {
return $step; return $step;
} }
/**
* Creates an artificial workflow with three steps.
*/
public static function create_active_workflow_with_steps() {
$workflow = self::create_active_workflow();
self::create_step('instance1', 'subpluginname', $workflow->id);
self::create_step('instance2', 'subpluginname', $workflow->id);
self::create_step('instance3', 'subpluginname', $workflow->id);
return $workflow;
}
/** /**
* Creates an trigger instance from delayedcourses and * Creates an trigger instance from delayedcourses and
* creates two instances of createbackup, which it is followed by. * creates two instances of createbackup, which it is followed by.
......
...@@ -20,6 +20,7 @@ require_once(__DIR__ . '/../../lib.php'); ...@@ -20,6 +20,7 @@ require_once(__DIR__ . '/../../lib.php');
use \tool_cleanupcourses\manager\process_manager; use \tool_cleanupcourses\manager\process_manager;
use \tool_cleanupcourses\manager\process_data_manager; use \tool_cleanupcourses\manager\process_data_manager;
use \tool_cleanupcourses\manager\step_manager;
/** /**
* Tests creating storing and retrieving process data. * Tests creating storing and retrieving process data.
...@@ -39,24 +40,25 @@ class tool_cleanupcourses_persist_process_data_testcase extends \advanced_testca ...@@ -39,24 +40,25 @@ class tool_cleanupcourses_persist_process_data_testcase extends \advanced_testca
public function setUp() { public function setUp() {
$this->resetAfterTest(true); $this->resetAfterTest(true);
$trigger = tool_cleanupcourses_generator::create_trigger_with_workflow(); $workflow = tool_cleanupcourses_generator::create_active_workflow_with_steps();
$course = $this->getDataGenerator()->create_course(); $course = $this->getDataGenerator()->create_course();
$this->process = process_manager::create_process($course->id, $trigger); $this->process = process_manager::create_process($course->id, $workflow->id);
} }
/** /**
* Test the getting and setting of process data. * Test the getting and setting of process data.
*/ */
public function test_get_set_process_data() { public function test_get_set_process_data() {
$step = step_manager::get_step_instance_by_workflow_index($this->process->workflowid, $this->process->stepindex);
process_data_manager::set_process_data( process_data_manager::set_process_data(
$this->process->id, $this->process->id,
$this->process->stepid, $step->id,
self::KEY, self::KEY,
self::VALUE self::VALUE
); );
$value = process_data_manager::get_process_data( $value = process_data_manager::get_process_data(
$this->process->id, $this->process->id,
$this->process->stepid, $step->id,
self::KEY self::KEY
); );
$this->assertEquals(self::VALUE, $value); $this->assertEquals(self::VALUE, $value);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment