Skip to content

Commit

Permalink
MDL-76654 behat: fixes and data generator
Browse files Browse the repository at this point in the history
  • Loading branch information
lameze committed May 10, 2024
1 parent 67373e1 commit cb36c63
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 32 deletions.
71 changes: 43 additions & 28 deletions mod/workshop/tests/behat/self_assessment.feature
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ Feature: Workshop self-assessment
Background:
Given the following "users" exist:
| username | firstname | lastname | email |
| student1 | Sam1 | Student1 | student1@example.com |
| student2 | Sam2 | Student2 | student2@example.com |
| student3 | Sam3 | Student3 | student3@example.com |
| teacher1 | Terry1 | Teacher1 | teacher1@example.com |
| student1 | Student | One | student1@example.com |
| student2 | Student | Two | student2@example.com |
| student3 | Student | Three | student3@example.com |
| teacher1 | Teacher | One | teacher1@example.com |
And the following "courses" exist:
| fullname | shortname |
| Course1 | c1 |
Expand All @@ -25,18 +25,23 @@ Feature: Workshop self-assessment
| workshop | TestWorkshop | c1 | workshop1 | 1 |
And I am on the "TestWorkshop" "workshop activity" page logged in as teacher1
And I change phase in workshop "TestWorkshop" to "Submission phase"
And I am on the "TestWorkshop" "workshop activity" page logged in as student1
And I add a submission in workshop "TestWorkshop" as:"
| Title | Submission1 |
| Submission content | Some content |
And I am on the "TestWorkshop" "workshop activity" page logged in as student2
And I add a submission in workshop "TestWorkshop" as:"
| Title | Submission2 |
| Submission content | Some content |
And I am on the "TestWorkshop" "workshop activity" page logged in as student3
And I add a submission in workshop "TestWorkshop" as:"
| Title | Submission3 |
| Submission content | Some content |
# And I am on the "TestWorkshop" "workshop activity" page logged in as student1
# And I add a submission in workshop "TestWorkshop" as:"
# | Title | Submission1 |
# | Submission content | Some content |
# And I am on the "TestWorkshop" "workshop activity" page logged in as student2
# And I add a submission in workshop "TestWorkshop" as:"
# | Title | Submission2 |
# | Submission content | Some content |
# And I am on the "TestWorkshop" "workshop activity" page logged in as student3
# And I add a submission in workshop "TestWorkshop" as:"
# | Title | Submission3 |
# | Submission content | Some content |
And the following "mod_workshop > submissions" exist:
| workshop | user |
| workshop1 | student1 |
| workshop1 | student2 |
| workshop1 | student3 |
And I am on the "TestWorkshop" "workshop activity" page logged in as teacher1
And I click on "Submissions allocation" "link"
And I select "Random allocation" from the "jump" singleselect
Expand All @@ -45,25 +50,35 @@ Feature: Workshop self-assessment
And I press "Save changes"

Scenario: Student can assess their own submission

When I select "Manual allocation" from the "jump" singleselect
Then the "by" select box should contain "Sam1 Student1"
And the "by" select box should contain "Sam2 Student2"
And the "by" select box should contain "Sam3 Student3"
And I should see "Sam1 Student1" in the "Sam1 Student1" "table_row"
And I should see "Sam2 Student2" in the "Sam2 Student2" "table_row"
And I should see "Sam3 Student3" in the "Sam3 Student3" "table_row"
# Then the following should exist in the "allocations" table:
# | Participant is reviewed by | Participant | Participant is reviewer of |
# | Sam1 Student1 | Sam1 Student1 | Sam1 Student1 |
# | Sam2 Student2 | Sam2 Student2 | Sam2 Student2 |
# | Sam3 Student3 | Sam3 Student3 | Sam3 Student3 |
# there are 3 by elements with same name (by).
Then the "by" select box should contain "Student One"
And the "by" select box should contain "Student Two"
And the "by" select box should contain "Student Three"

