Skip to content

Commit 1673a55

Browse files
committed
Fix automated tests
1 parent 5460598 commit 1673a55

10 files changed

+32
-25
lines changed

.github/workflows/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"main-moodle": "MOODLE_405_STABLE",
33
"main-php": "8.3",
44
"moodle-php": {
5-
"MOODLE_405_STABLE": ["8.1", "8.2", "8.3"]
5+
"MOODLE_405_STABLE": ["8.3"]
66
},
77
"moodle-plugin-ci": "4.4.5"
88
}

classes/local/backup/backup_lifecycle_workflow.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@
2222
*/
2323
namespace tool_lifecycle\local\backup;
2424

25-
require_once(__DIR__ . '/../../../config.php');
26-
require_once("$CFG->libdir/filelib.php");
25+
defined('MOODLE_INTERNAL') || die();
2726

28-
require_login();
27+
require_once("$CFG->libdir/filelib.php");
2928

3029
use tool_lifecycle\local\entity\step_subplugin;
3130
use tool_lifecycle\local\entity\trigger_subplugin;

tests/active_workflow_is_manual_test.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,14 @@ public function setUp(): void {
6868
$settings->displayname = self::MANUAL_TRIGGER1_DISPLAYNAME;
6969
$settings->capability = self::MANUAL_TRIGGER1_CAPABILITY;
7070
$this->manualworkflow = $generator->create_manual_workflow($settings);
71+
$generator->create_step("instance1", "createbackup", $this->manualworkflow->id);
7172
$this->automaticworkflow = $generator->create_workflow();
73+
$generator->create_step("instance1", "createbackup", $this->automaticworkflow->id);
7274

7375
$this->assertNull($this->manualworkflow->manual);
7476
$this->assertNull($this->automaticworkflow->manual);
7577

76-
// We do not need a sesskey check in theses tests.
78+
// We do not need a sesskey check in these tests.
7779
$USER->ignoresesskey = true;
7880
}
7981

tests/behat/manual_trigger.feature

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ Feature: Add a manual trigger and test view and actions as a teacher
3737
| Action name | Delete course |
3838
| Capability | moodle/course:manageactivities |
3939
And I press "Save changes"
40+
And I select "Create backup step" from the "tool_lifecycle-choose-step" singleselect
41+
And I set the field "Instance name" to "Create backup step"
42+
And I press "Save changes"
4043
And I am on workflowdrafts page
4144
And I press "Activate"
4245
And I log out

