MDL-41101 mod_assign: introduced event base class
authorMark Nelson <markn@moodle.com>
Sun, 23 Mar 2014 00:21:38 +0000 (17:21 -0700)
committerPetr Skoda <skodak@mujMac.local>
Thu, 17 Apr 2014 01:51:07 +0000 (09:51 +0800)
Also performed the following -

1) Deprecated the assignment's add_to_log function (part of it's functionality exists in the base class to set the legacy log data).
2) Edited existing events to use the new base class.
3) Renamed event_test.php to events_test.php to match the rest of core.
4) Moved the event tests from locallib_test.php to events_test.php.
5) When setting legacy data use lang_string, rather than get_string, as we may not be using them if legacy log is disabled.

19 files changed:
mod/assign/classes/event/all_submissions_downloaded.php
mod/assign/classes/event/assessable_submitted.php
mod/assign/classes/event/base.php [new file with mode: 0644]
mod/assign/classes/event/extension_granted.php
mod/assign/classes/event/identities_revealed.php
mod/assign/classes/event/marker_updated.php
mod/assign/classes/event/statement_accepted.php
mod/assign/classes/event/submission_created.php
mod/assign/classes/event/submission_duplicated.php
mod/assign/classes/event/submission_graded.php
mod/assign/classes/event/submission_locked.php
mod/assign/classes/event/submission_status_updated.php
mod/assign/classes/event/submission_unlocked.php
mod/assign/classes/event/submission_updated.php
mod/assign/classes/event/workflow_state_updated.php
mod/assign/locallib.php
mod/assign/tests/event_test.php [deleted file]
mod/assign/tests/events_test.php [new file with mode: 0644]
mod/assign/tests/locallib_test.php

