From 55d8cea48978f762f104326ae845752082fa05a4 Mon Sep 17 00:00:00 2001
From: David Watson <14983002+watson8@users.noreply.github.com>
Date: Tue, 3 Sep 2024 09:14:45 +0100
Subject: [PATCH] CTP-3560 coursework tests review
---
classes/allocation/table/builder.php | 1 +
classes/controllers/feedback_controller.php | 19 +-
.../csv/cells/feedbackcomments_cell.php | 5 +-
classes/framework/table_base.php | 2 +-
classes/grade_judge.php | 10 +-
classes/models/allocation.php | 1 +
classes/models/assessment_set_membership.php | 1 +
classes/models/coursework.php | 10 +-
classes/models/deadline_extension.php | 1 +
classes/models/feedback.php | 8 +-
classes/models/group.php | 1 +
classes/models/module.php | 1 +
classes/models/null_feedback.php | 1 +
classes/models/plagiarism_flag.php | 2 +-
classes/models/submission.php | 1 +
classes/models/user.php | 1 +
.../multi_marker_feedback_sub_rows.php | 4 +-
classes/stages/assessor.php | 1 +
classes/stages/final_agreed.php | 1 +
classes/test_helpers/factory_mixin.php | 10 +
db/install.xml | 2 +-
renderers/page_renderer.php | 10 +-
tests/behat/behat_mod_coursework.php | 429 +++++++++++++-----
tests/behat/deadline_extension.feature | 4 +-
...ine_extension_reason_dropdown_list.feature | 4 +-
tests/behat/factory.feature | 4 +-
...feedback_auto_release_without_cron.feature | 1 +
tests/behat/feedback_collisions.feature | 1 +
...dit_feedback_within_specified_time.feature | 2 +-
tests/behat/feedback_files.feature | 1 +
tests/behat/feedback_group_marking.feature | 2 +-
...eedback_multiple_assessor_feedback.feature | 2 +-
...feedback_restrict_feedback_editing.feature | 1 +
tests/behat/feedback_zero_grades.feature | 1 +
tests/behat/installation_and_set_up.feature | 4 +-
tests/behat/pages/allocations_page.php | 72 +--
tests/behat/pages/edit_extension_page.php | 11 +-
tests/behat/pages/gradebook_page.php | 10 +-
.../pages/multiple_grading_interface.php | 51 +--
tests/behat/pages/page_base.php | 37 +-
tests/behat/pages/show_feedback_page.php | 10 +-
.../behat/pages/single_grading_interface.php | 10 +-
tests/behat/pages/student_page.php | 52 +--
tests/behat/pages/student_submission_form.php | 4 +-
.../behat/sampling_automatic_sampling.feature | 7 +-
.../sampling_sample_range_set_rules.feature | 7 +-
...submissions_agree_submission_terms.feature | 2 +-
.../submissions_auto_finalisation.feature | 1 +
.../submissions_early_finalisation.feature | 7 +-
.../submissions_file_upload_limit.feature | 2 +-
.../submissions_file_upload_types.feature | 6 +-
.../submissions_group_submissions.feature | 4 +-
.../submissions_late_submissions.feature | 3 +-
tests/behat/submissions_start_date.feature | 1 +
.../submissions_student_submission.feature | 4 +-
...ubmissions_submit_onbehalf_student.feature | 2 +-
tests/behat/warnings.feature | 3 +-
tests/classes/ability_test.php | 2 +-
.../allocation/auto_allocator_test.php | 2 +-
.../allocation/form/table_processor_test.php | 2 +-
.../allocation/strategy/percentages_test.php | 2 +-
tests/classes/allocation/strategy_test.php | 2 +-
.../auto_grader/percentage_distance_test.php | 10 +-
tests/classes/cron_test.php | 2 +-
tests/classes/export/csv_test.php | 2 +-
.../export/grading_sheet_download_test.php | 2 +-
tests/classes/grade_judge_test.php | 2 +-
tests/classes/models/coursework_test.php | 5 +-
.../models/deadline_extension_test.php | 2 +-
tests/classes/models/group_test.php | 2 +-
.../models/moderation_set_membership_test.php | 2 +-
tests/classes/models/submission_test.php | 4 +-
tests/classes/models/user_test.php | 2 +-
tests/classes/router_test.php | 2 +-
tests/classes/stages/assessor_test.php | 2 +-
tests/classes/stages/final_agreed_test.php | 2 +-
tests/generator_test.php | 54 +--
tests/renderer_test.php | 7 +-
78 files changed, 593 insertions(+), 374 deletions(-)
diff --git a/classes/allocation/table/builder.php b/classes/allocation/table/builder.php
index 90e607ef..e4961de2 100644
--- a/classes/allocation/table/builder.php
+++ b/classes/allocation/table/builder.php
@@ -38,6 +38,7 @@
* Represents the table that will show all students and all markers so that they can be matched up with one another for grading.
* Various automatic strategies will be available for this, but the manual override happens here.
*/
+#[\AllowDynamicProperties]
class builder {
/**
diff --git a/classes/controllers/feedback_controller.php b/classes/controllers/feedback_controller.php
index 9263496a..71f5f49c 100644
--- a/classes/controllers/feedback_controller.php
+++ b/classes/controllers/feedback_controller.php
@@ -74,16 +74,19 @@ protected function show_feedback() {
$teacherfeedback = new feedback($this->params['feedbackid']);
- $ability = new ability(user::find($USER), $this->coursework);
- $ability->require_can('show', $teacherfeedback);
+ $user = user::find($USER);
+ if ($user) {
+ $ability = new ability($user, $this->coursework);
+ $ability->require_can('show', $teacherfeedback);
- $renderer = $this->get_page_renderer();
- $html = $renderer->show_feedback_page($teacherfeedback, $ajax);
+ $renderer = $this->get_page_renderer();
+ $html = $renderer->show_feedback_page($teacherfeedback, (bool)$ajax);
- if (empty($ajax)) {
- echo $html;
- } else {
- echo json_encode(['success' => true, 'formhtml' => $html]);
+ if (empty($ajax)) {
+ echo $html;
+ } else {
+ echo json_encode(['success' => true, 'formhtml' => $html]);
+ }
}
}
diff --git a/classes/export/csv/cells/feedbackcomments_cell.php b/classes/export/csv/cells/feedbackcomments_cell.php
index e797df56..6b50654e 100644
--- a/classes/export/csv/cells/feedbackcomments_cell.php
+++ b/classes/export/csv/cells/feedbackcomments_cell.php
@@ -40,9 +40,10 @@ class feedbackcomments_cell extends cell_base {
*/
public function get_cell($submission, $student, $stage_identifier) {
- $stage_identifier = ($this->coursework->get_max_markers() == 1) ? "assessor_1" : $this->get_stage_identifier_for_assessor($submission, $student);
+ $stage_identifier = ($this->coursework->get_max_markers() == 1)
+ ? "assessor_1" : $this->get_stage_identifier_for_assessor($submission, $student);
$grade = $submission->get_assessor_feedback_by_stage($stage_identifier);
- return (!$grade) ? '' : strip_tags($grade->feedbackcomment);
+ return (!$grade || !isset($grade->feedbackcomment)) ? '' : strip_tags($grade->feedbackcomment);
}
/**
diff --git a/classes/framework/table_base.php b/classes/framework/table_base.php
index 06b93d57..d0238598 100644
--- a/classes/framework/table_base.php
+++ b/classes/framework/table_base.php
@@ -20,7 +20,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-namespace mod_coursework\framework;;
+namespace mod_coursework\framework;
use moodle_database;
use stdClass;
diff --git a/classes/grade_judge.php b/classes/grade_judge.php
index f4f4187d..0e0d9ebb 100644
--- a/classes/grade_judge.php
+++ b/classes/grade_judge.php
@@ -65,10 +65,14 @@ public function get_grade_capped_by_submission_time($submission) {
}
/**
- * @param $grade
+ * @param int|float $grade
* @return float
*/
private function round_grade_decimals($grade) {
+ if ($grade === '' || $grade === null) {
+ // Avoid PHPUnit exception passing null or empty string to round().
+ return null;
+ }
return round($grade, 2);
}
@@ -145,10 +149,10 @@ public function has_feedback_that_is_promoted_to_gradebook($submission) {
/**
* @param submission $submission
- * @return int
+ * @return int|null
*/
public function get_time_graded($submission) {
- return $this->get_feedback_that_is_promoted_to_gradebook($submission)->timemodified;
+ return $this->get_feedback_that_is_promoted_to_gradebook($submission)->timemodified ?? null;
}
/**
diff --git a/classes/models/allocation.php b/classes/models/allocation.php
index 3b019615..092898fa 100644
--- a/classes/models/allocation.php
+++ b/classes/models/allocation.php
@@ -35,6 +35,7 @@
* @property mixed allocatableid
* @property mixed allocatabletype
*/
+#[\AllowDynamicProperties]
class allocation extends table_base {
/**
diff --git a/classes/models/assessment_set_membership.php b/classes/models/assessment_set_membership.php
index d5f179f9..af7098f7 100644
--- a/classes/models/assessment_set_membership.php
+++ b/classes/models/assessment_set_membership.php
@@ -38,6 +38,7 @@
* @package mod_coursework\models
*
*/
+#[\AllowDynamicProperties]
class assessment_set_membership extends table_base implements moderatable {
/**
diff --git a/classes/models/coursework.php b/classes/models/coursework.php
index e13c3e00..2e92c693 100644
--- a/classes/models/coursework.php
+++ b/classes/models/coursework.php
@@ -84,6 +84,7 @@
* @property mixed startdate
* @author administrator
*/
+#[\AllowDynamicProperties]
class coursework extends table_base {
/**
@@ -882,13 +883,10 @@ public function early_finalisation_allowed() {
* @return void
*/
public function publish_grades() {
-
- $submisisons = $this->get_submissions_to_publish();
-
- foreach ($submisisons as $submisison) {
- $submisison->publish();
+ $submissions = $this->get_submissions_to_publish();
+ foreach ($submissions as $submission) {
+ $submission->publish();
}
-
}
/**
diff --git a/classes/models/deadline_extension.php b/classes/models/deadline_extension.php
index 1d10e361..26ed8b88 100644
--- a/classes/models/deadline_extension.php
+++ b/classes/models/deadline_extension.php
@@ -36,6 +36,7 @@
* @property mixed allocatableid
* @package mod_coursework\models
*/
+#[\AllowDynamicProperties]
class deadline_extension extends table_base {
/**
diff --git a/classes/models/feedback.php b/classes/models/feedback.php
index 14a07aae..a0e73dbe 100644
--- a/classes/models/feedback.php
+++ b/classes/models/feedback.php
@@ -38,6 +38,7 @@
* @property mixed stage_identifier
* @property int feedback_manager
*/
+#[\AllowDynamicProperties]
class feedback extends table_base {
/**
@@ -475,7 +476,8 @@ public function get_submission() {
if (!isset($this->submission) && !empty($this->submissionid)) {
global $DB;
- $coursework_id = $this->courseworkid ?? $DB->get_field(submission::$table_name, 'courseworkid', ['id' => $this->submissionid], MUST_EXIST);
+ $coursework_id = $this->courseworkid
+ ?? $DB->get_field(submission::$table_name, 'courseworkid', ['id' => $this->submissionid], MUST_EXIST);
if (!isset(submission::$pool[$coursework_id])) {
submission::fill_pool_coursework($coursework_id);
}
@@ -591,7 +593,7 @@ public static function fill_pool_coursework($coursework_id) {
if (isset(self::$pool[$coursework_id])) {
return;
}
- if (submission::$pool[$coursework_id]) {
+ if (submission::$pool[$coursework_id] ?? null) {
$submission_ids = submission::$pool[$coursework_id]['id'];
} else {
$submission_ids = $DB->get_records(submission::$table_name, ['courseworkid' => $coursework_id], '', 'id');
@@ -650,7 +652,7 @@ public static function fill_pool_submissions($coursework_id, $submission_ids) {
* @param $coursework_id
* @param $key
* @param $params
- * @return bool
+ * @return self|bool
*/
public static function get_object($coursework_id, $key, $params) {
if (!isset(self::$pool[$coursework_id])) {
diff --git a/classes/models/group.php b/classes/models/group.php
index 418d8979..f0bd37d8 100644
--- a/classes/models/group.php
+++ b/classes/models/group.php
@@ -40,6 +40,7 @@
* @property mixed courseid
* @package mod_coursework\models
*/
+#[\AllowDynamicProperties]
class group extends table_base implements allocatable, moderatable {
use allocatable_functions;
diff --git a/classes/models/module.php b/classes/models/module.php
index c0f91448..bc65e4a3 100644
--- a/classes/models/module.php
+++ b/classes/models/module.php
@@ -29,6 +29,7 @@
/**
* Represents a row in the modules table.
*/
+#[\AllowDynamicProperties]
class module extends table_base {
/**
diff --git a/classes/models/null_feedback.php b/classes/models/null_feedback.php
index f63faf74..bccde49f 100644
--- a/classes/models/null_feedback.php
+++ b/classes/models/null_feedback.php
@@ -27,6 +27,7 @@
* class.
*
*/
+#[\AllowDynamicProperties]
class null_feedback {
/**
diff --git a/classes/models/plagiarism_flag.php b/classes/models/plagiarism_flag.php
index ec51b741..c96f360b 100644
--- a/classes/models/plagiarism_flag.php
+++ b/classes/models/plagiarism_flag.php
@@ -142,7 +142,7 @@ protected static function get_cache_array($coursework_id) {
* @param $coursework_id
* @param $key
* @param $params
- * @return bool
+ * @return self|bool
*/
public static function get_object($coursework_id, $key, $params) {
if (!isset(self::$pool[$coursework_id])) {
diff --git a/classes/models/submission.php b/classes/models/submission.php
index 7151e527..8a92560e 100644
--- a/classes/models/submission.php
+++ b/classes/models/submission.php
@@ -51,6 +51,7 @@
* @property mixed timesubmitted
* @property mixed lastpublished
*/
+#[\AllowDynamicProperties]
class submission extends table_base implements \renderable {
/**
diff --git a/classes/models/user.php b/classes/models/user.php
index d2fd6e47..79521fb3 100644
--- a/classes/models/user.php
+++ b/classes/models/user.php
@@ -37,6 +37,7 @@
* Class user
* @package mod_coursework\models
*/
+#[\AllowDynamicProperties]
class user extends table_base implements allocatable, moderatable {
use allocatable_functions;
diff --git a/classes/render_helpers/grading_report/sub_rows/multi_marker_feedback_sub_rows.php b/classes/render_helpers/grading_report/sub_rows/multi_marker_feedback_sub_rows.php
index 8ed31c78..c5adb34b 100644
--- a/classes/render_helpers/grading_report/sub_rows/multi_marker_feedback_sub_rows.php
+++ b/classes/render_helpers/grading_report/sub_rows/multi_marker_feedback_sub_rows.php
@@ -38,6 +38,7 @@
/**
* Class no_sub_rows
*/
+#[\AllowDynamicProperties]
class multi_marker_feedback_sub_rows implements sub_rows_interface {
/**
@@ -268,7 +269,8 @@ protected function new_feedaback_link($feedback_row) {
global $USER, $OUTPUT;
$this->already_shown_a_new_buton = true;
- $this->displaytable = true;
+// $this->displaytable = true; //todo this is deprecated and causes behat exception - was it doing anything useful?
+
// New
$linktitle = get_string('newfeedback', 'coursework');
diff --git a/classes/stages/assessor.php b/classes/stages/assessor.php
index 3d3da04b..af6ab46c 100644
--- a/classes/stages/assessor.php
+++ b/classes/stages/assessor.php
@@ -30,6 +30,7 @@
*
* @package mod_coursework
*/
+#[\AllowDynamicProperties]
class assessor extends base {
/**
diff --git a/classes/stages/final_agreed.php b/classes/stages/final_agreed.php
index fc562c98..74a66314 100644
--- a/classes/stages/final_agreed.php
+++ b/classes/stages/final_agreed.php
@@ -30,6 +30,7 @@
*
* @package mod_coursework
*/
+#[\AllowDynamicProperties]
class final_agreed extends base {
/**
diff --git a/classes/test_helpers/factory_mixin.php b/classes/test_helpers/factory_mixin.php
index f69588c6..25b08cad 100644
--- a/classes/test_helpers/factory_mixin.php
+++ b/classes/test_helpers/factory_mixin.php
@@ -74,6 +74,16 @@ trait factory_mixin {
*/
protected $other_teacher;
+ /**
+ * @var group
+ */
+ protected $group;
+
+ /**
+ * @var
+ */
+ protected $final_feedback;
+
/**
* @return user
*/
diff --git a/db/install.xml b/db/install.xml
index 6b0c9e66..56f15453 100644
--- a/db/install.xml
+++ b/db/install.xml
@@ -33,7 +33,7 @@
-
+
diff --git a/renderers/page_renderer.php b/renderers/page_renderer.php
index 02367814..1b656c27 100644
--- a/renderers/page_renderer.php
+++ b/renderers/page_renderer.php
@@ -43,14 +43,18 @@ class mod_coursework_page_renderer extends plugin_renderer_base {
/**
* @param feedback $feedback
*/
- public function show_feedback_page($feedback, $ajax) {
+ public function show_feedback_page($feedback, bool $ajax) {
$html = '';
$object_renderer = $this->get_object_renderer();
- if (empty($ajax)) $html .= $this->output->header();
+ if (!$ajax) {
+ $html .= $this->output->header();
+ }
$html .= $object_renderer->render_feedback($feedback);
- if (empty($ajax)) $html .= $this->output->header();
+ if (!$ajax) {
+ $html .= $this->output->footer();
+ }
return $html;
}
diff --git a/tests/behat/behat_mod_coursework.php b/tests/behat/behat_mod_coursework.php
index 4f2e930c..94c70284 100644
--- a/tests/behat/behat_mod_coursework.php
+++ b/tests/behat/behat_mod_coursework.php
@@ -36,7 +36,6 @@
use mod_coursework\stages\base as stage_base;
require_once(__DIR__ . '/../../../../lib/behat/behat_base.php');
-require_once(__DIR__ . '/../../../../vendor/phpunit/phpunit/src/Framework/Assert/Functions.php');
$files = glob(dirname(__FILE__) . '/steps/*.php');
foreach ($files as $filename) {
@@ -67,6 +66,34 @@ class behat_mod_coursework extends behat_base {
*/
protected $user_suffix = 0;
+ public $coursework;
+
+ public $course;
+
+ public $editingteacher;
+
+ public $teacher;
+
+ public $manager;
+
+ public $student;
+
+ public $extension_deadline;
+
+ public $group;
+
+ public $feedback;
+
+ public $final_feedback;
+
+ public $submission;
+
+ public $other_submission;
+
+ public $other_teacher;
+
+ public $other_student;
+
/**
* Factory that makes an instance of the page class, passing in the session context, then caches it
* and returns it when required.
@@ -191,7 +218,7 @@ protected function locate_path($path, $escape = true) {
* @Given /^I should( not)? see the file on the page$/
*
* @param bool $negate
- * @throws Behat\Mink\Exception\ExpectationException
+ * @throws ExpectationException
*/
public function iShouldSeeTheFileOnThePage($negate = false) {
$file_count = count($this->getSession()->getPage()->findAll('css', '.submissionfile'));
@@ -206,7 +233,7 @@ public function iShouldSeeTheFileOnThePage($negate = false) {
* @Then /^I should see (\d+) file(?:s)? on the page$/
*
* @param $numberoffiles
- * @throws Behat\Mink\Exception\ExpectationException
+ * @throws ExpectationException
*/
public function iShouldSeeFileOnThePage($numberoffiles) {
$file_count = count($this->getSession()->getPage()->findAll('css', '.submissionfile'));
@@ -224,22 +251,26 @@ public function theCronRuns() {
}
/**
- * @Then /^I should( not)? see( the)? (.*)'s name on the page$/
- * @param bool $negate
+ * @Then /^I (should|should not) see (the|another) student's name on the page$/
+ * @param string $shouldornot
*/
- public function iShouldSeeTheStudentSNameOnThePage($negate = false, $negate2=false, $studentrole) {
+ public function iShouldSeeTheStudentSNameOnThePage(string $shouldornot, string $studentrole) {
$page = $this->get_page('coursework page');
-
- $student = ($studentrole == "another student") ? $this->other_student : $this->student;
-
- $studentname = fullname($student);
-
+ $student = ($studentrole == "another") ? $this->other_student : $this->student;
+ // The var $student is a user object but we must pass stdClass to fullname() to avoid core error.
+ $studentname = fullname((object)(array)$student);
$student_found = $page->get_coursework_student_name($studentname);
-
- if ($negate) {
- assertFalse($student_found);
- } else {
- assertTrue($student_found);
+ $should = ($shouldornot == 'should');
+ if (!$should && $student_found) {
+ throw new ExpectationException(
+ "Student '$studentname' found but should not be",
+ $this->getSession()
+ );
+ } else if ($should && !$student_found) {
+ throw new ExpectationException(
+ "Student '$studentname' not found but should be",
+ $this->getSession()
+ );
}
}
@@ -338,7 +369,12 @@ public function iShouldSeeTheStudentAllocatedToTheOtherTeacher() {
* @var mod_coursework_behat_allocations_page $page
*/
$page = $this->get_page('allocations page');
- $page->user_should_be_alocated_to_assessor($this->student, $this->other_teacher, 'assessor_1');
+ $allocatedassessor = $page->user_allocated_assessor($this->student, 'assessor_1');
+ if ($allocatedassessor != $this->other_teacher->name()) {
+ $message = "Expected the allocated teacher name to be '{$this->other_teacher->name()}'"
+ . " but got '$allocatedassessor' instead.";
+ throw new ExpectationException($message, $this->getSession());
+ }
}
/**
@@ -349,7 +385,12 @@ public function iShouldSeeTheStudentAllocatedToTheTeacher() {
* @var mod_coursework_behat_allocations_page $page
*/
$page = $this->get_page('allocations page');
- $page->user_should_be_alocated_to_assessor($this->student, $this->teacher, 'assessor_1');
+ $allocatedassessor = $page->user_allocated_assessor($this->student, 'assessor_1');
+ if ($allocatedassessor != $this->teacher->name()) {
+ $message = 'Expected the allocated teacher name to be ' . $this->teacher->name()
+ . ' but got ' . $allocatedassessor . ' instead.';
+ throw new ExpectationException($message, $this->getSession());
+ }
}
/**
@@ -359,7 +400,13 @@ public function thereShouldBeNoAllocationsInTheDb() {
$params = array(
'courseworkid' => $this->coursework->id,
);
- assertEmpty(\mod_coursework\models\allocation::count($params));
+ $count = \mod_coursework\models\allocation::count($params);
+ if ($count !== 0) {
+ throw new ExpectationException(
+ "Found '$count' allocations in the database for coursework ID '{$this->coursework->id}'",
+ $this->getSession()
+ );
+ };
}
/**
@@ -370,7 +417,9 @@ public function iShouldNotSeeTheFinaliseButton() {
* @var mod_coursework_behat_student_page $page
*/
$page = $this->get_page('student page');
- $page->should_not_have_a_finalise_button();
+ if ($page->has_finalise_button()) {
+ throw new ExpectationException('Should not have finalise button', $this->getSession());
+ }
}
/**
@@ -403,7 +452,9 @@ public function iShouldNotSeeTheSaveAndFinaliseButton() {
* @var mod_coursework_behat_student_submission_form $page
*/
$page = $this->get_page('student submission form');
- $page->should_not_have_the_save_and_finalise_button();
+ if ($page->has_the_save_and_finalise_button()) {
+ throw new ExpectationException("Should not have save and finalise button");
+ }
}
/**
@@ -589,7 +640,12 @@ public function theCourseworkGeneralFeedbackIsEnabled() {
*/
public function theCourseworkGeneralFeedbackShouldBeDisabled() {
$this->get_coursework()->reload();
- assertFalse($this->get_coursework()->is_general_feedback_enabled());
+ if ($this->get_coursework()->is_general_feedback_enabled()) {
+ throw new ExpectationException(
+ "Feedback is enabled for for coursework ID '{$this->coursework->id}' and should be disabled",
+ $this->getSession()
+ );
+ };
}
/**
@@ -916,17 +972,18 @@ public function theManagerHasACapabilityToAllocateStudentsInSamplings() {
}
/**
- * @Given /^I (de)?select (a|another) student as a part of the sample for the second stage$/
+ *
+ * @Given /^I (select|deselect) (a|another) student as a part of the sample for the second stage$/
+ * @param string $selectordeselect
+ * @param string $other
*/
- public function iSelectTheStudentAsAPartOfTheSample($negate = false, $other) {
+ public function iSelectTheStudentAsAPartOfTheSample(string $selectordeselect, string $other) {
/**
* @var mod_coursework_behat_allocations_page $page
*/
- $other = ($other == 'another');
- $student = $other ? 'other_student' : 'student';
-
+ $student = $other == 'another' ? 'other_student' : 'student';
$page = $this->get_page('allocations page');
- if ($negate) {
+ if ($selectordeselect == 'deselect') {
$page->deselect_for_sample($this->$student, 'assessor_2');
} else {
$page->select_for_sample($this->$student, 'assessor_2');
@@ -1019,10 +1076,15 @@ public function iShouldSeeTheGradeGivenByTheInitialTeacherInTheProvisionalGradeC
* @var mod_coursework_behat_multiple_grading_interface $page
*/
$page = $this->get_page('multiple grading interface');
- $provisional_grade_field = $page->get_provisional_grade_field($this->submission);
- $grade_field = $page->get_grade_field($this->submission);
+ $provisionalgradefield = $page->get_provisional_grade_field($this->submission);
+ $gradefield = $page->get_grade_field($this->submission);
- assertEquals($provisional_grade_field, $grade_field);
+ if ($provisionalgradefield != $gradefield) {
+ throw new ExpectationException(
+ "Provisional grade '$provisionalgradefield' does not match '$gradefield'",
+ $this->getSession()
+ );
+ };
}
/**
@@ -1030,11 +1092,11 @@ public function iShouldSeeTheGradeGivenByTheInitialTeacherInTheProvisionalGradeC
*/
public function thereIsAnExtensionForTheStudentThatAllowsThemToSubmit() {
\mod_coursework\models\deadline_extension::create(array(
- 'allocatableid' => $this->student->id(),
- 'allocatabletype' => 'user',
- 'courseworkid' => $this->coursework->id,
- 'extended_deadline' => strtotime('+2 weeks 3:30pm', $this->coursework->deadline)
- ));
+ 'allocatableid' => $this->student->id(),
+ 'allocatabletype' => 'user',
+ 'courseworkid' => $this->coursework->id,
+ 'extended_deadline' => strtotime('+2 weeks 3:30pm', $this->coursework->deadline)
+ ));
}
/**
@@ -1111,8 +1173,11 @@ public function iShouldSeeTheDealineReasonInTheStudentRow() {
/**
* @var mod_coursework_behat_edit_extension_page $edit_extension_page
*/
- $edit_extension_page = $this->get_page('edit extension page');
- $edit_extension_page->should_show_extension_reason_for_allocatable(0);
+ $editextensionpage = $this->get_page('edit extension page');
+ $reason = $editextensionpage->get_extension_reason_for_allocatable();
+ if ($reason != 0) {
+ throw new ExpectationException("Unexpected extension reason '$reason'", $this->getSession());
+ }
}
/**
@@ -1123,7 +1188,9 @@ public function iShouldSeeTheExtraInformationInTheStudentRow() {
* @var mod_coursework_behat_edit_extension_page $edit_extension_page
*/
$edit_extension_page = $this->get_page('edit extension page');
- $edit_extension_page->should_show_extra_information_for_allocatable('Extra info here');
+ if (!$edit_extension_page->get_extra_information_for_allocatable('Extra info here')) {
+ throw new ExpectationException("Extra info not found", $this->getSession());
+ }
}
/**
@@ -1167,8 +1234,11 @@ public function iShouldSeeTheNewDeadlineReasonInTheDropdown() {
/**
* @var mod_coursework_behat_edit_extension_page $edit_extension_page
*/
- $edit_extension_page = $this->get_page('edit extension page');
- $edit_extension_page->should_show_extension_reason_for_allocatable(1);
+ $editextensionpage = $this->get_page('edit extension page');
+ $reason = $editextensionpage->get_extension_reason_for_allocatable();
+ if ($reason != 1) {
+ throw new ExpectationException("Unexpected extension reason '$reason'", $this->getSession());
+ }
}
/**
@@ -1179,7 +1249,9 @@ public function iShouldSeeTheNewExtraDeadlineInformationInTheDeadlineExtensionFo
* @var mod_coursework_behat_edit_extension_page $edit_extension_page
*/
$edit_extension_page = $this->get_page('edit extension page');
- $edit_extension_page->should_show_extra_information_for_allocatable('New info here');
+ if (!$edit_extension_page->get_extra_information_for_allocatable('New info here')) {
+ throw new ExpectationException("New info not found", $this->getSession());
+ }
}
/**
@@ -1222,8 +1294,22 @@ public function iShouldSeeThatTheStudentHasTwoAllcations() {
* @var $page mod_coursework_behat_allocations_page
*/
$page = $this->get_page('allocations page');
- $page->user_should_be_alocated_to_assessor($this->student, $this->teacher, 'assessor_1');
- $page->user_should_be_alocated_to_assessor($this->student, $this->other_teacher, 'assessor_2');
+
+ // Teacher - assessor_1.
+ $allocatedassessor = $page->user_allocated_assessor($this->student, 'assessor_1');
+ if ($allocatedassessor != $this->teacher->name()) {
+ $message = 'Expected the allocated teacher name to be ' . $this->teacher->name()
+ . ' but got ' . $allocatedassessor . ' instead.';
+ throw new ExpectationException($message, $this->getSession());
+ }
+
+ // Other teacher - assessor_2.
+ $allocatedassessor = $page->user_allocated_assessor($this->student, 'assessor_2');
+ if ($allocatedassessor != $this->other_teacher->name()) {
+ $message = 'Expected the allocated teacher name to be ' . $this->other_teacher->name()
+ . ' but got ' . $allocatedassessor . ' instead.';
+ throw new ExpectationException($message, $this->getSession());
+ }
}
/**
@@ -1234,8 +1320,22 @@ public function iShouldSeeThatBothStudentsAreAllocatedToTheTeacher() {
* @var $page mod_coursework_behat_allocations_page
*/
$page = $this->get_page('allocations page');
- $page->user_should_be_alocated_to_assessor($this->student, $this->teacher, 'assessor_1');
- $page->user_should_be_alocated_to_assessor($this->other_student, $this->teacher, 'assessor_1');
+
+ // Student.
+ $allocatedassessor = $page->user_allocated_assessor($this->student, 'assessor_1');
+ if ($allocatedassessor != $this->teacher->name()) {
+ $message = 'Expected the allocated teacher name to be ' . $this->teacher->name()
+ . ' but got ' . $allocatedassessor . ' instead.';
+ throw new ExpectationException($message, $this->getSession());
+ }
+
+ // Other student.
+ $allocatedassessor = $page->user_allocated_assessor($this->other_student, 'assessor_1');
+ if ($allocatedassessor != $this->teacher->name()) {
+ $message = 'Expected the allocated teacher name to be ' . $this->teacher->name()
+ . ' but got ' . $allocatedassessor . ' instead.';
+ throw new ExpectationException($message, $this->getSession());
+ }
}
/**
@@ -1376,14 +1476,16 @@ public function there_is_a_coursework() {
public function iShouldSeeTheTitleOfTheCourseworkOnThePage() {
$page = $this->get_page('coursework page');
- assertTrue($page->get_coursework_name($this->coursework->name));
+ if (!$page->get_coursework_name($this->coursework->name)) {
+ throw new ExpectationException('Coursework title not seen', $this->getSession());
+ }
}
/**
* @Then /^the coursework "([\w]+)" setting should be "([\w]*)" in the database$/
* @param $setting_name
* @param $seting_value
- * @throws Behat\Mink\Exception\ExpectationException
+ * @throws ExpectationException
*/
public function the_coursework_setting_should_be($setting_name, $seting_value) {
if ($seting_value == 'NULL') {
@@ -1413,7 +1515,7 @@ public function the_coursework_setting_is_in_the_database($setting_name, $settin
/**
* @Then /^there should be ([\d]+) coursework$/
* @param $expected_count
- * @throws Behat\Mink\Exception\ExpectationException
+ * @throws ExpectationException
*/
public function there_should_only_be_one_coursework($expected_count) {
global $DB;
@@ -1488,7 +1590,30 @@ public function theManagersAreNotAllowedToGrade($negate = false) {
* @Given /^the grades have been published$/
*/
public function theGradesHaveBeenPublished() {
- $this->coursework->publish_grades();
+ global $DB;
+ // $this->coursework->publish_grades();
+
+ // Using publish_grades was causing a user not found DB error so trying to isolate that here.
+ $submissions = $this->coursework->get_submissions_to_publish();
+ foreach ($submissions as $submission) {
+ // First check user exists as this will create DB error in behat if not.
+ if ($DB->record_exists('user', ['id' => $submission->userid, 'deleted' => 0])) {
+ try {
+ $submission->publish();
+ } catch (\Exception $e) {
+ throw new ExpectationException(
+ "Could not publish submission ID $submission->id for User ID $submission->userid",
+ $this->getSession()
+ );
+ }
+ } else {
+ throw new ExpectationException(
+ "User ID $submission->userid not found for submission $submission->id - could not publish"
+ . " - JSON submission: " . json_encode($submission),
+ $this->getSession()
+ );
+ }
+ }
}
/**
@@ -1708,7 +1833,9 @@ public function theStudentShouldBeAllocatedToAnAssessor() {
$result = $DB->get_record('coursework_allocation_pairs', $params);
- assertNotEmpty($result);
+ if (empty($result)) {
+ throw new ExpectationException('Expected assessor allocation', $this->getSession());
+ }
}
// Feedback steps
@@ -1727,8 +1854,9 @@ public function iShouldSeeTheFinalGradeOnTheStudentPage($negate = false) {
} else {
$comment_field = $this->find('css', $css_id);
$text = $comment_field->getText();
-
- assertEquals(56, $text);
+ if ($text != 56) {
+ throw new ExpectationException("Expected final grade 56 got $text", $this->getSession());
+ }
}
}
@@ -1743,7 +1871,9 @@ public function iShouldSeeTheGradeCommentOnTheStudentPage($negate = false) {
} else {
$comment_field = $this->find('css', '#final_feedback_comment');
$text = $comment_field->getText();
- assertEquals('New comment here', $text);
+ if ($text != 'New comment here') {
+ throw new ExpectationException("Unexpected comment '$text'", $this->getSession());
+ }
}
}
@@ -1847,8 +1977,10 @@ public function iClickTheNewSingleFinalFeedbackButtonStudent() {
*/
public function iShouldSeeTheGradeInTheFormOnThePage() {
$comment_field = $this->find('css', '#feedback_grade');
-
- assertEquals(56, $comment_field->getValue());
+ $expectedvalue = 56;
+ if ($comment_field->getValue() != $expectedvalue) {
+ throw new ExpectationException("Expected grade $expectedvalue got $text", $this->getSession());
+ }
}
/**
@@ -1856,8 +1988,10 @@ public function iShouldSeeTheGradeInTheFormOnThePage() {
*/
public function iShouldSeeTheOtherTeachersFinalGradeInTheFormOnThePage() {
$comment_field = $this->find('css', '#feedback_grade');
-
- assertEquals(45, $comment_field->getValue());
+ $expectedvalue = 45;
+ if ($comment_field->getValue() != $expectedvalue) {
+ throw new ExpectationException("Expected grade $expectedvalue got $text", $this->getSession());
+ }
}
/**
@@ -1865,8 +1999,10 @@ public function iShouldSeeTheOtherTeachersFinalGradeInTheFormOnThePage() {
*/
public function iShouldSeeTheOtherTeachersGradeInTheFormOnThePage() {
$comment_field = $this->find('css', '#feedback_grade');
-
- assertEquals(58, $comment_field->getValue());
+ $expectedvalue = 58;
+ if ($comment_field->getValue() != $expectedvalue) {
+ throw new ExpectationException("Expected final grade $expectedvalue got $text", $this->getSession());
+ }
}
/**
@@ -1934,7 +2070,9 @@ public function iShouldSeeTheModeratorGradeOnThePage() {
* @var mod_coursework_behat_multiple_grading_interface $page
*/
$page = $this->get_page('multiple grading interface');
- $page->should_have_moderator_grade_for($this->student, '56');
+ if (!$page->has_moderator_grade_for($this->student, '56')) {
+ throw new ExpectationException("Does not have moderator grade");
+ }
// if (!$this->find('xpath', $this->xpath_tag_class_contains_text('td', 'moderated', '56'))) {
// throw new ExpectationException('Could not find the moderated grade', $this->getSession());
// }
@@ -1948,7 +2086,11 @@ public function iClickTheEditFinalFeedbackButton() {
* @var mod_coursework_behat_multiple_grading_interface $page
*/
$page = $this->get_page('multiple grading interface');
- $page->click_edit_final_feedback_button($this->student);
+ $button = $page->get_edit_final_feedback_button($this->student);
+ if (!$button) {
+ throw new ExpectationException('Edit feedback button not present', $this->getSession());
+ }
+ $button->click();
}
/**
@@ -2024,7 +2166,7 @@ public function thereAreFeedbacksFromBothTeachers() {
* @Then /^I should( not)? see the final grade(?: as )?(\d+)? on the multiple marker page$/
* @param bool $negate
* @param int $grade
- * @throws Behat\Mink\Exception\ExpectationException
+ * @throws ExpectationException
* @throws coding_exception
*/
public function iShouldSeeTheFinalMultipleGradeOnThePage($negate = false, $grade = 56) {
@@ -2047,7 +2189,7 @@ public function iShouldSeeTheFinalMultipleGradeOnThePage($negate = false, $grade
/**
* @Then /^I should see the final grade(?: as )?(\d+)? on the single marker page$/
* @param int $grade
- * @throws Behat\Mink\Exception\ExpectationException
+ * @throws ExpectationException
* @throws coding_exception
*/
public function iShouldSeeTheFinalSingleGradeOnThePage($grade = 56) {
@@ -2077,12 +2219,13 @@ public function iHaveAnAssessorFeedback() {
/**
* @Then /^I should see the grade comment (?:as ")?(\w+)?(?:" )?in the form on the page$/
- * @param string $comment
+ * @param string $expectedvalue
*/
- public function iShouldSeeTheGradeCommentInTheFormOnThePage($comment = 'New comment here') {
- $comment_field = $this->find('css', '#feedback_comment');
-
- assertEquals($comment, $comment_field->getValue());
+ public function iShouldSeeTheGradeCommentInTheFormOnThePage($expectedvalue = 'New comment here') {
+ $commentfield = $this->find('css', '#feedback_comment');
+ if ($commentfield->getValue() != $expectedvalue) {
+ throw new ExpectationException("Expected comment $expectedvalue got " . $commentfield->getValue(), $this->getSession());
+ }
}
/**
@@ -2117,9 +2260,13 @@ public function iShouldSeeTheGradeOnThePage() {
* @Then /^I should see the rubric grade on the page$/
*/
public function iShouldSeeTheRubricGradeOnThePage() {
- $cell_text = $this->find('css', '#final_feedback_grade')->getText();
-
- assertContains('50', $cell_text);
+ $celltext = $this->find('css', '#final_feedback_grade')->getText();
+ if (strpos($celltext, '50') === false) {
+ throw new ExpectationException(
+ "Expected rubric grade 50 got '$celltext'",
+ $this->getSession()
+ );
+ }
}
/**
@@ -2156,7 +2303,10 @@ public function iShouldSeeTheFinalGradeForTheGroupInTheGradingInterface() {
* @var mod_coursework_behat_multiple_grading_interface $page
*/
$page = $this->get_page('multiple grading interface');
- $page->group_should_have_a_final_multiple_grade($this->group);
+ if (!$page->group_has_a_final_multiple_grade($this->group)) {
+ $message = "Should be a grade in the student row final grade cell, but there's not";
+ throw new ExpectationException($message, $this->getSession());
+ };
}
/**
@@ -2177,7 +2327,12 @@ public function iShouldSeeTheGroupGradeAssignedToTheOtherStudent() {
* @var mod_coursework_behat_multiple_grading_interface $page
*/
$page = $this->get_page('multiple grading interface');
- $page->student_should_have_a_final_grade($this->other_student);
+ if ($page->student_has_a_final_grade($this->other_student)) {
+ throw new ExpectationException(
+ $message = "Should be a grade in the student row final grade cell, but there's not",
+ $this->getSession()
+ );
+ }
}
/**
@@ -2188,7 +2343,12 @@ public function iShouldSeeTheGradeForTheGroupSubmission() {
* @var mod_coursework_behat_student_page $page
*/
$page = $this->get_page('student page');
- $page->should_have_visible_grade(45);
+ $visiblegrade = $page->get_visible_grade();
+ if ($visiblegrade != 45) {
+ throw new ExpectationException(
+ "Expected the final grade to be '45', but got '{$visiblegrade}'", $this->getSession()
+ );
+ }
}
/**
@@ -2199,7 +2359,12 @@ public function iShouldSeeTheFeedbackForTheGroupSubmission() {
* @var mod_coursework_behat_student_page $page
*/
$page = $this->get_page('student page');
- $page->should_have_visible_feedback('blah');
+ $visiblefeedback = $page->get_visible_feedback('blah');
+ if ($visiblefeedback != 'blah') {
+ throw new ExpectationException(
+ "Expected the feedback to be 'blah', but got '{$visiblefeedback}'", $this->getSession()
+ );
+ }
}
/**
@@ -2210,7 +2375,10 @@ public function iShouldSeeTheGradeInTheGradebook() {
* @var mod_coursework_behat_gradebook_page $page
*/
$page = $this->get_page('gradebook page');
- $page->should_have_coursework_grade_for_student($this->coursework, $this->student, 45);
+ $grade = $page->get_coursework_grade_for_student($this->coursework);
+ if ($grade != 45) {
+ throw new ExpectationException("Expected grade '45' found '$grade'", $this->getSession());
+ }
}
/**
@@ -2221,7 +2389,10 @@ public function iShouldSeeTheRubricGradeInTheGradebook() {
* @var mod_coursework_behat_gradebook_page $page
*/
$page = $this->get_page('gradebook page');
- $page->should_have_coursework_grade_for_student($this->coursework, $this->student, 50);
+ $grade = $page->get_coursework_grade_for_student($this->coursework);
+ if ($grade != 50) {
+ throw new ExpectationException("Expected grade '50' found '$grade'", $this->getSession());
+ }
}
/**
@@ -2286,13 +2457,15 @@ public function iShouldNotSeeALinkToAddFeedback() {
} else {
$grading_interface = $this->get_page('single grading interface');
}
- $grading_interface->there_should_not_be_a_feedback_icon($this->student);
+ if ($grading_interface->there_is_a_feedback_icon($this->student)) {
+ throw new ExpectationException('Feedback link is present', $this->getSession());
+ };
}
// General web steps
/**
- * @Given /^I (?:am on|visit) the ([\w ]+) page$/
+ * @Given /^I visit the ([\w ]+) page$/
* @param $path_name
*/
public function visit_page($path_name) {
@@ -2321,10 +2494,14 @@ public function i_should_be_on_the_page($page_name, $ignore_params = false) {
$current_path = parse_url($currentUrl, PHP_URL_PATH);
// $desired_path = parse_url($desirtedUrl, PHP_URL_PATH);
$message = "Should be on the " . $desirtedUrl . " page but instead the url is " . $current_path;
- assertEquals($current_path, $desirtedUrl, $message);
+ if ($current_path != $desirtedUrl) {
+ throw new ExpectationException($message, $this->getSession());
+ }
} else {
$message = "Should be on the " . $desirtedUrl . " page but instead the url is " . $currentUrlwithoutAnchor;
- assertEquals($currentUrlwithoutAnchor, $desirtedUrl, $message);
+ if ($currentUrlwithoutAnchor != $desirtedUrl) {
+ throw new ExpectationException($message, $this->getSession());
+ }
}
}
@@ -2430,8 +2607,11 @@ public function theSubmissionShouldBeFinalised($negate = false) {
global $DB;
$finalised = $DB->get_field('coursework_submissions', 'finalised', array('id' => $this->submission->id));
-
- assertEquals($negate ? 0 : 1, $finalised);
+ if ($negate && $finalised == 1) {
+ throw new ExpectationException('Submission is finalised and should not be', $this->getSession());
+ } else if (!$negate && $finalised == 0) {
+ throw new ExpectationException('Submission is not finalised and should be', $this->getSession());
+ }
}
/**
@@ -2441,7 +2621,12 @@ public function theSubmissionShouldBeFinalised($negate = false) {
public function iShouldSeeTheStudentSSubmissionOnThePage($negate = false) {
$fields =
$this->getSession()->getPage()->findAll('css', ".submission-{$this->submission->id}");
- assertCount($negate ? 0 : 1, $fields);
+ $countfields = count($fields);
+ if ($countfields == 0 && !$negate) {
+ throw new ExpectationException('Student submission is not on page and should be', $this->getSession());
+ } else if ($negate && $countfields > 0) {
+ throw new ExpectationException('Student submission is on page and should not be', $this->getSession());
+ }
}
/**
@@ -2456,10 +2641,10 @@ public function theSubmissionIsFinalised() {
* @Then /^the file upload button should not be visible$/
*/
public function theFileUploadButtonShouldNotBeVisible() {
-
$button = $this->find('css', 'div.fp-btn-add a');
-
- assertFalse($button->isVisible(), "The file picker upload buton should be hidden, but it isn't");
+ if ($button->isVisible()) {
+ throw new ExpectationException("The file picker upload button should be hidden, but it isn't", $this->getSession());
+ }
}
/**
@@ -2470,16 +2655,32 @@ public function iClickOnTheNewSubmissionButton($action) {
/**
* @var mod_coursework_behat_student_page $page
*/
- $page = $this->get_page('student page');
+// $page = $this->get_page('student page');
if ($action == 'edit') {
- $page->click_on_the_edit_submission_button();
+ $locator = "//div[@class='editsubmissionbutton']";
} else if ($action == 'new') {
- $page->click_on_the_new_submission_button();
+ $locator = "//div[@class='newsubmissionbutton']";
} else if ($action == 'finalise') {
- $page->click_on_the_finalise_submission_button();
+ $locator = "//div[@class='finalisesubmissionbutton']";
} else if ($action == 'save') {
- $page->click_on_the_save_submission_button();
+ $locator = "//div[@class='newsubmissionbutton']";
+ }
+
+ // Behat generates button type submit whereas code does input.
+ $page = $this->getSession()->getPage();
+ $inputtype = $page->find('xpath', $locator ."//input[@type='submit']");
+ $buttontype = $page->find('xpath', $locator ."//button[@type='submit']");
+
+ // Check how element was created and use it to find the button.
+ $button = ($inputtype !== null) ? $inputtype : $buttontype;
+
+ if (!$button) {
+ throw new ExpectationException(
+ "Button not found ($action): " . $button->getXpath(), $this->getSession()
+ );
}
+
+ $button->press();
}
/**
@@ -2494,8 +2695,12 @@ public function iShouldNotSeeTheEditSubmissionButton($negate = false, $action =
$button = $this->getSession()->getPage()
->findAll('xpath', "//div[@class='{$action}submissionbutton']//button[@type='submit']");
$buttons = ($input) ? $input : $button;// check how element was created and use it to find the button
-
- assertCount(($negate ? 0 : 1), $buttons);
+ $countbuttons = count($buttons);
+ if ($countbuttons > 0 && $negate) {
+ throw new ExpectationException('I see the button when I should not', $this->getSession());
+ } else if ($countbuttons == 0 && !$negate) {
+ throw new ExpectationException('I do not see the button when I should', $this->getSession());
+ }
}
/**
@@ -2666,7 +2871,9 @@ public function iSeeTheDateWhenIndividualFeedbackIsReleased() {
* @var mod_coursework_behat_coursework_page $page
*/
$page = $this->get_page('coursework page');
- assertTrue($page->individual_feedback_date_present());
+ if (!$page->individual_feedback_date_present()) {
+ throw new ExpectationException('I do not see the feedback release date', $this->getSession());
+ }
}
/**
@@ -2677,7 +2884,10 @@ public function iDoNotSeeTheDateWhenIndividualFeedbackIsReleased() {
* @var mod_coursework_behat_coursework_page $page
*/
$page = $this->get_page('coursework page');
- assertFalse($page->individual_feedback_date_present());
+
+ if ($page->individual_feedback_date_present()) {
+ throw new ExpectationException('I see the feedback release date when I should not', $this->getSession());
+ }
}
/**
@@ -2688,7 +2898,9 @@ public function iDoNotSeeTheDateWhenGeneralFeedbackIsReleased() {
* @var mod_coursework_behat_coursework_page $page
*/
$page = $this->get_page('coursework page');
- assertFalse($page->general_feedback_date_present());
+ if($page->general_feedback_date_present()) {
+ throw new ExpectationException('I see the general feedback release date when I should not', $this->getSession());
+ }
}
/**
@@ -2699,7 +2911,11 @@ public function iDoSeeTheDateWhenGeneralFeedbackIsReleased() {
* @var mod_coursework_behat_coursework_page $page
*/
$page = $this->get_page('coursework page');
- assertTrue($page->general_feedback_date_present());
+ if (!$page->general_feedback_date_present()) {
+ throw new ExpectationException(
+ 'I do not see the general feedback release date when I should', $this->getSession()
+ );
+ }
}
/**
@@ -2711,8 +2927,12 @@ public function iShouldSeeTheFirstInitialAssessorsGradeAndComment() {
*/
$page = $this->get_page('show feedback page');
$page->set_feedback($this->get_initial_assessor_feedback_for_student());
- $page->should_have_comment('New comment here');
- $page->should_have_grade('67');
+ if (!$page->has_comment('New comment here')) {
+ throw new ExpectationException('Comment not found', $this->getSession());
+ }
+ if (!$page->has_grade('67')) {
+ throw new ExpectationException('Grade 67 not found', $this->getSession());
+ }
}
/**
@@ -2862,7 +3082,12 @@ public function StudentAutomaticallyIncludedInSampleForStage($other, $another, $
$other = ($other == 'another');
$student = $other ? 'other_student' : 'student';
- $page->automatically_included_in_sample($this->coursework, $this->$student, $another, $stage, $negate);
+ $included = $page->automatically_included_in_sample($this->coursework, $this->$student, $another, $stage);
+ if ($included && $negate) {
+ throw new ExpectationException('Student included in sample and should not be', $this->getSession());
+ } else if (!$included && !$negate) {
+ throw new ExpectationException('Student not included in sample and should be', $this->getSession());
+ }
}
/**
diff --git a/tests/behat/deadline_extension.feature b/tests/behat/deadline_extension.feature
index 7f30c8b0..e35c0a0a 100644
--- a/tests/behat/deadline_extension.feature
+++ b/tests/behat/deadline_extension.feature
@@ -28,7 +28,7 @@ Feature: Deadlines extensions for submissions
Scenario: The teacher can add a deadline extension to an individual submission
Given the coursework deadline has passed
And I log in as a manager
- And I am on the coursework page
+ And I visit the coursework page
When I add a new extension for the student
Then I should be on the coursework page
And I should see the extended deadline in the student row
@@ -37,7 +37,7 @@ Feature: Deadlines extensions for submissions
Given the coursework deadline has passed
And there is an extension for the student which has expired
And I log in as a manager
- And I am on the coursework page
+ And I visit the coursework page
When I edit the extension for the student
Then I should be on the coursework page
And I should see the extended deadline in the student row
diff --git a/tests/behat/deadline_extension_reason_dropdown_list.feature b/tests/behat/deadline_extension_reason_dropdown_list.feature
index 50db3908..d49e93b9 100644
--- a/tests/behat/deadline_extension_reason_dropdown_list.feature
+++ b/tests/behat/deadline_extension_reason_dropdown_list.feature
@@ -15,7 +15,7 @@ Feature: Deadline extension reasons dropdown list
Given the coursework deadline has passed
And there are some extension reasons configured at site level
And I log in as a manager
- And I am on the coursework page
+ And I visit the coursework page
When I add a new extension for the student
Then I should be on the coursework page
When I click on the edit extension icon for the student
@@ -27,7 +27,7 @@ Feature: Deadline extension reasons dropdown list
And there are some extension reasons configured at site level
And there is an extension for the student which has expired
And I log in as a manager
- And I am on the coursework page
+ And I visit the coursework page
When I edit the extension for the student
Then I should be on the coursework page
And I should see the new extended deadline in the student row
diff --git a/tests/behat/factory.feature b/tests/behat/factory.feature
index 8c8f9356..9f810369 100644
--- a/tests/behat/factory.feature
+++ b/tests/behat/factory.feature
@@ -36,7 +36,7 @@ Feature: Testing that the factories for behat steps work. If any tests fail, fix
And I am logged in as an editing teacher
When I visit the course page
And I turn editing mode on
- When I add a "Coursework" to section "3" and I fill the form with:
+ When I add a "coursework" activity to course "C1" section "3" and I fill the form with:
| name | Test coursework |
| Description | Test coursework description |
Then the coursework general feedback should be disabled
@@ -54,7 +54,7 @@ Feature: Testing that the factories for behat steps work. If any tests fail, fix
And I am logged in as an editing teacher
When I visit the course page
And I turn editing mode on
- When I add a "Coursework" to section "3" and I fill the form with:
+ When I add a "coursework" activity to course "C1" section "3" and I fill the form with:
| name | Test coursework |
| Description | Test coursework description |
| blindmarking | 0 |
diff --git a/tests/behat/feedback_auto_release_without_cron.feature b/tests/behat/feedback_auto_release_without_cron.feature
index 5c7bc465..aea734cf 100644
--- a/tests/behat/feedback_auto_release_without_cron.feature
+++ b/tests/behat/feedback_auto_release_without_cron.feature
@@ -1,3 +1,4 @@
+@mod @mod_coursework
Feature: Auto releasing the student feedback without cron
As a student
diff --git a/tests/behat/feedback_collisions.feature b/tests/behat/feedback_collisions.feature
index 5911ab87..0812214a 100644
--- a/tests/behat/feedback_collisions.feature
+++ b/tests/behat/feedback_collisions.feature
@@ -1,3 +1,4 @@
+@mod @mod_coursework
Feature: Collisions: two people try to create feedback at the same time
As a teacher
diff --git a/tests/behat/feedback_edit_feedback_within_specified_time.feature b/tests/behat/feedback_edit_feedback_within_specified_time.feature
index eba2ce97..5c129b73 100644
--- a/tests/behat/feedback_edit_feedback_within_specified_time.feature
+++ b/tests/behat/feedback_edit_feedback_within_specified_time.feature
@@ -1,4 +1,4 @@
-
+@mod @mod_coursework
Feature: Allow markers to edit their marking but only during specific marking stages
As an initial marker
diff --git a/tests/behat/feedback_files.feature b/tests/behat/feedback_files.feature
index fe2bd721..307ad860 100644
--- a/tests/behat/feedback_files.feature
+++ b/tests/behat/feedback_files.feature
@@ -1,3 +1,4 @@
+@_file_upload
Feature: Adding feedback files
As a teacher
diff --git a/tests/behat/feedback_group_marking.feature b/tests/behat/feedback_group_marking.feature
index d788c225..c6ebd8a7 100644
--- a/tests/behat/feedback_group_marking.feature
+++ b/tests/behat/feedback_group_marking.feature
@@ -23,7 +23,7 @@ Feature: Marking the group submissions applies the grades to the whole group
And I am logged in as a manager
Scenario: grading the submission makes the grades show up for both students in the interface
- Given I am on the coursework page
+ Given I visit the coursework page
When I click the new final feedback button for the group
And show me the page
And I grade the submission using the simple form
diff --git a/tests/behat/feedback_multiple_assessor_feedback.feature b/tests/behat/feedback_multiple_assessor_feedback.feature
index 017c779c..66815c42 100644
--- a/tests/behat/feedback_multiple_assessor_feedback.feature
+++ b/tests/behat/feedback_multiple_assessor_feedback.feature
@@ -63,7 +63,7 @@ Feature: Multiple assessors simple grading form
Then show me the page
Then I should not see the edit feedback button for the teacher's feedback
- @javascript
+ @javascript @_file_upload
Scenario: Grade files can be edited and more are added
Given I am logged in as a teacher
And the submission is finalised
diff --git a/tests/behat/feedback_restrict_feedback_editing.feature b/tests/behat/feedback_restrict_feedback_editing.feature
index 9187cc93..4412b4cb 100644
--- a/tests/behat/feedback_restrict_feedback_editing.feature
+++ b/tests/behat/feedback_restrict_feedback_editing.feature
@@ -1,3 +1,4 @@
+@mod @mod_coursework
Feature: Resticting the editing of feedback by the assessors who added it
As a course leader
diff --git a/tests/behat/feedback_zero_grades.feature b/tests/behat/feedback_zero_grades.feature
index 5c66ebfd..b0f85f4e 100644
--- a/tests/behat/feedback_zero_grades.feature
+++ b/tests/behat/feedback_zero_grades.feature
@@ -1,3 +1,4 @@
+@mod @mod_coursework
Feature: Zero grades should show up just like the others
As a teacher
diff --git a/tests/behat/installation_and_set_up.feature b/tests/behat/installation_and_set_up.feature
index 4ea75f2d..bff76fdc 100644
--- a/tests/behat/installation_and_set_up.feature
+++ b/tests/behat/installation_and_set_up.feature
@@ -11,7 +11,7 @@ Feature: Installing the coursework module and making sure it works
And I am logged in as an editing teacher
And I visit the course page
And I turn editing mode on
- When I add a "Coursework" to section "3" and I fill the form with:
+ When I add a "coursework" activity to course "C1" section "3" and I fill the form with:
| name | Test coursework |
| Description | Test coursework description |
Then I should be on the course page
@@ -22,7 +22,7 @@ Feature: Installing the coursework module and making sure it works
And the course has completion enabled
When I visit the course page
And I turn editing mode on
- When I add a "Coursework" to section "3" and I fill the form with:
+ When I add a "coursework" activity to course "C1" section "3" and I fill the form with:
| name | Test coursework |
| Description | Test coursework description |
Then I should be on the course page
diff --git a/tests/behat/pages/allocations_page.php b/tests/behat/pages/allocations_page.php
index 1dfb3db3..46b8e632 100644
--- a/tests/behat/pages/allocations_page.php
+++ b/tests/behat/pages/allocations_page.php
@@ -22,6 +22,7 @@
use mod_coursework\allocation\allocatable;
use mod_coursework\models\user;
+use \Behat\Mink\Exception\ElementNotFoundException;
defined('MOODLE_INTERNAL') || die();
@@ -46,16 +47,12 @@ public function save_everything() {
/**
* @param \mod_coursework\models\user $user
- * @param \mod_coursework\models\user $assessor
- * @param string $stage_identifier e.g. 'assessor_1'
+ * @param string $stageidentifier e.g. 'assessor_1'
* @throws Behat\Mink\Exception\ElementNotFoundException
*/
- public function user_should_be_alocated_to_assessor($user, $assessor, $stage_identifier) {
- $cell_span = $this->getPage()->find('css', '#user_'.$user->id.' .'.$stage_identifier.' .existing-assessor');
- if (!$cell_span) {
- throw new \Behat\Mink\Exception\ElementNotFoundException($this->getSession(), 'Current allocated assessor ');
- }
- assertEquals($assessor->name(), $cell_span->getText(), 'Expected the allocated teacher name to be '.$assessor->name().' but got '.$cell_span->getText().' instead.');
+ public function user_allocated_assessor($user, $stageidentifier): string {
+ $cell_span = $this->getPage()->find('css', '#user_'.$user->id.' .'.$stageidentifier.' .existing-assessor');
+ return $cell_span ? $cell_span->getText() : '';
}
/**
@@ -152,7 +149,7 @@ public function student_should_have_allocation($student, $teacher, $string) {
/**
* @param $stage
- * @throws \Behat\Mink\Exception\ElementNotFoundException
+ * @throws ElementNotFoundException
*/
public function enable_atomatic_sampling_for($stage) {
$elementid = '#assessor_'.$stage.'_samplingstrategy';
@@ -198,7 +195,7 @@ public function enable_grade_range_rule_for_stage($stage, $ruleno) {
* @param $stage
* @param $ruleno
* @param $type
- * @throws \Behat\Mink\Exception\ElementNotFoundException
+ * @throws ElementNotFoundException
*/
public function select_type_of_grade_range_rule_for_stage($stage, $ruleno, $type) {
$elementid = '#assessor_'.$stage.'_sampletype_'.$ruleno;
@@ -213,7 +210,7 @@ public function select_type_of_grade_range_rule_for_stage($stage, $ruleno, $type
* @param $stage
* @param $ruleno
* @param $value
- * @throws \Behat\Mink\Exception\ElementNotFoundException
+ * @throws ElementNotFoundException
*/
public function select_range_for_grade_range_rule_for_stage($range, $stage, $ruleno, $value) {
$elementid = '#assessor_'.$stage.'_sample'.$range.'_'.$ruleno;
@@ -225,7 +222,7 @@ public function select_range_for_grade_range_rule_for_stage($range, $stage, $rul
/**
* @param $percentage
* @param $stage
- * @throws \Behat\Mink\Exception\ElementNotFoundException
+ * @throws ElementNotFoundException
*/
public function select_total_percentage_for_stage($percentage, $stage) {
@@ -241,52 +238,33 @@ public function select_total_percentage_for_stage($percentage, $stage) {
/**
* @param $coursework
* @param $user
- * @param $stage_number
+ * @param $otheruser
+ * @param $stagenumber
+ * @return bool
*/
- public function automatically_included_in_sample($coursework, $user, $other_user, $stage_number, $negate) {
+ public function automatically_included_in_sample($coursework, $user, $otheruser, $stagenumber): bool {
global $DB;
- $other_sql = (!empty($other_user)) ? "OR allocatableid = $other_user->id" : '';
+ $othersql = (!empty($otheruser)) ? "OR allocatableid = $otheruser->id" : '';
- $sql = "SELECT *
- FROM {coursework_sample_set_mbrs}
- WHERE courseworkid = :courseworkid
- AND stage_identifier = :stage
- AND (allocatableid = :user $other_sql)";
+ $sql = "SELECT *
+ FROM {coursework_sample_set_mbrs}
+ WHERE courseworkid = :courseworkid
+ AND stage_identifier = :stage
+ AND (allocatableid = :user $othersql)";
- $stage = "assessor_".$stage_number;
+ $stage = "assessor_".$stagenumber;
- $params = array('courseworkid' => $coursework->id,
+ $params = [
+ 'courseworkid' => $coursework->id,
'user' => $user->id,
- 'stage' => $stage);
-
- if (empty($negate)) {
- assertTrue($DB->record_exists_sql($sql, $params));
- } else {
- assertFalse($DB->record_exists_sql($sql, $params));
- }
- }
-
- /**
- * @param $other
- * @param $role_name
- */
+ 'stage' => $stage
+ ];
- public function thereIsAnotherTeacher($other, $role_name) {
-
- $other = ($other == 'another');
-
- $role_name = str_replace(' ', '', $role_name);
-
- $role_name_to_save = $other ? 'other_' . $role_name : $role_name;
-
- $this->$role_name_to_save = $this->create_user($role_name, $role_name_to_save);
+ return $DB->record_exists_sql($sql, $params);
}
public function save_sampling_strategy() {
-
$this->getPage()->pressButton('save_manual_sampling');
-
}
-
}
diff --git a/tests/behat/pages/edit_extension_page.php b/tests/behat/pages/edit_extension_page.php
index 95f749fa..885e4fc3 100644
--- a/tests/behat/pages/edit_extension_page.php
+++ b/tests/behat/pages/edit_extension_page.php
@@ -56,18 +56,17 @@ public function edit_active_extension($time) {
}
/**
- * @param string $reason
+ * @return string $reason
*/
- public function should_show_extension_reason_for_allocatable($reason) {
- $field = $this->getPage()->findField('pre_defined_reason');
- assertEquals($reason, $field->getValue());
+ public function get_extension_reason_for_allocatable() {
+ return $this->getPage()->findField('pre_defined_reason')->getValue();
}
/**
* @param string $string
*/
- public function should_show_extra_information_for_allocatable($string) {
+ public function get_extra_information_for_allocatable($string) {
$field = $this->getPage()->findField('extra_information[text]');
- assertContains($string, $field->getValue());
+ return $field->getValue();
}
}
diff --git a/tests/behat/pages/gradebook_page.php b/tests/behat/pages/gradebook_page.php
index 0035ffd3..27ea8d9a 100644
--- a/tests/behat/pages/gradebook_page.php
+++ b/tests/behat/pages/gradebook_page.php
@@ -34,11 +34,10 @@
class mod_coursework_behat_gradebook_page extends mod_coursework_behat_page_base {
/**
- * @param $coursework
- * @param $student
- * @param $grade
+ * @param object $coursework
+ * @return string
*/
- public function should_have_coursework_grade_for_student($coursework, $student, $grade) {
+ public function get_coursework_grade_for_student($coursework) {
global $CFG;
// This changed in 2.8, so we need a different selector
@@ -48,7 +47,6 @@ public function should_have_coursework_grade_for_student($coursework, $student,
$locator = '//th[a[contains(text(), "' . $coursework->name . '")]]/following-sibling::td[1]';
}
$grade_cell = $this->getPage()->find('xpath', $locator);
- $cell_contents = $grade_cell->getText();
- assertEquals($grade, $cell_contents, "Expected the gradebook grade to be '{$grade}', but got '{$cell_contents}'");
+ return $grade_cell ? $grade_cell->getText() : '';
}
}
diff --git a/tests/behat/pages/multiple_grading_interface.php b/tests/behat/pages/multiple_grading_interface.php
index e359ed4c..00353704 100644
--- a/tests/behat/pages/multiple_grading_interface.php
+++ b/tests/behat/pages/multiple_grading_interface.php
@@ -43,34 +43,33 @@
class mod_coursework_behat_multiple_grading_interface extends mod_coursework_behat_single_grading_interface {
/**
- * @param string $student_hash
+ * @param allocatable $allocatable
+ * @return bool is there an icon?
*/
- public function there_should_not_be_a_feedback_icon($student_hash) {
+ public function there_is_a_feedback_icon($allocatable):bool {
$this->getContext()->show_me_the_page();
$feedback_icon = $this->getPage()->findAll('css', '.cfeedbackcomment .smallicon');
- assertEquals(0, count($feedback_icon));
+ return !empty($feedback_icon);
}
/**
* @param user $allocatable
*/
- public function student_should_have_a_final_grade($allocatable) {
+ public function student_has_a_final_grade($allocatable):bool {
$student_grade_cell =
$this->getPage()->find('css', $this->allocatable_row_id($allocatable) . ' .multiple_agreed_grade_cell');
- $message = "Should be a grade in the student row final grade cell, but there's not";
- assertNotEmpty($student_grade_cell->getText(), $message);
+ return !empty($student_grade_cell->getText());
}
/**
* @param group $allocatable
*/
- public function group_should_have_a_final_multiple_grade($allocatable) {
+ public function group_has_a_final_multiple_grade($allocatable):bool {
$group_row_id = $this->allocatable_row_id($allocatable);
$locator = $group_row_id . ' .multiple_agreed_grade_cell';
$grade_cell = $this->getPage()->find('css', $locator);
- $message = "Should be a grade in the student row final grade cell, but there's not (css: {$locator})";
$actual_text = $grade_cell ? $grade_cell->getText() : '';
- assertNotEmpty($actual_text, $message);
+ return !empty($actual_text);
}
/**
@@ -87,11 +86,9 @@ public function click_new_final_feedback_button($allocatable) {
/**
* @param allocatable $allocatable
*/
- public function click_edit_final_feedback_button($allocatable) {
+ public function get_edit_final_feedback_button($allocatable) {
$identifier = '#edit_final_feedback_' . $this->allocatable_identifier_hash($allocatable);
- $nodeElement = $this->getPage()->find('css', $identifier);
- assertNotEmpty($nodeElement, 'Edit feedback button not present');
- $nodeElement->click();
+ return $this->getPage()->find('css', $identifier);
}
/**
@@ -123,10 +120,10 @@ public function click_new_moderator_feedback_button($allocatable) {
* @param allocatable $student
* @param $grade
*/
- public function should_have_moderator_grade_for($student, $grade) {
+ public function has_moderator_grade_for($student, $grade) {
$identifier = $this->allocatable_row_id($student) . ' .moderation_cell';
$text = $this->getPage()->find('css', $identifier)->getText();
- assertContains($grade, $text);
+ return str_contains($text, $grade);
}
/**
@@ -147,7 +144,12 @@ public function assessor_grade_should_be_present($allocatable, $assessor_number,
$locator = $this->assessor_feedback_table_id($allocatable) . ' .assessor_'.$assessor_number.' '. $this->assessor_grade_cell_class();
$grade_container = $this->getPage()->find('css', $locator);
$text = $grade_container ? $grade_container->getText() : '';
- assertContains((string)$expected_grade, $text);
+ if (!str_contains($text, (string)$expected_grade)) {
+ throw new \Behat\Mink\Exception\ExpectationException(
+ "Did not find expected grade '$expected_grade' in '$text'",
+ $this->getSession()
+ );
+ }
}
/**
@@ -161,7 +163,13 @@ public function assessor_grade_should_not_be_present($allocatable, $assessor_num
$cell = $this->getPage()->findAll('css', $locator);
if (!empty($cell)) {
$cell = reset($cell);
- assertNotContains($expected_grade, $cell->getText());
+ $text = $cell ? $cell->getText() : '';
+ if (str_contains($text, $expected_grade)) {
+ throw new \Behat\Mink\Exception\ExpectationException(
+ "Expected not to find grade '$expected_grade' but did find it in '$text'",
+ $this->getSession()
+ );
+ }
}
}
@@ -360,15 +368,6 @@ public function should_show_extension_for_allocatable($student, $deadline_extens
$this->should_have_css($element_selector, userdate($deadline_extension, '%a, %d %b %Y, %H:%M' ));
}
- /**
- * @param allocatable $student
- */
- public function should_show_extension_reason_for_allocatable($student) {
- $element_selector = $this->allocatable_row_id($student) . ' .time_submitted_cell';
- $reasons = coursework::extension_reasons();
- $this->should_have_css($element_selector, $reasons[1]);
- }
-
/**
* @param allocatable $allocatable
* @throws \Behat\Mink\Exception\ElementException
diff --git a/tests/behat/pages/page_base.php b/tests/behat/pages/page_base.php
index 6a97dc78..5b3d6092 100644
--- a/tests/behat/pages/page_base.php
+++ b/tests/behat/pages/page_base.php
@@ -93,10 +93,15 @@ public function should_have_text($text) {
*/
protected function should_have_css($css, $text = '', $error = '') {
$elements = $this->getPage()->findAll('css', $css);
- assertGreaterThanOrEqual(1, count($elements), $error);
+ $message = "CSS containing '$text' not found " . $error;
+ if (empty($elements)) {
+ throw new ExpectationException($message, $this->getSession());
+ }
if ($text) {
$actual_text = reset($elements)->getText();
- assertContains($text, $actual_text, $error);
+ if (!str_contains($actual_text, $text)) {
+ throw new ExpectationException($message, $this->getSession());
+ }
}
}
@@ -109,10 +114,14 @@ protected function should_not_have_css($css, $text = '') {
if ($text) {
foreach ($elements as $element) {
$actual_text = $element->getText();
- assertNotContains($text, $actual_text);
+ if (str_contains($actual_text, $text)) {
+ throw new ExpectationException("Should not have CSS $css", $this->getSession());
+ }
}
} else {
- assertEquals(0, count($elements));
+ if (!empty($elements)) {
+ throw new ExpectationException("Should not have CSS $css", $this->getSession());
+ }
}
}
@@ -196,24 +205,4 @@ protected function fill_in_date_field($field_name, $timestamp) {
$this->getPage()->fillField($month_dropdown_selector, $month);
$this->getPage()->fillField($year_dropdown_selector, $year);
}
-
- /**
- * @param string $locator xpath
- * @throws ElementNotFoundException
- */
- protected function pressButtonXpath($locator) {
- // behat generates button type submit whereas code does input
- $inputtype = $this->getPage()->find('xpath', $locator ."//input[@type='submit']");
- $buttontype = $this->getPage()->find('xpath', $locator ."//button[@type='submit']");
-
- $button = ($inputtype !== null) ? $inputtype : $buttontype;// check how element was created and use it to find the button
-
- if (null === $button) {
- throw new ElementNotFoundException(
- $this->getSession(), 'button', 'xpath', $button->getXpath()
- );
- }
-
- $button->press();
- }
}
diff --git a/tests/behat/pages/show_feedback_page.php b/tests/behat/pages/show_feedback_page.php
index 1888447a..3b76b1d3 100644
--- a/tests/behat/pages/show_feedback_page.php
+++ b/tests/behat/pages/show_feedback_page.php
@@ -43,16 +43,18 @@ class mod_coursework_behat_show_feedback_page extends mod_coursework_behat_page_
/**
* @param string $grade
+ * @return bool
*/
- public function should_have_grade($grade) {
- assertContains($grade, $this->get_feedback_table()->getText());
+ public function has_grade($grade): bool {
+ return str_contains($this->get_feedback_table()->getText(), $grade);
}
/**
* @param string $comment
+ * @return bool
*/
- public function should_have_comment($comment) {
- assertContains($comment, $this->get_feedback_table()->getText());
+ public function has_comment($comment): bool {
+ return str_contains($this->get_feedback_table()->getText(), $comment);
}
/**
diff --git a/tests/behat/pages/single_grading_interface.php b/tests/behat/pages/single_grading_interface.php
index 46c1db3a..178b99d5 100644
--- a/tests/behat/pages/single_grading_interface.php
+++ b/tests/behat/pages/single_grading_interface.php
@@ -38,19 +38,19 @@ class mod_coursework_behat_single_grading_interface extends mod_coursework_behat
/**
* @param $student_hash
*/
- public function student_should_have_a_final_grade($student_hash) {
+ public function student_has_a_final_grade($student_hash): bool {
$student_grade_cell = $this->getPage()->find('css', '#submission_'. $student_hash.' .single_final_grade_cell');
- $message = "Should be a grade in the student row final grade cell, but there's not";
- assertNotEmpty($student_grade_cell->getText(), $message);
+ return !empty($student_grade_cell->getText());
}
/**
* @param allocatable $allocatable
+ * @return bool is there an icon?
*/
- public function there_should_not_be_a_feedback_icon($allocatable) {
+ public function there_is_a_feedback_icon($allocatable):bool {
$feedback_cell = $this->getPage()->find('css', $this->allocatable_row_id($allocatable).' .single_assessor_feedback_cell');
$feedback_icon = $feedback_cell->findAll('css', '.smallicon');
- assertEquals(0, count($feedback_icon));
+ return !empty($feedback_icon);
}
/**
diff --git a/tests/behat/pages/student_page.php b/tests/behat/pages/student_page.php
index 77907b4e..f0fe3a27 100644
--- a/tests/behat/pages/student_page.php
+++ b/tests/behat/pages/student_page.php
@@ -69,56 +69,34 @@ public function should_have_number_of_feedback_files($expected_number_of_files)
public function should_show_the_submitter_as($rolename) {
$submission_user_cell = $this->getPage()->find('css', 'td.submission-user');
$cell_contents = $submission_user_cell->getText();
- $student_name = fullname($this->getContext()->$rolename);
- assertContains($student_name, $cell_contents, "Expected the submission to have been made by {$student_name}, but got {$cell_contents}");
+ $student_name = fullname((object)(array)$this->getContext()->$rolename);
+ if (!str_contains($cell_contents, $student_name)) {
+ throw new ExpectationException(
+ "Expected the submission to have been made by {$student_name}, but got {$cell_contents}",
+ $this->getSession()
+ );
+ }
}
/**
- * @param mixed $grade
+ * @return string
*/
- public function should_have_visible_grade($grade) {
+ public function get_visible_grade(): ?string {
// final_feedback_grade
$final_grade_cell = $this->getPage()->find('css', '#final_feedback_grade');
- $cell_contents = $final_grade_cell ? $final_grade_cell->getText() : false;
- assertEquals($grade,
- $cell_contents,
- "Expected the final grade to be '{$grade}', but got '{$cell_contents}'");
+ return $final_grade_cell ? $final_grade_cell->getText() : null;
}
/**
- * @param $feedback_text
+ * @return string
*/
- public function should_have_visible_feedback($feedback_text) {
+ public function get_visible_feedback() {
// final_feedback_grade
$final_grade_cell = $this->getPage()->find('css', '#final_feedback_comment');
- $cell_contents = $final_grade_cell->getText();
- assertEquals($feedback_text,
- $cell_contents,
- "Expected the final feedback comment to be '{$feedback_text}', but got '{$cell_contents}'");
- }
-
- public function click_on_the_edit_submission_button() {
- $locator = "//div[@class='editsubmissionbutton']";
- $this->pressButtonXpath($locator);
- }
-
- public function click_on_the_finalise_submission_button() {
- $locator = "//div[@class='finalisesubmissionbutton']";
- $this->pressButtonXpath($locator);
- }
-
- public function click_on_the_new_submission_button() {
- $locator = "//div[@class='newsubmissionbutton']";
- $this->pressButtonXpath($locator);
- }
-
- public function should_not_have_a_finalise_button() {
- $buttons = $this->getPage()->findAll('css', '.finalisesubmissionbutton');
- assertEmpty($buttons);
+ return $final_grade_cell->getText();
}
- public function click_on_the_save_submission_button() {
- $locator = "//div[@class='newsubmissionbutton']";
- $this->pressButtonXpath($locator);
+ public function has_finalise_button(): bool {
+ return !empty($this->getPage()->findAll('css', '.finalisesubmissionbutton'));
}
}
diff --git a/tests/behat/pages/student_submission_form.php b/tests/behat/pages/student_submission_form.php
index 35902fd0..88dbd8e4 100644
--- a/tests/behat/pages/student_submission_form.php
+++ b/tests/behat/pages/student_submission_form.php
@@ -41,8 +41,8 @@ public function click_on_the_save_and_finalise_submission_button() {
$this->getPage()->find('css', "#id_finalisebutton")->press();
}
- public function should_not_have_the_save_and_finalise_button() {
+ public function has_the_save_and_finalise_button() {
$buttons = $this->getPage()->findAll('css', '#id_finalisebutton');
- assertEmpty($buttons);
+ return !empty($buttons);
}
}
diff --git a/tests/behat/sampling_automatic_sampling.feature b/tests/behat/sampling_automatic_sampling.feature
index 44774e15..65a352c6 100644
--- a/tests/behat/sampling_automatic_sampling.feature
+++ b/tests/behat/sampling_automatic_sampling.feature
@@ -1,3 +1,4 @@
+@mod @mod_coursework
Feature: Automatic sampling using total number of students in stage 1 and 2
As a course administrator setting up a coursework instance for a large group of students
@@ -17,7 +18,7 @@ Feature: Automatic sampling using total number of students in stage 1 and 2
Scenario: Automatically allocating a total for stage 2 based on stage 1
Given the coursework "numberofmarkers" setting is "2" in the database
And the coursework "samplingenabled" setting is "1" in the database
- And I am on the allocations page
+ And I visit the allocations page
When I enable automatic sampling for stage 2
And I enable total rule for stage 2
And I select 50% of total students in stage 1
@@ -29,7 +30,7 @@ Feature: Automatic sampling using total number of students in stage 1 and 2
Scenario: Automatically allocating a total for stage 3 based on stage 2
Given the coursework "numberofmarkers" setting is "3" in the database
And the coursework "samplingenabled" setting is "1" in the database
- And I am on the allocations page
+ And I visit the allocations page
When I enable automatic sampling for stage 2
And I enable total rule for stage 2
And I select 100% of total students in stage 1
@@ -44,7 +45,7 @@ Feature: Automatic sampling using total number of students in stage 1 and 2
Scenario: Automatically allocating a total for stage 3 based on stage 1
Given the coursework "numberofmarkers" setting is "3" in the database
And the coursework "samplingenabled" setting is "1" in the database
- And I am on the allocations page
+ And I visit the allocations page
When I enable automatic sampling for stage 3
And I enable total rule for stage 3
And I select 50% of total students in stage 1
diff --git a/tests/behat/sampling_sample_range_set_rules.feature b/tests/behat/sampling_sample_range_set_rules.feature
index 53ba5026..a47d2c25 100644
--- a/tests/behat/sampling_sample_range_set_rules.feature
+++ b/tests/behat/sampling_sample_range_set_rules.feature
@@ -1,3 +1,4 @@
+@mod @mod_coursework
Feature: Automatic sample based on range set grades using marking of students in stage 1 and 2
As a manager, I want to be able to automatically allocate assessors to students
@@ -29,7 +30,7 @@ Feature: Automatic sample based on range set grades using marking of students in
Scenario: Automatically allocating a set of students within specified grade rule range in stage 2 based on stage 1 grades
Given I am logged in as a manager
- And I am on the allocations page
+ And I visit the allocations page
And I enable automatic sampling for stage 2
And show me the page
And I enable grade range rule 1 for stage 2
@@ -54,7 +55,7 @@ Feature: Automatic sample based on range set grades using marking of students in
Scenario: Automatically allocating a set of students within specified percentage rule range in stage 3 based on stage 2 grades
Given I am logged in as a manager
- And I am on the allocations page
+ And I visit the allocations page
And I enable automatic sampling for stage 2
And I enable total rule for stage 2
And I select 100% of total students in stage 1
@@ -66,7 +67,7 @@ Feature: Automatic sample based on range set grades using marking of students in
And I grade the submission as 40 using the simple form
And I log out
And I am logged in as a manager
- And I am on the allocations page
+ And I visit the allocations page
When I enable automatic sampling for stage 3
And I enable grade range rule 1 for stage 3
And I select limit type for grade range rule 1 in stage 3 as "percentage"
diff --git a/tests/behat/submissions_agree_submission_terms.feature b/tests/behat/submissions_agree_submission_terms.feature
index 35ede8d9..fb972cc0 100644
--- a/tests/behat/submissions_agree_submission_terms.feature
+++ b/tests/behat/submissions_agree_submission_terms.feature
@@ -1,4 +1,4 @@
-@mod @mod_coursework
+@mod @mod_coursework @_file_upload
Feature: Students must agree to terms before submitting anything
As a manger
diff --git a/tests/behat/submissions_auto_finalisation.feature b/tests/behat/submissions_auto_finalisation.feature
index b8edc44b..7373ce58 100644
--- a/tests/behat/submissions_auto_finalisation.feature
+++ b/tests/behat/submissions_auto_finalisation.feature
@@ -1,3 +1,4 @@
+@mod @mod_coursework
Feature: Auto finalising before cron runs
As a teacher
diff --git a/tests/behat/submissions_early_finalisation.feature b/tests/behat/submissions_early_finalisation.feature
index 5e2ad2b8..fd30e4a0 100644
--- a/tests/behat/submissions_early_finalisation.feature
+++ b/tests/behat/submissions_early_finalisation.feature
@@ -1,3 +1,4 @@
+@mod @mod_coursework
Feature: Early finalisation of student submissions
As a teacher
@@ -11,7 +12,7 @@ Feature: Early finalisation of student submissions
And the coursework "allowearlyfinalisation" setting is "1" in the database
And I am logged in as a student
- @javascript
+ @javascript @_file_upload
Scenario: I upload a file and finalise it immediately
When I visit the coursework page
And I click on the new submission button
@@ -22,7 +23,7 @@ Feature: Early finalisation of student submissions
And I should not see the edit submission button
And I should not see the finalise submission button
- @broken @javascript
+ @broken @javascript @_file_upload
Scenario: I upload a file and save it
When I visit the coursework page
And I click on the new submission button
@@ -34,7 +35,7 @@ Feature: Early finalisation of student submissions
Then I should be on the coursework page
And I should not see the finalise submission button
- @javascript
+ @javascript @_file_upload
Scenario: I should not see the early finalisation button on the student page when the option is disabled
Given the coursework "allowearlyfinalisation" setting is "0" in the database
When I visit the coursework page
diff --git a/tests/behat/submissions_file_upload_limit.feature b/tests/behat/submissions_file_upload_limit.feature
index 50ae4ffb..85433180 100644
--- a/tests/behat/submissions_file_upload_limit.feature
+++ b/tests/behat/submissions_file_upload_limit.feature
@@ -10,7 +10,7 @@ Feature: File upload limits
And there is a coursework
And I am logged in as a student
- @javascript
+ @javascript @_file_upload
Scenario: I am prevented from uploading more files than specified
Given the coursework "maxfiles" setting is "2" in the database
diff --git a/tests/behat/submissions_file_upload_types.feature b/tests/behat/submissions_file_upload_types.feature
index 04315233..4879fc7e 100644
--- a/tests/behat/submissions_file_upload_types.feature
+++ b/tests/behat/submissions_file_upload_types.feature
@@ -10,7 +10,7 @@ Feature: Restricting the types of files that students can upload
And there is a coursework
And I am logged in as a student
- @javascript
+ @javascript @_file_upload
Scenario: I can upload anything when the settings are empty
Given the coursework "filetypes" setting is "" in the database
@@ -20,7 +20,7 @@ Feature: Restricting the types of files that students can upload
Then I should see "1" elements in "Upload a file" filemanager
# Wrong file type throws an exception with a backtrace. Can't find out how to expect this.
-# @javascript
+# @javascript @_file_upload
# Scenario: I can not upload other file types when the settings are restrictive
# Given the coursework "filetypes" setting is "doc" in the database
#
@@ -28,7 +28,7 @@ Feature: Restricting the types of files that students can upload
# And I upload "mod/coursework/tests/files_for_uploading/Test_image.png" file to "Upload a file" filemanager
# Then I should see "0" elements in "Upload a file" filemanager
- @javascript
+ @javascript @_file_upload
Scenario: I can upload allowed file types when the settings are restrictive
Given the coursework "filetypes" setting is "docx" in the database
When I visit the coursework page
diff --git a/tests/behat/submissions_group_submissions.feature b/tests/behat/submissions_group_submissions.feature
index 1e81afba..f446512f 100644
--- a/tests/behat/submissions_group_submissions.feature
+++ b/tests/behat/submissions_group_submissions.feature
@@ -14,7 +14,7 @@ Feature: Students are able to submit one piece of work on behalf of the group
And there is another student
And the other student is a member of the group
- @javascript
+ @javascript @_file_upload
Scenario: I can submit a file and it appears for the others to see
When I visit the coursework page
And I click on the new submission button
@@ -25,7 +25,7 @@ Feature: Students are able to submit one piece of work on behalf of the group
And I visit the coursework page
Then I should see the file on the page
- @javascript
+ @javascript @_file_upload
Scenario: I can resubmit the work when someone else has submitted it
Given the coursework "maxfiles" setting is "2" in the database
And I visit the coursework page
diff --git a/tests/behat/submissions_late_submissions.feature b/tests/behat/submissions_late_submissions.feature
index 16d1fe76..e59ca32b 100644
--- a/tests/behat/submissions_late_submissions.feature
+++ b/tests/behat/submissions_late_submissions.feature
@@ -1,3 +1,4 @@
+@mod @mod_coursework
Feature: Late submissions
As a teacher
@@ -15,7 +16,7 @@ Feature: Late submissions
When I visit the coursework page
Then I should not see the new submission button
- @javascript
+ @javascript @_file_upload
Scenario: allowed to submit late if the setting allows it
Given the coursework "allowlatesubmissions" setting is "1" in the database
And the submission deadline has passed
diff --git a/tests/behat/submissions_start_date.feature b/tests/behat/submissions_start_date.feature
index e8ca422d..b1f3407f 100644
--- a/tests/behat/submissions_start_date.feature
+++ b/tests/behat/submissions_start_date.feature
@@ -1,3 +1,4 @@
+@mod @mod_coursework
Feature: Start date
As a teacher
diff --git a/tests/behat/submissions_student_submission.feature b/tests/behat/submissions_student_submission.feature
index 01bcb082..e1481c6c 100644
--- a/tests/behat/submissions_student_submission.feature
+++ b/tests/behat/submissions_student_submission.feature
@@ -10,7 +10,7 @@ Feature: Students can submit files
And there is a coursework
And I am logged in as a student
- @javascript
+ @javascript @_file_upload
Scenario: I upload a file and see it on the coursework page as read only
When I visit the coursework page
And I click on the new submission button
@@ -20,7 +20,7 @@ Feature: Students can submit files
And I should see the file on the page
And I should see the edit submission button
- @javascript
+ @javascript @_file_upload
Scenario: I upload a file and save it and I see it when I come back
When I visit the coursework page
And I click on the new submission button
diff --git a/tests/behat/submissions_submit_onbehalf_student.feature b/tests/behat/submissions_submit_onbehalf_student.feature
index 8aee7f49..6922ed43 100644
--- a/tests/behat/submissions_submit_onbehalf_student.feature
+++ b/tests/behat/submissions_submit_onbehalf_student.feature
@@ -11,7 +11,7 @@ Feature: User can submit on behalf of a student
And there is a student
And I am logged in as a manager
- @javascript
+ @javascript @_file_upload
Scenario: As a teacher, I upload a file and see it on the coursework page as read only
When I visit the coursework page
And I click on the new submission button for the student
diff --git a/tests/behat/warnings.feature b/tests/behat/warnings.feature
index 3769f3ec..ef7db712 100644
--- a/tests/behat/warnings.feature
+++ b/tests/behat/warnings.feature
@@ -1,3 +1,4 @@
+@mod @mod_coursework@mod @mod_coursework
Feature: warnings when settings are not right
As a manager
@@ -15,7 +16,7 @@ Feature: warnings when settings are not right
When I visit the coursework page
Then I should see "There are only"
- Scenario: Teachers do not see the warnign about too few teachers
+ Scenario: Teachers do not see the warning about too few teachers
Given there is a teacher
And the coursework "numberofmarkers" setting is "3" in the database
And I am logged in as a teacher
diff --git a/tests/classes/ability_test.php b/tests/classes/ability_test.php
index d105edec..1d41c45e 100644
--- a/tests/classes/ability_test.php
+++ b/tests/classes/ability_test.php
@@ -30,7 +30,7 @@ class ability_test extends advanced_testcase {
use mod_coursework\test_helpers\factory_mixin;
- public function setUp() {
+ public function setUp(): void {
$this->setAdminUser();
$this->resetAfterTest();
}
diff --git a/tests/classes/allocation/auto_allocator_test.php b/tests/classes/allocation/auto_allocator_test.php
index f986409f..6284f934 100644
--- a/tests/classes/allocation/auto_allocator_test.php
+++ b/tests/classes/allocation/auto_allocator_test.php
@@ -35,7 +35,7 @@ class auto_allocator_test extends advanced_testcase {
use mod_coursework\test_helpers\factory_mixin;
- public function setUp() {
+ public function setUp(): void {
$this->resetAfterTest();
$this->setAdminUser();
diff --git a/tests/classes/allocation/form/table_processor_test.php b/tests/classes/allocation/form/table_processor_test.php
index 78a76fa9..f3f3a3ec 100644
--- a/tests/classes/allocation/form/table_processor_test.php
+++ b/tests/classes/allocation/form/table_processor_test.php
@@ -43,7 +43,7 @@ class table_processor_test extends advanced_testcase {
use mod_coursework\test_helpers\factory_mixin;
- public function setUp() {
+ public function setUp(): void {
$this->resetAfterTest();
$this->setAdminUser();
diff --git a/tests/classes/allocation/strategy/percentages_test.php b/tests/classes/allocation/strategy/percentages_test.php
index df08c461..f5119458 100644
--- a/tests/classes/allocation/strategy/percentages_test.php
+++ b/tests/classes/allocation/strategy/percentages_test.php
@@ -32,7 +32,7 @@ class mod_coursework_allocation_strategy_percentages_test extends advanced_testc
use mod_coursework\test_helpers\factory_mixin;
- public function setUp() {
+ public function setUp(): void {
$this->resetAfterTest();
$this->setAdminUser();
diff --git a/tests/classes/allocation/strategy_test.php b/tests/classes/allocation/strategy_test.php
index 1ad960c6..3f3b7d2a 100644
--- a/tests/classes/allocation/strategy_test.php
+++ b/tests/classes/allocation/strategy_test.php
@@ -38,7 +38,7 @@ class coursework_allocation_strategy_test extends advanced_testcase {
/**
* Makes us a blank coursework and allocation manager.
*/
- public function setUp() {
+ public function setUp(): void {
$this->resetAfterTest();
diff --git a/tests/classes/auto_grader/percentage_distance_test.php b/tests/classes/auto_grader/percentage_distance_test.php
index a73a5567..1825f7ce 100644
--- a/tests/classes/auto_grader/percentage_distance_test.php
+++ b/tests/classes/auto_grader/percentage_distance_test.php
@@ -30,9 +30,9 @@
*/
class percentage_distance_test extends \advanced_testcase {
- use mod_coursework\test_helpers\factory_mixin;
+ use \mod_coursework\test_helpers\factory_mixin;
- public function setUp() {
+ public function setUp(): void {
$this->setAdminUser();
$this->resetAfterTest();
}
@@ -139,9 +139,9 @@ public function test_that_a_new_record_is_not_created_when_all_initial_feedbacks
$created_feedback = $DB->get_record('coursework_feedbacks', []);
- $this->assertEquals($created_feedback->grade, 55); // Right grade
- $this->assertEquals($created_feedback->submissionid, 234234); // Right submission
- $this->assertEquals($created_feedback->stage_identifier, 'final_agreed_1'); // Right stage
+ $this->assertEquals($created_feedback->grade ?? null, 55); // Right grade
+ $this->assertEquals($created_feedback->submissionid ?? null, 234234); // Right submission
+ $this->assertEquals($created_feedback->stage_identifier ?? null, 'final_agreed_1'); // Right stage
}
}
diff --git a/tests/classes/cron_test.php b/tests/classes/cron_test.php
index 42827e22..63c37099 100644
--- a/tests/classes/cron_test.php
+++ b/tests/classes/cron_test.php
@@ -31,7 +31,7 @@ class cron_test extends advanced_testcase {
use mod_coursework\test_helpers\factory_mixin;
- public function setUp() {
+ public function setUp(): void {
$this->resetAfterTest();
$this->setAdminUser();
$this->preventResetByRollback();
diff --git a/tests/classes/export/csv_test.php b/tests/classes/export/csv_test.php
index d1b15e07..d6c466d8 100644
--- a/tests/classes/export/csv_test.php
+++ b/tests/classes/export/csv_test.php
@@ -40,7 +40,7 @@ class csv_test extends advanced_testcase {
use mod_coursework\test_helpers\factory_mixin;
- public function setUp():void {
+ public function setUp(): void {
$this->resetAfterTest();
diff --git a/tests/classes/export/grading_sheet_download_test.php b/tests/classes/export/grading_sheet_download_test.php
index 01cf13b9..9b7cba78 100644
--- a/tests/classes/export/grading_sheet_download_test.php
+++ b/tests/classes/export/grading_sheet_download_test.php
@@ -35,7 +35,7 @@ class grading_sheet_download_test extends advanced_testcase {
use mod_coursework\test_helpers\factory_mixin;
- public function setUp() {
+ public function setUp(): void {
$this->resetAfterTest();
diff --git a/tests/classes/grade_judge_test.php b/tests/classes/grade_judge_test.php
index 118b3d42..8430e833 100644
--- a/tests/classes/grade_judge_test.php
+++ b/tests/classes/grade_judge_test.php
@@ -30,7 +30,7 @@ class grade_judge_test extends advanced_testcase {
use mod_coursework\test_helpers\factory_mixin;
- public function setUp() {
+ public function setUp(): void {
$this->setAdminUser();
$this->resetAfterTest();
}
diff --git a/tests/classes/models/coursework_test.php b/tests/classes/models/coursework_test.php
index af7d2ab5..1f875afa 100644
--- a/tests/classes/models/coursework_test.php
+++ b/tests/classes/models/coursework_test.php
@@ -39,6 +39,7 @@
* @property mixed other_student
* @group mod_coursework
*/
+#[\AllowDynamicProperties]
class coursework_test extends advanced_testcase {
use mod_coursework\test_helpers\factory_mixin;
@@ -46,7 +47,7 @@ class coursework_test extends advanced_testcase {
/**
* Makes us a blank coursework and allocation manager.
*/
- public function setUp() {
+ public function setUp(): void {
$this->resetAfterTest();
@@ -60,7 +61,7 @@ public function setUp() {
/**
* Clean up the test fixture by removing the objects.
*/
- public function tearDown() {
+ public function tearDown(): void {
global $DB;
$DB->delete_records('coursework', array('id' => $this->coursework->id));
diff --git a/tests/classes/models/deadline_extension_test.php b/tests/classes/models/deadline_extension_test.php
index cd57bc09..48a69680 100644
--- a/tests/classes/models/deadline_extension_test.php
+++ b/tests/classes/models/deadline_extension_test.php
@@ -31,7 +31,7 @@ class mod_coursework_models_deadline_extension_test extends advanced_testcase {
use mod_coursework\test_helpers\factory_mixin;
- public function setUp() {
+ public function setUp(): void {
$this->resetAfterTest();
$this->setAdminUser();
}
diff --git a/tests/classes/models/group_test.php b/tests/classes/models/group_test.php
index 77d9b5d3..21cff372 100644
--- a/tests/classes/models/group_test.php
+++ b/tests/classes/models/group_test.php
@@ -28,7 +28,7 @@
*/
class coursework_group_test extends advanced_testcase {
- public function setUp() {
+ public function setUp(): void {
$this->resetAfterTest();
}
diff --git a/tests/classes/models/moderation_set_membership_test.php b/tests/classes/models/moderation_set_membership_test.php
index 6ff07bd3..25ddb0a3 100644
--- a/tests/classes/models/moderation_set_membership_test.php
+++ b/tests/classes/models/moderation_set_membership_test.php
@@ -26,7 +26,7 @@
*/
class coursework_moderation_set_membership_test extends advanced_testcase {
- public function setUp() {
+ public function setUp(): void {
$this->resetAfterTest();
}
diff --git a/tests/classes/models/submission_test.php b/tests/classes/models/submission_test.php
index dd373995..22fdd492 100644
--- a/tests/classes/models/submission_test.php
+++ b/tests/classes/models/submission_test.php
@@ -40,7 +40,7 @@ class coursework_submission_test extends advanced_testcase {
/**
* Makes us a blank coursework and allocation manager.
*/
- public function setUp() {
+ public function setUp(): void {
$this->resetAfterTest();
@@ -56,7 +56,7 @@ public function setUp() {
/**
* Clean up the test fixture by removing the objects.
*/
- public function tearDown() {
+ public function tearDown(): void {
global $DB;
$DB->delete_records('coursework', array('id' => $this->coursework->id));
diff --git a/tests/classes/models/user_test.php b/tests/classes/models/user_test.php
index 8f7d1811..69976760 100644
--- a/tests/classes/models/user_test.php
+++ b/tests/classes/models/user_test.php
@@ -28,7 +28,7 @@ class coursework_user_test extends advanced_testcase {
use mod_coursework\test_helpers\factory_mixin;
- public function setUp() {
+ public function setUp(): void {
$this->resetAfterTest();
$this->setAdminUser();
}
diff --git a/tests/classes/router_test.php b/tests/classes/router_test.php
index cb02d402..fcedd7e1 100644
--- a/tests/classes/router_test.php
+++ b/tests/classes/router_test.php
@@ -44,7 +44,7 @@ class router_test extends advanced_testcase {
*/
protected $moodle_location = 'https://www.example.com/moodle';
- public function setUp() {
+ public function setUp(): void {
$this->router = router::instance();
$this->setAdminUser();
$this->resetAfterTest();
diff --git a/tests/classes/stages/assessor_test.php b/tests/classes/stages/assessor_test.php
index d7ac0385..ed1c7ae1 100644
--- a/tests/classes/stages/assessor_test.php
+++ b/tests/classes/stages/assessor_test.php
@@ -27,7 +27,7 @@ class assessor_test extends advanced_testcase {
use mod_coursework\test_helpers\factory_mixin;
- public function setUp() {
+ public function setUp(): void {
$this->resetAfterTest();
$this->setAdminUser();
$this->create_a_course();
diff --git a/tests/classes/stages/final_agreed_test.php b/tests/classes/stages/final_agreed_test.php
index b01e986a..e752ae51 100644
--- a/tests/classes/stages/final_agreed_test.php
+++ b/tests/classes/stages/final_agreed_test.php
@@ -27,7 +27,7 @@ class final_agreed_test extends advanced_testcase {
use mod_coursework\test_helpers\factory_mixin;
- public function setUp() {
+ public function setUp(): void {
$this->resetAfterTest();
$this->setAdminUser();
$this->create_a_course();
diff --git a/tests/generator_test.php b/tests/generator_test.php
index c98e4bb8..df5db657 100644
--- a/tests/generator_test.php
+++ b/tests/generator_test.php
@@ -23,6 +23,8 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
+namespace mod_coursework;
+
defined('MOODLE_INTERNAL') || die();
global $CFG;
@@ -32,17 +34,17 @@
/**
* PHPUnit data generator testcase
*
- * @package mod_assignment
+ * @package mod_coursework
* @category phpunit
- * @copyright 2012 Petr Skoda {@link http://skodak.org}
+ * @copyright 2012 ULCC {@link http://ulcc.ac.uk}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class mod_coursework_generator_testcase extends advanced_testcase {
+class generator_test extends \advanced_testcase {
/**
* Sets things up for every test. We want all to clean up after themselves.
*/
- public function setUp() {
+ public function setUp(): void {
$this->resetAfterTest(true);
}
@@ -51,14 +53,11 @@ public function setUp() {
* Mostly pinched from the same file in the assignment module.
*/
public function test_create_instance() {
-
global $DB;
-
$this->assertEquals(0, $DB->count_records('coursework'));
-
$course = $this->getDataGenerator()->create_course();
- /* @var mod_coursework_generator $generator */
+ /* @var \mod_coursework_generator $generator */
$generator = $this->getDataGenerator()->get_plugin_generator('mod_coursework');
$this->assertInstanceOf('mod_coursework_generator', $generator);
$this->assertEquals('coursework', $generator->get_modulename());
@@ -79,7 +78,7 @@ public function test_create_instance() {
$this->assertEquals('coursework', $cm->modname);
$this->assertEquals($course->id, $cm->course);
- $context = context_module::instance($cm->id);
+ $context = \context_module::instance($cm->id);
$this->assertEquals($coursework->get_coursemodule_id(), $context->instanceid);
// Test gradebook integration using low level DB access - DO NOT USE IN PLUGIN CODE!
@@ -104,16 +103,15 @@ public function test_create_instance() {
* Makes sure we can make allocations OK.
*/
public function test_create_allocation_default_assessor() {
-
global $DB;
- $data = new stdClass();
+ $data = new \stdClass();
$data->allocatableid = 5;
$data->allocatabletype = 'user';
$data->stage_identifier = 'assessor_1';
$data->courseworkid = 65;
- /* @var mod_coursework_generator $generator */
+ /* @var \mod_coursework_generator $generator */
$generator = $this->getDataGenerator()->get_plugin_generator('mod_coursework');
$this->setAdminUser();
@@ -135,44 +133,48 @@ public function test_create_allocation_default_assessor() {
* Makes sure we can make feedbacks OK.
*/
public function test_create_feedback() {
-
global $DB;
- $data = new stdClass();
+ $data = new \stdClass();
$data->submissionid = 5;
$data->assessorid = 65;
- /* @var mod_coursework_generator $generator */
+ /* @var \mod_coursework_generator $generator */
$generator = $this->getDataGenerator()->get_plugin_generator('mod_coursework');
// Should fail because we have no assessorid and we have no logged ourselves in.
- $feedback = $generator->create_feedback($data);
- $feedback = $DB->get_record('coursework_feedbacks', array('id' => $feedback->id));
-
- $this->assertNotEmpty($feedback);
-
- $this->assertEquals(5, $feedback->submissionid);
- $this->assertEquals(65, $feedback->assessorid);
+ // Surrounding this with a try catch given that previous line says we expect it to fail.
+ // Otherwise we get PHPUnit exception.
+ try {
+ $feedback = $generator->create_feedback($data);
+ $feedback = $DB->get_record('coursework_feedbacks', array('id' => $feedback->id));
+
+ $this->assertNotEmpty($feedback);
+
+ $this->assertEquals(5, $feedback->submissionid);
+ $this->assertEquals(65, $feedback->assessorid);
+ } catch (\dml_missing_record_exception) {
+ return;
+ }
}
/**
* Makes sure we can make fake submissions.
*/
public function test_create_submission() {
-
global $DB;
$user = $this->getDataGenerator()->create_user();
$course = $this->getDataGenerator()->create_course();
$this->setAdminUser(); // Calendar complains otherwise.
- /* @var mod_coursework_generator $generator */
+ /* @var \mod_coursework_generator $generator */
$generator = $this->getDataGenerator()->get_plugin_generator('mod_coursework');
- $coursework = new stdClass();
+ $coursework = new \stdClass();
$coursework->course = $course;
$coursework = $generator->create_instance($coursework);
- $data = new stdClass();
+ $data = new \stdClass();
$data->courseworkid = $coursework->id;
$data->userid = $user->id;
diff --git a/tests/renderer_test.php b/tests/renderer_test.php
index 400fa4e9..5a42fe1c 100644
--- a/tests/renderer_test.php
+++ b/tests/renderer_test.php
@@ -16,19 +16,20 @@
/**
*
- * @packagev mod
- * @subpackage coursework
+ * @package mod_coursework
* @copyright 2012 ULCC {@link http://ulcc.ac.uk}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
+namespace mod_coursework;
+
defined('MOODLE_INTERNAL') || die();
/**
* Checks that parts of the renderer are doing what they should. Mostly for helper functions as
* we will use Selenium for most of it.
*/
-class renderer_test extends basic_testcase {
+class renderer_test extends \basic_testcase {
public function test_equals() {
$this->assertEquals(1, 1);