Merge branch 'MDL-40053-master' of git://github.com/ankitagarwal/moodle

This commit is contained in:
Damyon Wiese
2013-10-08 16:19:25 +08:00
10 changed files with 751 additions and 23 deletions
+4
View File
@@ -36,6 +36,10 @@ $string['deleteconfirm'] = 'Delete this note?';
$string['deletenotes'] = 'Delete all notes';
$string['editnote'] = 'Edit note';
$string['enablenotes'] = 'Enable notes';
$string['eventnotecreated'] = 'Note created';
$string['eventnoteupdate'] = 'Note updated';
$string['eventnotedeleted'] = 'Note deleted';
$string['eventnotesviewed'] = 'Notes viewed';
$string['groupaddnewnote'] = 'Add a common note';
$string['invalidid'] = 'Invalid note ID specified';
$string['invaliduserid'] = 'Invalid user id: {$a}';
+87
View File
@@ -0,0 +1,87 @@
<?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/>.
namespace core\event;
defined('MOODLE_INTERNAL') || die();
/**
* Event for when a new note entry is added.
*
* @package core
* @copyright 2013 Ankit Agarwal
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Class note_created
*
* Class for event to be triggered when a note is created.
*
* @package core
* @copyright 2013 Ankit Agarwal
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class note_created extends \core\event\base {
/**
* Set basic properties for the event.
*/
protected function init() {
$this->data['objecttable'] = 'post';
$this->data['crud'] = 'c';
$this->data['level'] = self::LEVEL_OTHER;
}
/**
* Returns localised general event name.
*
* @return string
*/
public static function get_name() {
return get_string("eventnotecreated", "core_notes");
}
/**
* Returns non-localised event description with id's for admin use only.
*
* @return string
*/
public function get_description() {
return 'Note for user with id "'. $this->relateduserid . '" was created by user with id "' . $this->userid . '"';
}
/**
* Returns relevant URL.
* @return \moodle_url
*/
public function get_url() {
$logurl = new \moodle_url('/note/index.php', array('course' => $this->courseid, 'user' => $this->relateduserid));
$logurl->set_anchor('note-' . $this->objectid);
return $logurl;
}
/**
* replace add_to_log() statement.
*
* @return array of parameters to be passed to legacy add_to_log() function.
*/
protected function get_legacy_logdata() {
$logurl = new \moodle_url('index.php', array('course' => $this->courseid, 'user' => $this->relateduserid));
$logurl->set_anchor('note-' . $this->objectid);
return array($this->courseid, 'notes', 'add', $logurl, 'add note');
}
}
+77
View File
@@ -0,0 +1,77 @@
<?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/>.
namespace core\event;
defined('MOODLE_INTERNAL') || die();
/**
* Event for when a new note entry deleted.
*
* @package core
* @copyright 2013 Ankit Agarwal
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Class note_deleted
*
* Class for event to be triggered when a note is deleted.
*
* @package core
* @copyright 2013 Ankit Agarwal
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class note_deleted extends \core\event\base {
/**
* Set basic properties for the event.
*/
protected function init() {
$this->data['objecttable'] = 'post';
$this->data['crud'] = 'd';
$this->data['level'] = self::LEVEL_OTHER;
}
/**
* Returns localised general event name.
*
* @return string
*/
public static function get_name() {
return get_string("eventnotedeleted", "core_notes");
}
/**
* Returns non-localised event description with id's for admin use only.
*
* @return string
*/
public function get_description() {
return 'Note for user with id "'. $this->relateduserid . '" was deleted by user with id "' . $this->userid . '"';
}
/**
* replace add_to_log() statement.
*
* @return array of parameters to be passed to legacy add_to_log() function.
*/
protected function get_legacy_logdata() {
$logurl = new \moodle_url('index.php', array('course' => $this->courseid, 'user' => $this->relateduserid));
$logurl->set_anchor('note-' . $this->objectid);
return array($this->courseid, 'notes', 'delete', $logurl, 'delete note');
}
}
+87
View File
@@ -0,0 +1,87 @@
<?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/>.
namespace core\event;
defined('MOODLE_INTERNAL') || die();
/**
* Event for when a new note entry is updated.
*
* @package core
* @copyright 2013 Ankit Agarwal
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Class note_updated
*
* Class for event to be triggered when a note is updated.
*
* @package core
* @copyright 2013 Ankit Agarwal
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class note_updated extends \core\event\base {
/**
* Set basic properties for the event.
*/
protected function init() {
$this->data['objecttable'] = 'post';
$this->data['crud'] = 'u';
$this->data['level'] = self::LEVEL_OTHER;
}
/**
* Returns localised general event name.
*
* @return string
*/
public static function get_name() {
return get_string("eventnoteupdated", "core_notes");
}
/**
* Returns non-localised event description with id's for admin use only.
*
* @return string
*/
public function get_description() {
return 'Note for user with id "'. $this->relateduserid . '" was updated by user with id "'. $this->userid . '"';
}
/**
* Returns relevant URL.
* @return \moodle_url
*/
public function get_url() {
$logurl = new \moodle_url('/note/index.php', array('course' => $this->courseid, 'user' => $this->relateduserid));
$logurl->set_anchor('note-' . $this->objectid);
return $logurl;
}
/**
* Replace add_to_log() statement.
*
* @return array of parameters to be passed to legacy add_to_log() function.
*/
protected function get_legacy_logdata() {
$logurl = new \moodle_url('index.php', array('course' => $this->courseid, 'user' => $this->relateduserid));
$logurl->set_anchor('note-' . $this->objectid);
return array($this->courseid, 'notes', 'update', $logurl, 'update note');
}
}
+83
View File
@@ -0,0 +1,83 @@
<?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/>.
namespace core\event;
defined('MOODLE_INTERNAL') || die();
/**
* Event for when a new note entry viewed.
*
* @package core
* @copyright 2013 Ankit Agarwal
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Class note_viewed
*
* Class for event to be triggered when a note is viewed.
*
* @package core
* @copyright 2013 Ankit Agarwal
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class notes_viewed extends \core\event\content_viewed {
/**
* Set basic properties for the event.
*/
protected function init() {
$this->data['crud'] = 'r';
$this->data['level'] = self::LEVEL_OTHER;
}
/**
* Returns localised general event name.
*
* @return string
*/
public static function get_name() {
return get_string("eventnotesviewed", "core_notes");
}
/**
* Returns non-localised event description with id's for admin use only.
*
* @return string
*/
public function get_description() {
return 'Note for user with id "'. $this->relateduserid . '" was viewed by user with id "'. $this->userid . '"';
}
/**
* Returns relevant URL.
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/note/index.php', array('course' => $this->courseid, 'user' => $this->relateduserid));
}
/**
* replace add_to_log() statement.
*
* @return array of parameters to be passed to legacy add_to_log() function.
*/
protected function get_legacy_logdata() {
return array($this->courseid, 'notes', 'view', 'index.php?course=' . $this->courseid.'&amp;user=' . $this->relateduserid,
'view notes');
}
}
+13 -6
View File
@@ -61,12 +61,6 @@ if ($userid) {
/// require login to access notes
require_login($course);
add_to_log($courseid, 'notes', 'view', 'index.php?course='.$courseid.'&amp;user='.$userid, 'view notes');
if (empty($CFG->enablenotes)) {
print_error('notesdisabled', 'notes');
}
/// output HTML
if ($course->id == SITEID) {
$coursecontext = context_system::instance(); // SYSTEM context
@@ -75,6 +69,19 @@ if ($course->id == SITEID) {
}
$systemcontext = context_system::instance(); // SYSTEM context
// Trigger event.
$event = \core\event\notes_viewed::create(array(
'courseid' => $courseid,
'relateduserid' => $userid,
'context' => $coursecontext,
'other' => array('content' => 'notes')
));
$event->trigger();
if (empty($CFG->enablenotes)) {
print_error('notesdisabled', 'notes');
}
$strnotes = get_string('notes', 'notes');
if ($userid) {
$PAGE->set_context(context_user::instance($user->id));
+45 -17
View File
@@ -66,7 +66,7 @@ function note_list($courseid=0, $userid=0, $state = '', $author = 0, $order='las
* Retrieves a note object based on its id.
*
* @param int $note_id id of the note to retrieve
* @return note object
* @return stdClass object
*/
function note_load($note_id) {
global $DB;
@@ -79,13 +79,13 @@ function note_load($note_id) {
* Saves a note object. The note object is passed by reference and its fields (i.e. id)
* might change during the save.
*
* @param note $note object to save
* @param stdClass $note object to save
* @return boolean true if the object was saved; false otherwise
*/
function note_save(&$note) {
global $USER, $DB;
// setup & clean fields
// Setup & clean fields.
$note->module = 'notes';
$note->lastmodified = time();
$note->usermodified = $USER->id;
@@ -95,23 +95,40 @@ function note_save(&$note) {
if (empty($note->publishstate)) {
$note->publishstate = NOTES_STATE_PUBLIC;
}
// save data
// Save data.
if (empty($note->id)) {
// insert new note
// Insert new note.
$note->created = $note->lastmodified;
$id = $DB->insert_record('post', $note);
$note = note_load($id);
$logurl = new moodle_url('index.php', array('course'=> $note->courseid, 'user'=>$note->userid));
$logurl->set_anchor('note-' . $id);
add_to_log($note->courseid, 'notes', 'add', $logurl, 'add note');
// Trigger event.
$event = \core\event\note_created::create(array(
'objectid' => $note->id,
'courseid' => $note->courseid,
'relateduserid' => $note->userid,
'userid' => $note->usermodified,
'context' => context_course::instance($note->courseid),
'other' => array('publishstate' => $note->publishstate)
));
$event->add_record_snapshot('post', $note);
$event->trigger();
} else {
// update old note
// Update old note.
$DB->update_record('post', $note);
$note = note_load($note->id);
$logurl = new moodle_url('index.php', array('course'=> $note->courseid, 'user'=>$note->userid));
$logurl->set_anchor('note-' . $note->id);
add_to_log($note->courseid, 'notes', 'update', $logurl , 'update note');
// Trigger event.
$event = \core\event\note_updated::create(array(
'objectid' => $note->id,
'courseid' => $note->courseid,
'relateduserid' => $note->userid,
'userid' => $note->usermodified,
'context' => context_course::instance($note->courseid),
'other' => array('publishstate' => $note->publishstate)
));
$event->add_record_snapshot('post', $note);
$event->trigger();
}
unset($note->module);
return true;
@@ -127,12 +144,23 @@ function note_delete($note) {
global $DB;
if (is_int($note)) {
$note = note_load($note);
debugging('Warning: providing note_delete with a note object would improve performance.',DEBUG_DEVELOPER);
debugging('Warning: providing note_delete with a note object would improve performance.', DEBUG_DEVELOPER);
}
$logurl = new moodle_url('index.php', array('course'=> $note->courseid, 'user'=>$note->userid));
$logurl->set_anchor('note-' . $note->id);
add_to_log($note->courseid, 'notes', 'delete', $logurl, 'delete note');
return $DB->delete_records('post', array('id'=>$note->id, 'module'=>'notes'));
$return = $DB->delete_records('post', array('id' => $note->id, 'module' => 'notes'));
// Trigger event.
$event = \core\event\note_deleted::create(array(
'objectid' => $note->id,
'courseid' => $note->courseid,
'relateduserid' => $note->userid,
'userid' => $note->usermodified,
'context' => context_course::instance($note->courseid),
'other' => array('publishstate' => $note->publishstate)
));
$event->add_record_snapshot('post', $note);
$event->trigger();
return $return;
}
/**
+146
View File
@@ -0,0 +1,146 @@
<?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 for notes events.
*
* @package core_notes
* @copyright 2013 Ankit Agarwal
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
*/
defined('MOODLE_INTERNAL') || die();
/**
* Class core_notes_events_testcase
*
* Class for tests related to notes events.
*
* @package core_notes
* @copyright 2013 Ankit Agarwal
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
*/
class core_notes_events_testcase extends advanced_testcase {
/** @var stdClass A note object. */
private $eventnote;
public function setUp() {
$this->resetAfterTest();
$this->setAdminUser();
$course = $this->getDataGenerator()->create_course();
$user = $this->getDataGenerator()->create_user();
$gen = $this->getDataGenerator()->get_plugin_generator('core_notes');
$this->eventnote = $gen->create_instance(array('courseid' => $course->id, 'userid' => $user->id));
}
/**
* Tests for event note_deleted.
*/
public function test_note_deleted_event() {
// Delete a note.
$sink = $this->redirectEvents();
note_delete($this->eventnote);
$events = $sink->get_events();
$event = array_pop($events); // Delete note event.
$sink->close();
// Validate event data.
$this->assertInstanceOf('\core\event\note_deleted', $event);
$this->assertEquals($this->eventnote->id, $event->objectid);
$this->assertEquals($this->eventnote->usermodified, $event->userid);
$this->assertEquals($this->eventnote->userid, $event->relateduserid);
$this->assertEquals('post', $event->objecttable);
$this->assertEquals(null, $event->get_url());
$this->assertEquals($this->eventnote, $event->get_record_snapshot('post', $event->objectid));
$this->assertEquals(NOTES_STATE_SITE, $event->other['publishstate']);
// Test legacy data.
$logurl = new \moodle_url('index.php',
array('course' => $this->eventnote->courseid, 'user' => $this->eventnote->userid));
$logurl->set_anchor('note-' . $this->eventnote->id);
$arr = array($this->eventnote->courseid, 'notes', 'delete', $logurl, 'delete note');
$this->assertEventLegacyLogData($arr, $event);
}
/**
* Tests for event note_created.
*/
public function test_note_created_event() {
// Delete a note.
$sink = $this->redirectEvents();
$note = clone $this->eventnote;
unset($note->id);
note_save($note);
$events = $sink->get_events();
$event = array_pop($events); // Delete note event.
$sink->close();
// Validate event data.
$this->assertInstanceOf('\core\event\note_created', $event);
$this->assertEquals($note->id, $event->objectid);
$this->assertEquals($note->usermodified, $event->userid);
$this->assertEquals($note->userid, $event->relateduserid);
$this->assertEquals('post', $event->objecttable);
$this->assertEquals($note, $event->get_record_snapshot('post', $event->objectid));
$this->assertEquals(NOTES_STATE_SITE, $event->other['publishstate']);
// Test legacy data.
$logurl = new \moodle_url('index.php',
array('course' => $note->courseid, 'user' => $note->userid));
$logurl->set_anchor('note-' . $note->id);
$arr = array($note->courseid, 'notes', 'add', $logurl, 'add note');
$this->assertEventLegacyLogData($arr, $event);
}
/**
* Tests for event note_updated.
*/
public function test_note_updated_event() {
// Delete a note.
$sink = $this->redirectEvents();
$note = clone $this->eventnote;
$note->publishstate = NOTES_STATE_DRAFT;
note_save($note);
$events = $sink->get_events();
$event = array_pop($events); // Delete note event.
$sink->close();
// Validate event data.
$this->assertInstanceOf('\core\event\note_updated', $event);
$this->assertEquals($note->id, $event->objectid);
$this->assertEquals($note->usermodified, $event->userid);
$this->assertEquals($note->userid, $event->relateduserid);
$this->assertEquals('post', $event->objecttable);
$this->assertEquals($note, $event->get_record_snapshot('post', $event->objectid));
$this->assertEquals(NOTES_STATE_DRAFT, $event->other['publishstate']);
// Test legacy data.
$logurl = new \moodle_url('index.php',
array('course' => $note->courseid, 'user' => $note->userid));
$logurl->set_anchor('note-' . $note->id);
$arr = array($note->courseid, 'notes', 'update', $logurl, 'update note');
$this->assertEventLegacyLogData($arr, $event);
}
}
+127
View File
@@ -0,0 +1,127 @@
<?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/>.
/**
* core_notes data generator.
*
* @package core_notes
* @category test
* @copyright 2013 Ankit Agarwal
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* core_notes data generator class.
*
* @package core_notes
* @category test
* @copyright 2013 Ankit Agarwal
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class core_notes_generator extends component_generator_base {
/**
* @var number of created instances
*/
protected $instancecount = 0;
/**
* To be called from data reset code only,
* do not use in tests.
* @return void
*/
public function reset() {
$this->instancecount = 0;
}
/**
* Create a new note.
*
* @param array|stdClass $record
* @throws coding_exception
* @return stdClass activity record with extra cmid field
*/
public function create_instance($record = null) {
global $CFG, $USER;
require_once("$CFG->dirroot/notes/lib.php");
$this->instancecount++;
$i = $this->instancecount;
$record = (object)(array)$record;
if (empty($record->courseid)) {
throw new coding_exception('Module generator requires $record->courseid.');
}
if (empty($record->userid)) {
throw new coding_exception('Module generator requires $record->userid.');
}
if (!isset($record->module)) {
$record->module = 'notes';
}
if (!isset($record->groupid)) {
$record->groupid = 0;
}
if (!isset($record->moduleid)) {
$record->moduleid = 0;
}
if (!isset($record->coursemoduleid)) {
$record->coursemoduleid = 0;
}
if (!isset($record->subject)) {
$record->subject = '';
}
if (!isset($record->summary)) {
$record->summary = null;
}
if (!isset($record->content)) {
$record->content = "This is test generated note - $i .";
}
if (!isset($record->uniquehash)) {
$record->uniquehash = '';
}
if (!isset($record->rating)) {
$record->rating = 0;
}
if (!isset($record->format)) {
$record->format = FORMAT_PLAIN;
}
if (!isset($record->summaryformat)) {
$record->summaryformat = FORMAT_MOODLE;
}
if (!isset($record->attachment)) {
$record->attachment = null;
}
if (!isset($record->publishstate)) {
$record->publishstate = NOTES_STATE_SITE;
}
if (!isset($record->lastmodified)) {
$record->lastmodified = time();
}
if (!isset($record->created)) {
$record->created = time();
}
if (!isset($record->usermodified)) {
$record->usermodified = $USER->id;
}
note_save($record);
return $record;
}
}
+82
View File
@@ -0,0 +1,82 @@
<?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/>.
/**
* Generator tests.
*
* @package core_notes
* @copyright 2013 Ankit Agarwal
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Generator tests class.
*
* @package core_notes
* @copyright 2013 Ankit Agarwal
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class core_notes_generator_testcase extends advanced_testcase {
/** Test create_instance method */
public function test_create_instance() {
global $DB;
$this->resetAfterTest();
$this->setAdminUser();
$course = $this->getDataGenerator()->create_course();
$user = $this->getDataGenerator()->create_user();
$gen = $this->getDataGenerator()->get_plugin_generator('core_notes');
$this->assertFalse($DB->record_exists('post', array('courseid' => $course->id)));
$note = $gen->create_instance(array('courseid' => $course->id, 'userid' => $user->id));
$this->assertEquals(1, $DB->count_records('post', array('courseid' => $course->id, 'userid' => $user->id)));
$this->assertTrue($DB->record_exists('post', array('id' => $note->id)));
$params = array('courseid' => $course->id, 'userid' => $user->id, 'publishstate' => NOTES_STATE_DRAFT);
$note = $gen->create_instance($params);
$this->assertEquals(2, $DB->count_records('post', array('courseid' => $course->id, 'userid' => $user->id)));
$this->assertEquals(NOTES_STATE_DRAFT, $DB->get_field_select('post', 'publishstate', 'id = :id',
array('id' => $note->id)));
}
/** Test Exceptions thrown by create_instance method */
public function test_create_instance_exceptions() {
$this->resetAfterTest();
$gen = $this->getDataGenerator()->get_plugin_generator('core_notes');
// Test not setting userid.
try {
$gen->create_instance(array('courseid' => 2));
$this->fail('A note should not be allowed to be created without associcated userid');
} catch (coding_exception $e) {
$this->assertContains('Module generator requires $record->userid', $e->getMessage());
}
// Test not setting courseid.
try {
$gen->create_instance(array('userid' => 2));
$this->fail('A note should not be allowed to be created without associcated courseid');
} catch (coding_exception $e) {
$this->assertContains('Module generator requires $record->courseid', $e->getMessage());
}
}
}