# Verify that each student has themself listed as a reviewer.
Then the following should exist in the "allocations" table:
| -1- | -2- | -3- |
| Student One | Student One | Student One |
| Student Three | Student Three | Student Three |
| Student Two | Student Two | Student Two |
And I change phase in workshop "TestWorkshop" to "Assessment phase"
And I am on the "TestWorkshop" "workshop activity" page logged in as student1
# And I pause
And I should see "Assess yourself"
And I should see "Your submission"
And I should see "Assigned submissions to assess"
And I should see "Submission1"
And I should see "by Sam1 Student1"
# And I should see "by Sam1 Student1"
# And "//ul[@class='tasks']/li[div[@class='title' and contains(.,'Assess peers')]]/div[@class='details' and contains(.,'pending: 2') and contains(.,'total: 2')]" "xpath_element" should exist
# And I assess submission "Sam2" in workshop "TestWorkshop" as:
# | grade__idx_0 | 5 / 10 |
# | peercomment__idx_0 | You can do better |
# | grade__idx_1 | 10 / 10 |
# | peercomment__idx_1 | Amazing |
# | Feedback for the author | Good work |
# And "//ul[@class='tasks']/li[div[@class='title' and contains(.,'Assess peers')]]/div[@class='details' and contains(.,'pending: 1') and contains(.,'total: 2')]" "xpath_element" should exist
And the "Assess" "button" should be enabled
And I am on the "TestWorkshop" "workshop activity" page logged in as student2
And I should see "Assess yourself"
Expand Down
1 change: 1 addition & 0 deletions mod/workshop/tests/behat/workshop_assessment.feature
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ Feature: Workshop submission and assessment
And I change phase in workshop "TestWorkshop" to "Assessment phase"
# student1 assesses work of student2 and student3
And I am on the TestWorkshop "workshop activity" page logged in as student1
And I pause
And "//ul[@class='tasks']/li[div[@class='title' and contains(.,'Assess peers')]]/div[@class='details' and contains(.,'pending: 2') and contains(.,'total: 2')]" "xpath_element" should exist
And I assess submission "Sam2" in workshop "TestWorkshop" as:
| grade__idx_0 | 5 / 10 |
Expand Down
54 changes: 54 additions & 0 deletions mod/workshop/tests/generator/behat_mod_workshop_generator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Behat data generator for mod_workshop.
*
* @package mod_workshop
* @category test
* @copyright 2024 Simey Lameze
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class behat_mod_workshop_generator extends behat_generator_base
{

/**
* Get a list of the entities that Behat can create using the generator step.
*
* @return array
*/
protected function get_creatable_entities(): array
{
return [
'submissions' => [
'singular' => 'submission',
'datagenerator' => 'submission',
'required' => ['workshop', 'user'],
'switchids' => ['workshop' => 'workshopid', 'user' => 'authorid'],
],
];
}

/**
* Get the assignment CMID using an activity idnumber.
*
* @param string $idnumber
* @return int The cmid
*/
protected function get_workshop_id(string $idnumber): int {
return $this->get_activity_id($idnumber);
}
}
9 changes: 5 additions & 4 deletions mod/workshop/tests/generator/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,17 @@ public function create_instance($record = null, array $options = null) {
* @param stdClass|array $options Optional explicit properties.
* @return int The new submission id.
*/
public function create_submission($workshopid, $authorid, $options = null) {
public function create_submission(array $record = null, $options = null) {
global $DB;

$timenow = time();
$options = (array)$options;
$submission = (array)$record;
// $submission['workshopid'] = $record['workshopid'];
// $submission['authorid'] = $record['authorid'];

$record = $options + array(
'workshopid' => $workshopid,
'example' => 0,
'authorid' => $authorid,
'timecreated' => $timenow,
'timemodified' => $timenow,
'title' => 'Generated submission',
Expand All @@ -126,7 +127,7 @@ public function create_submission($workshopid, $authorid, $options = null) {
'contenttrust' => 0,
);

$id = $DB->insert_record('workshop_submissions', $record);
$id = $DB->insert_record('workshop_submissions', array_merge($submission, $record));

return $id;
}
Expand Down

0 comments on commit cb36c63

Please sign in to comment.