Merge branch 'MDL-40697_master_alt_usergraded' of https://github.com/markn86/moodle
authorDan Poltawski <dan@moodle.com>
Wed, 8 Oct 2014 07:39:31 +0000 (08:39 +0100)
committerDan Poltawski <dan@moodle.com>
Wed, 8 Oct 2014 07:39:31 +0000 (08:39 +0100)
13 files changed:
grade/edit/tree/grade.php
grade/report/grader/ajax_callbacks.php
grade/report/grader/lib.php
lang/en/grades.php
lib/classes/event/grade_deleted.php [new file with mode: 0644]
lib/grade/grade_category.php
lib/grade/grade_grade.php
lib/grade/grade_item.php
lib/tests/event_grade_deleted_test.php [new file with mode: 0644]
lib/tests/event_user_graded_test.php
mod/assign/tests/events_test.php
mod/quiz/tests/events_test.php
mod/scorm/tests/events_test.php

index 62536f6..dd9cce3 100644 (file)
@@ -265,14 +265,6 @@ if ($mform->is_cancelled()) {
         $grade_item->force_regrading();
     }
 
-    $grade_grade = new grade_grade(array('userid'=>$data->userid, 'itemid'=>$grade_item->id), true);
-    if ($old_grade_grade->finalgrade != $grade_grade->finalgrade
-        or empty($old_grade_grade->overridden) != empty($grade_grade->overridden)
-    ) {
-        $grade_grade->grade_item = $grade_item;
-        \core\event\user_graded::create_from_grade($grade_grade)->trigger();
-    }
-
     redirect($returnurl);
 }
 
