MDL-41101 mod_assign: replaced 'submission statement accepted' add_to_log call with...
authorMark Nelson <markn@moodle.com>
Thu, 27 Mar 2014 01:39:56 +0000 (18:39 -0700)
committerPetr Skoda <skodak@mujMac.local>
Thu, 17 Apr 2014 01:51:10 +0000 (09:51 +0800)
mod/assign/classes/event/statement_accepted.php
mod/assign/locallib.php
mod/assign/tests/events_test.php

index 34736dd..671e238 100644 (file)
@@ -61,7 +61,7 @@ class statement_accepted extends base {
      */
     protected function init() {
         $this->data['crud'] = 'r';
-        $this->data['edulevel'] = self::LEVEL_PARTICIPATING;
+        $this->data['edulevel'] = self::LEVEL_OTHER;
         $this->data['objecttable'] = 'assign_submission';
     }
 }
index 2b4bc88..ab19da5 100644 (file)
@@ -4820,7 +4820,13 @@ class assign {
                 $logmessage = get_string('submissionstatementacceptedlog',
                                          'mod_assign',
                                          fullname($USER));
-                $this->add_to_log('submission statement accepted', $logmessage);
+                $params = array(
+                    'context' => $this->context,
+                    'objectid' => $submission->id
+                );
+                $event = \mod_assign\event\statement_accepted::create($params);
+                $event->set_legacy_logdata('submission statement accepted', $logmessage);
+                $event->trigger();
             }
             $this->notify_graders($submission);
             $this->notify_student_submission_receipt($submission);
@@ -5612,6 +5618,7 @@ class assign {
                 }
             }
         }
+
         $allempty = $this->submission_empty($submission);
         if ($pluginerror || $allempty) {
             if ($allempty) {
index 596b34d..33a4bc3 100644 (file)
@@ -712,4 +712,75 @@ class assign_events_testcase extends mod_assign_base_testcase {
         $this->assertEventLegacyLogData($expected, $event);
         $this->assertEventContextNotUsed($event);
     }
+
+    /**
+     * Test the statement_accepted event.
+     */
+    public function test_statement_accepted() {
+        // We want to be a student so we can submit assignments.
+        $this->setUser($this->students[0]);
+
+        // We do not want to send any messages to the student during the PHPUNIT test.
+        set_config('submissionreceipts', false, 'assign');
+
+        $assign = $this->create_instance();
+
+        // Create the data we want to pass to the submit_for_grading function.
+        $data = new stdClass();
+        $data->submissionstatement = 'We are the Borg. You will be assimilated. Resistance is futile. - do you agree
+            to these terms?';
+
+        // Trigger and capture the event.
+        $sink = $this->redirectEvents();
+        $assign->submit_for_grading($data, array());
+        $events = $sink->get_events();
+        $event = reset($events);
+
+        // Check that the event contains the expected values.
+        $this->assertInstanceOf('\mod_assign\event\statement_accepted', $event);
+        $this->assertEquals($assign->get_context(), $event->get_context());
+        $expected = array(
+            $assign->get_course()->id,
+            'assign',
+            'submission statement accepted',
+            'view.php?id=' . $assign->get_course_module()->id,
+            get_string('submissionstatementacceptedlog',
+                'mod_assign',
+                fullname($this->students[0])),
+            $assign->get_course_module()->id
+        );
+        $this->assertEventLegacyLogData($expected, $event);
+        $this->assertEventContextNotUsed($event);
+
+        // Enable the online text submission plugin.
+        $submissionplugins = $assign->get_submission_plugins();
+        foreach ($submissionplugins as $plugin) {
+            if ($plugin->get_type() === 'onlinetext') {
+                $plugin->enable();
+                break;
+            }
+        }
+
+        // Create the data we want to pass to the save_submission function.
+        $data = new stdClass();
+        $data->onlinetext_editor = array(
+            'text' => 'Online text',
+            'format' => FORMAT_HTML,
+            'itemid' => file_get_unused_draft_itemid()
+        );
+        $data->submissionstatement = 'We are the Borg. You will be assimilated. Resistance is futile. - do you agree
+            to these terms?';
+
+        // Trigger and capture the event.
+        $sink = $this->redirectEvents();
+        $assign->save_submission($data, $notices);
+        $events = $sink->get_events();
+        $event = $events[2];
+
+        // Check that the event contains the expected values.
+        $this->assertInstanceOf('\mod_assign\event\statement_accepted', $event);
+        $this->assertEquals($assign->get_context(), $event->get_context());
+        $this->assertEventLegacyLogData($expected, $event);
+        $this->assertEventContextNotUsed($event);
+    }
 }