From 8c8c257f8e7860141103242ac6c876e77bb2b5d5 Mon Sep 17 00:00:00 2001 From: David Watson <14983002+watson8@users.noreply.github.com> Date: Tue, 22 Oct 2024 11:43:18 +0100 Subject: [PATCH] CTP-3783 deadlines 2 --- .../deadline_extensions_controller.php | 3 +- .../renderers/deadline_extension_renderer.php | 6 +-- lang/en/coursework.php | 2 +- tests/behat/behat_mod_coursework.php | 50 +++++++++++-------- tests/behat/deadline_extension.feature | 27 +++++++--- ...ine_extension_reason_dropdown_list.feature | 8 +-- 6 files changed, 59 insertions(+), 37 deletions(-) diff --git a/classes/controllers/deadline_extensions_controller.php b/classes/controllers/deadline_extensions_controller.php index 1a632169..c0d2af7c 100644 --- a/classes/controllers/deadline_extensions_controller.php +++ b/classes/controllers/deadline_extensions_controller.php @@ -39,10 +39,9 @@ * @property deadline_extension_form form * @package mod_coursework\controllers */ +#[\AllowDynamicProperties] class deadline_extensions_controller extends controller_base { - private $deadlineextension; - protected function show_deadline_extension() { global $USER, $PAGE; diff --git a/classes/renderers/deadline_extension_renderer.php b/classes/renderers/deadline_extension_renderer.php index a613c069..bdd14f72 100644 --- a/classes/renderers/deadline_extension_renderer.php +++ b/classes/renderers/deadline_extension_renderer.php @@ -43,7 +43,7 @@ public function show_page($vars) { /** * @var allocatable $allocatable */ - $allocatable = $vars['deadline_extension']->get_allocatable(); + $allocatable = $vars['deadlineextension']->get_allocatable(); $PAGE->set_pagelayout('standard'); $heading = 'Deadline extension for ' . $allocatable->name(); @@ -70,7 +70,7 @@ public function new_page($vars) { $PAGE->set_title($SITE->fullname); $PAGE->set_heading($SITE->fullname); - $allocatable = $vars['deadline_extension']->get_allocatable(); + $allocatable = $vars['deadlineextension']->get_allocatable(); $html = '

Adding a new extension to the deadline for '.$allocatable->name().'

