mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 22:08:20 +01:00
Merge branch 'MDL-57554-master' of git://github.com/crazyserver/moodle
This commit is contained in:
commit
a04ad3675a
@ -680,7 +680,7 @@ class mod_forum_external extends external_api {
|
||||
* @throws moodle_exception
|
||||
*/
|
||||
public static function view_forum_discussion($discussionid) {
|
||||
global $DB, $CFG;
|
||||
global $DB, $CFG, $USER;
|
||||
require_once($CFG->dirroot . "/mod/forum/lib.php");
|
||||
|
||||
$params = self::validate_parameters(self::view_forum_discussion_parameters(),
|
||||
@ -702,6 +702,11 @@ class mod_forum_external extends external_api {
|
||||
// Call the forum/lib API.
|
||||
forum_discussion_view($modcontext, $forum, $discussion);
|
||||
|
||||
// Mark as read if required.
|
||||
if (!$CFG->forum_usermarksread && forum_tp_is_tracked($forum)) {
|
||||
forum_tp_mark_discussion_read($USER, $discussion->id);
|
||||
}
|
||||
|
||||
$result = array();
|
||||
$result['status'] = true;
|
||||
$result['warnings'] = $warnings;
|
||||
|
@ -211,6 +211,12 @@ class mod_forum_external_testcase extends externallib_advanced_testcase {
|
||||
$forum1 = self::getDataGenerator()->create_module('forum', $record);
|
||||
$forum1context = context_module::instance($forum1->cmid);
|
||||
|
||||
// Forum with tracking enabled.
|
||||
$record = new stdClass();
|
||||
$record->course = $course1->id;
|
||||
$forum2 = self::getDataGenerator()->create_module('forum', $record);
|
||||
$forum2context = context_module::instance($forum2->cmid);
|
||||
|
||||
// Add discussions to the forums.
|
||||
$record = new stdClass();
|
||||
$record->course = $course1->id;
|
||||
@ -224,6 +230,12 @@ class mod_forum_external_testcase extends externallib_advanced_testcase {
|
||||
$record->forum = $forum1->id;
|
||||
$discussion2 = self::getDataGenerator()->get_plugin_generator('mod_forum')->create_discussion($record);
|
||||
|
||||
$record = new stdClass();
|
||||
$record->course = $course1->id;
|
||||
$record->userid = $user2->id;
|
||||
$record->forum = $forum2->id;
|
||||
$discussion3 = self::getDataGenerator()->get_plugin_generator('mod_forum')->create_discussion($record);
|
||||
|
||||
// Add 2 replies to the discussion 1 from different users.
|
||||
$record = new stdClass();
|
||||
$record->discussion = $discussion1->id;
|
||||
@ -345,6 +357,31 @@ class mod_forum_external_testcase extends externallib_advanced_testcase {
|
||||
$posts = external_api::clean_returnvalue(mod_forum_external::get_forum_discussion_posts_returns(), $posts);
|
||||
$this->assertEquals(1, count($posts['posts']));
|
||||
|
||||
// Test discussion tracking on not tracked forum.
|
||||
$result = mod_forum_external::view_forum_discussion($discussion1->id);
|
||||
$result = external_api::clean_returnvalue(mod_forum_external::view_forum_discussion_returns(), $result);
|
||||
$this->assertTrue($result['status']);
|
||||
$this->assertEmpty($result['warnings']);
|
||||
|
||||
// Test posts have not been marked as read.
|
||||
$posts = mod_forum_external::get_forum_discussion_posts($discussion1->id, 'modified', 'DESC');
|
||||
$posts = external_api::clean_returnvalue(mod_forum_external::get_forum_discussion_posts_returns(), $posts);
|
||||
foreach ($posts['posts'] as $post) {
|
||||
$this->assertFalse($post['postread']);
|
||||
}
|
||||
|
||||
// Test discussion tracking on tracked forum.
|
||||
$result = mod_forum_external::view_forum_discussion($discussion3->id);
|
||||
$result = external_api::clean_returnvalue(mod_forum_external::view_forum_discussion_returns(), $result);
|
||||
$this->assertTrue($result['status']);
|
||||
$this->assertEmpty($result['warnings']);
|
||||
|
||||
// Test posts have been marked as read.
|
||||
$posts = mod_forum_external::get_forum_discussion_posts($discussion3->id, 'modified', 'DESC');
|
||||
$posts = external_api::clean_returnvalue(mod_forum_external::get_forum_discussion_posts_returns(), $posts);
|
||||
foreach ($posts['posts'] as $post) {
|
||||
$this->assertTrue($post['postread']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user