index d49e265..f0c7188 100644 (file)
@@ -120,8 +120,6 @@ switch ($action) {
             } else {
                 $json_object->gradevalue = $finalvalue;
 
-                $old_grade_grade = new grade_grade(array('userid' => $userid, 'itemid' => $grade_item->id), true);
-
                 if ($grade_item->update_final_grade($userid, $finalgrade, 'gradebook', $feedback, FORMAT_MOODLE)) {
                     $json_object->result = 'success';
                     $json_object->message = false;
@@ -132,14 +130,6 @@ switch ($action) {
                     die();
                 }
 
-                $grade_grade = new grade_grade(array('userid' => $userid, 'itemid' => $grade_item->id), true);
-                if ($old_grade_grade->finalgrade != $grade_grade->finalgrade
-                    or empty($old_grade_grade->overridden) != empty($grade_grade->overridden)
-                ) {
-                    $grade_grade->load_grade_item();
-                    \core\event\user_graded::create_from_grade($grade_grade)->trigger();
-                }
-
                 // Get row data
                 $sql = "SELECT gg.id, gi.id AS itemid, gi.scaleid AS scale, gg.userid AS userid, finalgrade, gg.overridden AS overridden "
                      . "FROM {grade_grades} gg, {grade_items} gi WHERE "
index 6aabf4c..586650b 100644 (file)
@@ -305,19 +305,8 @@ class grade_report_grader extends grade_report {
                         }
                     }
 
-                    $oldgradegrade = new grade_grade(array('userid' => $userid, 'itemid' => $gradeitem->id), true);
-
                     $gradeitem->update_final_grade($userid, $finalgrade, 'gradebook', $feedback, FORMAT_MOODLE);
 
-                    $gradegrade = new grade_grade(array('userid' => $userid, 'itemid' => $gradeitem->id), true);
-
-                    if ($oldgradegrade->finalgrade != $gradegrade->finalgrade
-                        or empty($oldgradegrade->overridden) != empty($gradegrade->overridden)
-                    ) {
-                        $gradegrade->grade_item = $gradeitem;
-                        \core\event\user_graded::create_from_grade($gradegrade)->trigger();
-                    }
-
                     // We can update feedback without reloading the grade item as it doesn't affect grade calculations
                     if ($datatype === 'feedback') {
                         $this->grades[$userid][$itemid]->feedback = $feedback;
index fa07263..abd1312 100644 (file)
@@ -194,8 +194,9 @@ $string['errorupdatinggradecategoryaggregateoutcomes'] = 'Error updating the "In
 $string['errorupdatinggradecategoryaggregatesubcats'] = 'Error updating the "Aggregate including subcategories" setting of grade category ID {$a->id}';
 $string['errorupdatinggradecategoryaggregation'] = 'Error updating the aggregation type of grade category ID {$a->id}';
 $string['errorupdatinggradeitemaggregationcoef'] = 'Error updating the aggregation coefficient (weight or extra credit) of grade item ID {$a->id}';
+$string['eventgradedeleted'] = 'Grade deleted';
 $string['eventgradeviewed'] = 'Grades were viewed in the gradebook';
-$string['eventusergraded'] = 'User grade edited in gradebook';
+$string['eventusergraded'] = 'User graded';
 $string['excluded'] = 'Excluded';
 $string['excluded_help'] = 'If ticked, the grade will not be included in any aggregation.';
 $string['expand'] = 'Expand category';
diff --git a/lib/classes/event/grade_deleted.php b/lib/classes/event/grade_deleted.php
new file mode 100644 (file)
index 0000000..ffb6543
--- /dev/null
@@ -0,0 +1,134 @@
+<?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/>.
+
+/**
+ * Grade deleted event.
+ *
+ * @package    core
+ * @copyright  2014 Mark Nelson <markn@moodle.com>
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+namespace core\event;
+
+defined('MOODLE_INTERNAL') || die();
+
+/**
+ * Grade deleted event class.
+ *
+ * @property-read array $other {
+ *      Extra information about the event.
+ *
+ *      - int itemid: grade item id.
+ *      - bool overridden: is this a grade override?
+ *      - float finalgrade: (optional) the final grade value.
+ * }
+ *
+ * @package    core
+ * @since      Moodle 2.8
+ * @copyright  2014 Mark Nelson <markn@moodle.com>
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class grade_deleted extends base {
+
+    /** @var \grade_grade $grade */
+    protected $grade;
+
+    /**
+     * Init method.
+     *
+     * @return void
+     */
+    protected function init() {
+        $this->data['objecttable'] = 'grade_grades';
+        $this->data['crud'] = 'd';
+        $this->data['edulevel'] = self::LEVEL_TEACHING;
+    }
+
+    /**
+     * Utility method to create new event.
+     *
+     * @param \grade_grade $grade
+     * @return user_graded
+     */
+    public static function create_from_grade(\grade_grade $grade) {
+        $event = self::create(array(
+            'objectid'      => $grade->id,
+            'context'       => \context_course::instance($grade->grade_item->courseid),
+            'relateduserid' => $grade->userid,
+            'other'         => array(
+                'itemid'     => $grade->itemid,
+                'overridden' => !empty($grade->overridden),
+                'finalgrade' => $grade->finalgrade),
+        ));
+        $event->grade = $grade;
+        return $event;
+    }
+
+    /**
+     * Get grade object.
+     *
+     * @throws \coding_exception
+     * @return \grade_grade
+     */
+    public function get_grade() {
+        if ($this->is_restored()) {
+            throw new \coding_exception('get_grade() is intended for event observers only');
+        }
+        return $this->grade;
+    }
+
+    /**
+     * Return localised event name.
+     *
+     * @return string
+     */
+    public static function get_name() {
+        return get_string('eventgradedeleted', 'core_grades');
+    }
+
+    /**
+     * Returns description of what happened.
+     *
+     * @return string
+     */
+    public function get_description() {
+        return "The user with id '$this->userid' deleted the grade with id '$this->objectid' for the user with " .
+            "id '$this->relateduserid' for the grade item with id '{$this->other['itemid']}'.";
+    }
+
+    /**
+     * Custom validation.
+     *
+     * @throws \coding_exception when validation does not pass.
+     * @return void
+     */
+    protected function validate_data() {
+        parent::validate_data();
+
+        if (!isset($this->relateduserid)) {
+            throw new \coding_exception('The \'relateduserid\' must be set.');
+        }
+
+        if (!isset($this->other['itemid'])) {
+            throw new \coding_exception('The \'itemid\' value must be set in other.');
+        }
+
+        if (!isset($this->other['overridden'])) {
+            throw new \coding_exception('The \'overridden\' value must be set in other.');
+        }
+    }
+}
index f26f821..01015ce 100644 (file)
@@ -628,7 +628,12 @@ class grade_category extends grade_object {
             $grade->finalgrade = null;
 
             if (!is_null($oldfinalgrade)) {
-                $grade->update('aggregation');
+                $success = $grade->update('aggregation');
+
+                // If successful trigger a user_graded event.
+                if ($success) {
+                    \core\event\user_graded::create_from_grade($grade)->trigger();
+                }
             }
             $dropped = $grade_values;
             $this->set_usedinaggregation($userid, $usedweights, $novalue, $dropped, $extracredit);
@@ -707,7 +712,12 @@ class grade_category extends grade_object {
             $grade->finalgrade = null;
 
             if (!is_null($oldfinalgrade)) {
-                $grade->update('aggregation');
+                $success = $grade->update('aggregation');
+
+                // If successful trigger a user_graded event.
+                if ($success) {
+                    \core\event\user_graded::create_from_grade($grade)->trigger();
+                }
             }
             $this->set_usedinaggregation($userid, $usedweights, $novalue, $dropped, $extracredit);
             return;
@@ -744,7 +754,12 @@ class grade_category extends grade_object {
         if (grade_floats_different($grade->finalgrade, $oldfinalgrade) ||
                 grade_floats_different($grade->rawgrademax, $oldrawgrademax) ||
                 grade_floats_different($grade->rawgrademin, $oldrawgrademin)) {
-            $grade->update('aggregation');
+            $success = $grade->update('aggregation');
+
+            // If successful trigger a user_graded event.
+            if ($success) {
+                \core\event\user_graded::create_from_grade($grade)->trigger();
+            }
         }
 
         $this->set_usedinaggregation($userid, $usedweights, $novalue, $dropped, $extracredit);
index be9ee40..46eea2d 100644 (file)
@@ -946,6 +946,24 @@ class grade_grade extends grade_object {
         return parent::update($source);
     }
 
+    /**
+     * Deletes the grade_grade instance from the database.
+     *
+     * @param string $source The location the deletion occurred (mod/forum, manual, etc.).
+     * @return bool Returns true if the deletion was successful, false otherwise.
+     */
+    public function delete($source = null) {
+        $success = parent::delete($source);
+
+        // If the grade was deleted successfully trigger a grade_deleted event.
+        if ($success) {
+            $this->load_grade_item();
+            \core\event\grade_deleted::create_from_grade($this)->trigger();
+        }
+
+        return $success;
+    }
+
     /**
      * Used to notify the completion system (if necessary) that a user's grade
      * has changed, and clear up a possible score cache.
index 6fc05cf..1e94ea8 100644 (file)
@@ -719,7 +719,13 @@ class grade_item extends grade_object {
                 $grade->finalgrade = $this->adjust_raw_grade($grade->rawgrade, $grade->rawgrademin, $grade->rawgrademax);
 
                 if (grade_floats_different($grade_record->finalgrade, $grade->finalgrade)) {
-                    if (!$grade->update('system')) {
+                    $success = $grade->update('system');
+
+                    // If successful trigger a user_graded event.
+                    if ($success) {
+                        $grade->load_grade_item();
+                        \core\event\user_graded::create_from_grade($grade)->trigger();
+                    } else {
                         $result = "Internal error updating final grade";
                     }
                 }
@@ -1606,12 +1612,21 @@ class grade_item extends grade_object {
             $grade->timemodified = time(); // hack alert - date graded
             $result = (bool)$grade->insert($source);
 
+            // If the grade insert was successful and the final grade was not null then trigger a user_graded event.
+            if ($result && !is_null($grade->finalgrade)) {
+                \core\event\user_graded::create_from_grade($grade)->trigger();
+            }
         } else if (grade_floats_different($grade->finalgrade, $oldgrade->finalgrade)
                 or $grade->feedback       !== $oldgrade->feedback
                 or $grade->feedbackformat != $oldgrade->feedbackformat
                 or ($oldgrade->overridden == 0 and $grade->overridden > 0)) {
             $grade->timemodified = time(); // hack alert - date graded
             $result = $grade->update($source);
+
+            // If the grade update was successful and the actual grade has changed then trigger a user_graded event.
+            if ($result && grade_floats_different($grade->finalgrade, $oldgrade->finalgrade)) {
+                \core\event\user_graded::create_from_grade($grade)->trigger();
+            }
         } else {
             // no grade change
             return $result;
@@ -1757,6 +1772,10 @@ class grade_item extends grade_object {
         if (empty($grade->id)) {
             $result = (bool)$grade->insert($source);
 
+            // If the grade insert was successful and the final grade was not null then trigger a user_graded event.
+            if ($result && !is_null($grade->finalgrade)) {
+                \core\event\user_graded::create_from_grade($grade)->trigger();
+            }
         } else if (grade_floats_different($grade->finalgrade,  $oldgrade->finalgrade)
                 or grade_floats_different($grade->rawgrade,    $oldgrade->rawgrade)
                 or grade_floats_different($grade->rawgrademin, $oldgrade->rawgrademin)
@@ -1768,6 +1787,11 @@ class grade_item extends grade_object {
                 or $grade->timemodified   != $oldgrade->timemodified // part of hack above
                 ) {
             $result = $grade->update($source);
+
+            // If the grade update was successful and the actual grade has changed then trigger a user_graded event.
+            if ($result && grade_floats_different($grade->finalgrade, $oldgrade->finalgrade)) {
+                \core\event\user_graded::create_from_grade($grade)->trigger();
+            }
         } else {
             return $result;
         }
@@ -1971,7 +1995,12 @@ class grade_item extends grade_object {
         // update in db if changed
         if (grade_floats_different($grade->finalgrade, $oldfinalgrade)) {
             $grade->timemodified = time();
-            $grade->update('compute');
+            $success = $grade->update('compute');
+
+            // If successful trigger a user_graded event.
+            if ($success) {
+                \core\event\user_graded::create_from_grade($grade)->trigger();
+            }
         }
 
         if ($result !== false) {
diff --git a/lib/tests/event_grade_deleted_test.php b/lib/tests/event_grade_deleted_test.php
new file mode 100644 (file)
index 0000000..77f3a21
--- /dev/null
@@ -0,0 +1,88 @@
+<?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/>.
+
+/**
+ * Tests the \core\event\grade_deleted event.
+ *
+ * @package    core
+ * @category   test
+ * @copyright  2014 Mark Nelson <markn@moodle.com>
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+/**
+ * Class core_event_grade_deleted_testcase
+ *
+ * Tests for event \core\event\grade_deleted
+ *
+ * @package    core
+ * @category   test
+ * @copyright  2014 Mark Nelson <markn@moodle.com>
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class core_event_grade_deleted_testcase extends advanced_testcase {
+
+    /**
+     * Tests the event details.
+     */
+    public function test_event() {
+        global $CFG;
+        require_once("$CFG->libdir/gradelib.php");
+
+        $this->resetAfterTest();
+
+        $course = $this->getDataGenerator()->create_course();
+        $user = $this->getDataGenerator()->create_user();
+        $quiz = $this->getDataGenerator()->create_module('quiz', array('course' => $course->id));
+
+        // Create a grade item for the quiz.
+        $grade = array();
+        $grade['userid'] = $user->id;
+        $grade['rawgrade'] = 50;
+        grade_update('mod/quiz', $course->id, 'mod', 'quiz', $quiz->id, 0, $grade);
+
+        // Get the grade item and override it.
+        $gradeitem = grade_item::fetch(array('itemtype' => 'mod', 'itemmodule' => 'quiz', 'iteminstance' => $quiz->id,
+            'courseid' => $course->id));
+        $gradeitem->update_final_grade($user->id, 10, 'gradebook');
+
+        // Get the grade_grade object.
+        $gradegrade = new grade_grade(array('userid' => $user->id, 'itemid' => $gradeitem->id), true);
+        $gradegrade->grade_item = $gradeitem;
+
+        // Trigger the event.
+        $sink = $this->redirectEvents();
+        course_delete_module($quiz->cmid);
+        $events = $sink->get_events();
+        $event = reset($events);
+        $sink->close();
+
+        // Check the event details are correct.
+        $grade = $event->get_grade();
+        $this->assertInstanceOf('grade_grade', $grade);
+        $this->assertInstanceOf('\core\event\grade_deleted', $event);
+        $this->assertEquals(context_course::instance($course->id), $event->get_context());
+        $this->assertSame($event->objecttable, 'grade_grades');
+        $this->assertEquals($event->objectid, $gradegrade->id);
+        $this->assertEquals($event->other['itemid'], $gradeitem->id);
+        $this->assertTrue($event->other['overridden']);
+        $this->assertEquals(10, $event->other['finalgrade']);
+        $this->assertEventContextNotUsed($event);
+        $this->assertEquals($gradegrade->id, $grade->id);
+    }
+}
index 293b00e..84159cf 100644 (file)
@@ -15,7 +15,7 @@
 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
 
 /**
- * Tests for base course module viewed event.
+ * Tests the \core\event\user_graded event.
  *
  * @package    core
  * @category   phpunit
 
 defined('MOODLE_INTERNAL') || die();
 
+global $CFG;
+
+require_once($CFG->libdir . '/mathslib.php');
+
 /**
  * Class core_event_user_graded_testcase
  *
  * Tests for event \core\event\user_graded
  *
  * @package    core
- * @category   phpunit
+ * @category   test
  * @copyright  2014 Petr Skoda
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 class core_event_user_graded_testcase extends advanced_testcase {
+
+    /**
+     * Tests set up.
+     */
+    public function setUp() {
+        $this->resetAfterTest();
+    }
+
     /**
-     * Test the event.
+     * Tests the event details.
      */
     public function test_event() {
         global $CFG;
         require_once("$CFG->libdir/gradelib.php");
 
-        $this->resetAfterTest();
-
         $course = $this->getDataGenerator()->create_course();
         $user = $this->getDataGenerator()->create_user();
         $this->getDataGenerator()->enrol_user($user->id, $course->id);
@@ -86,4 +96,123 @@ class core_event_user_graded_testcase extends advanced_testcase {
         $this->assertInstanceOf('grade_grade', $grade);
         $this->assertEquals($grade_grade->id, $grade->id);
     }
+
+    /**
+     * Tests that the event is fired in the correct locations in core.
+     */
+    public function test_event_is_triggered() {
+        global $DB;
+
+        // Create the items we need to test with.
+        $course = $this->getDataGenerator()->create_course();
+        $user = $this->getDataGenerator()->create_user();
+        $this->getDataGenerator()->enrol_user($user->id, $course->id);
+        $quiz = $this->getDataGenerator()->create_module('quiz', array('course' => $course->id));
+
+        // Now mark the quiz using grade_update as this is the function that modules use.
+        $grade = array();
+        $grade['userid'] = $user->id;
+        $grade['rawgrade'] = 50;
+
+        $sink = $this->redirectEvents();
+        grade_update('mod/quiz', $course->id, 'mod', 'quiz', $quiz->id, 0, $grade);
+        $events = $sink->get_events();
+        $event = reset($events);
+        $sink->close();
+
+        // Ensure we have a user_graded event.
+        $this->assertEquals(1, count($events));
+        $this->assertInstanceOf('\core\event\user_graded', $event);
+
+        // Get the grade item.
+        $gradeitem = grade_item::fetch(array('itemtype' => 'mod', 'itemmodule' => 'quiz', 'iteminstance' => $quiz->id,
+            'courseid' => $course->id));
+
+        // Let's alter the grade in the DB so when we call regrade_final_grades() it is changed and an event is called.
+        $sql = "UPDATE {grade_grades}
+                   SET finalgrade = '2'
+                 WHERE itemid = :itemid
+                   AND userid = :userid";
+        $DB->execute($sql, array('itemid' => $gradeitem->id, 'userid' => $user->id));
+
+        // Now check when we regrade this that there is a user graded event.
+        $sink = $this->redirectEvents();
+        $gradeitem->regrade_final_grades();
+        $events = $sink->get_events();
+        $event = reset($events);
+        $sink->close();
+
+        // Ensure we have a user_graded event.
+        $this->assertEquals(1, count($events));
+        $this->assertInstanceOf('\core\event\user_graded', $event);
+
+        // Remove the grades.
+        $gradeitem->delete_all_grades();
+
+        // Now, create a grade using update_raw_grade().
+        $sink = $this->redirectEvents();
+        $gradeitem->update_raw_grade($user->id, 50);
+        $events = $sink->get_events();
+        $event = reset($events);
+        $sink->close();
+
+        // Ensure we have a user_graded event.
+        $this->assertEquals(1, count($events));
+        $this->assertInstanceOf('\core\event\user_graded', $event);
+
+        // Now, update this grade using update_raw_grade().
+        $sink = $this->redirectEvents();
+        $gradeitem->update_raw_grade($user->id, 100);
+        $events = $sink->get_events();
+        $event = reset($events);
+        $sink->close();
+
+        $this->assertEquals(1, count($events));
+        $this->assertInstanceOf('\core\event\user_graded', $event);
+
+        // Remove the grades.
+        $gradeitem->delete_all_grades();
+
+        // Now, create a grade using update_final_grade().
+        $sink = $this->redirectEvents();
+        $gradeitem->update_final_grade($user->id, 50);
+        $events = $sink->get_events();
+        $event = reset($events);
+        $sink->close();
+
+        // Ensure we have a user_graded event.
+        $this->assertEquals(1, count($events));
+        $this->assertInstanceOf('\core\event\user_graded', $event);
+
+        // Now, update this grade using update_final_grade().
+        $sink = $this->redirectEvents();
+        $gradeitem->update_final_grade($user->id, 100);
+        $events = $sink->get_events();
+        $event = reset($events);
+        $sink->close();
+
+        $this->assertEquals(1, count($events));
+        $this->assertInstanceOf('\core\event\user_graded', $event);
+
+        // Let's change the calculation to anything that won't cause an error.
+        $calculation = calc_formula::unlocalize("=3");
+        $gradeitem->set_calculation($calculation);
+
+        // Let's alter the grade in the DB so when we call compute() it is changed and an event is called.
+        $sql = "UPDATE {grade_grades}
+                   SET finalgrade = 2, overridden = 0
+                 WHERE itemid = :itemid
+                   AND userid = :userid";
+        $DB->execute($sql, array('itemid' => $gradeitem->id, 'userid' => $user->id));
+
+        // Now check when we compute that there is a user graded event.
+        $sink = $this->redirectEvents();
+        $gradeitem->compute();
+        $events = $sink->get_events();
+        $event = reset($events);
+        $sink->close();
+
+        $this->assertEquals(1, count($events));
+        $this->assertInstanceOf('\core\event\user_graded', $event);
+    }
 }
index 7dfe839..e182212 100644 (file)
@@ -485,8 +485,8 @@ class assign_events_testcase extends mod_assign_base_testcase {
         $grade = $assign->get_user_grade($this->students[0]->id, false, 0);
 
         $events = $sink->get_events();
-        $this->assertCount(1, $events);
-        $event = reset($events);
+        $this->assertCount(3, $events);
+        $event = $events[2];
         $this->assertInstanceOf('\mod_assign\event\submission_graded', $event);
         $this->assertEquals($assign->get_context(), $event->get_context());
         $this->assertEquals($grade->id, $event->objectid);
@@ -514,8 +514,8 @@ class assign_events_testcase extends mod_assign_base_testcase {
         $this->assertEquals('60.0', $grade->grade);
 
         $events = $sink->get_events();
-        $this->assertCount(1, $events);
-        $event = reset($events);
+        $this->assertCount(3, $events);
+        $event = $events[2];
         $this->assertInstanceOf('\mod_assign\event\submission_graded', $event);
         $this->assertEquals($assign->get_context(), $event->get_context());
         $this->assertEquals($grade->id, $event->objectid);
@@ -540,8 +540,8 @@ class assign_events_testcase extends mod_assign_base_testcase {
         $this->assertEquals('50.0', $grade->grade);
         $events = $sink->get_events();
 
-        $this->assertCount(1, $events);
-        $event = reset($events);
+        $this->assertCount(3, $events);
+        $event = $events[2];
         $this->assertInstanceOf('\mod_assign\event\submission_graded', $event);
         $this->assertEquals($assign->get_context(), $event->get_context());
         $this->assertEquals($grade->id, $event->objectid);
index 2f92237..59d8139 100644 (file)
@@ -96,8 +96,8 @@ class mod_quiz_events_testcase extends advanced_testcase {
         $sink->close();
 
         // Validate the event.
-        $this->assertCount(1, $events);
-        $event = $events[0];
+        $this->assertCount(3, $events);
+        $event = $events[2];
         $this->assertInstanceOf('\mod_quiz\event\attempt_submitted', $event);
         $this->assertEquals('quiz_attempts', $event->objecttable);
         $this->assertEquals($quizobj->get_context(), $event->get_context());
index 97ee85e..48a80a9 100644 (file)
@@ -71,7 +71,7 @@ class mod_scorm_event_testcase extends advanced_testcase {
         $event = reset($events);
 
         // Verify data.
-        $this->assertCount(1, $events);
+        $this->assertCount(3, $events);
         $this->assertInstanceOf('\mod_scorm\event\attempt_deleted', $event);
         $this->assertEquals($USER->id, $event->userid);
         $this->assertEquals(context_module::instance($this->eventcm->id), $event->get_context());