MDL-41101 mod_assign: replaced 'view submit assignment form' add_to_log call with...
[moodle.git] / mod / assign / tests / events_test.php
index 2a781a4..27790b6 100644 (file)
@@ -641,4 +641,39 @@ class assign_events_testcase extends mod_assign_base_testcase {
         $this->assertEventLegacyLogData($expected, $event);
         $this->assertEventContextNotUsed($event);
     }
+
+    /**
+     * Test the submission_form_viewed event.
+     */
+    public function test_submission_form_viewed() {
+        global $PAGE;
+
+        $this->setUser($this->students[0]);
+
+        $assign = $this->create_instance();
+
+        // We need to set the URL in order to view the submission form.
+        $PAGE->set_url('/a_url');
+
+        // Trigger and capture the event.
+        $sink = $this->redirectEvents();
+        $assign->view('editsubmission');
+        $events = $sink->get_events();
+        $this->assertCount(1, $events);
+        $event = reset($events);
+
+        // Check that the event contains the expected values.
+        $this->assertInstanceOf('\mod_assign\event\submission_form_viewed', $event);
+        $this->assertEquals($assign->get_context(), $event->get_context());
+        $expected = array(
+            $assign->get_course()->id,
+            'assign',
+            'view submit assignment form',
+            'view.php?id=' . $assign->get_course_module()->id,
+            get_string('editsubmission', 'assign'),
+            $assign->get_course_module()->id
+        );
+        $this->assertEventLegacyLogData($expected, $event);
+        $this->assertEventContextNotUsed($event);
+    }
 }