'; @@ -88,7 +88,7 @@ public function new_page($vars) { public function edit_page($vars) { global $PAGE, $SITE, $OUTPUT; - $allocatable = $vars['deadline_extension']->get_allocatable(); + $allocatable = $vars['deadlineextension']->get_allocatable(); $PAGE->set_pagelayout('standard'); $PAGE->navbar->add('Edit deadline extension for '.$allocatable->name()); diff --git a/lang/en/coursework.php b/lang/en/coursework.php index 01103624..7836d7d6 100644 --- a/lang/en/coursework.php +++ b/lang/en/coursework.php @@ -60,7 +60,7 @@ $string['agreeterms'] = 'Students must agree to terms before submitting'; $string['agreetermsdescription'] = 'Students will see the message below and must click "I agree" before being allowed to continue to the file manager.'; $string['agreetermstext'] = 'Text of the terms that the student will agree to'; -$string['alert_extension_save_successful'] = 'Extension saved successfully!.'; +$string['alert_extension_save_successful'] = 'Extension saved successfully!'; $string['alert_feedback_save_successful'] = 'Your data has been saved.'; $string['alert_feedback_draft_save_successful'] = 'Your data has been saved as a draft.'; $string['alert_feedback_remove_successful'] = 'The feedback has been removed.'; diff --git a/tests/behat/behat_mod_coursework.php b/tests/behat/behat_mod_coursework.php index 973762bc..ef8240c1 100644 --- a/tests/behat/behat_mod_coursework.php +++ b/tests/behat/behat_mod_coursework.php @@ -1132,19 +1132,22 @@ public function there_is_an_extension_for_the_student_which_has_expired() { /** * I enter an extension in the form - * @When /^I enter an extension "(?P(?:[^"]|\\")*)" in the form$/ + * @When /^I enter an extension "(?P(?:[^"]|\\")*)" in the form(?: with reason code "(?P(?:[^"]|\\")*)")?$/ */ - public function i_enter_an_extension_in_the_form(string $timeextension) { + public function i_enter_an_extension_in_the_form(string $timeextension, string $reasoncode = '') { $newtime = strtotime('3:30pm', strtotime($timeextension)); // Put into format 30-09-2024 15:47. $newtimestring = date('d-m-Y H:i', $newtime); - $script = "document.querySelector('input#extension-extend-deadline').value = '$newtimestring'"; + $script = "const e = document.querySelector('input#extension-extend-deadline');" + . "e.value = '$newtimestring'; e.dispatchEvent(new Event('change'));"; behat_base::execute_script_in_session($this->getSession(), $script); + // The change event is to enable save button. - $reason = '0'; // 0 is "first reason" in the select menu - $script = "const e = document.querySelector('select#extension-reason-select');" - . "e.value = '$reason'; e.dispatchEvent(new Event('change'))"; - behat_base::execute_script_in_session($this->getSession(), $script); + if ($reasoncode) { + $reason = '0'; // 0 is "first reason" in the select menu + $script = "document.querySelector('select#extension-reason-select').value = '$reason'; "; + behat_base::execute_script_in_session($this->getSession(), $script); + } $extrainfo = 'Some extra information'; $script = "document.querySelector('textarea#id_extra_information').value = '$extrainfo'"; @@ -1153,9 +1156,9 @@ public function i_enter_an_extension_in_the_form(string $timeextension) { /** * I should see the extension in the form - * @When /^I should see the extension "(?P(?:[^"]|\\")*)" in the form$/ + * @When /^I should see the extension "(?P(?:[^"]|\\")*)" in the form(?: with reason code "(?P(?:[^"]|\\")*)")?$/ */ - public function i_should_see_the_extension_in_the_form(string $timeextension) { + public function i_should_see_the_extension_in_the_form(string $timeextension, string $reasoncode = '') { $newtime = strtotime('3:30pm', strtotime($timeextension)); // Put into format 30-09-2024 15:47. $newtimestring = date('d-m-Y H:i', $newtime); @@ -1165,10 +1168,12 @@ public function i_should_see_the_extension_in_the_form(string $timeextension) { throw new ExpectationException("Expected time '$newtimestring' got '$result'", $this->getSession()); } - $reason = '0'; // 0 is "first reason" in the select menu - $script = "document.querySelector('select#extension-reason-select').value === '$reason';"; - if (!$resulttwo = behat_base::evaluate_script_in_session($this->getSession(), $script)) { - throw new ExpectationException("Expected reason '$reason' got '$resulttwo'", $this->getSession()); + if ($reasoncode) { + // Reason code 0 is "first reason" in the select menu. + $script = "document.querySelector('select#extension-reason-select').value === '$reasoncode';"; + if (!$resulttwo = behat_base::evaluate_script_in_session($this->getSession(), $script)) { + throw new ExpectationException("Expected reason code '$reasoncode' got '$resulttwo'", $this->getSession()); + } } $extrainfo = 'Some extra information'; @@ -1179,14 +1184,19 @@ public function i_should_see_the_extension_in_the_form(string $timeextension) { } /** - * @Given /^I should see the extended deadline in the student row$/ + * @Given /^I should see the extended deadline "(?P(?:[^"]|\\")*)" in the student row$/ */ - public function i_should_see_the_extended_deadline_in_the_student_row() { - /** - * @var mod_coursework_behat_multiple_grading_interface $multigrader_page - */ - $multigraderpage = $this->get_page('multiple grading interface'); - $multigraderpage->should_show_extension_for_allocatable($this->student, $this->extensiondeadline); + public function i_should_see_the_extended_deadline_in_the_student_row(string $timestring) { + $newtime = strtotime('3:30pm', strtotime($timestring)); + // Put into format shown in UI. + $expectedtimestring = userdate($newtime, '%a, %d %b %Y, %H:%M'); + $node = $this->find('css', '.extension-submission'); + $text = $node->getText(); + if (!str_contains($text, $expectedtimestring)) { + throw new ExpectationException( + "Expected to see extension '$expectedtimestring' got '$text'", $this->getSession() + ); + } } /** diff --git a/tests/behat/deadline_extension.feature b/tests/behat/deadline_extension.feature index e35c0a0a..a94c9edf 100644 --- a/tests/behat/deadline_extension.feature +++ b/tests/behat/deadline_extension.feature @@ -1,4 +1,4 @@ -@mod @mod_coursework @RVC_PT_83106618 +@mod @mod_coursework @RVC_PT_83106618 @mod_coursework_deadline_extension Feature: Deadlines extensions for submissions As an OCM admin @@ -18,6 +18,7 @@ Feature: Deadlines extensions for submissions And I visit the coursework page Then I should see the new submission button + @javascript Scenario: The student can not submit when the start date is in the future Given the coursework deadline has passed And there is an extension for the student which has expired @@ -25,19 +26,31 @@ Feature: Deadlines extensions for submissions And I visit the coursework page Then I should not see the new submission button + @javascript 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 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 + And I click on "New extension" "link" + And I enter an extension "+1 week" in the form + And I click on "Save" "button" + And I wait until the page is ready + And I wait "1" seconds + And I should see "Extension saved successfully" + Then I visit the coursework page + And I should see the extended deadline "+1 week" in the student row + @javascript Scenario: The teacher can edit a deadline extension to an individual submission 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 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 + And I click on "Edit extension" "link" + And I enter an extension "+4 weeks" in the form + And I click on "Save" "button" + And I wait until the page is ready + And I wait "1" seconds + And I should see "Extension saved successfully" + Then I visit the coursework page + And I should see the extended deadline "+4 weeks" 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 87782600..cc358606 100644 --- a/tests/behat/deadline_extension_reason_dropdown_list.feature +++ b/tests/behat/deadline_extension_reason_dropdown_list.feature @@ -18,7 +18,7 @@ Feature: Deadline extension reasons dropdown list And I log in as a manager And I visit the coursework page And I click on "New extension" "link" - And I enter an extension "+1 week" in the form + And I enter an extension "+1 week" in the form with reason code "0" And I click on "Save" "button" And I wait until the page is ready And I wait "1" seconds @@ -27,7 +27,7 @@ Feature: Deadline extension reasons dropdown list When I click on the edit extension icon for the student And I wait until the page is ready And I wait "1" seconds - Then I should see the extension "+1 week" in the form + Then I should see the extension "+1 week" in the form with reason code "0" @javascript Scenario: The teacher can edit a deadline extension and its reason to an individual submission @@ -37,7 +37,7 @@ Feature: Deadline extension reasons dropdown list And I log in as a manager And I visit the coursework page And I click on "Edit extension" "link" - And I enter an extension "+4 weeks" in the form + And I enter an extension "+4 weeks" in the form with reason code "0" And I click on "Save" "button" And I wait until the page is ready And I wait "1" seconds @@ -46,4 +46,4 @@ Feature: Deadline extension reasons dropdown list And I click on the edit extension icon for the student And I wait until the page is ready And I wait "1" seconds - Then I should see the extension "+4 weeks" in the form + Then I should see the extension "+4 weeks" in the form with reason code "0"