protected $groupcount = 0;
protected $groupingcount = 0;
+ /**
+ * @var int keep track of how many forum discussions have been created.
+ */
+ protected $forumdiscussioncount = 0;
+
+ /**
+ * @var int keep track of how many forum posts have been created.
+ */
+ protected $forumpostcount = 0;
+
/** @var array list of plugin generators */
protected $generators = array();
$this->categorycount = 0;
$this->coursecount = 0;
$this->scalecount = 0;
+ $this->forumdiscussioncount = 0;
+ $this->forumpostcount = 0;
foreach ($this->generators as $generator) {
$generator->reset();
return $DB->get_record('groups', array('id'=>$id));
}
+ /**
+ * Create a test group member
+ * @param array|stdClass $record
+ * @throws coding_exception
+ * @return boolean
+ */
+ public function create_group_member($record) {
+ global $DB, $CFG;
+
+ require_once($CFG->dirroot . '/group/lib.php');
+
+ $record = (array)$record;
+
+ if (empty($record['userid'])) {
+ throw new coding_exception('user must be present in testing_util::create_group_member() $record');
+ }
+
+ if (!isset($record['groupid'])) {
+ throw new coding_exception('group must be present in testing_util::create_group_member() $record');
+ }
+
+ if (!isset($record['component'])) {
+ $record['component'] = null;
+ }
+ if (!isset($record['itemid'])) {
+ $record['itemid'] = 0;
+ }
+
+ return groups_add_member($record['groupid'], $record['userid'], $record['component'], $record['itemid']);
+ }
+
/**
* Create a test grouping for the specified course
*
return $DB->get_record('groupings', array('id'=>$id));
}
+ /**
+ * Create a test grouping group
+ * @param array|stdClass $record
+ * @throws coding_exception
+ * @return boolean
+ */
+ public function create_grouping_group($record) {
+ global $DB, $CFG;
+
+ require_once($CFG->dirroot . '/group/lib.php');
+
+ $record = (array)$record;
+
+ if (empty($record['groupingid'])) {
+ throw new coding_exception('grouping must be present in testing::create_grouping_group() $record');
+ }
+
+ if (!isset($record['groupid'])) {
+ throw new coding_exception('group must be present in testing_util::create_grouping_group() $record');
+ }
+
+ return groups_assign_grouping($record['groupingid'], $record['groupid']);
+ }
+
/**
* Create a test scale
* @param array|stdClass $record
return true;
}
+
+ /**
+ * Function to create a dummy discussion.
+ *
+ * @param array|stdClass $record
+ * @return stdClass the discussion object
+ */
+ public function create_forum_discussion($record = null) {
+ global $DB;
+
+ // Increment the forum discussion count.
+ $this->forumdiscussioncount++;
+
+ $record = (array) $record;
+
+ if (!isset($record['course'])) {
+ throw new coding_exception('course must be present in phpunit_util::create_forum_discussion() $record');
+ }
+
+ if (!isset($record['forum'])) {
+ throw new coding_exception('forum must be present in phpunit_util::create_forum_discussion() $record');
+ }
+
+ if (!isset($record['userid'])) {
+ throw new coding_exception('userid must be present in phpunit_util::create_forum_discussion() $record');
+ }
+
+ if (!isset($record['name'])) {
+ $record['name'] = "Discussion " . $this->forumdiscussioncount;
+ }
+
+ if (!isset($record['subject'])) {
+ $record['subject'] = "Subject for discussion " . $this->forumdiscussioncount;
+ }
+
+ if (!isset($record['message'])) {
+ $record['message'] = html_writer::tag('p', 'Message for discussion ' . $this->forumdiscussioncount);
+ }
+
+ if (!isset($record['messageformat'])) {
+ $record['messageformat'] = editors_get_preferred_format();
+ }
+
+ if (!isset($record['messagetrust'])) {
+ $record['messagetrust'] = "";
+ }
+
+ if (!isset($record['assessed'])) {
+ $record['assessed'] = '1';
+ }
+
+ if (!isset($record['groupid'])) {
+ $record['groupid'] = "-1";
+ }
+
+ if (!isset($record['timestart'])) {
+ $record['timestart'] = "0";
+ }
+
+ if (!isset($record['timeend'])) {
+ $record['timeend'] = "0";
+ }
+
+ if (!isset($record['mailnow'])) {
+ $record['mailnow'] = "0";
+ }
+
+ $record = (object) $record;
+
+ // Add the discussion.
+ $record->id = forum_add_discussion($record, null, null, $record->userid);
+
+ return $record;
+ }
+
+ /**
+ * Function to create a dummy post.
+ *
+ * @param array|stdClass $record
+ * @return stdClass the post object
+ */
+ public function create_forum_post($record = null) {
+ global $DB;
+
+ // Increment the forum post count.
+ $this->forumpostcount++;
+
+ // Variable to store time.
+ $time = time() + $this->forumpostcount;
+
+ $record = (array) $record;
+
+ if (!isset($record['discussion'])) {
+ throw new coding_exception('discussion must be present in phpunit_util::create_forum_post() $record');
+ }
+
+ if (!isset($record['userid'])) {
+ throw new coding_exception('userid must be present in phpunit_util::create_forum_post() $record');
+ }
+
+ if (!isset($record['parent'])) {
+ $record['parent'] = 0;
+ }
+
+ if (!isset($record['subject'])) {
+ $record['subject'] = 'Forum post subject ' . $this->forumpostcount;
+ }
+
+ if (!isset($record['message'])) {
+ $record['message'] = html_writer::tag('p', 'Forum message post ' . $this->forumpostcount);
+ }
+
+ if (!isset($record['created'])) {
+ $record['created'] = $time;
+ }
+
+ if (!isset($record['modified'])) {
+ $record['modified'] = $time;
+ }
+
+ $record = (object) $record;
+
+ // Add the post.
+ $record->id = $DB->insert_record('forum_posts', $record);
+
+ // Update the last post.
+ forum_discussion_update_last_post($record->discussion);
+
+ return $record;
+ }
}
/**
*/
function forum_get_course_forum($courseid, $type) {
// How to set up special 1-per-course forums
- global $CFG, $DB, $OUTPUT;
+ global $CFG, $DB, $OUTPUT, $USER;
if ($forums = $DB->get_records_select("forum", "course = ? AND type = ?", array($courseid, $type), "id ASC")) {
// There should always only be ONE, but with the right combination of
$forum = new stdClass();
$forum->course = $courseid;
$forum->type = "$type";
+ if (!empty($USER->htmleditor)) {
+ $forum->introformat = $USER->htmleditor;
+ }
switch ($forum->type) {
case "news":
$forum->name = get_string("namenews", "forum");
* @param object $forum
* @param object $cm
* @param mixed $mform
- * @param string $message
+ * @param string $unused
* @return bool
*/
- function forum_add_attachment($post, $forum, $cm, $mform=null, &$message=null) {
+ function forum_add_attachment($post, $forum, $cm, $mform=null, $unused=null) {
global $DB;
if (empty($mform)) {
* Given an object containing all the necessary data,
* create a new discussion and return the id
*
- * @global object
- * @global object
- * @global object
* @param object $post
* @param mixed $mform
- * @param string $message
+ * @param string $unused
* @param int $userid
* @return object
*/
- function forum_add_discussion($discussion, $mform=null, &$message=null, $userid=null) {
+ function forum_add_discussion($discussion, $mform=null, $unused=null, $userid=null) {
global $USER, $CFG, $DB;
$timenow = time();
$DB->set_field("forum_posts", "discussion", $post->discussion, array("id"=>$post->id));
if (!empty($cm->id)) {
- forum_add_attachment($post, $forum, $cm, $mform, $message);
+ forum_add_attachment($post, $forum, $cm, $mform, $unused);
}
if (forum_tp_can_track_forums($forum) && forum_tp_is_tracked($forum)) {