Skip to content

Commit

Permalink
MDL-45296 tests: ensure all submissions exist
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
stronk7 committed May 8, 2014
1 parent b95db26 commit 2fe085b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
2 changes: 2 additions & 0 deletions mod/assign/tests/events_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ public function test_submission_locked() {
$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();
Expand Down Expand Up @@ -446,6 +447,7 @@ public function test_submission_unlocked() {
$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();
Expand Down
22 changes: 20 additions & 2 deletions mod/assign/tests/externallib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ public function test_lock_submissions() {
$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);
Expand All @@ -481,6 +481,15 @@ public function test_lock_submissions() {
$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);
Expand Down Expand Up @@ -534,7 +543,7 @@ public function test_unlock_submissions() {
$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);
Expand All @@ -545,6 +554,15 @@ public function test_unlock_submissions() {
$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);
Expand Down

0 comments on commit 2fe085b

Please sign in to comment.