MDL-45296 tests: ensure all submissions exist

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.
This commit is contained in:
Eloy Lafuente (stronk7) 2014-05-08 19:47:47 +02:00
parent b95db263ca
commit 2fe085b284
2 changed files with 22 additions and 2 deletions

View 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();

View 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);