Skip to content

Commit

Permalink
CTP-3783 adapt behat to commit c1132f6
Browse files Browse the repository at this point in the history
  • Loading branch information
watson8 committed Oct 8, 2024
1 parent 71b27fc commit 5edf9f3
Show file tree
Hide file tree
Showing 19 changed files with 249 additions and 139 deletions.
10 changes: 8 additions & 2 deletions classes/controllers/feedback_controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,14 @@ protected function new_feedback() {
}

$ability = new ability(user::find($USER), $this->coursework);
$ability->require_can('new', $teacherfeedback);

if (!$ability->can('new', $teacherfeedback)) {
if ($this->params['ajax']) {
echo json_encode(['success' => false, 'message' => $ability->get_last_message()]);
die();
} else {
throw new access_denied($this->coursework, $ability->get_last_message());
}
}
$this->check_stage_permissions($this->params['stage_identifier']);

$urlparams = [];
Expand Down
7 changes: 0 additions & 7 deletions classes/models/outstanding_marking.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,6 @@

class outstanding_marking {

private $dayinsecs;

public function __construct() {

$this->day_in_secs = 86400;
}

/**
* @param $cwkrecord
* @param $userid
Expand Down
4 changes: 2 additions & 2 deletions classes/test_helpers/factory_mixin.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public function create_a_group_submission_for_the_student() {
* @return feedback
* @throws coding_exception
*/
public function create_a_final_feedback_for_the_submisison() {
public function create_a_final_feedback_for_the_submission() {
$generator = $this->get_coursework_generator();
$feedback = new stdClass();
$feedback->submissionid = $this->get_submission()->id;
Expand All @@ -269,7 +269,7 @@ public function create_a_final_feedback_for_the_submisison() {
* @return stdClass
* @throws \coding_exception
*/
public function create_an_assessor_feedback_for_the_submisison($assessor) {
public function create_an_assessor_feedback_for_the_submission($assessor) {
$count = $this->number_of_assessor_feedbacks();

$generator = $this->get_coursework_generator();
Expand Down
4 changes: 2 additions & 2 deletions datatables/js/datatables.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ $( document ).ready(function() {
}
else {
$('<tr class = "submissionrowmultisub row_assessors">'+
'<td class="assessors" colspan = "11"><table class="assessors" style="width:95%">' + $('#' + table_id).clone().html() + '</table></td>' +
'<td class="assessors" colspan = "11"><table class="assessors assessors_expanded" style="width:95%">' + $('#' + table_id).clone().html() + '</table></td>' +
'</tr>').insertAfter($(tr));
}

Expand Down Expand Up @@ -285,7 +285,7 @@ $( document ).ready(function() {
// row.child( format(row.data()) ).show();
row.child($(
'<table class="assessors" width="100%"><tr class = "submissionrowmultisub">'+
'<td class="assessors" colspan = "11"><table class="assessors">' + $('#' + table_id).clone().html() + '</table></td>' +
'<td class="assessors" colspan = "11"><table class="assessors assessors_expanded">' + $('#' + table_id).clone().html() + '</table></td>' +
'</tr></table>'
)).show();
tr.addClass('shown');
Expand Down
63 changes: 33 additions & 30 deletions datatables/js/edit_datatables.js
Original file line number Diff line number Diff line change
Expand Up @@ -727,41 +727,44 @@ $(document).ready(function () {
}).done(function(response) {
response = $.parseJSON(response);
var modalbody = $('#modal-grading').find('.modal-body');
modalbody.html(response.formhtml);
var filemanager = modalbody.find('.filemanager');
if (response.filemanageroptions && filemanager.length) {
var elementid = filemanager.attr('id');
var clientid = elementid.substr(12);
if (clientid) {
response.filemanageroptions.client_id = clientid;
M.form_filemanager.init(Y, response.filemanageroptions);
// Careful as not all requests return a response.success value. Only if it's false, show error.
if ((response.success ?? true) === false && (response.message ?? null)) {
modalbody.html(response.message);
} else {
modalbody.html(response.formhtml);
var filemanager = modalbody.find('.filemanager');
if (response.filemanageroptions && filemanager.length) {
var elementid = filemanager.attr('id');
var clientid = elementid.substr(12);
if (clientid) {
response.filemanageroptions.client_id = clientid;
M.form_filemanager.init(Y, response.filemanageroptions);
}
}
}
if (response.editoroptions) {
require(['editor_tiny/editor'], (Tiny) => {
Tiny.setupForElementId({
elementId: 'id_feedbackcomment',
options: JSON.parse(response.editoroptions),
if (response.editoroptions) {
require(['editor_tiny/editor'], (Tiny) => {
Tiny.setupForElementId({
elementId: 'id_feedbackcomment',
options: JSON.parse(response.editoroptions),
});
});
});
}

if (response.commentoptions) {
M.util.js_pending('gradingform_guide/comment_chooser');
require(['gradingform_guide/comment_chooser'], function(amd) {
$(".remark").each( function (i,ele) {
buttonele = $(ele).find(".commentchooser");
textele = $(ele).find(".markingguideremark");

buttonid = $(buttonele).attr("id");
textid = $(textele).attr("id");
}

amd.initialise(1, buttonid, textid, response.commentoptions) ;
M.util.js_complete('gradingform_guide/comment_chooser');
if (response.commentoptions) {
M.util.js_pending('gradingform_guide/comment_chooser');
require(['gradingform_guide/comment_chooser'], function(amd) {
$(".remark").each( function (i,ele) {
buttonele = $(ele).find(".commentchooser");
textele = $(ele).find(".markingguideremark");
buttonid = $(buttonele).attr("id");
textid = $(textele).attr("id");
amd.initialise(1, buttonid, textid, response.commentoptions);
M.util.js_complete('gradingform_guide/comment_chooser');

})
})

});
});
}
}
});
var cell_td = $(this).closest('td');
Expand Down
66 changes: 64 additions & 2 deletions tests/behat/behat_mod_coursework.php
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,28 @@ public function i_click_on_the_new_feedback_button_for_assessor($assessornumber)

}

/**
* The UI may contain multiple "New feedback" buttons some of which are not interactable
* @Given /^I click on the only interactable link with title "(?P<linktitle_string>(?:[^"]|\\")*)"$/
* @param string $linktitle
*/
public function i_click_on_the_only_interactable_link_with_title(string $linktitle) {
$nodes = $this->find_all('link', $linktitle);
$visible = [];
foreach ($nodes as $node) {
if ($node->isVisible()) {
$visible[] = $node;
}
}
$countvisible = count($visible);
if ($countvisible !== 1) {
throw new ExpectationException(
"Expected one '$linktitle' visible link but found $countvisible", $this->getSession()
);
}
reset($visible)->click();
}

/**
* @Given /^I click on the new feedback button for assessor (\d+) for another student$/
* @param $assessornumber
Expand Down Expand Up @@ -1992,7 +2014,7 @@ public function there_is_final_feedback() {
}

/**
* @Given /^there is final feedback from the other teacher$/
* @Given /^there is final feedback from the other teacher with grade 45$/
*/
public function there_is_final_feedback_from_the_other_teacher() {
$generator = $this->get_coursework_generator();
Expand Down Expand Up @@ -2169,7 +2191,7 @@ public function i_should_see_the_final_single_grade_on_the_page($grade = 56) {
}

/**
* @Given /^I have an assessor feedback$/
* @Given /^I have an assessor feedback at grade 67$/
*/
public function i_have_an_assessor_feedback() {
/**
Expand Down Expand Up @@ -2267,6 +2289,46 @@ public function i_grade_the_submission_using_the_simple_form($grade = 56, $witho
$this->feedback = feedback::last();
}

/**
* Launch the grade submission modal and complete with grade/comment.
* @When /^I grade the submission(?: as )?(\d+)? using the ajax form$/
*
* @param int $grade
* @param bool $withoutcomments
* @throws Behat\Mink\Exception\ElementException
* @throws Behat\Mink\Exception\ElementNotFoundException
*/
public function i_grade_the_submission_using_the_ajax_form($grade = 56) {
// Form loaded and sent by AJAX now so wait for it to load.
$this->wait_for_pending_js();
$this->wait_for_seconds(1);
$this->execute('behat_forms::i_set_the_field_to', [$this->escape("Grade"), $grade]);
$this->execute(
'behat_forms::i_set_the_field_to', [$this->escape("Comment"), "New comment here"]
);
$this->wait_for_pending_js();
$this->execute(
'behat_general::i_click_on', [get_string('saveandfinalise', 'coursework'), 'button']
);
$this->wait_for_pending_js();
$this->wait_for_seconds(2);
$this->assertSession()->pageTextContains(get_string('alert_feedback_save_successful', 'coursework'));
$this->feedback = feedback::last();
}

/**
* Expand the row in the grading form to expose feedback button.
* @When /^I expand the coursework grading row$/
* @return void
*/
public function i_expand_the_grading_row() {
$this->execute(
'behat_general::i_click_on', ['.details-control', 'css_element']
);
$this->wait_for_pending_js();
$this->wait_for_seconds(1);
}

/**
* @Then /^I should see the final grade for the group in the grading interface$/
*
Expand Down
37 changes: 20 additions & 17 deletions tests/behat/feedback_collisions.feature
Original file line number Diff line number Diff line change
Expand Up @@ -13,39 +13,42 @@ Feature: Collisions: two people try to create feedback at the same time
And the student has a submission
And the submission is finalised

Scenario: Single marker: If I submit feedback and it's already been given then the form should reload with a warning
@javascript
Scenario: Single marker: If I submit feedback and it's already been given then the form should show a warning
Given there is a teacher
And there is another teacher
And I am logged in as the other teacher
And the coursework is set to single marker
When I visit the coursework page
And I have an assessor feedback at grade 67
And I click the new single final feedback button for the student
And I have an assessor feedback
When I grade the submission using the simple form
Then I should be on the create feedback page
And I should see "has already submitted"
Then I should see the grade comment in the form on the page
And I should see the grade in the form on the page
And I should see "Allocatable already has feedback for this stage"

@javascript
Scenario: Multiple marker: If I submit feedback and it's already been given then it should be given a new stage_identifier
Given there is a teacher
And there is another teacher
And I am logged in as the other teacher
And the coursework is set to double marker
When I visit the coursework page
And I click on the new feedback button for assessor 1
And I have an assessor feedback
When I grade the submission using the simple form
Then I should be on the coursework page
And I have an assessor feedback at grade 67
And I visit the coursework page
And I expand the coursework grading row
And I click on "New feedback" "link"
And I grade the submission as 56 using the ajax form

@javascript
Scenario: Multiple marker: If I submit feedback and it's already been given by all teachers then it should fail
Given there is a teacher
And there is another teacher
And I am logged in as a manager
And the coursework is set to double marker
When I visit the coursework page
And I click on the new feedback button for assessor 1
And I have an assessor feedback
And there is final feedback from the other teacher
When I grade the submission using the simple form
Then I should be on the create feedback page
And I have an assessor feedback at grade 67
And there is final feedback from the other teacher with grade 45
And I expand the coursework grading row
And I wait until the page is ready
And I wait "2" seconds
And I click on "New feedback" "link"
And I wait until the page is ready
And I wait "2" seconds
And I should see "Allocatable already has feedback for this stage"
2 changes: 1 addition & 1 deletion tests/behat/feedback_files.feature
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@_file_upload
@mod @mod_coursework @_file_upload
Feature: Adding feedback files

As a teacher
Expand Down
38 changes: 22 additions & 16 deletions tests/behat/feedback_final_feedback_double_marking.feature
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@mod @mod_coursework
@mod @mod_coursework @mod_coursework_feedback_final_feedback_double_marking
Feature: Adding and editing final feedback

In order to provide students with a fair final grade that combines the component grades
Expand All @@ -15,42 +15,48 @@ Feature: Adding and editing final feedback
And the student has a submission
And the submission is finalised

@javascript
Scenario: Setting the final feedback grade
Given there are feedbacks from both teachers
And I am logged in as a manager
And I visit the coursework page
When I click the new multiple final feedback button for the student
When I grade the submission using the simple form
Then I should be on the coursework page
And I should see the final grade on the multiple marker page
And I click the new multiple final feedback button for the student
And I grade the submission as 57 using the ajax form
Then I visit the coursework page
And I should see the final grade as 57 on the multiple marker page

@javascript
Scenario: Setting the final feedback comment
Given there are feedbacks from both teachers
And I am logged in as a manager
And I visit the coursework page
When I click the new multiple final feedback button for the student
When I grade the submission using the simple form
Then I should be on the coursework page
And I click the new multiple final feedback button for the student
And I grade the submission as 58 using the ajax form
Then I visit the coursework page
When I click the edit final feedback button
Then I should see the grade comment in the form on the page
And I should see the grade in the form on the page
And I wait until the page is ready
And I wait "1" seconds
And the field "Grade" matches value "58"
And the field "Comment" matches value "New comment here"

@javascript
Scenario: I can be both an initial assessor and the manager who agrees grades
And managers do not have the manage capability
Given I am logged in as a manager
And there are feedbacks from both me and another teacher
And I visit the coursework page
When I click the new multiple final feedback button for the student
And I grade the submission using the simple form
Then I should be on the coursework page
And I grade the submission as 59 using the ajax form

@javascript
Scenario: Editing final feedback from others
And managers do not have the manage capability
Given I am logged in as a manager
And there are feedbacks from both me and another teacher
And there is final feedback from the other teacher
And there is final feedback from the other teacher with grade 45
When I visit the coursework page
When I click the edit final feedback button
And I should see the other teacher's final grade in the form on the page
And I grade the submission using the simple form
Then I should be on the coursework page
And I wait until the page is ready
And I wait "2" seconds
And I wait until the page is ready
And the field "Grade" matches value "45"
9 changes: 5 additions & 4 deletions tests/behat/feedback_group_marking.feature
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@mod @mod_coursework
@mod @mod_coursework @mod_coursework_feedback_group_marking
Feature: Marking the group submissions applies the grades to the whole group

As a teacher
Expand All @@ -22,10 +22,11 @@ Feature: Marking the group submissions applies the grades to the whole group
And there are feedbacks from both teachers
And I am logged in as a manager

@javascript
Scenario: grading the submission makes the grades show up for both students in the interface
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
Then I should be on the coursework page
And I grade the submission as 56 using the ajax form
Then I visit the coursework page
And I wait "2" seconds
And I should see the final grade for the group in the grading interface
Loading

0 comments on commit 5edf9f3

Please sign in to comment.