From cb36c63c6ba9f1b9545b4f27fbbf16d2452689ce Mon Sep 17 00:00:00 2001 From: Simey Lameze Date: Fri, 10 May 2024 15:00:32 +0800 Subject: [PATCH] MDL-76654 behat: fixes and data generator --- .../tests/behat/self_assessment.feature | 71 +++++++++++-------- .../tests/behat/workshop_assessment.feature | 1 + .../behat_mod_workshop_generator.php | 54 ++++++++++++++ mod/workshop/tests/generator/lib.php | 9 +-- 4 files changed, 103 insertions(+), 32 deletions(-) create mode 100644 mod/workshop/tests/generator/behat_mod_workshop_generator.php diff --git a/mod/workshop/tests/behat/self_assessment.feature b/mod/workshop/tests/behat/self_assessment.feature index 1986ab26a1dc8..1e0386e9e5b60 100644 --- a/mod/workshop/tests/behat/self_assessment.feature +++ b/mod/workshop/tests/behat/self_assessment.feature @@ -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 | @@ -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 @@ -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" diff --git a/mod/workshop/tests/behat/workshop_assessment.feature b/mod/workshop/tests/behat/workshop_assessment.feature index ebe61a35fb18c..d9ea7293d6b30 100644 --- a/mod/workshop/tests/behat/workshop_assessment.feature +++ b/mod/workshop/tests/behat/workshop_assessment.feature @@ -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 | diff --git a/mod/workshop/tests/generator/behat_mod_workshop_generator.php b/mod/workshop/tests/generator/behat_mod_workshop_generator.php new file mode 100644 index 0000000000000..16a374cdaf371 --- /dev/null +++ b/mod/workshop/tests/generator/behat_mod_workshop_generator.php @@ -0,0 +1,54 @@ +. + +/** + * 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); + } +} diff --git a/mod/workshop/tests/generator/lib.php b/mod/workshop/tests/generator/lib.php index 3fc2dcd22650d..62cff5218212f 100644 --- a/mod/workshop/tests/generator/lib.php +++ b/mod/workshop/tests/generator/lib.php @@ -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', @@ -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; }