Merge branch 'wip-mdl-43293' of https://github.com/rajeshtaneja/moodle
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* block_comments comment created event.
|
||||
*
|
||||
* @package block_comments
|
||||
* @copyright 2013 Rajesh Taneja <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace block_comments\event;
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* block_comments comment created event.
|
||||
*
|
||||
* @package block_comments
|
||||
* @copyright 2013 Rajesh Taneja <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class comment_created extends \core\event\comment_created {
|
||||
// No need to override any method.
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* block_comments comment deleted event.
|
||||
*
|
||||
* @package block_comments
|
||||
* @copyright 2013 Rajesh Taneja <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace block_comments\event;
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* block_comments comment deleted event.
|
||||
*
|
||||
* @package block_comments
|
||||
* @copyright 2013 Rajesh Taneja <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class comment_deleted extends \core\event\comment_deleted {
|
||||
// No need to override any method.
|
||||
}
|
||||
@@ -0,0 +1,182 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* Events tests.
|
||||
*
|
||||
* @package block_comments
|
||||
* @category test
|
||||
* @copyright 2013 Rajesh Taneja <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Events tests class.
|
||||
*
|
||||
* @package block_comments
|
||||
* @category test
|
||||
* @copyright 2013 Rajesh Taneja <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class block_comments_events_testcase extends advanced_testcase {
|
||||
/** @var stdClass Keeps course object */
|
||||
private $course;
|
||||
|
||||
/** @var stdClass Keeps wiki object */
|
||||
private $wiki;
|
||||
|
||||
/**
|
||||
* Setup test data.
|
||||
*/
|
||||
public function setUp() {
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
|
||||
// Create course and wiki.
|
||||
$this->course = $this->getDataGenerator()->create_course();
|
||||
$this->wiki = $this->getDataGenerator()->create_module('wiki', array('course' => $this->course->id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test comment_created event.
|
||||
*/
|
||||
public function test_comment_created() {
|
||||
global $CFG;
|
||||
|
||||
require_once($CFG->dirroot . '/comment/lib.php');
|
||||
|
||||
// Comment on course page.
|
||||
$context = context_course::instance($this->course->id);
|
||||
$args = new stdClass;
|
||||
$args->context = $context;
|
||||
$args->course = $this->course;
|
||||
$args->area = 'page_comments';
|
||||
$args->itemid = 0;
|
||||
$args->component = 'block_comments';
|
||||
$args->linktext = get_string('showcomments');
|
||||
$args->notoggle = true;
|
||||
$args->autostart = true;
|
||||
$args->displaycancel = false;
|
||||
$comment = new comment($args);
|
||||
|
||||
// Triggering and capturing the event.
|
||||
$sink = $this->redirectEvents();
|
||||
$comment->add('New comment');
|
||||
$events = $sink->get_events();
|
||||
$this->assertCount(1, $events);
|
||||
$event = reset($events);
|
||||
|
||||
// Checking that the event contains the expected values.
|
||||
$this->assertInstanceOf('\block_comments\event\comment_created', $event);
|
||||
$this->assertEquals($context, $event->get_context());
|
||||
$url = new moodle_url('/course/view.php', array('id' => $this->course->id));
|
||||
$this->assertEquals($url, $event->get_url());
|
||||
|
||||
// Comments when block is on module (wiki) page.
|
||||
$context = context_module::instance($this->wiki->id);
|
||||
$args = new stdClass;
|
||||
$args->context = $context;
|
||||
$args->course = $this->course;
|
||||
$args->area = 'page_comments';
|
||||
$args->itemid = 0;
|
||||
$args->component = 'block_comments';
|
||||
$args->linktext = get_string('showcomments');
|
||||
$args->notoggle = true;
|
||||
$args->autostart = true;
|
||||
$args->displaycancel = false;
|
||||
$comment = new comment($args);
|
||||
|
||||
// Triggering and capturing the event.
|
||||
$sink = $this->redirectEvents();
|
||||
$comment->add('New comment 1');
|
||||
$events = $sink->get_events();
|
||||
$this->assertCount(1, $events);
|
||||
$event = reset($events);
|
||||
|
||||
// Checking that the event contains the expected values.
|
||||
$this->assertInstanceOf('\block_comments\event\comment_created', $event);
|
||||
$this->assertEquals($context, $event->get_context());
|
||||
$url = new moodle_url('/mod/wiki/view.php', array('id' => $this->wiki->id));
|
||||
$this->assertEquals($url, $event->get_url());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test comment_deleted event.
|
||||
*/
|
||||
public function test_comment_deleted() {
|
||||
global $CFG;
|
||||
|
||||
require_once($CFG->dirroot . '/comment/lib.php');
|
||||
|
||||
// Comment on course page.
|
||||
$context = context_course::instance($this->course->id);
|
||||
$args = new stdClass;
|
||||
$args->context = $context;
|
||||
$args->course = $this->course;
|
||||
$args->area = 'page_comments';
|
||||
$args->itemid = 0;
|
||||
$args->component = 'block_comments';
|
||||
$args->linktext = get_string('showcomments');
|
||||
$args->notoggle = true;
|
||||
$args->autostart = true;
|
||||
$args->displaycancel = false;
|
||||
$comment = new comment($args);
|
||||
$newcomment = $comment->add('New comment');
|
||||
|
||||
// Triggering and capturing the event.
|
||||
$sink = $this->redirectEvents();
|
||||
$comment->delete($newcomment->id);
|
||||
$events = $sink->get_events();
|
||||
$this->assertCount(1, $events);
|
||||
$event = reset($events);
|
||||
|
||||
// Checking that the event contains the expected values.
|
||||
$this->assertInstanceOf('\block_comments\event\comment_deleted', $event);
|
||||
$this->assertEquals($context, $event->get_context());
|
||||
$url = new moodle_url('/course/view.php', array('id' => $this->course->id));
|
||||
$this->assertEquals($url, $event->get_url());
|
||||
|
||||
// Comments when block is on module (wiki) page.
|
||||
$context = context_module::instance($this->wiki->id);
|
||||
$args = new stdClass;
|
||||
$args->context = $context;
|
||||
$args->course = $this->course;
|
||||
$args->area = 'page_comments';
|
||||
$args->itemid = 0;
|
||||
$args->component = 'block_comments';
|
||||
$args->linktext = get_string('showcomments');
|
||||
$args->notoggle = true;
|
||||
$args->autostart = true;
|
||||
$args->displaycancel = false;
|
||||
$comment = new comment($args);
|
||||
$newcomment = $comment->add('New comment 1');
|
||||
|
||||
// Triggering and capturing the event.
|
||||
$sink = $this->redirectEvents();
|
||||
$comment->delete($newcomment->id);
|
||||
$events = $sink->get_events();
|
||||
$this->assertCount(1, $events);
|
||||
$event = reset($events);
|
||||
|
||||
// Checking that the event contains the expected values.
|
||||
$this->assertInstanceOf('\block_comments\event\comment_deleted', $event);
|
||||
$this->assertEquals($context, $event->get_context());
|
||||
$url = new moodle_url('/mod/wiki/view.php', array('id' => $this->wiki->id));
|
||||
$this->assertEquals($url, $event->get_url());
|
||||
}
|
||||
}
|
||||
@@ -362,7 +362,7 @@ class core_bloglib_testcase extends advanced_testcase {
|
||||
public function test_blog_entries_viewed_event() {
|
||||
|
||||
$this->setAdminUser();
|
||||
$this->resetAfterTest();
|
||||
|
||||
$other = array('entryid' => $this->postid, 'tagid' => $this->tagid, 'userid' => $this->userid, 'modid' => $this->cmid,
|
||||
'groupid' => $this->groupid, 'courseid' => $this->courseid, 'search' => 'search', 'fromstart' => 2);
|
||||
|
||||
@@ -382,5 +382,76 @@ class core_bloglib_testcase extends advanced_testcase {
|
||||
$arr = array(SITEID, 'blog', 'view', $url2->out(), 'view blog entry');
|
||||
$this->assertEventLegacyLogData($arr, $event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test comment_created event.
|
||||
*/
|
||||
public function test_blog_comment_created_event() {
|
||||
global $USER, $CFG;
|
||||
|
||||
$this->setAdminUser();
|
||||
|
||||
require_once($CFG->dirroot . '/comment/lib.php');
|
||||
$context = context_user::instance($USER->id);
|
||||
|
||||
$cmt = new stdClass();
|
||||
$cmt->context = $context;
|
||||
$cmt->courseid = $this->courseid;
|
||||
$cmt->area = 'format_blog';
|
||||
$cmt->itemid = $this->postid;
|
||||
$cmt->showcount = 1;
|
||||
$cmt->component = 'blog';
|
||||
$manager = new comment($cmt);
|
||||
|
||||
// Triggering and capturing the event.
|
||||
$sink = $this->redirectEvents();
|
||||
$manager->add("New comment");
|
||||
$events = $sink->get_events();
|
||||
$this->assertCount(1, $events);
|
||||
$event = reset($events);
|
||||
|
||||
// Checking that the event contains the expected values.
|
||||
$this->assertInstanceOf('\core\event\blog_comment_created', $event);
|
||||
$this->assertEquals($context, $event->get_context());
|
||||
$this->assertEquals($this->postid, $event->other['itemid']);
|
||||
$url = new moodle_url('/blog/index.php', array('entryid' => $this->postid));
|
||||
$this->assertEquals($url, $event->get_url());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test comment_deleted event.
|
||||
*/
|
||||
public function test_blog_comment_deleted_event() {
|
||||
global $USER, $CFG;
|
||||
|
||||
$this->setAdminUser();
|
||||
|
||||
require_once($CFG->dirroot . '/comment/lib.php');
|
||||
$context = context_user::instance($USER->id);
|
||||
|
||||
$cmt = new stdClass();
|
||||
$cmt->context = $context;
|
||||
$cmt->courseid = $this->courseid;
|
||||
$cmt->area = 'format_blog';
|
||||
$cmt->itemid = $this->postid;
|
||||
$cmt->showcount = 1;
|
||||
$cmt->component = 'blog';
|
||||
$manager = new comment($cmt);
|
||||
$newcomment = $manager->add("New comment");
|
||||
|
||||
// Triggering and capturing the event.
|
||||
$sink = $this->redirectEvents();
|
||||
$manager->delete($newcomment->id);
|
||||
$events = $sink->get_events();
|
||||
$this->assertCount(1, $events);
|
||||
$event = reset($events);
|
||||
|
||||
// Checking that the event contains the expected values.
|
||||
$this->assertInstanceOf('\core\event\blog_comment_deleted', $event);
|
||||
$this->assertEquals($context, $event->get_context());
|
||||
$this->assertEquals($this->postid, $event->other['itemid']);
|
||||
$url = new moodle_url('/blog/index.php', array('entryid' => $this->postid));
|
||||
$this->assertEquals($url, $event->get_url());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+10
-2
@@ -652,7 +652,11 @@ class comment {
|
||||
$newcmt->time = userdate($newcmt->timecreated, $newcmt->strftimeformat);
|
||||
|
||||
// Trigger comment created event.
|
||||
$eventclassname = '\\' . $this->component . '\\event\comment_created';
|
||||
if (core_component::is_core_subsystem($this->component)) {
|
||||
$eventclassname = '\\core\\event\\' . $this->component . '_comment_created';
|
||||
} else {
|
||||
$eventclassname = '\\' . $this->component . '\\event\comment_created';
|
||||
}
|
||||
if (class_exists($eventclassname)) {
|
||||
$event = $eventclassname::create(
|
||||
array(
|
||||
@@ -724,7 +728,11 @@ class comment {
|
||||
}
|
||||
$DB->delete_records('comments', array('id'=>$commentid));
|
||||
// Trigger comment delete event.
|
||||
$eventclassname = '\\' . $this->component . '\\event\comment_deleted';
|
||||
if (core_component::is_core_subsystem($this->component)) {
|
||||
$eventclassname = '\\core\\event\\' . $this->component . '_comment_deleted';
|
||||
} else {
|
||||
$eventclassname = '\\' . $this->component . '\\event\comment_deleted';
|
||||
}
|
||||
if (class_exists($eventclassname)) {
|
||||
$event = $eventclassname::create(
|
||||
array(
|
||||
|
||||
@@ -1013,4 +1013,14 @@ $cache = '.var_export($cache, true).';
|
||||
opcache_invalidate($file, true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if subsystemname is core subsystem.
|
||||
*
|
||||
* @param string $subsystemname name of the subsystem.
|
||||
* @return bool true if core subsystem.
|
||||
*/
|
||||
public static function is_core_subsystem($subsystemname) {
|
||||
return isset(self::$subsystems[$subsystemname]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* blog comment created event.
|
||||
*
|
||||
* @package core
|
||||
* @copyright 2013 Rajesh Taneja <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace core\event;
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* blog comment created event.
|
||||
*
|
||||
* @package core
|
||||
* @copyright 2013 Rajesh Taneja <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class blog_comment_created extends \core\event\comment_created {
|
||||
/**
|
||||
* Get URL related to the action.
|
||||
*
|
||||
* @return \moodle_url
|
||||
*/
|
||||
public function get_url() {
|
||||
return new \moodle_url('/blog/index.php', array('entryid' => $this->other['itemid']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of what happened.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_description() {
|
||||
return 'User with id ' . $this->userid . ' added comment for blog with id ' . $this->other['itemid'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* blog comment deleted event.
|
||||
*
|
||||
* @package core
|
||||
* @copyright 2013 Rajesh Taneja <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace core\event;
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* blog comment deleted event.
|
||||
*
|
||||
* @package core
|
||||
* @copyright 2013 Rajesh Taneja <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class blog_comment_deleted extends \core\event\comment_deleted {
|
||||
/**
|
||||
* Get URL related to the action.
|
||||
*
|
||||
* @return \moodle_url
|
||||
*/
|
||||
public function get_url() {
|
||||
return new \moodle_url('/blog/index.php', array('entryid' => $this->other['itemid']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of what happened.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_description() {
|
||||
return 'User with id ' . $this->userid . ' deleted comment for blog with id ' . $this->other['itemid'];
|
||||
}
|
||||
}
|
||||
@@ -69,10 +69,19 @@ abstract class comment_created extends \core\event\base {
|
||||
* @return string
|
||||
*/
|
||||
public function get_description() {
|
||||
return 'User with id '. $this->userid . ' added comment for ' . $this->component . ' with instance id ' .
|
||||
return 'User with id ' . $this->userid . ' added comment for ' . $this->component . ' with instance id ' .
|
||||
$this->contextinstanceid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get URL related to the action.
|
||||
*
|
||||
* @return \moodle_url
|
||||
*/
|
||||
public function get_url() {
|
||||
return $this->context->get_url();
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom validation.
|
||||
*
|
||||
|
||||
@@ -69,10 +69,19 @@ abstract class comment_deleted extends \core\event\base {
|
||||
* @return string
|
||||
*/
|
||||
public function get_description() {
|
||||
return 'User with id '. $this->userid . ' deleted comment for ' . $this->component . ' with instance id ' .
|
||||
return 'User with id ' . $this->userid . ' deleted comment for ' . $this->component . ' with instance id ' .
|
||||
$this->contextinstanceid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get URL related to the action.
|
||||
*
|
||||
* @return \moodle_url
|
||||
*/
|
||||
public function get_url() {
|
||||
return $this->context->get_url();
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom validation.
|
||||
*
|
||||
|
||||
@@ -65,4 +65,13 @@ abstract class comments_viewed extends \core\event\base {
|
||||
return 'User with id '. $this->userid . ' viewed comments for ' . $this->component . ' with instance id ' .
|
||||
$this->objectid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get URL related to the action.
|
||||
*
|
||||
* @return \moodle_url
|
||||
*/
|
||||
public function get_url() {
|
||||
return $this->context->get_url();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* assignsubmission_comments comment created event.
|
||||
*
|
||||
* @package assignsubmission_comments
|
||||
* @copyright 2013 Rajesh Taneja <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace assignsubmission_comments\event;
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* assignsubmission_comments comment created event.
|
||||
*
|
||||
* @package assignsubmission_comments
|
||||
* @copyright 2013 Rajesh Taneja <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class comment_created extends \core\event\comment_created {
|
||||
/**
|
||||
* 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));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of what happened.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_description() {
|
||||
return 'User with id ' . $this->userid . ' added comment for assignment submission with id ' . $this->other['itemid'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* assignsubmission_comments comment deleted event.
|
||||
*
|
||||
* @package assignsubmission_comments
|
||||
* @copyright 2013 Rajesh Taneja <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace assignsubmission_comments\event;
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* assignsubmission_comments comment deleted event.
|
||||
*
|
||||
* @package assignsubmission_comments
|
||||
* @copyright 2013 Rajesh Taneja <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class comment_deleted extends \core\event\comment_deleted {
|
||||
/**
|
||||
* 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));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of what happened.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_description() {
|
||||
return 'User with id ' . $this->userid . ' deleted comment for assignment submission with id ' . $this->other['itemid'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* Events tests.
|
||||
*
|
||||
* @package assignsubmission_comments
|
||||
* @category test
|
||||
* @copyright 2013 Rajesh Taneja <[email protected]>
|
||||
* @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/lib.php');
|
||||
require_once($CFG->dirroot . '/mod/assign/locallib.php');
|
||||
require_once($CFG->dirroot . '/mod/assign/tests/base_test.php');
|
||||
|
||||
/**
|
||||
* Events tests class.
|
||||
*
|
||||
* @package assignsubmission_comments
|
||||
* @category test
|
||||
* @copyright 2013 Rajesh Taneja <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class assignsubmission_comments_events_testcase extends mod_assign_base_testcase {
|
||||
|
||||
/**
|
||||
* Test comment_created event.
|
||||
*/
|
||||
public function test_comment_created() {
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot . '/comment/lib.php');
|
||||
|
||||
$this->setUser($this->editingteachers[0]);
|
||||
$assign = $this->create_instance();
|
||||
$submission = $assign->get_user_submission($this->students[0]->id, true);
|
||||
|
||||
$context = $assign->get_context();
|
||||
$options = new stdClass();
|
||||
$options->area = 'submission_comments';
|
||||
$options->course = $assign->get_course();
|
||||
$options->context = $context;
|
||||
$options->itemid = $submission->id;
|
||||
$options->component = 'assignsubmission_comments';
|
||||
$options->showcount = true;
|
||||
$options->displaycancel = true;
|
||||
|
||||
$comment = new comment($options);
|
||||
|
||||
// Triggering and capturing the event.
|
||||
$sink = $this->redirectEvents();
|
||||
$comment->add('New comment');
|
||||
$events = $sink->get_events();
|
||||
$this->assertCount(1, $events);
|
||||
$event = reset($events);
|
||||
|
||||
// Checking that the event contains the expected values.
|
||||
$this->assertInstanceOf('\assignsubmission_comments\event\comment_created', $event);
|
||||
$this->assertEquals($context, $event->get_context());
|
||||
$url = new moodle_url('/mod/assign/view.php', array('id' => $submission->id));
|
||||
$this->assertEquals($url, $event->get_url());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test comment_deleted event.
|
||||
*/
|
||||
public function test_comment_deleted() {
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot . '/comment/lib.php');
|
||||
|
||||
$this->setUser($this->editingteachers[0]);
|
||||
$assign = $this->create_instance();
|
||||
$submission = $assign->get_user_submission($this->students[0]->id, true);
|
||||
|
||||
$context = $assign->get_context();
|
||||
$options = new stdClass();
|
||||
$options->area = 'submission_comments';
|
||||
$options->course = $assign->get_course();
|
||||
$options->context = $context;
|
||||
$options->itemid = $submission->id;
|
||||
$options->component = 'assignsubmission_comments';
|
||||
$options->showcount = true;
|
||||
$options->displaycancel = true;
|
||||
$comment = new comment($options);
|
||||
$newcomment = $comment->add('New comment 1');
|
||||
|
||||
// Triggering and capturing the event.
|
||||
$sink = $this->redirectEvents();
|
||||
$comment->delete($newcomment->id);
|
||||
$events = $sink->get_events();
|
||||
$this->assertCount(1, $events);
|
||||
$event = reset($events);
|
||||
|
||||
// Checking that the event contains the expected values.
|
||||
$this->assertInstanceOf('\assignsubmission_comments\event\comment_deleted', $event);
|
||||
$this->assertEquals($context, $event->get_context());
|
||||
$url = new moodle_url('/mod/assign/view.php', array('id' => $submission->id));
|
||||
$this->assertEquals($url, $event->get_url());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* mod_data comment created event.
|
||||
*
|
||||
* @package mod_data
|
||||
* @copyright 2013 Rajesh Taneja <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace mod_data\event;
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* mod_data comment created event.
|
||||
*
|
||||
* @package mod_data
|
||||
* @copyright 2013 Rajesh Taneja <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class comment_created extends \core\event\comment_created {
|
||||
/**
|
||||
* Get URL related to the action.
|
||||
*
|
||||
* @return \moodle_url
|
||||
*/
|
||||
public function get_url() {
|
||||
return new \moodle_url('/mod/data/view.php', array('id' => $this->other['itemid']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of what happened.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_description() {
|
||||
return 'User with id ' . $this->userid . ' added comment for database activity with id ' . $this->other['itemid'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* mod_data comment deleted event.
|
||||
*
|
||||
* @package mod_data
|
||||
* @copyright 2013 Rajesh Taneja <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace mod_data\event;
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* mod_data comment deleted event.
|
||||
*
|
||||
* @package mod_data
|
||||
* @copyright 2013 Rajesh Taneja <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class comment_deleted extends \core\event\comment_deleted {
|
||||
/**
|
||||
* Get URL related to the action.
|
||||
*
|
||||
* @return \moodle_url
|
||||
*/
|
||||
public function get_url() {
|
||||
return new \moodle_url('/mod/data/view.php', array('id' => $this->other['itemid']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of what happened.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_description() {
|
||||
return 'User with id ' . $this->userid . ' deleted comment for database activity with id ' . $this->other['itemid'];
|
||||
}
|
||||
}
|
||||
+126
-1
@@ -104,4 +104,129 @@ class data_lib_testcase extends advanced_testcase {
|
||||
// Make sure the function returns true on a successful deletion.
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test comment_created event.
|
||||
*/
|
||||
public function test_data_comment_created_event() {
|
||||
global $CFG, $DB;
|
||||
require_once($CFG->dirroot . '/comment/lib.php');
|
||||
|
||||
$this->resetAfterTest();
|
||||
|
||||
// Create a record for deleting.
|
||||
$this->setAdminUser();
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$record = new stdClass();
|
||||
$record->course = $course->id;
|
||||
$record->name = "Mod data delete test";
|
||||
$record->intro = "Some intro of some sort";
|
||||
$record->comments = 1;
|
||||
|
||||
$module = $this->getDataGenerator()->create_module('data', $record);
|
||||
$field = data_get_field_new('text', $module);
|
||||
|
||||
$fielddetail = new stdClass();
|
||||
$fielddetail->name = 'Name';
|
||||
$fielddetail->description = 'Some name';
|
||||
|
||||
$field->define_field($fielddetail);
|
||||
$field->insert_field();
|
||||
$recordid = data_add_record($module);
|
||||
|
||||
$datacontent = array();
|
||||
$datacontent['fieldid'] = $field->field->id;
|
||||
$datacontent['recordid'] = $recordid;
|
||||
$datacontent['content'] = 'Asterix';
|
||||
|
||||
$contentid = $DB->insert_record('data_content', $datacontent);
|
||||
$cm = get_coursemodule_from_instance('data', $module->id, $course->id);
|
||||
|
||||
$context = context_module::instance($module->id);
|
||||
$cmt = new stdClass();
|
||||
$cmt->context = $context;
|
||||
$cmt->course = $course;
|
||||
$cmt->cm = $cm;
|
||||
$cmt->area = 'database_entry';
|
||||
$cmt->itemid = $contentid;
|
||||
$cmt->showcount = true;
|
||||
$cmt->component = 'mod_data';
|
||||
$comment = new comment($cmt);
|
||||
|
||||
// Triggering and capturing the event.
|
||||
$sink = $this->redirectEvents();
|
||||
$comment->add('New comment');
|
||||
$events = $sink->get_events();
|
||||
$this->assertCount(1, $events);
|
||||
$event = reset($events);
|
||||
|
||||
// Checking that the event contains the expected values.
|
||||
$this->assertInstanceOf('\mod_data\event\comment_created', $event);
|
||||
$this->assertEquals($context, $event->get_context());
|
||||
$url = new moodle_url('/mod/data/view.php', array('id' => $module->id));
|
||||
$this->assertEquals($url, $event->get_url());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test comment_deleted event.
|
||||
*/
|
||||
public function test_data_comment_deleted_event() {
|
||||
global $CFG, $DB;
|
||||
require_once($CFG->dirroot . '/comment/lib.php');
|
||||
|
||||
$this->resetAfterTest();
|
||||
|
||||
// Create a record for deleting.
|
||||
$this->setAdminUser();
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$record = new stdClass();
|
||||
$record->course = $course->id;
|
||||
$record->name = "Mod data delete test";
|
||||
$record->intro = "Some intro of some sort";
|
||||
$record->comments = 1;
|
||||
|
||||
$module = $this->getDataGenerator()->create_module('data', $record);
|
||||
$field = data_get_field_new('text', $module);
|
||||
|
||||
$fielddetail = new stdClass();
|
||||
$fielddetail->name = 'Name';
|
||||
$fielddetail->description = 'Some name';
|
||||
|
||||
$field->define_field($fielddetail);
|
||||
$field->insert_field();
|
||||
$recordid = data_add_record($module);
|
||||
|
||||
$datacontent = array();
|
||||
$datacontent['fieldid'] = $field->field->id;
|
||||
$datacontent['recordid'] = $recordid;
|
||||
$datacontent['content'] = 'Asterix';
|
||||
|
||||
$contentid = $DB->insert_record('data_content', $datacontent);
|
||||
$cm = get_coursemodule_from_instance('data', $module->id, $course->id);
|
||||
|
||||
$context = context_module::instance($module->id);
|
||||
$cmt = new stdClass();
|
||||
$cmt->context = $context;
|
||||
$cmt->course = $course;
|
||||
$cmt->cm = $cm;
|
||||
$cmt->area = 'database_entry';
|
||||
$cmt->itemid = $contentid;
|
||||
$cmt->showcount = true;
|
||||
$cmt->component = 'mod_data';
|
||||
$comment = new comment($cmt);
|
||||
$newcomment = $comment->add('New comment 1');
|
||||
|
||||
// Triggering and capturing the event.
|
||||
$sink = $this->redirectEvents();
|
||||
$comment->delete($newcomment->id);
|
||||
$events = $sink->get_events();
|
||||
$this->assertCount(1, $events);
|
||||
$event = reset($events);
|
||||
|
||||
// Checking that the event contains the expected values.
|
||||
$this->assertInstanceOf('\mod_data\event\comment_deleted', $event);
|
||||
$this->assertEquals($context, $event->get_context());
|
||||
$url = new moodle_url('/mod/data/view.php', array('id' => $module->id));
|
||||
$this->assertEquals($url, $event->get_url());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* mod_glossary comment created event.
|
||||
*
|
||||
* @package mod_glossary
|
||||
* @copyright 2013 Rajesh Taneja <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace mod_glossary\event;
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* mod_glossary comment created event.
|
||||
*
|
||||
* @package mod_glossary
|
||||
* @copyright 2013 Rajesh Taneja <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class comment_created extends \core\event\comment_created {
|
||||
/**
|
||||
* Get URL related to the action.
|
||||
*
|
||||
* @return \moodle_url
|
||||
*/
|
||||
public function get_url() {
|
||||
return new \moodle_url('/mod/glossary/view.php', array('id' => $this->other['itemid']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of what happened.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_description() {
|
||||
return 'User with id ' . $this->userid . ' added comment for glossary activity with id ' . $this->other['itemid'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* mod_glossary comment deleted event.
|
||||
*
|
||||
* @package mod_glossary
|
||||
* @copyright 2013 Rajesh Taneja <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace mod_glossary\event;
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* mod_glossary comment deleted event.
|
||||
*
|
||||
* @package mod_glossary
|
||||
* @copyright 2013 Rajesh Taneja <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class comment_deleted extends \core\event\comment_deleted {
|
||||
/**
|
||||
* Get URL related to the action.
|
||||
*
|
||||
* @return \moodle_url
|
||||
*/
|
||||
public function get_url() {
|
||||
return new \moodle_url('/mod/glossary/view.php', array('id' => $this->other['itemid']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of what happened.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_description() {
|
||||
return 'User with id ' . $this->userid . ' deleted comment for glossary activity with id ' . $this->other['itemid'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* Unit tests for lib.php
|
||||
*
|
||||
* @package mod_glossary
|
||||
* @category test
|
||||
* @copyright 2013 Rajesh Taneja <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Unit tests for glossary events.
|
||||
*
|
||||
* @package mod_glossary
|
||||
* @category test
|
||||
* @copyright 2013 Rajesh Taneja <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class glossary_event_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test comment_created event.
|
||||
*/
|
||||
public function test_comment_created() {
|
||||
global $CFG, $DB;
|
||||
require_once($CFG->dirroot . '/comment/lib.php');
|
||||
|
||||
$this->resetAfterTest();
|
||||
|
||||
// Create a record for adding comment.
|
||||
$this->setAdminUser();
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$glossary = $this->getDataGenerator()->create_module('glossary', array('course' => $course));
|
||||
$glossarygenerator = $this->getDataGenerator()->get_plugin_generator('mod_glossary');
|
||||
|
||||
$entry = $glossarygenerator->create_content($glossary);
|
||||
|
||||
$context = context_module::instance($glossary->id);
|
||||
$cm = get_coursemodule_from_instance('data', $glossary->id, $course->id);
|
||||
$cmt = new stdClass();
|
||||
$cmt->component = 'mod_glossary';
|
||||
$cmt->context = $context;
|
||||
$cmt->course = $course;
|
||||
$cmt->cm = $cm;
|
||||
$cmt->area = 'glossary_entry';
|
||||
$cmt->itemid = $entry->id;
|
||||
$cmt->showcount = true;
|
||||
$comment = new comment($cmt);
|
||||
|
||||
// Triggering and capturing the event.
|
||||
$sink = $this->redirectEvents();
|
||||
$comment->add('New comment');
|
||||
$events = $sink->get_events();
|
||||
$this->assertCount(1, $events);
|
||||
$event = reset($events);
|
||||
|
||||
// Checking that the event contains the expected values.
|
||||
$this->assertInstanceOf('\mod_glossary\event\comment_created', $event);
|
||||
$this->assertEquals($context, $event->get_context());
|
||||
$url = new moodle_url('/mod/glossary/view.php', array('id' => $glossary->id));
|
||||
$this->assertEquals($url, $event->get_url());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test comment_deleted event.
|
||||
*/
|
||||
public function test_comment_deleted() {
|
||||
global $CFG, $DB;
|
||||
require_once($CFG->dirroot . '/comment/lib.php');
|
||||
|
||||
$this->resetAfterTest();
|
||||
|
||||
// Create a record for deleting comment.
|
||||
$this->setAdminUser();
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$glossary = $this->getDataGenerator()->create_module('glossary', array('course' => $course));
|
||||
$glossarygenerator = $this->getDataGenerator()->get_plugin_generator('mod_glossary');
|
||||
|
||||
$entry = $glossarygenerator->create_content($glossary);
|
||||
|
||||
$context = context_module::instance($glossary->id);
|
||||
$cm = get_coursemodule_from_instance('data', $glossary->id, $course->id);
|
||||
$cmt = new stdClass();
|
||||
$cmt->component = 'mod_glossary';
|
||||
$cmt->context = $context;
|
||||
$cmt->course = $course;
|
||||
$cmt->cm = $cm;
|
||||
$cmt->area = 'glossary_entry';
|
||||
$cmt->itemid = $entry->id;
|
||||
$cmt->showcount = true;
|
||||
$comment = new comment($cmt);
|
||||
$newcomment = $comment->add('New comment 1');
|
||||
|
||||
// Triggering and capturing the event.
|
||||
$sink = $this->redirectEvents();
|
||||
$comment->delete($newcomment->id);
|
||||
$events = $sink->get_events();
|
||||
$this->assertCount(1, $events);
|
||||
$event = reset($events);
|
||||
|
||||
// Checking that the event contains the expected values.
|
||||
$this->assertInstanceOf('\mod_glossary\event\comment_deleted', $event);
|
||||
$this->assertEquals($context, $event->get_context());
|
||||
$url = new moodle_url('/mod/glossary/view.php', array('id' => $glossary->id));
|
||||
$this->assertEquals($url, $event->get_url());
|
||||
}
|
||||
}
|
||||
@@ -55,7 +55,6 @@ class comment_created extends \core\event\comment_created {
|
||||
* @return string
|
||||
*/
|
||||
public function get_description() {
|
||||
return 'User with id '. $this->userid . ' added comment for ' . $this->component . ' with page id ' .
|
||||
$this->other['itemid'];
|
||||
return 'User with id ' . $this->userid . ' added comment for wiki with page id ' . $this->other['itemid'];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,7 +55,6 @@ class comment_deleted extends \core\event\comment_deleted {
|
||||
* @return string
|
||||
*/
|
||||
public function get_description() {
|
||||
return 'User with id '. $this->userid . ' deleted comment for ' . $this->component . ' with page id ' .
|
||||
$this->other['itemid'];
|
||||
return 'User with id ' . $this->userid . ' deleted comment for wiki with page id ' . $this->other['itemid'];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ class comments_viewed extends \core\event\comments_viewed {
|
||||
* @return string
|
||||
*/
|
||||
public function get_description() {
|
||||
return 'User with id '. $this->userid . ' viewed comments for wiki page id ' .
|
||||
return 'User with id ' . $this->userid . ' viewed comments for wiki page id ' .
|
||||
$this->objectid;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user