コード例 #1
0
 /**
  * Tests for event blog_association_created.
  */
 public function test_blog_association_created_event()
 {
     global $USER;
     $this->setAdminUser();
     $this->resetAfterTest();
     $sitecontext = context_system::instance();
     $coursecontext = context_course::instance($this->courseid);
     $contextmodule = context_module::instance($this->cmid);
     // Add blog associations with a course.
     $blog = new blog_entry($this->postid);
     $sink = $this->redirectEvents();
     $blog->add_association($coursecontext->id);
     $events = $sink->get_events();
     $event = reset($events);
     $sink->close();
     // Validate event data.
     $this->assertInstanceOf('\\core\\event\\blog_association_created', $event);
     $this->assertEquals($sitecontext->id, $event->contextid);
     $url = new moodle_url('/blog/index.php', array('entryid' => $event->other['blogid']));
     $this->assertEquals($url, $event->get_url());
     $this->assertEquals($blog->id, $event->other['blogid']);
     $this->assertEquals($this->courseid, $event->other['associateid']);
     $this->assertEquals('course', $event->other['associatetype']);
     $this->assertEquals($blog->subject, $event->other['subject']);
     $this->assertEquals($USER->id, $event->userid);
     $this->assertEquals($this->userid, $event->relateduserid);
     $this->assertEquals('blog_association', $event->objecttable);
     $arr = array(SITEID, 'blog', 'add association', 'index.php?userid=' . $this->userid . '&entryid=' . $blog->id, $blog->subject, 0, $this->userid);
     $this->assertEventLegacyLogData($arr, $event);
     // Add blog associations with a module.
     $blog = new blog_entry($this->postid);
     $sink = $this->redirectEvents();
     $blog->add_association($contextmodule->id);
     $events = $sink->get_events();
     $event = reset($events);
     $sink->close();
     // Validate event data.
     $this->assertEquals($blog->id, $event->other['blogid']);
     $this->assertEquals($this->cmid, $event->other['associateid']);
     $this->assertEquals('coursemodule', $event->other['associatetype']);
     $arr = array(SITEID, 'blog', 'add association', 'index.php?userid=' . $this->userid . '&entryid=' . $blog->id, $blog->subject, $this->cmid, $this->userid);
     $this->assertEventLegacyLogData($arr, $event);
     $this->assertEventContextNotUsed($event);
 }
コード例 #2
0
ファイル: lib_test.php プロジェクト: janeklb/moodle
 public function test_blog_get_listing_module()
 {
     $this->setAdminUser();
     $coursecontext = context_course::instance($this->courseid);
     $contextmodule = context_module::instance($this->cmid);
     $anothermodule = $this->getDataGenerator()->create_module('page', array('course' => $this->courseid));
     // Add blog associations with a course.
     $blog = new blog_entry($this->postid);
     $blog->add_association($contextmodule->id);
     // There is no entry associated with a course.
     $bloglisting = new blog_listing(array('course' => $this->courseid));
     $this->assertCount(0, $bloglisting->get_entries());
     // There is one entry associated with a module.
     $bloglisting = new blog_listing(array('module' => $this->cmid));
     $this->assertCount(1, $bloglisting->get_entries());
     // There is no entry associated with a wrong module.
     $bloglisting = new blog_listing(array('module' => $anothermodule->cmid));
     $this->assertCount(0, $bloglisting->get_entries());
     // There is one entry associated with a site (id is ignored).
     $bloglisting = new blog_listing(array('site' => 12345));
     $this->assertCount(1, $bloglisting->get_entries());
     // There is one entry associated with course context (module is a subcontext of a course).
     $bloglisting = new blog_listing(array('context' => $coursecontext->id));
     $this->assertCount(1, $bloglisting->get_entries());
 }