MDL-45296 tests: ensure all submissions exist v2.7.0-rc2
authorEloy Lafuente (stronk7) <stronk7@moodle.org>
Thu, 8 May 2014 17:47:47 +0000 (19:47 +0200)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Thu, 8 May 2014 18:03:34 +0000 (20:03 +0200)
The changes performed with the change from
create_from_user() to create_from_submission()
in practice enforce a new restriction about
submissions having to exist in order to fire
their lock/unlock events.

This did not exist before the change and, also,
it seems that the assign api itself, submission->lock() ...
also accepts non existing submissions.

So I was not 100% sure about how to fix these events:

1) enforcing submission to exist.
2) firing them only if the submission exist.

I've gone with 1) for now, making tests to pass. But will
raise the question in the Tracker, just in case we have
to move to the 2) approach for any reason.

mod/assign/tests/events_test.php
mod/assign/tests/externallib_test.php

index bbf9a42..521fc36 100644 (file)
@@ -212,6 +212,7 @@ class assign_events_testcase extends mod_assign_base_testcase {
         $assign = $this->create_instance();
         $sink = $this->redirectEvents();
 
+        $submission = $assign->get_user_submission($this->students[0]->id, true);
         $assign->lock_submission($this->students[0]->id);
 
         $events = $sink->get_events();
@@ -446,6 +447,7 @@ class assign_events_testcase extends mod_assign_base_testcase {
         $assign = $this->create_instance();
         $sink = $this->redirectEvents();
 
+        $submission = $assign->get_user_submission($this->students[0]->id, true);
         $assign->unlock_submission($this->students[0]->id);
 
         $events = $sink->get_events();
index f764d23..c002b6e 100644 (file)
@@ -470,7 +470,7 @@ class mod_assign_external_testcase extends externallib_advanced_testcase {
                                               $course->id,
                                               $teacherrole->id);
 
-        // Create a student1 with an online text submission.
+        // Create a student1 and student2 with an online text submission.
         // Simulate a submission.
         $this->setUser($student1);
         $submission = $assign->get_user_submission($student1->id, true);
@@ -481,6 +481,15 @@ class mod_assign_external_testcase extends externallib_advanced_testcase {
         $plugin = $assign->get_submission_plugin_by_type('onlinetext');
         $plugin->save($submission, $data);
 
+        $this->setUser($student2);
+        $submission = $assign->get_user_submission($student2->id, true);
+        $data = new stdClass();
+        $data->onlinetext_editor = array('itemid'=>file_get_unused_draft_itemid(),
+                                         'text'=>'Submission text',
+                                         'format'=>FORMAT_MOODLE);
+        $plugin = $assign->get_submission_plugin_by_type('onlinetext');
+        $plugin->save($submission, $data);
+
         // Ready to test.
         $this->setUser($teacher);
         $students = array($student1->id, $student2->id);
@@ -534,7 +543,7 @@ class mod_assign_external_testcase extends externallib_advanced_testcase {
                                               $course->id,
                                               $teacherrole->id);
 
-        // Create a student1 with an online text submission.
+        // Create a student1 and student2 with an online text submission.
         // Simulate a submission.
         $this->setUser($student1);
         $submission = $assign->get_user_submission($student1->id, true);
@@ -545,6 +554,15 @@ class mod_assign_external_testcase extends externallib_advanced_testcase {
         $plugin = $assign->get_submission_plugin_by_type('onlinetext');
         $plugin->save($submission, $data);
 
+        $this->setUser($student2);
+        $submission = $assign->get_user_submission($student2->id, true);
+        $data = new stdClass();
+        $data->onlinetext_editor = array('itemid'=>file_get_unused_draft_itemid(),
+                                         'text'=>'Submission text',
+                                         'format'=>FORMAT_MOODLE);
+        $plugin = $assign->get_submission_plugin_by_type('onlinetext');
+        $plugin->save($submission, $data);
+
         // Ready to test.
         $this->setUser($teacher);
         $students = array($student1->id, $student2->id);