tests/generator/lib.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class tool_lifecycle_generator extends testing_module_generator {
7979
* @throws coding_exception
8080
* @throws moodle_exception
8181
*/
82-
public static function create_workflow($triggernames = ['startdatedelay'], $stepnames = []) {
82+
public static function create_workflow($triggernames = ['startdatedelay'], $stepnames = ['createbackup']) {
8383
// Create Workflow.
8484
$record = new stdClass();
8585
$record->id = null;
@@ -101,15 +101,15 @@ public static function create_workflow($triggernames = ['startdatedelay'], $step
101101
throw new coding_exception("You can use only those triggernames,".
102102
"which are defined as defaults in this generator.");
103103
}
104-
$step = self::create_trigger($subpluginname, $subpluginname, $workflow->id);
105-
settings_manager::save_settings($step->id, settings_type::TRIGGER, $subpluginname,
104+
$trigger = self::create_trigger($subpluginname, $subpluginname, $workflow->id);
105+
settings_manager::save_settings($trigger->id, settings_type::TRIGGER, $subpluginname,
106106
self::$defaulttrigger[$subpluginname]);
107107
}
108108
return $workflow;
109109
}
110110

111111
/**
112-
* Creates an artificial workflow without steps, which is triggered manually.
112+
* Creates an artificial workflow which is triggered manually.
113113
* @param \stdClass $triggersettings settings of the manual trigger
114114
* @return workflow
115115
* @throws moodle_exception

tests/manual_trigger_tools_test.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,16 @@ public function setUp(): void {
7272
$triggersettings->displayname = self::MANUAL_TRIGGER1_DISPLAYNAME;
7373
$triggersettings->capability = self::MANUAL_TRIGGER1_CAPABILITY;
7474
$this->workflow1 = $generator->create_manual_workflow($triggersettings);
75+
$generator->create_step("instance1", "createbackup", $this->workflow1->id);
7576

7677
$triggersettings = new \stdClass();
7778
$triggersettings->icon = self::MANUAL_TRIGGER2_ICON;
7879
$triggersettings->displayname = self::MANUAL_TRIGGER2_DISPLAYNAME;
7980
$triggersettings->capability = self::MANUAL_TRIGGER2_CAPABILITY;
8081
$this->workflow2 = $generator->create_manual_workflow($triggersettings);
82+
$generator->create_step("instance1", "createbackup", $this->workflow2->id);
8183

82-
// We do not need a sesskey check in theses tests.
84+
// We do not need a sesskey check in these tests.
8385
$USER->ignoresesskey = true;
8486
}
8587

tests/persistence/persist_step_test.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ public function test_add_step(): void {
7070
$this->workflow->id);
7171
$this->assertNotEmpty($step->id);
7272
$this->assertEquals($this->workflow->id, $step->workflowid);
73-
$this->assertEquals(1, $step->sortindex);
73+
$this->assertEquals(2, $step->sortindex);
7474
}
7575

7676
/**
77-
* Test that sortindizes are created correclty when creating multiple steps.
77+
* Test that sort indices are created correctly when creating multiple steps.
7878
* @covers \tool_lifecycle\local\manager\step_manager
7979
*/
8080
public function test_add_multiple_steps(): void {
@@ -90,9 +90,9 @@ public function test_add_multiple_steps(): void {
9090
'instance3',
9191
'subpluginname',
9292
$this->workflow->id);
93-
$this->assertEquals(1, $step1->sortindex);
94-
$this->assertEquals(2, $step2->sortindex);
95-
$this->assertEquals(3, $step3->sortindex);
93+
$this->assertEquals(2, $step1->sortindex);
94+
$this->assertEquals(3, $step2->sortindex);
95+
$this->assertEquals(4, $step3->sortindex);
9696
}
9797

9898
/**
@@ -118,14 +118,14 @@ public function test_remove_step(): void {
118118
$step2 = step_manager::get_step_instance($step2->id);
119119
$step3 = step_manager::get_step_instance($step3->id);
120120
$this->assertNull($step1);
121-
$this->assertEquals(1, $step2->sortindex);
122-
$this->assertEquals(2, $step3->sortindex);
121+
$this->assertEquals(2, $step2->sortindex);
122+
$this->assertEquals(3, $step3->sortindex);
123123
// Delete third step.
124124
step_manager::handle_action(action::STEP_INSTANCE_DELETE, $step3->id, $this->workflow->id);
125125
$step3 = step_manager::get_step_instance($step3->id);
126126
$step2 = step_manager::get_step_instance($step2->id);
127127
$this->assertNull($step3);
128-
$this->assertEquals(1, $step2->sortindex);
128+
$this->assertEquals(2, $step2->sortindex);
129129
}
130130

131131
/**
@@ -154,8 +154,8 @@ public function test_add_after_remove_step(): void {
154154
$step2 = step_manager::get_step_instance($step2->id);
155155
$step3 = step_manager::get_step_instance($step3->id);
156156
$this->assertNull($step1);
157-
$this->assertEquals(1, $step2->sortindex);
158-
$this->assertEquals(2, $step3->sortindex);
157+
$this->assertEquals(2, $step2->sortindex);
158+
$this->assertEquals(3, $step3->sortindex);
159159
}
160160

161161
}

tests/process_status_message_test.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ final class process_status_message_test extends \advanced_testcase {
5656
public function setUp(): void {
5757
global $USER;
5858

59-
// We do not need a sesskey check in theses tests.
59+
// We do not need a sesskey check in these tests.
6060
$USER->ignoresesskey = true;
6161

6262
$this->resetAfterTest(false);
@@ -66,10 +66,10 @@ public function setUp(): void {
6666
$settings->displayname = self::MANUAL_TRIGGER1_DISPLAYNAME;
6767
$settings->capability = self::MANUAL_TRIGGER1_CAPABILITY;
6868
$this->workflow = $this->generator->create_manual_workflow($settings);
69-
workflow_manager::handle_action(action::WORKFLOW_ACTIVATE, $this->workflow->id);
70-
7169
$this->generator->create_step("instance1", "createbackup", $this->workflow->id);
7270
$this->generator->create_step("instance2", "email", $this->workflow->id);
71+
workflow_manager::handle_action(action::WORKFLOW_ACTIVATE, $this->workflow->id);
72+
7373
}
7474

7575
/**

tests/workflow_actions_testcase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ abstract class workflow_actions_testcase extends \advanced_testcase {
5353
*/
5454
public function setUp(): void {
5555
global $USER;
56-
// We do not need a sesskey check in theses tests.
56+
// We do not need a sesskey check in these tests.
5757
$USER->ignoresesskey = true;
5858

5959
$this->resetAfterTest(true);

workflowoverview.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
$showdetailslink = new moodle_url(urls::WORKFLOW_DETAILS, $params);
103103

104104
$action = optional_param('action', null, PARAM_TEXT);
105+
$msg = "";
105106
if ($action) {
106107
if ($action == 'select') {
107108
$cid = required_param('cid', PARAM_INT);
@@ -133,7 +134,7 @@
133134
}
134135
}
135136
}
136-
redirect($PAGE->url, $msg, 3, notification::NOTIFY_SUCCESS);
137+
redirect($PAGE->url, $msg, null, notification::NOTIFY_SUCCESS);
137138
}
138139

139140
$PAGE->set_pagetype('admin-setting-' . 'tool_lifecycle');

0 commit comments

Comments
 (0)