MDL-65017 mod_forum: Test based on event type and not objectid
authorJun Pataleta <jun@moodle.com>
Fri, 25 Oct 2019 00:32:02 +0000 (08:32 +0800)
committerJun Pataleta <jun@moodle.com>
Fri, 25 Oct 2019 00:39:32 +0000 (08:39 +0800)
* Plus fix warning about \test_capability_manager::can_delete_post()

mod/forum/tests/events_test.php
mod/forum/tests/exporters_post_test.php

index b4ee7ed..bf54d50 100644 (file)
@@ -1631,10 +1631,9 @@ class mod_forum_events_testcase extends advanced_testcase {
 
         // Loop through the events and check they are valid.
         foreach ($events as $event) {
-
-            if ($event->objectid == $discussion->id) {
+            if ($event instanceof \mod_forum\event\discussion_deleted) {
                 // Check that the event contains the expected values.
-                $this->assertInstanceOf('\mod_forum\event\discussion_deleted', $event);
+                $this->assertEquals($event->objectid, $discussion->id);
                 $this->assertEquals(context_module::instance($forum->cmid), $event->get_context());
                 $expected = array($course->id, 'forum', 'delete discussion', "view.php?id={$forum->cmid}",
                     $forum->id, $forum->cmid);
@@ -1647,6 +1646,7 @@ class mod_forum_events_testcase extends advanced_testcase {
                 $post = $posts[$event->objectid];
                 // Check that the event contains the expected values.
                 $this->assertInstanceOf('\mod_forum\event\post_deleted', $event);
+                $this->assertEquals($event->objectid, $post->id);
                 $this->assertEquals(context_module::instance($forum->cmid), $event->get_context());
                 $expected = array($course->id, 'forum', 'delete post', "discuss.php?d={$discussion->id}", $post->id, $forum->cmid);
                 $this->assertEventLegacyLogData($expected, $event);
index 67cbcdf..7f6e463 100644 (file)
@@ -485,9 +485,11 @@ class test_capability_manager extends capability_manager {
      * @param stdClass $user The user
      * @param discussion_entity $discussion The discussion
      * @param post_entity $post The post
+     * @param bool $hasreplies
      * @return bool
      */
-    public function can_delete_post(stdClass $user, discussion_entity $discussion, post_entity $post) : bool {
+    public function can_delete_post(stdClass $user, discussion_entity $discussion, post_entity $post,
+                                    bool $hasreplies = false) : bool {
         return $this->delete;
     }