Skip to content

Commit 40b1fd7

Browse files
committed
fix phpunit tests
1 parent dca1b2c commit 40b1fd7

File tree

18 files changed

+264
-135
lines changed

18 files changed

+264
-135
lines changed

classes/local/manager/delayed_courses_manager.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,15 +155,30 @@ public static function get_course_delayed_workflow($courseid, $workflowid) {
155155
}
156156

157157
/**
158-
* Build where sql for the processor to select only delayed courses.
159-
* @return array
158+
* Build where SQL for the processor to select delayed courses.
159+
* @return array sql-where-clause and params
160160
*/
161161
public static function get_course_delayed_wheresql() {
162162
$where = "{course}.id IN (SELECT courseid FROM {tool_lifecycle_delayed} WHERE delayeduntil > :now)";
163163
$params = ["now" => time()];
164164
return [$where, $params];
165165
}
166166

167+
/**
168+
* Build where SQL for the processor to select courses delayed for workflow.
169+
* @return array sql-where-clause and params
170+
*/
171+
public static function get_course_delayed_all_wheresql($workflowid) {
172+
$where = "(";
173+
$where .= "c.id IN (SELECT courseid FROM {tool_lifecycle_delayed_workf} WHERE delayeduntil > :now1
174+
AND workflowid = :workflowid)";
175+
$where .= " OR c.id IN (SELECT courseid FROM {tool_lifecycle_delayed} WHERE delayeduntil > :now2)";
176+
$where .= ")";
177+
$now = time();
178+
$params = ["now1" => $now, "workflowid" => $workflowid, "now2" => $now];
179+
return [$where, $params];
180+
}
181+
167182
/**
168183
* Get the globally delayed courses.
169184
* @return array array of course ids.

step/adminapprove/lang/de/lifecyclestep_adminapprove.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,19 @@
3939
$string['plugindescription'] = 'In diesem Schritt wird die Bestätigung eines Systemadministrators eingeholt bevor die Ausführung des Workflows fortgesetzt werden kann.';
4040
$string['pluginname'] = 'Adminbestätigungs-Schritt';
4141
$string['proceed'] = 'Fortführen';
42-
$string['proceedall'] = 'Alle fortführen';
4342
$string['proceedbuttonlabel'] = 'Beschriftung des Fortsetzen-Buttons';
4443
$string['proceedbuttonlabel_help'] = 'Ändert die Beschriftung des Fortsetzen-Buttons. Wenn das Feld leer bleibt, wird die Standardbeschriftung beibehalten.';
4544
$string['proceedselected'] = 'Ausgewählte fortführen';
4645
$string['proceedselectedbuttonlabel'] = 'Ausgewählte fortführen';
4746
$string['proceedselectedbuttonlabel_help'] = 'Ändert die Beschriftung des Buttons \'Ausgewählte fortführen\'. Wenn das Feld leer bleibt, wird die Standardbeschriftung beibehalten.';
4847
$string['rollback'] = 'Zurücksetzten';
49-
$string['rollbackall'] = 'Alle zurücksetzten';
50-
$string['rollbackallbuttonlabel'] = 'Alle zurücksetzten';
51-
$string['rollbackallbuttonlabel_help'] = 'Ändert die Beschriftung des Buttons \'Alle zurücksetzten\'. Wenn das Feld leer bleibt, wird die Standardbeschriftung beibehalten.';
5248
$string['rollbackbuttonlabel'] = 'Beschriftung des Zurücksetzten-Buttons';
5349
$string['rollbackbuttonlabel_help'] = 'Ändert die Beschriftung des Zurücksetzten-Buttons. Wenn das Feld leer bleibt, wird die Standardbeschriftung beibehalten.';
5450
$string['rollbackselected'] = 'Ausgewählte zurücksetzten';
5551
$string['rollbackselectedbuttonlabel'] = 'Ausgewählte zurücksetzten';
5652
$string['rollbackselectedbuttonlabel_help'] = 'Ändert die Beschriftung des Buttons \'Ausgewählte zurücksetzten\'. Wenn das Feld leer bleibt, wird die Standardbeschriftung beibehalten.';
5753
$string['statusmessage'] = 'Statusnachricht';
5854
$string['statusmessage_help'] = 'Statusnachricht, welche dem Lehrer angezeigt wird, wenn ein Prozess eines Kurses den Adminbestätigungs-Schritt bearbeitet.';
55+
$string['statusmessagedefault'] = 'In Admin-Bestätigungs-Schritt';
5956
$string['tools'] = 'Aktionen';
6057
$string['workflow'] = 'Workflow';

step/adminapprove/lang/en/lifecyclestep_adminapprove.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,13 @@
4747
$string['proceedselectedbuttonlabel'] = 'Label of the proceed selected button';
4848
$string['proceedselectedbuttonlabel_help'] = 'Option to customize the label of the button \'Proceed selected\'. Leave it empty if you are ok with the default value.';
4949
$string['rollback'] = 'Rollback';
50-
$string['rollbackall'] = 'Rollback all';
51-
$string['rollbackallbuttonlabel'] = 'Label of the rollback all button';
52-
$string['rollbackallbuttonlabel_help'] = 'Option to customize the label of the button \'Rollback all\'. Leave it empty if you are ok with the default value.';
5350
$string['rollbackbuttonlabel'] = 'Label of the rollback button';
5451
$string['rollbackbuttonlabel_help'] = 'Option to customize the label of the button \'Rollback\'. Leave it empty if you are ok with the default value.';
5552
$string['rollbackselected'] = 'Rollback selected';
5653
$string['rollbackselectedbuttonlabel'] = 'Label of the rollback selected button';
5754
$string['rollbackselectedbuttonlabel_help'] = 'Option to customize the label of the button \'Rollback selected\'. Leave it empty if you are ok with the default value.';
5855
$string['statusmessage'] = 'Status message';
5956
$string['statusmessage_help'] = 'Status message, which is displayed to a teacher, if a process of a course is at this admin approve step.';
57+
$string['statusmessagedefault'] = 'In Admin Approve step';
6058
$string['tools'] = 'Tools';
6159
$string['workflow'] = 'Workflow';

step/adminapprove/lib.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,21 +159,29 @@ public function extend_add_instance_form_definition($mform) {
159159
$mform->addElement('text', $elementname, get_string('statusmessage', 'lifecyclestep_adminapprove'));
160160
$mform->addHelpButton($elementname, 'statusmessage', 'lifecyclestep_adminapprove');
161161
$mform->setType($elementname, PARAM_TEXT);
162+
$mform->setDefault($elementname, get_string('statusmessagedefault', 'lifecyclestep_adminapprove'));
163+
164+
$mform->addElement('static', 'statusmsgdefault', " ",
165+
get_string('default').": ".get_string('statusmessagedefault', 'lifecyclestep_adminapprove'));
162166

163167
$buttons = [
164-
'proceedbuttonlabel',
165-
'rollbackbuttonlabel',
166-
'proceedselectedbuttonlabel',
167-
'rollbackselectedbuttonlabel',
168+
['proceedbuttonlabel', get_string('proceed', 'lifecyclestep_adminapprove')],
169+
['rollbackbuttonlabel', get_string('rollback', 'lifecyclestep_adminapprove')],
170+
['proceedselectedbuttonlabel', get_string('proceedselected', 'lifecyclestep_adminapprove')],
171+
['rollbackselectedbuttonlabel', get_string('rollbackselected', 'lifecyclestep_adminapprove')],
168172
];
169173

170174
foreach ($buttons as $button) {
171-
$elementname = $button;
175+
$elementname = $button[0];
176+
172177
$mform->addElement('text', $elementname,
173178
get_string($elementname, 'lifecyclestep_adminapprove'));
174179
$mform->addHelpButton($elementname, $elementname, 'lifecyclestep_adminapprove');
175180
$mform->setType($elementname, PARAM_TEXT);
176-
// Default: empty in order to keep translation.
181+
$mform->setDefault($elementname, $button[1]);
182+
183+
$mform->addElement('static', $elementname."default", " ",
184+
get_string('default').": ".$button[1]);
177185
}
178186
}
179187

step/adminapprove/tests/admin_approve_test.php

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,18 @@
2828
* Tests the admin approve step.
2929
*
3030
* @package lifecyclestep_adminapprove
31-
* @group lifecyclestep_adminapprove
32-
* @group lifecyclestep
33-
* @category test
34-
* @covers \tool_lifecycle\step\adminapprove
3531
* @copyright 2019 Justus Dieckmann
3632
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
3733
*/
3834
final class admin_approve_test extends \advanced_testcase {
3935

4036
/**
4137
* Starts a manual trigger and checks that one mail is send.
42-
* @covers \tool_lifecycle\step\adminapprove
4338
* @return void
44-
* @throws coding_exception
45-
* @throws dml_exception
46-
* @throws dml_transaction_exception
47-
* @throws moodle_exception
39+
* @throws \coding_exception
40+
* @throws \dml_exception
41+
* @throws \dml_transaction_exception
42+
* @throws \moodle_exception
4843
*/
4944
public function test_admin_mail(): void {
5045
$this->resetAfterTest(true);
@@ -65,14 +60,12 @@ public function test_admin_mail(): void {
6560
process_manager::manually_trigger_process($course3->id, $trigger->id);
6661
process_manager::manually_trigger_process($course4->id, $trigger->id);
6762

68-
// Prevent output from the task execution.
69-
$this->setOutputCallback(function() {
70-
});
71-
7263
// Create an email sink to query it after the processing.
7364
$sink = $this->redirectEmails();
7465
$task = new lifecycle_task();
66+
ob_start();
7567
$task->execute();
68+
ob_end_clean();
7669
$this->assertCount(1, $sink->get_messages());
7770
$sink->close();
7871
}

step/email/tests/lib_test.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
1616

1717
/**
18-
* Unit tests for the lifecyclestep_email lib.php.
18+
* Unit tests for the lifecyclestep_email.
1919
*
2020
* @package lifecyclestep_email
2121
* @copyright 2024 Justus Dieckmann, University of Münster.
@@ -41,7 +41,6 @@ final class lib_test extends \advanced_testcase {
4141
/**
4242
* Tests \tool_lifecycle\step\email::replace_placeholders.
4343
*
44-
* @covers \tool_lifecycle\step\email::replace_placeholders
4544
*/
4645
public function test_replace_placeholders(): void {
4746
$this->resetAfterTest();

step/makeinvisible/tests/make_invisible_test.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929
* Tests the make invisible step.
3030
*
3131
* @package lifecyclestep_makeinvisible
32-
* @group lifecyclestep_makeinvisible
33-
* @category test
3432
* @copyright 2019 Justus Dieckmann
3533
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
3634
*/
@@ -53,12 +51,11 @@ public function setUp(): void {
5351
/**
5452
* Test the visibility of courses after the step is executed.
5553
*
56-
* @covers \tool_lifecycle\step\makeinvisible
5754
* @return void
58-
* @throws coding_exception
59-
* @throws dml_exception
60-
* @throws dml_transaction_exception
61-
* @throws moodle_exception
55+
* @throws \coding_exception
56+
* @throws \dml_exception
57+
* @throws \dml_transaction_exception
58+
* @throws \moodle_exception
6259
*/
6360
public function test_make_invisible(): void {
6461
$generator = $this->getDataGenerator()->get_plugin_generator('tool_lifecycle');

trigger/byrole/tests/lifecycletrigger_byrole_test.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ final class lifecycletrigger_byrole_test extends \advanced_testcase {
4545

4646
/**
4747
* Set up environment for phpunit test.
48-
* @return mixed data for test
48+
* @return void data for test
4949
*/
5050
protected function setUp(): void {
5151
// Recommended in Moodle docs to always include CFG.
@@ -58,7 +58,7 @@ protected function setUp(): void {
5858

5959
/**
6060
* Test the locallib function for valid courses.
61-
* @covers \tool_lifecycle\trigger\byrole
61+
*
6262
* @return void
6363
* @throws \coding_exception
6464
* @throws \dml_exception
@@ -78,7 +78,7 @@ public function test_lib_validcourse(): void {
7878

7979
/**
8080
* Test the locallib function for a invalid course that is recognized for the first time.
81-
* @covers \tool_lifecycle\trigger\byrole
81+
*
8282
* @return void
8383
* @throws \coding_exception
8484
* @throws \dml_exception
@@ -99,7 +99,7 @@ public function test_lib_norolecourse(): void {
9999

100100
/**
101101
* Test the locallib function for a invalid course that is old enough to be triggered.
102-
* @covers \tool_lifecycle\trigger\byrole
102+
*
103103
* @return void
104104
* @throws \coding_exception
105105
* @throws \dml_exception
@@ -124,7 +124,7 @@ public function test_lib_norolefoundcourse(): void {
124124

125125
/**
126126
* Test the locallib function for a course that was invalid and has a responsible person again.
127-
* @covers \tool_lifecycle\trigger\byrole
127+
*
128128
* @return void
129129
* @throws \coding_exception
130130
* @throws \dml_exception

trigger/categories/tests/trigger_test.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
* Trigger test for categories trigger.
1919
*
2020
* @package lifecycletrigger_categories
21-
* @group lifecycletrigger
2221
* @copyright 2017 Tobias Reischmann WWU
2322
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
2423
*/
@@ -37,7 +36,6 @@
3736
* Trigger test for categories trigger.
3837
*
3938
* @package lifecycletrigger_categories
40-
* @group lifecycletrigger
4139
* @copyright 2017 Tobias Reischmann WWU
4240
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
4341
*/
@@ -85,7 +83,6 @@ public function setUp(): void {
8583

8684
/**
8785
* Tests if courses, which are in the category are correctly triggered.
88-
* @covers \tool_lifecycle\processor \tool_lifecycle\trigger\categories
8986
*/
9087
public function test_course_has_cat(): void {
9188

@@ -110,7 +107,6 @@ public function test_course_has_cat(): void {
110107

111108
/**
112109
* Tests if courses, which are in the category are correctly triggered.
113-
* @covers \tool_lifecycle\processor \tool_lifecycle\trigger\categories
114110
*/
115111
public function test_course_within_cat(): void {
116112

@@ -135,7 +131,6 @@ public function test_course_within_cat(): void {
135131

136132
/**
137133
* Tests if courses, which are not in the category are correctly triggered.
138-
* @covers \tool_lifecycle\processor \tool_lifecycle\trigger\categories
139134
*/
140135
public function test_course_not_within_cat(): void {
141136
$course = $this->getDataGenerator()->create_course();

trigger/customfielddelay/tests/trigger_test.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
* Trigger test for start date delay trigger.
1919
*
2020
* @package lifecycletrigger_customfielddelay
21-
* @group lifecycletrigger
2221
* @copyright 2020 Tobias Reischmann WWU
2322
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
2423
*/
@@ -36,7 +35,6 @@
3635
* Trigger test for start date delay trigger.
3736
*
3837
* @package lifecycletrigger_customfielddelay
39-
* @group lifecycletrigger
4038
* @copyright 2020 Tobias Reischmann WWU
4139
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
4240
*/
@@ -78,7 +76,7 @@ public function setUp(): void {
7876

7977
/**
8078
* Tests if courses, which have a customfield date in the future are not triggered by this plugin.
81-
* @covers \tool_lifecycle\trigger\customfielddelay
79+
*
8280
* @return void
8381
* @throws \coding_exception
8482
* @throws \dml_exception
@@ -102,7 +100,7 @@ public function test_young_course(): void {
102100
/**
103101
* Tests if courses, which have a customfield date in the future are not triggered by this plugin.
104102
* In addition a second custom course field is added to the course, which has a value that could trigger the course.
105-
* @covers \tool_lifecycle\trigger\customfielddelay
103+
*
106104
* @return void
107105
* @throws \coding_exception
108106
* @throws \dml_exception
@@ -132,7 +130,7 @@ public function test_young_course_with_second_customcourse_field(): void {
132130

133131
/**
134132
* Tests if courses, which are older than the default of 190 days are triggered by this plugin.
135-
* @covers \tool_lifecycle\trigger\customfielddelay
133+
*
136134
* @return void
137135
* @throws \coding_exception
138136
* @throws \dml_exception

0 commit comments

Comments
 (0)