Skip to content

Commit

Permalink
CTP-3783 deadlines 2
Browse files Browse the repository at this point in the history
  • Loading branch information
watson8 committed Oct 22, 2024
1 parent c0b0f7a commit 8c8c257
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 37 deletions.
3 changes: 1 addition & 2 deletions classes/controllers/deadline_extensions_controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
6 changes: 3 additions & 3 deletions classes/renderers/deadline_extension_renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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 = '<h1>Adding a new extension to the deadline for '.$allocatable->name().'</h1>';

Expand All @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion lang/en/coursework.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.';
Expand Down
50 changes: 30 additions & 20 deletions tests/behat/behat_mod_coursework.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<time_string>(?:[^"]|\\")*)" in the form$/
* @When /^I enter an extension "(?P<time_string>(?:[^"]|\\")*)" in the form(?: with reason code "(?P<reasoncode_string>(?:[^"]|\\")*)")?$/
*/
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'";
Expand All @@ -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<time_string>(?:[^"]|\\")*)" in the form$/
* @When /^I should see the extension "(?P<time_string>(?:[^"]|\\")*)" in the form(?: with reason code "(?P<reason_string>(?:[^"]|\\")*)")?$/
*/
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);
Expand All @@ -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';
Expand All @@ -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<time_string>(?:[^"]|\\")*)" 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()
);
}
}

/**
Expand Down
27 changes: 20 additions & 7 deletions tests/behat/deadline_extension.feature
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -18,26 +18,39 @@ 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
When I log in as a student
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
8 changes: 4 additions & 4 deletions tests/behat/deadline_extension_reason_dropdown_list.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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"

0 comments on commit 8c8c257

Please sign in to comment.