index dfa2249..fcbb141 100644 (file)
@@ -34,14 +34,7 @@ defined('MOODLE_INTERNAL') || die();
  * @copyright  2013 Frédéric Massart
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
-class all_submissions_downloaded extends \core\event\base {
-
-    /**
-     * Legacy log data.
-     *
-     * @var array
-     */
-    protected $legacylogdata;
+class all_submissions_downloaded extends base {
 
     /**
      * Returns description of what happened.
@@ -52,15 +45,6 @@ class all_submissions_downloaded extends \core\event\base {
         return "User {$this->userid} has downloaded all the submissions.";
     }
 
-    /**
-     * Return legacy data for add_to_log().
-     *
-     * @return array
-     */
-    protected function get_legacy_logdata() {
-        return $this->legacylogdata;
-    }
-
     /**
      * Return localised event name.
      *
@@ -70,25 +54,6 @@ class all_submissions_downloaded extends \core\event\base {
         return get_string('eventallsubmissionsdownloaded', 'mod_assign');
     }
 
-    /**
-     * Get URL related to the action.
-     *
-     * @return \moodle_url
-     */
-    public function get_url() {
-        return new \moodle_url('/mod/assign/view.php', array('id' => $this->contextinstanceid));
-    }
-
-    /**
-     * Sets the legacy event log data.
-     *
-     * @param \stdClass $legacylogdata legacy log data.
-     * @return void
-     */
-    public function set_legacy_logdata($legacylogdata) {
-        $this->legacylogdata = $legacylogdata;
-    }
-
     /**
      * Init method.
      *
@@ -99,5 +64,4 @@ class all_submissions_downloaded extends \core\event\base {
         $this->data['edulevel'] = self::LEVEL_TEACHING;
         $this->data['objecttable'] = 'assign';
     }
-
 }
index 2ca9695..7781acc 100644 (file)
@@ -40,14 +40,7 @@ defined('MOODLE_INTERNAL') || die();
  * @copyright  2013 Frédéric Massart
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
-class assessable_submitted extends \core\event\assessable_submitted {
-
-    /**
-     * Legacy log data.
-     *
-     * @var array
-     */
-    protected $legacylogdata;
+class assessable_submitted extends base {
 
     /**
      * Returns description of what happened.
@@ -83,15 +76,6 @@ class assessable_submitted extends \core\event\assessable_submitted {
         return 'assessable_submitted';
     }
 
-    /**
-     * Return legacy data for add_to_log().
-     *
-     * @return array
-     */
-    protected function get_legacy_logdata() {
-        return $this->legacylogdata;
-    }
-
     /**
      * Return localised event name.
      *
@@ -101,33 +85,15 @@ class assessable_submitted extends \core\event\assessable_submitted {
         return get_string('eventassessablesubmitted', 'mod_assign');
     }
 
-    /**
-     * Get URL related to the action
-     *
-     * @return \moodle_url
-     */
-    public function get_url() {
-        return new \moodle_url('/mod/assign/view.php', array('id' => $this->contextinstanceid));
-    }
-
-    /**
-     * Sets the legacy event log data.
-     *
-     * @param \stdClass $legacylogdata legacy log data.
-     * @return void
-     */
-    public function set_legacy_logdata($legacylogdata) {
-        $this->legacylogdata = $legacylogdata;
-    }
-
     /**
      * Init method.
      *
      * @return void
      */
     protected function init() {
-        parent::init();
         $this->data['objecttable'] = 'assign_submission';
+        $this->data['crud'] = 'u';
+        $this->data['edulevel'] = self::LEVEL_PARTICIPATING;
     }
 
     /**
@@ -138,8 +104,13 @@ class assessable_submitted extends \core\event\assessable_submitted {
      */
     protected function validate_data() {
         parent::validate_data();
+
         if (!isset($this->other['submission_editable'])) {
             throw new \coding_exception('Other must contain the key submission_editable.');
         }
+
+        if ($this->contextlevel != CONTEXT_MODULE) {
+            throw new \coding_exception('Context passed must be module context.');
+        }
     }
 }
diff --git a/mod/assign/classes/event/base.php b/mod/assign/classes/event/base.php
new file mode 100644 (file)
index 0000000..33ae32b
--- /dev/null
@@ -0,0 +1,78 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * The mod_assign abstract base class.
+ *
+ * Most events can extend this class.
+ *
+ * @package    mod_assign
+ * @since      Moodle 2.7
+ * @copyright  2014 Mark Nelson
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+namespace mod_assign\event;
+
+defined('MOODLE_INTERNAL') || die();
+
+abstract class base extends \core\event\base {
+
+    /**
+     * Legacy log data.
+     *
+     * @var array
+     */
+    protected $legacylogdata;
+
+    /**
+     * Returns relevant URL.
+     *
+     * @return \moodle_url
+     */
+    public function get_url() {
+        return new \moodle_url('/mod/assign/view.php', array('id' => $this->contextinstanceid));
+    }
+
+    /**
+     * Sets the legacy event log data.
+     *
+     * @param string $action The current action
+     * @param string $info A detailed description of the change. But no more than 255 characters.
+     * @param string $url The url to the assign module instance.
+     */
+    public function set_legacy_logdata($action = '', $info = '', $url = '') {
+        $fullurl = 'view.php?id=' . $this->contextinstanceid;
+        if ($url != '') {
+            $fullurl .= '&' . $url;
+        }
+
+        $this->legacylogdata = array($this->courseid, 'assign', $action, $fullurl, $info, $this->contextinstanceid);
+    }
+
+    /**
+     * Return legacy data for add_to_log().
+     *
+     * @return array
+     */
+    protected function get_legacy_logdata() {
+        if (isset($this->legacylogdata)) {
+            return $this->legacylogdata;
+        }
+
+        return null;
+    }
+}
index 4a27e2b..cd66010 100644 (file)
@@ -34,14 +34,7 @@ defined('MOODLE_INTERNAL') || die();
  * @copyright  2013 Frédéric Massart
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
-class extension_granted extends \core\event\base {
-
-    /**
-     * Legacy log data.
-     *
-     * @var array
-     */
-    protected $legacylogdata;
+class extension_granted extends base {
 
     /**
      * Returns description of what happened.
@@ -52,15 +45,6 @@ class extension_granted extends \core\event\base {
         return "User {$this->userid} has granted an extension to {$this->relateduserid}.";
     }
 
-    /**
-     * Return legacy data for add_to_log().
-     *
-     * @return array
-     */
-    protected function get_legacy_logdata() {
-        return $this->legacylogdata;
-    }
-
     /**
      * Return localised event name.
      *
@@ -70,15 +54,6 @@ class extension_granted extends \core\event\base {
         return get_string('eventextensiongranted', 'mod_assign');
     }
 
-    /**
-     * Get URL related to the action
-     *
-     * @return \moodle_url
-     */
-    public function get_url() {
-        return new \moodle_url('/mod/assign/view.php', array('id' => $this->contextinstanceid));
-    }
-
     /**
      * Init method.
      *
@@ -90,16 +65,6 @@ class extension_granted extends \core\event\base {
         $this->data['objecttable'] = 'assign';
     }
 
-    /**
-     * Sets the legacy event log data.
-     *
-     * @param \stdClass $legacylogdata legacy log data.
-     * @return void
-     */
-    public function set_legacy_logdata($legacylogdata) {
-        $this->legacylogdata = $legacylogdata;
-    }
-
     /**
      * Custom validation.
      *
index c33f9ad..d140a75 100644 (file)
@@ -34,14 +34,7 @@ defined('MOODLE_INTERNAL') || die();
  * @copyright  2013 Frédéric Massart
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
-class identities_revealed extends \core\event\base {
-
-    /**
-     * Legacy log data.
-     *
-     * @var array
-     */
-    protected $legacylogdata;
+class identities_revealed extends base {
 
     /**
      * Returns description of what happened.
@@ -52,15 +45,6 @@ class identities_revealed extends \core\event\base {
         return "User {$this->userid} has revealed the identities in assignment {$this->objectid}.";
     }
 
-    /**
-     * Return legacy data for add_to_log().
-     *
-     * @return array
-     */
-    protected function get_legacy_logdata() {
-        return $this->legacylogdata;
-    }
-
     /**
      * Return localised event name.
      *
@@ -70,15 +54,6 @@ class identities_revealed extends \core\event\base {
         return get_string('eventidentitiesrevealed', 'mod_assign');
     }
 
-    /**
-     * Get URL related to the action
-     *
-     * @return \moodle_url
-     */
-    public function get_url() {
-        return new \moodle_url('/mod/assign/view.php', array('id' => $this->contextinstanceid));
-    }
-
     /**
      * Init method.
      *
@@ -89,15 +64,4 @@ class identities_revealed extends \core\event\base {
         $this->data['edulevel'] = self::LEVEL_TEACHING;
         $this->data['objecttable'] = 'assign';
     }
-
-    /**
-     * Sets the legacy event log data.
-     *
-     * @param \stdClass $legacylogdata legacy log data.
-     * @return void
-     */
-    public function set_legacy_logdata($legacylogdata) {
-        $this->legacylogdata = $legacylogdata;
-    }
-
 }
index babb758..bc036ab 100644 (file)
@@ -40,14 +40,7 @@ defined('MOODLE_INTERNAL') || die();
  * @copyright  2013 Frédéric Massart
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
-class marker_updated extends \core\event\base {
-
-    /**
-     * Legacy log data.
-     *
-     * @var array
-     */
-    protected $legacylogdata;
+class marker_updated extends base {
 
     /**
      * Returns description of what happened.
@@ -58,15 +51,6 @@ class marker_updated extends \core\event\base {
         return "User {$this->userid} has set the marker of {$this->relateduserid} to {$this->other['markerid']}.";
     }
 
-    /**
-     * Return legacy data for add_to_log().
-     *
-     * @return array
-     */
-    protected function get_legacy_logdata() {
-        return $this->legacylogdata;
-    }
-
     /**
      * Return localised event name.
      *
@@ -76,15 +60,6 @@ class marker_updated extends \core\event\base {
         return get_string('eventmarkerupdated', 'mod_assign');
     }
 
-    /**
-     * Get URL related to the action
-     *
-     * @return \moodle_url
-     */
-    public function get_url() {
-        return new \moodle_url('/mod/assign/view.php', array('id' => $this->contextinstanceid));
-    }
-
     /**
      * Init method.
      *
@@ -96,16 +71,6 @@ class marker_updated extends \core\event\base {
         $this->data['objecttable'] = 'assign';
     }
 
-    /**
-     * Sets the legacy event log data.
-     *
-     * @param \stdClass $legacylogdata legacy log data.
-     * @return void
-     */
-    public function set_legacy_logdata($legacylogdata) {
-        $this->legacylogdata = $legacylogdata;
-    }
-
     /**
      * Custom validation.
      *
index 1694bf7..34736dd 100644 (file)
@@ -34,14 +34,7 @@ defined('MOODLE_INTERNAL') || die();
  * @copyright  2013 Frédéric Massart
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
-class statement_accepted extends \core\event\base {
-
-    /**
-     * Legacy log data.
-     *
-     * @var array
-     */
-    protected $legacylogdata;
+class statement_accepted extends base {
 
     /**
      * Returns description of what happened.
@@ -52,15 +45,6 @@ class statement_accepted extends \core\event\base {
         return "The user {$this->userid} has accepted the statement of the submission {$this->objectid}.";
     }
 
-    /**
-     * Return legacy data for add_to_log().
-     *
-     * @return array
-     */
-    protected function get_legacy_logdata() {
-        return $this->legacylogdata;
-    }
-
     /**
      * Return localised event name.
      *
@@ -70,15 +54,6 @@ class statement_accepted extends \core\event\base {
         return get_string('eventstatementaccepted', 'mod_assign');
     }
 
-    /**
-     * Get URL related to the action.
-     *
-     * @return \moodle_url
-     */
-    public function get_url() {
-        return new \moodle_url('/mod/assign/view.php', array('id' => $this->contextinstanceid));
-    }
-
     /**
      * Init method.
      *
@@ -89,15 +64,4 @@ class statement_accepted extends \core\event\base {
         $this->data['edulevel'] = self::LEVEL_PARTICIPATING;
         $this->data['objecttable'] = 'assign_submission';
     }
-
-    /**
-     * Sets the legacy event log data.
-     *
-     * @param \stdClass $legacylogdata legacy log data.
-     * @return void
-     */
-    public function set_legacy_logdata($legacylogdata) {
-        $this->legacylogdata = $legacylogdata;
-    }
-
 }
index ad67856..af1c9e9 100644 (file)
@@ -41,7 +41,7 @@ defined('MOODLE_INTERNAL') || die();
  * @copyright  2014 Adrian Greeve <adrian@moodle.com>
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
-abstract class submission_created extends \core\event\base {
+abstract class submission_created extends base {
 
     /**
      * Init method.
@@ -60,14 +60,6 @@ abstract class submission_created extends \core\event\base {
         return get_string('eventsubmissioncreated', 'mod_assign');
     }
 
-    /**
-     * Returns relevant URL.
-     * @return \moodle_url
-     */
-    public function get_url() {
-        return new \moodle_url('/mod/assign/view.php', array('id' => $this->contextinstanceid));
-    }
-
     /**
      * Custom validation.
      *
index 752c217..819299a 100644 (file)
@@ -34,14 +34,7 @@ defined('MOODLE_INTERNAL') || die();
  * @copyright  2013 Frédéric Massart
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
-class submission_duplicated extends \core\event\base {
-
-    /**
-     * Legacy log data.
-     *
-     * @var array
-     */
-    protected $legacylogdata;
+class submission_duplicated extends base {
 
     /**
      * Returns description of what happened.
@@ -52,15 +45,6 @@ class submission_duplicated extends \core\event\base {
         return "The user {$this->userid} duplicated his submission {$this->objectid}.";
     }
 
-    /**
-     * Return legacy data for add_to_log().
-     *
-     * @return array
-     */
-    protected function get_legacy_logdata() {
-        return $this->legacylogdata;
-    }
-
     /**
      * Return localised event name.
      *
@@ -70,15 +54,6 @@ class submission_duplicated extends \core\event\base {
         return get_string('eventsubmissionduplicated', 'mod_assign');
     }
 
-    /**
-     * Get URL related to the action.
-     *
-     * @return \moodle_url
-     */
-    public function get_url() {
-        return new \moodle_url('/mod/assign/view.php', array('id' => $this->contextinstanceid));
-    }
-
     /**
      * Init method.
      *
@@ -89,15 +64,4 @@ class submission_duplicated extends \core\event\base {
         $this->data['edulevel'] = self::LEVEL_PARTICIPATING;
         $this->data['objecttable'] = 'assign_submission';
     }
-
-    /**
-     * Sets the legacy event log data.
-     *
-     * @param \stdClass $legacylogdata legacy log data.
-     * @return void
-     */
-    public function set_legacy_logdata($legacylogdata) {
-        $this->legacylogdata = $legacylogdata;
-    }
-
 }
index 3afef96..3132db2 100644 (file)
@@ -34,14 +34,7 @@ defined('MOODLE_INTERNAL') || die();
  * @copyright  2013 Frédéric Massart
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
-class submission_graded extends \core\event\base {
-
-    /**
-     * Legacy log data.
-     *
-     * @var array
-     */
-    protected $legacylogdata;
+class submission_graded extends base {
 
     /**
      * Returns description of what happened.
@@ -52,15 +45,6 @@ class submission_graded extends \core\event\base {
         return "User {$this->userid} has graded the submission {$this->objectid}.";
     }
 
-    /**
-     * Return legacy data for add_to_log().
-     *
-     * @return array
-     */
-    protected function get_legacy_logdata() {
-        return $this->legacylogdata;
-    }
-
     /**
      * Return localised event name.
      *
@@ -70,15 +54,6 @@ class submission_graded extends \core\event\base {
         return get_string('eventsubmissiongraded', 'mod_assign');
     }
 
-    /**
-     * Get URL related to the action
-     *
-     * @return \moodle_url
-     */
-    public function get_url() {
-        return new \moodle_url('/mod/assign/view.php', array('id' => $this->contextinstanceid));
-    }
-
     /**
      * Init method.
      *
@@ -90,16 +65,6 @@ class submission_graded extends \core\event\base {
         $this->data['objecttable'] = 'assign_grades';
     }
 
-    /**
-     * Sets the legacy event log data.
-     *
-     * @param \stdClass $legacylogdata legacy log data.
-     * @return void
-     */
-    public function set_legacy_logdata($legacylogdata) {
-        $this->legacylogdata = $legacylogdata;
-    }
-
     /**
      * Custom validation.
      *
index 3963431..cf9183a 100644 (file)
@@ -34,14 +34,7 @@ defined('MOODLE_INTERNAL') || die();
  * @copyright  2013 Frédéric Massart
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
-class submission_locked extends \core\event\base {
-
-    /**
-     * Legacy log data.
-     *
-     * @var array
-     */
-    protected $legacylogdata;
+class submission_locked extends base {
 
     /**
      * Returns description of what happened.
@@ -52,15 +45,6 @@ class submission_locked extends \core\event\base {
         return "User {$this->userid} locked the submission for user {$this->relateduserid}.";
     }
 
-    /**
-     * Return legacy data for add_to_log().
-     *
-     * @return array
-     */
-    protected function get_legacy_logdata() {
-        return $this->legacylogdata;
-    }
-
     /**
      * Return localised event name.
      *
@@ -70,15 +54,6 @@ class submission_locked extends \core\event\base {
         return get_string('eventsubmissionlocked', 'mod_assign');
     }
 
-    /**
-     * Get URL related to the action
-     *
-     * @return \moodle_url
-     */
-    public function get_url() {
-        return new \moodle_url('/mod/assign/view.php', array('id' => $this->contextinstanceid));
-    }
-
     /**
      * Init method.
      *
@@ -90,16 +65,6 @@ class submission_locked extends \core\event\base {
         $this->data['objecttable'] = 'assign';
     }
 
-    /**
-     * Sets the legacy event log data.
-     *
-     * @param \stdClass $legacylogdata legacy log data.
-     * @return void
-     */
-    public function set_legacy_logdata($legacylogdata) {
-        $this->legacylogdata = $legacylogdata;
-    }
-
     /**
      * Custom validation.
      *
index aaee15f..58290cc 100644 (file)
@@ -40,14 +40,7 @@ defined('MOODLE_INTERNAL') || die();
  * @copyright  2013 Frédéric Massart
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
-class submission_status_updated extends \core\event\base {
-
-    /**
-     * Legacy log data.
-     *
-     * @var array
-     */
-    protected $legacylogdata;
+class submission_status_updated extends base {
 
     /**
      * Returns description of what happened.
@@ -58,15 +51,6 @@ class submission_status_updated extends \core\event\base {
         return "User {$this->userid} has updated the status of the submission {$this->objectid} to {$this->other['newstatus']}.";
     }
 
-    /**
-     * Return legacy data for add_to_log().
-     *
-     * @return array
-     */
-    protected function get_legacy_logdata() {
-        return $this->legacylogdata;
-    }
-
     /**
      * Return localised event name.
      *
@@ -76,15 +60,6 @@ class submission_status_updated extends \core\event\base {
         return get_string('eventsubmissionstatusupdated', 'mod_assign');
     }
 
-    /**
-     * Get URL related to the action
-     *
-     * @return \moodle_url
-     */
-    public function get_url() {
-        return new \moodle_url('/mod/assign/view.php', array('id' => $this->contextinstanceid));
-    }
-
     /**
      * Init method.
      *
@@ -96,16 +71,6 @@ class submission_status_updated extends \core\event\base {
         $this->data['objecttable'] = 'assign_submission';
     }
 
-    /**
-     * Sets the legacy event log data.
-     *
-     * @param \stdClass $legacylogdata legacy log data.
-     * @return void
-     */
-    public function set_legacy_logdata($legacylogdata) {
-        $this->legacylogdata = $legacylogdata;
-    }
-
     /**
      * Custom validation.
      *
index 5fa618c..83d1c76 100644 (file)
@@ -34,14 +34,7 @@ defined('MOODLE_INTERNAL') || die();
  * @copyright  2013 Frédéric Massart
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
-class submission_unlocked extends \core\event\base {
-
-    /**
-     * Legacy log data.
-     *
-     * @var array
-     */
-    protected $legacylogdata;
+class submission_unlocked extends base {
 
     /**
      * Returns description of what happened.
@@ -52,15 +45,6 @@ class submission_unlocked extends \core\event\base {
         return "User {$this->userid} unlocked the submission for user {$this->relateduserid}.";
     }
 
-    /**
-     * Return legacy data for add_to_log().
-     *
-     * @return array
-     */
-    protected function get_legacy_logdata() {
-        return $this->legacylogdata;
-    }
-
     /**
      * Return localised event name.
      *
@@ -70,15 +54,6 @@ class submission_unlocked extends \core\event\base {
         return get_string('eventsubmissionunlocked', 'mod_assign');
     }
 
-    /**
-     * Get URL related to the action
-     *
-     * @return \moodle_url
-     */
-    public function get_url() {
-        return new \moodle_url('/mod/assign/view.php', array('id' => $this->contextinstanceid));
-    }
-
     /**
      * Init method.
      *
@@ -90,16 +65,6 @@ class submission_unlocked extends \core\event\base {
         $this->data['objecttable'] = 'assign';
     }
 
-    /**
-     * Sets the legacy event log data.
-     *
-     * @param \stdClass $legacylogdata legacy log data.
-     * @return void
-     */
-    public function set_legacy_logdata($legacylogdata) {
-        $this->legacylogdata = $legacylogdata;
-    }
-
     /**
      * Custom validation.
      *
index d2cebf4..8b22fd4 100644 (file)
@@ -41,7 +41,7 @@ defined('MOODLE_INTERNAL') || die();
  * @copyright  2013 Frédéric Massart
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
-abstract class submission_updated extends \core\event\base {
+abstract class submission_updated extends base {
 
     /**
      * Init method.
@@ -60,14 +60,6 @@ abstract class submission_updated extends \core\event\base {
         return get_string('eventsubmissionupdated', 'mod_assign');
     }
 
-    /**
-     * Returns relevant URL.
-     * @return \moodle_url
-     */
-    public function get_url() {
-        return new \moodle_url('/mod/assign/view.php', array('id' => $this->contextinstanceid));
-    }
-
     /**
      * Custom validation.
      *
index 055f65e..1bd24f1 100644 (file)
@@ -40,14 +40,7 @@ defined('MOODLE_INTERNAL') || die();
  * @copyright  2013 Frédéric Massart
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
-class workflow_state_updated extends \core\event\base {
-
-    /**
-     * Legacy log data.
-     *
-     * @var array
-     */
-    protected $legacylogdata;
+class workflow_state_updated extends base {
 
     /**
      * Returns description of what happened.
@@ -58,15 +51,6 @@ class workflow_state_updated extends \core\event\base {
         return "User {$this->userid} has set the workflow state of {$this->relateduserid} to {$this->other['newstate']}.";
     }
 
-    /**
-     * Return legacy data for add_to_log().
-     *
-     * @return array
-     */
-    protected function get_legacy_logdata() {
-        return $this->legacylogdata;
-    }
-
     /**
      * Return localised event name.
      *
@@ -76,15 +60,6 @@ class workflow_state_updated extends \core\event\base {
         return get_string('eventworkflowstateupdated', 'mod_assign');
     }
 
-    /**
-     * Get URL related to the action
-     *
-     * @return \moodle_url
-     */
-    public function get_url() {
-        return new \moodle_url('/mod/assign/view.php', array('id' => $this->contextinstanceid));
-    }
-
     /**
      * Init method.
      *
@@ -96,16 +71,6 @@ class workflow_state_updated extends \core\event\base {
         $this->data['objecttable'] = 'assign';
     }
 
-    /**
-     * Sets the legacy event log data.
-     *
-     * @param \stdClass $legacylogdata legacy log data.
-     * @return void
-     */
-    public function set_legacy_logdata($legacylogdata) {
-        $this->legacylogdata = $legacylogdata;
-    }
-
     /**
      * Custom validation.
      *
index 04e5944..46fce4f 100644 (file)
@@ -2500,13 +2500,12 @@ class assign {
             $result .= $this->get_renderer()->continue_button($url);
             $result .= $this->view_footer();
         } else if ($zipfile = $this->pack_files($filesforzipping)) {
-            $addtolog = $this->add_to_log('download all submissions', get_string('downloadall', 'assign'), '', true);
             $params = array(
                 'context' => $this->context,
                 'objectid' => $this->get_instance()->id
             );
             $event = \mod_assign\event\all_submissions_downloaded::create($params);
-            $event->set_legacy_logdata($addtolog);
+            $event->set_legacy_logdata('download all submissions', new lang_string('downloadall', 'assign'));
             $event->trigger();
             // Send file and delete after sending.
             send_temp_file($zipfile, $filename);
@@ -2518,6 +2517,9 @@ class assign {
     /**
      * Util function to add a message to the log.
      *
+     * @deprecated since 2.7 - Use new events system instead.
+     *             (see http://docs.moodle.org/dev/Migrating_logging_calls_in_plugins).
+     *
      * @param string $action The current action
      * @param string $info A detailed description of the change. But no more than 255 characters.
      * @param string $url The url to the assign module instance.
@@ -2543,6 +2545,9 @@ class assign {
         );
 
         if ($return) {
+            // We only need to call debugging when returning a value. This is because the call to
+            // call_user_func_array('add_to_log', $args) will trigger a debugging message of it's own.
+            debugging('The mod_assign add_to_log() function is now deprecated.', DEBUG_DEVELOPER);
             return $args;
         }
         call_user_func_array('add_to_log', $args);
@@ -4760,7 +4765,6 @@ class assign {
                                          fullname($USER));
                 $this->add_to_log('submission statement accepted', $logmessage);
             }
-            $logdata = $this->add_to_log('submit for grading', $this->format_submission_for_log($submission), '', true);
             $this->notify_graders($submission);
             $this->notify_student_submission_receipt($submission);
 
@@ -4773,7 +4777,7 @@ class assign {
                 )
             );
             $event = \mod_assign\event\assessable_submitted::create($params);
-            $event->set_legacy_logdata($logdata);
+            $event->set_legacy_logdata('submit for grading', $this->format_submission_for_log($submission));
             $event->trigger();
             return true;
         }
@@ -4884,14 +4888,13 @@ class assign {
         $result = $this->update_user_flags($flags);
 
         if ($result) {
-            $addtolog = $this->add_to_log('grant extension', $userid, '', true);
             $params = array(
                 'context' => $this->context,
                 'objectid' => $flags->assignment,
                 'relateduserid' => $userid
             );
             $event = \mod_assign\event\extension_granted::create($params);
-            $event->set_legacy_logdata($addtolog);
+            $event->set_legacy_logdata('grant extension', $userid);
             $event->trigger();
         }
         return $result;
@@ -5148,14 +5151,13 @@ class assign {
                 }
             }
 
-            $addtolog = $this->add_to_log('grade submission', $this->format_grade_for_log($grade), '', true);
             $params = array(
                 'context' => $this->context,
                 'objectid' => $grade->id,
                 'relateduserid' => $userid
             );
             $event = \mod_assign\event\submission_graded::create($params);
-            $event->set_legacy_logdata($addtolog);
+            $event->set_legacy_logdata('grade submission', $this->format_grade_for_log($grade));
             $event->trigger();
         }
 
@@ -5206,13 +5208,12 @@ class assign {
             $this->gradebook_item_update(null, $grade);
         }
 
-        $addtolog = $this->add_to_log('reveal identities', get_string('revealidentities', 'assign'), '', true);
         $params = array(
             'context' => $this->context,
             'objectid' => $update->id
         );
         $event = \mod_assign\event\identities_revealed::create($params);
-        $event->set_legacy_logdata($addtolog);
+        $event->set_legacy_logdata('reveal identities', new lang_string('revealidentities', 'assign'));
         $event->trigger();
     }
 
@@ -5439,13 +5440,12 @@ class assign {
             return false;
         }
 
-        $addtolog = $this->add_to_log('submissioncopied', $this->format_submission_for_log($submission), '', true);
         $params = array(
             'context' => $this->context,
             'objectid' => $submission->id
         );
         $event = \mod_assign\event\submission_duplicated::create($params);
-        $event->set_legacy_logdata($addtolog);
+        $event->set_legacy_logdata('submissioncopied', $this->format_submission_for_log($submission));
         $event->trigger();
 
         $complete = COMPLETION_INCOMPLETE;
@@ -5475,6 +5475,7 @@ class assign {
                 )
             );
             $event = \mod_assign\event\assessable_submitted::create($params);
+            $event->set_legacy_logdata('submit for grading', $this->format_submission_for_log($submission));
             $event->trigger();
         }
         return true;
@@ -5566,17 +5567,13 @@ class assign {
 
         // Logging.
         if (isset($data->submissionstatement) && ($userid == $USER->id)) {
-            $logmessage = get_string('submissionstatementacceptedlog',
-                                     'mod_assign',
-                                     fullname($USER));
-            $this->add_to_log('submission statement accepted', $logmessage);
-            $addtolog = $this->add_to_log('submission statement accepted', $logmessage, '', true);
+            $logmessage = new lang_string('submissionstatementacceptedlog', 'mod_assign', fullname($USER));
             $params = array(
                 'context' => $this->context,
                 'objectid' => $submission->id
             );
             $event = \mod_assign\event\statement_accepted::create($params);
-            $event->set_legacy_logdata($addtolog);
+            $event->set_legacy_logdata('submission statement accepted', $logmessage);
             $event->trigger();
         }
 
@@ -5601,6 +5598,7 @@ class assign {
                 )
             );
             $event = \mod_assign\event\assessable_submitted::create($params);
+            $event->set_legacy_logdata('submit for grading', $this->format_submission_for_log($submission));
             $event->trigger();
         }
         return true;
@@ -6118,10 +6116,8 @@ class assign {
                 $this->get_instance()->completionsubmit) {
             $completion->update_state($this->get_course_module(), COMPLETION_INCOMPLETE, $userid);
         }
-        $logmessage = get_string('reverttodraftforstudent',
-                                 'assign',
-                                 array('id'=>$user->id, 'fullname'=>fullname($user)));
-        $addtolog = $this->add_to_log('revert submission to draft', $logmessage, '', true);
+        $logmessage = new lang_string('reverttodraftforstudent', 'assign', array('id' => $user->id,
+            'fullname' => fullname($user)));
         $params = array(
             'context' => $this->context,
             'objectid' => $submission->id,
@@ -6131,7 +6127,7 @@ class assign {
             )
         );
         $event = \mod_assign\event\submission_status_updated::create($params);
-        $event->set_legacy_logdata($addtolog);
+        $event->set_legacy_logdata('revert submission to draft', $logmessage);
         $event->trigger();
         return true;
     }
@@ -6180,17 +6176,15 @@ class assign {
 
         $user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
 
-        $logmessage = get_string('locksubmissionforstudent',
-                                 'assign',
-                                 array('id'=>$user->id, 'fullname'=>fullname($user)));
-        $addtolog = $this->add_to_log('lock submission', $logmessage, '', true);
+        $logmessage = new lang_string('locksubmissionforstudent', 'assign', array('id' => $user->id,
+            'fullname' => fullname($user)));
         $params = array(
             'context' => $this->context,
             'objectid' => $flags->assignment,
             'relateduserid' => $user->id
         );
         $event = \mod_assign\event\submission_locked::create($params);
-        $event->set_legacy_logdata($addtolog);
+        $event->set_legacy_logdata('lock submission', $logmessage);
         $event->trigger();
         return true;
     }
@@ -6233,8 +6227,7 @@ class assign {
                 $params = array('id'=>$user->id,
                                 'fullname'=>fullname($user),
                                 'state'=>$state);
-                $message = get_string('setmarkingworkflowstateforlog', 'assign', $params);
-                $addtolog = $this->add_to_log('set marking workflow state', $message, '', true);
+                $message = new lang_string('setmarkingworkflowstateforlog', 'assign', $params);
                 $params = array(
                     'context' => $this->context,
                     'objectid' => $this->get_instance()->id,
@@ -6244,7 +6237,7 @@ class assign {
                     )
                 );
                 $event = \mod_assign\event\workflow_state_updated::create($params);
-                $event->set_legacy_logdata($addtolog);
+                $event->set_legacy_logdata('set marking workflow state', $message);
                 $event->trigger();
             }
         }
@@ -6286,8 +6279,7 @@ class assign {
                 $params = array('id'=>$user->id,
                     'fullname'=>fullname($user),
                     'marker'=>fullname($marker));
-                $message = get_string('setmarkerallocationforlog', 'assign', $params);
-                $addtolog = $this->add_to_log('set marking allocation', $message, '', true);
+                $message = new lang_string('setmarkerallocationforlog', 'assign', $params);
                 $params = array(
                     'context' => $this->context,
                     'objectid' => $this->get_instance()->id,
@@ -6297,7 +6289,7 @@ class assign {
                     )
                 );
                 $event = \mod_assign\event\marker_updated::create($params);
-                $event->set_legacy_logdata($addtolog);
+                $event->set_legacy_logdata('set marking allocation', $message);
                 $event->trigger();
             }
         }
@@ -6350,17 +6342,15 @@ class assign {
 
         $user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
 
-        $logmessage = get_string('unlocksubmissionforstudent',
-                                 'assign',
-                                 array('id'=>$user->id, 'fullname'=>fullname($user)));
-        $addtolog = $this->add_to_log('unlock submission', $logmessage, '', true);
+        $logmessage = new lang_string('unlocksubmissionforstudent', 'assign', array('id' => $user->id,
+            'fullname' => fullname($user)));
         $params = array(
             'context' => $this->context,
             'objectid' => $flags->assignment,
             'relateduserid' => $user->id
         );
         $event = \mod_assign\event\submission_unlocked::create($params);
-        $event->set_legacy_logdata($addtolog);
+        $event->set_legacy_logdata('unlock submission', $logmessage);
         $event->trigger();
         return true;
     }
@@ -6440,14 +6430,13 @@ class assign {
             $this->notify_grade_modified($grade);
         }
 
-        $addtolog = $this->add_to_log('grade submission', $this->format_grade_for_log($grade), '', true);
         $params = array(
             'context' => $this->context,
             'objectid' => $grade->id,
             'relateduserid' => $userid
         );
         $event = \mod_assign\event\submission_graded::create($params);
-        $event->set_legacy_logdata($addtolog);
+        $event->set_legacy_logdata('grade submission', $this->format_grade_for_log($grade));
         $event->trigger();
     }
 
diff --git a/mod/assign/tests/event_test.php b/mod/assign/tests/event_test.php
deleted file mode 100644 (file)
index 1175360..0000000
+++ /dev/null
@@ -1,171 +0,0 @@
-<?php
-// This file is part of Moodle - http://moodle.org/
-//
-// Moodle is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// Moodle is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
-
-/**
- * Contains the event tests for the module assign.
- *
- * @package   mod_assign
- * @copyright 2014 Adrian Greeve <adrian@moodle.com>
- * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
-require_once($CFG->dirroot . '/mod/assign/tests/base_test.php');
-require_once($CFG->dirroot . '/mod/assign/tests/fixtures/event_mod_assign_fixtures.php');
-
-/**
- * Contains the event tests for the module assign.
- *
- * @package   mod_assign
- * @copyright 2014 Adrian Greeve <adrian@moodle.com>
- * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-class assign_events_testcase extends advanced_testcase {
-
-    /** @var stdClass $user A user to submit an assignment. */
-    protected $user;
-
-    /** @var stdClass $course New course created to hold the assignment activity. */
-    protected $course;
-
-    /** @var stdClass $cm A context module object. */
-    protected $cm;
-
-    /** @var stdClass $context Context of the assignment activity. */
-    protected $context;
-
-    /** @var array $params Standard event parameters. */
-    protected $params;
-
-    /**
-     * Setup all the various parts of an assignment activity.
-     */
-    protected function setUp() {
-        $this->user = $this->getDataGenerator()->create_user();
-        $this->course = $this->getDataGenerator()->create_course();
-        $generator = $this->getDataGenerator()->get_plugin_generator('mod_assign');
-        $instance = $generator->create_instance(array('course' => $this->course->id));
-        $this->cm = get_coursemodule_from_instance('assign', $instance->id);
-        $this->context = context_module::instance($this->cm->id);
-
-        // Standard Event parameters.
-        $this->params = array(
-            'context' => $this->context,
-            'courseid' => $this->course->id
-        );
-    }
-
-    /**
-     * Basic tests for the submission_created() abstract class.
-     */
-    public function test_submission_created() {
-        $this->resetAfterTest();
-
-        $eventinfo = $this->params;
-        $eventinfo['other'] = array(
-            'submissionid' => '17',
-            'submissionattempt' => 0,
-            'submissionstatus' => 'submitted'
-        );
-
-        $sink = $this->redirectEvents();
-        $event = \mod_assign_unittests\event\submission_created::create($eventinfo);
-        $event->trigger();
-        $result = $sink->get_events();
-        $event = reset($result);
-        $sink->close();
-
-        $this->assertEquals($this->context->id, $event->contextid);
-        $this->assertEquals($this->course->id, $event->courseid);
-
-        // Check that an error occurs when teamsubmission is not set.
-        try {
-            \mod_assign_unittests\event\submission_created::create($this->params);
-            $this->fail('Other must contain the key submissionid.');
-        } catch (Exception $e) {
-            $this->assertInstanceOf('coding_exception', $e);
-        }
-        // Check that the submission status debugging is fired.
-        $subinfo = $this->params;
-        $subinfo['other'] = array('submissionid' => '23');
-        try {
-            \mod_assign_unittests\event\submission_created::create($subinfo);
-            $this->fail('Other must contain the key submissionattempt.');
-        } catch (Exception $e) {
-            $this->assertInstanceOf('coding_exception', $e);
-        }
-
-        $subinfo['other'] = array('submissionattempt' => '0');
-        try {
-            \mod_assign_unittests\event\submission_created::create($subinfo);
-            $this->fail('Other must contain the key submissionstatus.');
-        } catch (Exception $e) {
-            $this->assertInstanceOf('coding_exception', $e);
-        }
-    }
-
-    /**
-     * Basic tests for the submission_updated() abstract class.
-     */
-    public function test_submission_updated() {
-        $this->resetAfterTest();
-
-        $eventinfo = $this->params;
-        $eventinfo['other'] = array(
-            'submissionid' => '17',
-            'submissionattempt' => 0,
-            'submissionstatus' => 'submitted'
-        );
-
-        $sink = $this->redirectEvents();
-        $event = \mod_assign_unittests\event\submission_updated::create($eventinfo);
-        $event->trigger();
-        $result = $sink->get_events();
-        $event = reset($result);
-        $sink->close();
-
-        $this->assertEquals($this->context->id, $event->contextid);
-        $this->assertEquals($this->course->id, $event->courseid);
-
-        // Check that an error occurs when teamsubmission is not set.
-        try {
-            \mod_assign_unittests\event\submission_created::create($this->params);
-            $this->fail('Other must contain the key submissionid.');
-        } catch (Exception $e) {
-            $this->assertInstanceOf('coding_exception', $e);
-        }
-        // Check that the submission status debugging is fired.
-        $subinfo = $this->params;
-        $subinfo['other'] = array('submissionid' => '23');
-        try {
-            \mod_assign_unittests\event\submission_created::create($subinfo);
-            $this->fail('Other must contain the key submissionattempt.');
-        } catch (Exception $e) {
-            $this->assertInstanceOf('coding_exception', $e);
-        }
-
-        $subinfo['other'] = array('submissionattempt' => '0');
-        try {
-            \mod_assign_unittests\event\submission_created::create($subinfo);
-            $this->fail('Other must contain the key submissionstatus.');
-        } catch (Exception $e) {
-            $this->assertInstanceOf('coding_exception', $e);
-        }
-    }
-}
-
diff --git a/mod/assign/tests/events_test.php b/mod/assign/tests/events_test.php
new file mode 100644 (file)
index 0000000..d565927
--- /dev/null
@@ -0,0 +1,474 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Contains the event tests for the module assign.
+ *
+ * @package   mod_assign
+ * @copyright 2014 Adrian Greeve <adrian@moodle.com>
+ * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+global $CFG;
+require_once($CFG->dirroot . '/mod/assign/tests/base_test.php');
+require_once($CFG->dirroot . '/mod/assign/tests/fixtures/event_mod_assign_fixtures.php');
+
+/**
+ * Contains the event tests for the module assign.
+ *
+ * @package   mod_assign
+ * @copyright 2014 Adrian Greeve <adrian@moodle.com>
+ * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class assign_events_testcase extends mod_assign_base_testcase {
+
+    /**
+     * Basic tests for the submission_created() abstract class.
+     */
+    public function test_submission_created() {
+        $generator = $this->getDataGenerator()->get_plugin_generator('mod_assign');
+        $instance = $generator->create_instance(array('course' => $this->course->id));
+        $modcontext = context_module::instance($instance->cmid);
+
+        // Standard Event parameters.
+        $params = array(
+            'context' => $modcontext,
+            'courseid' => $this->course->id
+        );
+
+        $eventinfo = $params;
+        $eventinfo['other'] = array(
+            'submissionid' => '17',
+            'submissionattempt' => 0,
+            'submissionstatus' => 'submitted'
+        );
+
+        $sink = $this->redirectEvents();
+        $event = \mod_assign_unittests\event\submission_created::create($eventinfo);
+        $event->trigger();
+        $result = $sink->get_events();
+        $event = reset($result);
+        $sink->close();
+
+        $this->assertEquals($modcontext->id, $event->contextid);
+        $this->assertEquals($this->course->id, $event->courseid);
+
+        // Check that an error occurs when teamsubmission is not set.
+        try {
+            \mod_assign_unittests\event\submission_created::create($params);
+            $this->fail('Other must contain the key submissionid.');
+        } catch (Exception $e) {
+            $this->assertInstanceOf('coding_exception', $e);
+        }
+        // Check that the submission status debugging is fired.
+        $subinfo = $params;
+        $subinfo['other'] = array('submissionid' => '23');
+        try {
+            \mod_assign_unittests\event\submission_created::create($subinfo);
+            $this->fail('Other must contain the key submissionattempt.');
+        } catch (Exception $e) {
+            $this->assertInstanceOf('coding_exception', $e);
+        }
+
+        $subinfo['other'] = array('submissionattempt' => '0');
+        try {
+            \mod_assign_unittests\event\submission_created::create($subinfo);
+            $this->fail('Other must contain the key submissionstatus.');
+        } catch (Exception $e) {
+            $this->assertInstanceOf('coding_exception', $e);
+        }
+    }
+
+    /**
+     * Basic tests for the submission_updated() abstract class.
+     */
+    public function test_submission_updated() {
+        $generator = $this->getDataGenerator()->get_plugin_generator('mod_assign');
+        $instance = $generator->create_instance(array('course' => $this->course->id));
+        $modcontext = context_module::instance($instance->cmid);
+
+        // Standard Event parameters.
+        $params = array(
+            'context' => $modcontext,
+            'courseid' => $this->course->id
+        );
+
+        $eventinfo = $params;
+        $eventinfo['other'] = array(
+            'submissionid' => '17',
+            'submissionattempt' => 0,
+            'submissionstatus' => 'submitted'
+        );
+
+        $sink = $this->redirectEvents();
+        $event = \mod_assign_unittests\event\submission_updated::create($eventinfo);
+        $event->trigger();
+        $result = $sink->get_events();
+        $event = reset($result);
+        $sink->close();
+
+        $this->assertEquals($modcontext->id, $event->contextid);
+        $this->assertEquals($this->course->id, $event->courseid);
+
+        // Check that an error occurs when teamsubmission is not set.
+        try {
+            \mod_assign_unittests\event\submission_created::create($params);
+            $this->fail('Other must contain the key submissionid.');
+        } catch (Exception $e) {
+            $this->assertInstanceOf('coding_exception', $e);
+        }
+        // Check that the submission status debugging is fired.
+        $subinfo = $params;
+        $subinfo['other'] = array('submissionid' => '23');
+        try {
+            \mod_assign_unittests\event\submission_created::create($subinfo);
+            $this->fail('Other must contain the key submissionattempt.');
+        } catch (Exception $e) {
+            $this->assertInstanceOf('coding_exception', $e);
+        }
+
+        $subinfo['other'] = array('submissionattempt' => '0');
+        try {
+            \mod_assign_unittests\event\submission_created::create($subinfo);
+            $this->fail('Other must contain the key submissionstatus.');
+        } catch (Exception $e) {
+            $this->assertInstanceOf('coding_exception', $e);
+        }
+    }
+
+    public function test_extension_granted() {
+        $this->setUser($this->editingteachers[0]);
+
+        $tomorrow = time() + 24*60*60;
+        $yesterday = time() - 24*60*60;
+
+        $assign = $this->create_instance(array('duedate' => $yesterday, 'cutoffdate' => $yesterday));
+        $sink = $this->redirectEvents();
+
+        $assign->testable_save_user_extension($this->students[0]->id, $tomorrow);
+
+        $events = $sink->get_events();
+        $this->assertCount(1, $events);
+        $event = reset($events);
+        $this->assertInstanceOf('\mod_assign\event\extension_granted', $event);
+        $this->assertEquals($assign->get_context(), $event->get_context());
+        $this->assertEquals($assign->get_instance()->id, $event->objectid);
+        $this->assertEquals($this->students[0]->id, $event->relateduserid);
+        $expected = array(
+            $assign->get_course()->id,
+            'assign',
+            'grant extension',
+            'view.php?id=' . $assign->get_course_module()->id,
+            $this->students[0]->id,
+            $assign->get_course_module()->id
+        );
+        $this->assertEventLegacyLogData($expected, $event);
+        $sink->close();
+    }
+
+    public function test_submission_locked() {
+        $this->editingteachers[0]->ignoresesskey = true;
+        $this->setUser($this->editingteachers[0]);
+
+        $assign = $this->create_instance();
+        $sink = $this->redirectEvents();
+
+        $assign->lock_submission($this->students[0]->id);
+
+        $events = $sink->get_events();
+        $this->assertCount(1, $events);
+        $event = reset($events);
+        $this->assertInstanceOf('\mod_assign\event\submission_locked', $event);
+        $this->assertEquals($assign->get_context(), $event->get_context());
+        $this->assertEquals($assign->get_instance()->id, $event->objectid);
+        $this->assertEquals($this->students[0]->id, $event->relateduserid);
+        $expected = array(
+            $assign->get_course()->id,
+            'assign',
+            'lock submission',
+            'view.php?id=' . $assign->get_course_module()->id,
+            get_string('locksubmissionforstudent', 'assign', array('id' => $this->students[0]->id,
+                'fullname' => fullname($this->students[0]))),
+            $assign->get_course_module()->id
+        );
+        $this->assertEventLegacyLogData($expected, $event);
+        $sink->close();
+
+        // Revert to defaults.
+        $this->editingteachers[0]->ignoresesskey = false;
+    }
+
+    public function test_identities_revealed() {
+        $this->editingteachers[0]->ignoresesskey = true;
+        $this->setUser($this->editingteachers[0]);
+
+        $assign = $this->create_instance(array('blindmarking'=>1));
+        $sink = $this->redirectEvents();
+
+        $assign->reveal_identities();
+
+        $events = $sink->get_events();
+        $this->assertCount(1, $events);
+        $event = reset($events);
+        $this->assertInstanceOf('\mod_assign\event\identities_revealed', $event);
+        $this->assertEquals($assign->get_context(), $event->get_context());
+        $this->assertEquals($assign->get_instance()->id, $event->objectid);
+        $expected = array(
+            $assign->get_course()->id,
+            'assign',
+            'reveal identities',
+            'view.php?id=' . $assign->get_course_module()->id,
+            get_string('revealidentities', 'assign'),
+            $assign->get_course_module()->id
+        );
+        $this->assertEventLegacyLogData($expected, $event);
+        $sink->close();
+
+        // Revert to defaults.
+        $this->editingteachers[0]->ignoresesskey = false;
+    }
+
+    public function test_submission_status_updated() {
+        $this->editingteachers[0]->ignoresesskey = true;
+        $this->setUser($this->editingteachers[0]);
+
+        $assign = $this->create_instance();
+        $submission = $assign->get_user_submission($this->students[0]->id, true);
+        $submission->status = ASSIGN_SUBMISSION_STATUS_SUBMITTED;
+        $assign->testable_update_submission($submission, $this->students[0]->id, true, false);
+
+        $sink = $this->redirectEvents();
+        $assign->revert_to_draft($this->students[0]->id);
+
+        $events = $sink->get_events();
+        $this->assertCount(1, $events);
+        $event = reset($events);
+        $this->assertInstanceOf('\mod_assign\event\submission_status_updated', $event);
+        $this->assertEquals($assign->get_context(), $event->get_context());
+        $this->assertEquals($submission->id, $event->objectid);
+        $this->assertEquals($this->students[0]->id, $event->relateduserid);
+        $this->assertEquals(ASSIGN_SUBMISSION_STATUS_DRAFT, $event->other['newstatus']);
+        $expected = array(
+            $assign->get_course()->id,
+            'assign',
+            'revert submission to draft',
+            'view.php?id=' . $assign->get_course_module()->id,
+            get_string('reverttodraftforstudent', 'assign', array('id' => $this->students[0]->id,
+                'fullname' => fullname($this->students[0]))),
+            $assign->get_course_module()->id
+        );
+        $this->assertEventLegacyLogData($expected, $event);
+        $sink->close();
+
+        // Revert to defaults.
+        $this->editingteachers[0]->ignoresesskey = false;
+    }
+
+    public function test_marker_updated() {
+        $this->editingteachers[0]->ignoresesskey = true;
+        $this->setUser($this->editingteachers[0]);
+
+        $assign = $this->create_instance();
+
+        $sink = $this->redirectEvents();
+        $assign->testable_process_set_batch_marking_allocation($this->students[0]->id, $this->teachers[0]->id);
+
+        $events = $sink->get_events();
+        $this->assertCount(1, $events);
+        $event = reset($events);
+        $this->assertInstanceOf('\mod_assign\event\marker_updated', $event);
+        $this->assertEquals($assign->get_context(), $event->get_context());
+        $this->assertEquals($assign->get_instance()->id, $event->objectid);
+        $this->assertEquals($this->students[0]->id, $event->relateduserid);
+        $this->assertEquals($this->editingteachers[0]->id, $event->userid);
+        $this->assertEquals($this->teachers[0]->id, $event->other['markerid']);
+        $expected = array(
+            $assign->get_course()->id,
+            'assign',
+            'set marking allocation',
+            'view.php?id=' . $assign->get_course_module()->id,
+            get_string('setmarkerallocationforlog', 'assign', array('id' => $this->students[0]->id,
+                'fullname' => fullname($this->students[0]), 'marker' => fullname($this->teachers[0]))),
+            $assign->get_course_module()->id
+        );
+        $this->assertEventLegacyLogData($expected, $event);
+        $sink->close();
+
+        // Revert to defaults.
+        $this->editingteachers[0]->ignoresesskey = false;
+    }
+
+    public function test_workflow_state_updated() {
+        $this->editingteachers[0]->ignoresesskey = true;
+        $this->setUser($this->editingteachers[0]);
+
+        $assign = $this->create_instance();
+
+        $sink = $this->redirectEvents();
+        $assign->testable_process_set_batch_marking_workflow_state($this->students[0]->id, ASSIGN_MARKING_WORKFLOW_STATE_INREVIEW);
+
+        $events = $sink->get_events();
+        $this->assertCount(1, $events);
+        $event = reset($events);
+        $this->assertInstanceOf('\mod_assign\event\workflow_state_updated', $event);
+        $this->assertEquals($assign->get_context(), $event->get_context());
+        $this->assertEquals($assign->get_instance()->id, $event->objectid);
+        $this->assertEquals($this->students[0]->id, $event->relateduserid);
+        $this->assertEquals($this->editingteachers[0]->id, $event->userid);
+        $this->assertEquals(ASSIGN_MARKING_WORKFLOW_STATE_INREVIEW, $event->other['newstate']);
+        $expected = array(
+            $assign->get_course()->id,
+            'assign',
+            'set marking workflow state',
+            'view.php?id=' . $assign->get_course_module()->id,
+            get_string('setmarkingworkflowstateforlog', 'assign', array('id' => $this->students[0]->id,
+                'fullname' => fullname($this->students[0]), 'state' => ASSIGN_MARKING_WORKFLOW_STATE_INREVIEW)),
+            $assign->get_course_module()->id
+        );
+        $this->assertEventLegacyLogData($expected, $event);
+        $sink->close();
+
+        // Revert to defaults.
+        $this->editingteachers[0]->ignoresesskey = false;
+    }
+
+    public function test_submission_duplicated() {
+        $this->setUser($this->students[0]);
+
+        $assign = $this->create_instance();
+        $submission1 = $assign->get_user_submission($this->students[0]->id, true, 0);
+        $submission2 = $assign->get_user_submission($this->students[0]->id, true, 1);
+        $submission2->status = ASSIGN_SUBMISSION_STATUS_REOPENED;
+        $assign->testable_update_submission($submission2, $this->students[0]->id, time(), $assign->get_instance()->teamsubmission);
+
+        $sink = $this->redirectEvents();
+        $notices = null;
+        $assign->copy_previous_attempt($notices);
+
+        $events = $sink->get_events();
+        $this->assertCount(1, $events);
+        $event = reset($events);
+        $this->assertInstanceOf('\mod_assign\event\submission_duplicated', $event);
+        $this->assertEquals($assign->get_context(), $event->get_context());
+        $this->assertEquals($submission2->id, $event->objectid);
+        $this->assertEquals($this->students[0]->id, $event->userid);
+        $submission2->status = ASSIGN_SUBMISSION_STATUS_DRAFT;
+        $expected = array(
+            $assign->get_course()->id,
+            'assign',
+            'submissioncopied',
+            'view.php?id=' . $assign->get_course_module()->id,
+            $assign->testable_format_submission_for_log($submission2),
+            $assign->get_course_module()->id
+        );
+        $this->assertEventLegacyLogData($expected, $event);
+        $sink->close();
+    }
+
+    public function test_submission_unlocked() {
+        $this->editingteachers[0]->ignoresesskey = true;
+        $this->setUser($this->editingteachers[0]);
+
+        $assign = $this->create_instance();
+        $sink = $this->redirectEvents();
+
+        $assign->unlock_submission($this->students[0]->id);
+
+        $events = $sink->get_events();
+        $this->assertCount(1, $events);
+        $event = reset($events);
+        $this->assertInstanceOf('\mod_assign\event\submission_unlocked', $event);
+        $this->assertEquals($assign->get_context(), $event->get_context());
+        $this->assertEquals($assign->get_instance()->id, $event->objectid);
+        $this->assertEquals($this->students[0]->id, $event->relateduserid);
+        $expected = array(
+            $assign->get_course()->id,
+            'assign',
+            'unlock submission',
+            'view.php?id=' . $assign->get_course_module()->id,
+            get_string('unlocksubmissionforstudent', 'assign', array('id' => $this->students[0]->id,
+                'fullname' => fullname($this->students[0]))),
+            $assign->get_course_module()->id
+        );
+        $this->assertEventLegacyLogData($expected, $event);
+        $sink->close();
+
+        // Revert to defaults.
+        $this->editingteachers[0]->ignoresesskey = false;
+    }
+
+    public function test_submission_graded() {
+        $this->setUser($this->editingteachers[0]);
+        $assign = $this->create_instance();
+
+        // Test apply_grade_to_user.
+        $sink = $this->redirectEvents();
+
+        $data = new stdClass();
+        $data->grade = '50.0';
+        $assign->testable_apply_grade_to_user($data, $this->students[0]->id, 0);
+        $grade = $assign->get_user_grade($this->students[0]->id, false, 0);
+
+        $events = $sink->get_events();
+        $this->assertCount(1, $events);
+        $event = reset($events);
+        $this->assertInstanceOf('\mod_assign\event\submission_graded', $event);
+        $this->assertEquals($assign->get_context(), $event->get_context());
+        $this->assertEquals($grade->id, $event->objectid);
+        $this->assertEquals($this->students[0]->id, $event->relateduserid);
+        $expected = array(
+            $assign->get_course()->id,
+            'assign',
+            'grade submission',
+            'view.php?id=' . $assign->get_course_module()->id,
+            $assign->format_grade_for_log($grade),
+            $assign->get_course_module()->id
+        );
+        $this->assertEventLegacyLogData($expected, $event);
+        $sink->close();
+
+        // Test process_save_quick_grades.
+        $sink = $this->redirectEvents();
+
+        $data = array(
+            'grademodified_' . $this->students[0]->id => time(),
+            'quickgrade_' . $this->students[0]->id => '60.0'
+        );
+        $assign->testable_process_save_quick_grades($data);
+        $grade = $assign->get_user_grade($this->students[0]->id, false);
+        $this->assertEquals('60.0', $grade->grade);
+
+        $events = $sink->get_events();
+        $this->assertCount(1, $events);
+        $event = reset($events);
+        $this->assertInstanceOf('\mod_assign\event\submission_graded', $event);
+        $this->assertEquals($assign->get_context(), $event->get_context());
+        $this->assertEquals($grade->id, $event->objectid);
+        $this->assertEquals($this->students[0]->id, $event->relateduserid);
+        $expected = array(
+            $assign->get_course()->id,
+            'assign',
+            'grade submission',
+            'view.php?id=' . $assign->get_course_module()->id,
+            $assign->format_grade_for_log($grade),
+            $assign->get_course_module()->id
+        );
+        $this->assertEventLegacyLogData($expected, $event);
+        $sink->close();
+    }
+}
index 49afbf7..de3103a 100644 (file)
@@ -1147,133 +1147,7 @@ class mod_assign_locallib_testcase extends mod_assign_base_testcase {
         $this->assertNotEquals(true, strpos($output, $this->students[0]->lastname));
     }
 
-    public function test_extension_granted_event() {
-        $this->setUser($this->editingteachers[0]);
-
-        $tomorrow = time() + 24*60*60;
-        $yesterday = time() - 24*60*60;
-
-        $assign = $this->create_instance(array('duedate' => $yesterday, 'cutoffdate' => $yesterday));
-        $sink = $this->redirectEvents();
-
-        $assign->testable_save_user_extension($this->students[0]->id, $tomorrow);
-
-        $events = $sink->get_events();
-        $this->assertCount(1, $events);
-        $event = reset($events);
-        $this->assertInstanceOf('\mod_assign\event\extension_granted', $event);
-        $this->assertEquals($assign->get_context(), $event->get_context());
-        $this->assertEquals($assign->get_instance()->id, $event->objectid);
-        $this->assertEquals($this->students[0]->id, $event->relateduserid);
-        $expected = array(
-            $assign->get_course()->id,
-            'assign',
-            'grant extension',
-            'view.php?id=' . $assign->get_course_module()->id,
-            $this->students[0]->id,
-            $assign->get_course_module()->id
-        );
-        $this->assertEventLegacyLogData($expected, $event);
-        $sink->close();
-    }
-
-    public function test_submission_locked_event() {
-        $this->editingteachers[0]->ignoresesskey = true;
-        $this->setUser($this->editingteachers[0]);
 
-        $assign = $this->create_instance();
-        $sink = $this->redirectEvents();
-
-        $assign->lock_submission($this->students[0]->id);
-
-        $events = $sink->get_events();
-        $this->assertCount(1, $events);
-        $event = reset($events);
-        $this->assertInstanceOf('\mod_assign\event\submission_locked', $event);
-        $this->assertEquals($assign->get_context(), $event->get_context());
-        $this->assertEquals($assign->get_instance()->id, $event->objectid);
-        $this->assertEquals($this->students[0]->id, $event->relateduserid);
-        $expected = array(
-            $assign->get_course()->id,
-            'assign',
-            'lock submission',
-            'view.php?id=' . $assign->get_course_module()->id,
-            get_string('locksubmissionforstudent', 'assign', array('id' => $this->students[0]->id,
-                'fullname' => fullname($this->students[0]))),
-            $assign->get_course_module()->id
-        );
-        $this->assertEventLegacyLogData($expected, $event);
-        $sink->close();
-
-        // Revert to defaults.
-        $this->editingteachers[0]->ignoresesskey = false;
-    }
-
-    public function test_identities_revealed_event() {
-        $this->editingteachers[0]->ignoresesskey = true;
-        $this->setUser($this->editingteachers[0]);
-
-        $assign = $this->create_instance(array('blindmarking'=>1));
-        $sink = $this->redirectEvents();
-
-        $assign->reveal_identities();
-
-        $events = $sink->get_events();
-        $this->assertCount(1, $events);
-        $event = reset($events);
-        $this->assertInstanceOf('\mod_assign\event\identities_revealed', $event);
-        $this->assertEquals($assign->get_context(), $event->get_context());
-        $this->assertEquals($assign->get_instance()->id, $event->objectid);
-        $expected = array(
-            $assign->get_course()->id,
-            'assign',
-            'reveal identities',
-            'view.php?id=' . $assign->get_course_module()->id,
-            get_string('revealidentities', 'assign'),
-            $assign->get_course_module()->id
-        );
-        $this->assertEventLegacyLogData($expected, $event);
-        $sink->close();
-
-        // Revert to defaults.
-        $this->editingteachers[0]->ignoresesskey = false;
-    }
-
-    public function test_submission_status_updated_event() {
-        $this->editingteachers[0]->ignoresesskey = true;
-        $this->setUser($this->editingteachers[0]);
-
-        $assign = $this->create_instance();
-        $submission = $assign->get_user_submission($this->students[0]->id, true);
-        $submission->status = ASSIGN_SUBMISSION_STATUS_SUBMITTED;
-        $assign->testable_update_submission($submission, $this->students[0]->id, true, false);
-
-        $sink = $this->redirectEvents();
-        $assign->revert_to_draft($this->students[0]->id);
-
-        $events = $sink->get_events();
-        $this->assertCount(1, $events);
-        $event = reset($events);
-        $this->assertInstanceOf('\mod_assign\event\submission_status_updated', $event);
-        $this->assertEquals($assign->get_context(), $event->get_context());
-        $this->assertEquals($submission->id, $event->objectid);
-        $this->assertEquals($this->students[0]->id, $event->relateduserid);
-        $this->assertEquals(ASSIGN_SUBMISSION_STATUS_DRAFT, $event->other['newstatus']);
-        $expected = array(
-            $assign->get_course()->id,
-            'assign',
-            'revert submission to draft',
-            'view.php?id=' . $assign->get_course_module()->id,
-            get_string('reverttodraftforstudent', 'assign', array('id' => $this->students[0]->id,
-                'fullname' => fullname($this->students[0]))),
-            $assign->get_course_module()->id
-        );
-        $this->assertEventLegacyLogData($expected, $event);
-        $sink->close();
-
-        // Revert to defaults.
-        $this->editingteachers[0]->ignoresesskey = false;
-    }
 
     public function test_teacher_submit_for_student() {
         global $PAGE;
@@ -1359,199 +1233,6 @@ class mod_assign_locallib_testcase extends mod_assign_base_testcase {
         $sink->close();
     }
 
-    public function test_marker_updated_event() {
-        $this->editingteachers[0]->ignoresesskey = true;
-        $this->setUser($this->editingteachers[0]);
-
-        $assign = $this->create_instance();
-
-        $sink = $this->redirectEvents();
-        $assign->testable_process_set_batch_marking_allocation($this->students[0]->id, $this->teachers[0]->id);
-
-        $events = $sink->get_events();
-        $this->assertCount(1, $events);
-        $event = reset($events);
-        $this->assertInstanceOf('\mod_assign\event\marker_updated', $event);
-        $this->assertEquals($assign->get_context(), $event->get_context());
-        $this->assertEquals($assign->get_instance()->id, $event->objectid);
-        $this->assertEquals($this->students[0]->id, $event->relateduserid);
-        $this->assertEquals($this->editingteachers[0]->id, $event->userid);
-        $this->assertEquals($this->teachers[0]->id, $event->other['markerid']);
-        $expected = array(
-            $assign->get_course()->id,
-            'assign',
-            'set marking allocation',
-            'view.php?id=' . $assign->get_course_module()->id,
-            get_string('setmarkerallocationforlog', 'assign', array('id' => $this->students[0]->id,
-                'fullname' => fullname($this->students[0]), 'marker' => fullname($this->teachers[0]))),
-            $assign->get_course_module()->id
-        );
-        $this->assertEventLegacyLogData($expected, $event);
-        $sink->close();
-
-        // Revert to defaults.
-        $this->editingteachers[0]->ignoresesskey = false;
-    }
-
-    public function test_workflow_state_updated_event() {
-        $this->editingteachers[0]->ignoresesskey = true;
-        $this->setUser($this->editingteachers[0]);
-
-        $assign = $this->create_instance();
-
-        $sink = $this->redirectEvents();
-        $assign->testable_process_set_batch_marking_workflow_state($this->students[0]->id, ASSIGN_MARKING_WORKFLOW_STATE_INREVIEW);
-
-        $events = $sink->get_events();
-        $this->assertCount(1, $events);
-        $event = reset($events);
-        $this->assertInstanceOf('\mod_assign\event\workflow_state_updated', $event);
-        $this->assertEquals($assign->get_context(), $event->get_context());
-        $this->assertEquals($assign->get_instance()->id, $event->objectid);
-        $this->assertEquals($this->students[0]->id, $event->relateduserid);
-        $this->assertEquals($this->editingteachers[0]->id, $event->userid);
-        $this->assertEquals(ASSIGN_MARKING_WORKFLOW_STATE_INREVIEW, $event->other['newstate']);
-        $expected = array(
-            $assign->get_course()->id,
-            'assign',
-            'set marking workflow state',
-            'view.php?id=' . $assign->get_course_module()->id,
-            get_string('setmarkingworkflowstateforlog', 'assign', array('id' => $this->students[0]->id,
-                'fullname' => fullname($this->students[0]), 'state' => ASSIGN_MARKING_WORKFLOW_STATE_INREVIEW)),
-            $assign->get_course_module()->id
-        );
-        $this->assertEventLegacyLogData($expected, $event);
-        $sink->close();
-
-        // Revert to defaults.
-        $this->editingteachers[0]->ignoresesskey = false;
-    }
-
-    public function test_submission_duplicated_event() {
-        $this->setUser($this->students[0]);
-
-        $assign = $this->create_instance();
-        $submission1 = $assign->get_user_submission($this->students[0]->id, true, 0);
-        $submission2 = $assign->get_user_submission($this->students[0]->id, true, 1);
-        $submission2->status = ASSIGN_SUBMISSION_STATUS_REOPENED;
-        $assign->testable_update_submission($submission2, $this->students[0]->id, time(), $assign->get_instance()->teamsubmission);
-
-        $sink = $this->redirectEvents();
-        $notices = null;
-        $assign->copy_previous_attempt($notices);
-
-        $events = $sink->get_events();
-        $this->assertCount(1, $events);
-        $event = reset($events);
-        $this->assertInstanceOf('\mod_assign\event\submission_duplicated', $event);
-        $this->assertEquals($assign->get_context(), $event->get_context());
-        $this->assertEquals($submission2->id, $event->objectid);
-        $this->assertEquals($this->students[0]->id, $event->userid);
-        $submission2->status = ASSIGN_SUBMISSION_STATUS_DRAFT;
-        $expected = array(
-            $assign->get_course()->id,
-            'assign',
-            'submissioncopied',
-            'view.php?id=' . $assign->get_course_module()->id,
-            $assign->testable_format_submission_for_log($submission2),
-            $assign->get_course_module()->id
-        );
-        $this->assertEventLegacyLogData($expected, $event);
-        $sink->close();
-    }
-
-    public function test_submission_unlocked_event() {
-        $this->editingteachers[0]->ignoresesskey = true;
-        $this->setUser($this->editingteachers[0]);
-
-        $assign = $this->create_instance();
-        $sink = $this->redirectEvents();
-
-        $assign->unlock_submission($this->students[0]->id);
-
-        $events = $sink->get_events();
-        $this->assertCount(1, $events);
-        $event = reset($events);
-        $this->assertInstanceOf('\mod_assign\event\submission_unlocked', $event);
-        $this->assertEquals($assign->get_context(), $event->get_context());
-        $this->assertEquals($assign->get_instance()->id, $event->objectid);
-        $this->assertEquals($this->students[0]->id, $event->relateduserid);
-        $expected = array(
-            $assign->get_course()->id,
-            'assign',
-            'unlock submission',
-            'view.php?id=' . $assign->get_course_module()->id,
-            get_string('unlocksubmissionforstudent', 'assign', array('id' => $this->students[0]->id,
-                'fullname' => fullname($this->students[0]))),
-            $assign->get_course_module()->id
-        );
-        $this->assertEventLegacyLogData($expected, $event);
-        $sink->close();
-
-        // Revert to defaults.
-        $this->editingteachers[0]->ignoresesskey = false;
-    }
-
-    public function test_submission_graded_event() {
-        $this->setUser($this->editingteachers[0]);
-        $assign = $this->create_instance();
-
-        // Test apply_grade_to_user.
-        $sink = $this->redirectEvents();
-
-        $data = new stdClass();
-        $data->grade = '50.0';
-        $assign->testable_apply_grade_to_user($data, $this->students[0]->id, 0);
-        $grade = $assign->get_user_grade($this->students[0]->id, false, 0);
-
-        $events = $sink->get_events();
-        $this->assertCount(1, $events);
-        $event = reset($events);
-        $this->assertInstanceOf('\mod_assign\event\submission_graded', $event);
-        $this->assertEquals($assign->get_context(), $event->get_context());
-        $this->assertEquals($grade->id, $event->objectid);
-        $this->assertEquals($this->students[0]->id, $event->relateduserid);
-        $expected = array(
-            $assign->get_course()->id,
-            'assign',
-            'grade submission',
-            'view.php?id=' . $assign->get_course_module()->id,
-            $assign->format_grade_for_log($grade),
-            $assign->get_course_module()->id
-        );
-        $this->assertEventLegacyLogData($expected, $event);
-        $sink->close();
-
-        // Test process_save_quick_grades.
-        $sink = $this->redirectEvents();
-
-        $data = array(
-            'grademodified_' . $this->students[0]->id => time(),
-            'quickgrade_' . $this->students[0]->id => '60.0'
-        );
-        $assign->testable_process_save_quick_grades($data);
-        $grade = $assign->get_user_grade($this->students[0]->id, false);
-        $this->assertEquals('60.0', $grade->grade);
-
-        $events = $sink->get_events();
-        $this->assertCount(1, $events);
-        $event = reset($events);
-        $this->assertInstanceOf('\mod_assign\event\submission_graded', $event);
-        $this->assertEquals($assign->get_context(), $event->get_context());
-        $this->assertEquals($grade->id, $event->objectid);
-        $this->assertEquals($this->students[0]->id, $event->relateduserid);
-        $expected = array(
-            $assign->get_course()->id,
-            'assign',
-            'grade submission',
-            'view.php?id=' . $assign->get_course_module()->id,
-            $assign->format_grade_for_log($grade),
-            $assign->get_course_module()->id
-        );
-        $this->assertEventLegacyLogData($expected, $event);
-        $sink->close();
-    }
-
     public function test_disable_submit_after_cutoff_date() {
         global $PAGE;