|
|
|
@@ -274,253 +274,6 @@ class mod_forum_external_testcase extends externallib_advanced_testcase {
|
|
|
|
|
$this->assertFalse($response['pinned']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test get forum posts
|
|
|
|
|
*/
|
|
|
|
|
public function test_mod_forum_get_forum_discussion_posts() {
|
|
|
|
|
global $CFG, $PAGE;
|
|
|
|
|
|
|
|
|
|
$this->resetAfterTest(true);
|
|
|
|
|
|
|
|
|
|
// Set the CFG variable to allow track forums.
|
|
|
|
|
$CFG->forum_trackreadposts = true;
|
|
|
|
|
|
|
|
|
|
// Create a user who can track forums.
|
|
|
|
|
$record = new stdClass();
|
|
|
|
|
$record->trackforums = true;
|
|
|
|
|
$user1 = self::getDataGenerator()->create_user($record);
|
|
|
|
|
// Create a bunch of other users to post.
|
|
|
|
|
$user2 = self::getDataGenerator()->create_user();
|
|
|
|
|
$user3 = self::getDataGenerator()->create_user();
|
|
|
|
|
|
|
|
|
|
// Set the first created user to the test user.
|
|
|
|
|
self::setUser($user1);
|
|
|
|
|
|
|
|
|
|
// Create course to add the module.
|
|
|
|
|
$course1 = self::getDataGenerator()->create_course();
|
|
|
|
|
|
|
|
|
|
// Forum with tracking off.
|
|
|
|
|
$record = new stdClass();
|
|
|
|
|
$record->course = $course1->id;
|
|
|
|
|
$record->trackingtype = FORUM_TRACKING_OFF;
|
|
|
|
|
$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);
|
|
|
|
|
$forum2cm = get_coursemodule_from_id('forum', $forum2->cmid);
|
|
|
|
|
$forum2context = context_module::instance($forum2->cmid);
|
|
|
|
|
|
|
|
|
|
// Add discussions to the forums.
|
|
|
|
|
$record = new stdClass();
|
|
|
|
|
$record->course = $course1->id;
|
|
|
|
|
$record->userid = $user1->id;
|
|
|
|
|
$record->forum = $forum1->id;
|
|
|
|
|
$discussion1 = self::getDataGenerator()->get_plugin_generator('mod_forum')->create_discussion($record);
|
|
|
|
|
|
|
|
|
|
$record = new stdClass();
|
|
|
|
|
$record->course = $course1->id;
|
|
|
|
|
$record->userid = $user2->id;
|
|
|
|
|
$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;
|
|
|
|
|
$record->parent = $discussion1->firstpost;
|
|
|
|
|
$record->userid = $user2->id;
|
|
|
|
|
$discussion1reply1 = self::getDataGenerator()->get_plugin_generator('mod_forum')->create_post($record);
|
|
|
|
|
$filename = 'shouldbeanimage.jpg';
|
|
|
|
|
// Add a fake inline image to the post.
|
|
|
|
|
$filerecordinline = array(
|
|
|
|
|
'contextid' => $forum1context->id,
|
|
|
|
|
'component' => 'mod_forum',
|
|
|
|
|
'filearea' => 'post',
|
|
|
|
|
'itemid' => $discussion1reply1->id,
|
|
|
|
|
'filepath' => '/',
|
|
|
|
|
'filename' => $filename,
|
|
|
|
|
);
|
|
|
|
|
$fs = get_file_storage();
|
|
|
|
|
$timepost = time();
|
|
|
|
|
$fs->create_file_from_string($filerecordinline, 'image contents (not really)');
|
|
|
|
|
|
|
|
|
|
$record->parent = $discussion1reply1->id;
|
|
|
|
|
$record->userid = $user3->id;
|
|
|
|
|
$record->tags = array('Cats', 'Dogs');
|
|
|
|
|
$discussion1reply2 = self::getDataGenerator()->get_plugin_generator('mod_forum')->create_post($record);
|
|
|
|
|
|
|
|
|
|
// Enrol the user in the course.
|
|
|
|
|
$enrol = enrol_get_plugin('manual');
|
|
|
|
|
// Following line enrol and assign default role id to the user.
|
|
|
|
|
// So the user automatically gets mod/forum:viewdiscussion on all forums of the course.
|
|
|
|
|
$this->getDataGenerator()->enrol_user($user1->id, $course1->id);
|
|
|
|
|
$this->getDataGenerator()->enrol_user($user2->id, $course1->id);
|
|
|
|
|
|
|
|
|
|
// Delete one user, to test that we still receive posts by this user.
|
|
|
|
|
delete_user($user3);
|
|
|
|
|
|
|
|
|
|
// Create what we expect to be returned when querying the discussion.
|
|
|
|
|
$expectedposts = array(
|
|
|
|
|
'posts' => array(),
|
|
|
|
|
'ratinginfo' => array(
|
|
|
|
|
'contextid' => $forum1context->id,
|
|
|
|
|
'component' => 'mod_forum',
|
|
|
|
|
'ratingarea' => 'post',
|
|
|
|
|
'canviewall' => null,
|
|
|
|
|
'canviewany' => null,
|
|
|
|
|
'scales' => array(),
|
|
|
|
|
'ratings' => array(),
|
|
|
|
|
),
|
|
|
|
|
'warnings' => array(),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// User pictures are initially empty, we should get the links once the external function is called.
|
|
|
|
|
$expectedposts['posts'][] = array(
|
|
|
|
|
'id' => $discussion1reply2->id,
|
|
|
|
|
'discussion' => $discussion1reply2->discussion,
|
|
|
|
|
'parent' => $discussion1reply2->parent,
|
|
|
|
|
'userid' => (int) $discussion1reply2->userid,
|
|
|
|
|
'created' => $discussion1reply2->created,
|
|
|
|
|
'modified' => $discussion1reply2->modified,
|
|
|
|
|
'mailed' => $discussion1reply2->mailed,
|
|
|
|
|
'subject' => $discussion1reply2->subject,
|
|
|
|
|
'message' => file_rewrite_pluginfile_urls($discussion1reply2->message, 'pluginfile.php',
|
|
|
|
|
$forum1context->id, 'mod_forum', 'post', $discussion1reply2->id),
|
|
|
|
|
'messageformat' => 1, // This value is usually changed by external_format_text() function.
|
|
|
|
|
'messagetrust' => $discussion1reply2->messagetrust,
|
|
|
|
|
'attachment' => $discussion1reply2->attachment,
|
|
|
|
|
'totalscore' => $discussion1reply2->totalscore,
|
|
|
|
|
'mailnow' => $discussion1reply2->mailnow,
|
|
|
|
|
'children' => array(),
|
|
|
|
|
'canreply' => true,
|
|
|
|
|
'postread' => false,
|
|
|
|
|
'userfullname' => fullname($user3),
|
|
|
|
|
'userpictureurl' => '',
|
|
|
|
|
'deleted' => false,
|
|
|
|
|
'isprivatereply' => false,
|
|
|
|
|
'tags' => \core_tag\external\util::get_item_tags('mod_forum', 'forum_posts', $discussion1reply2->id),
|
|
|
|
|
);
|
|
|
|
|
// Cast to expected.
|
|
|
|
|
$this->assertCount(2, $expectedposts['posts'][0]['tags']);
|
|
|
|
|
$expectedposts['posts'][0]['tags'][0]['isstandard'] = (bool) $expectedposts['posts'][0]['tags'][0]['isstandard'];
|
|
|
|
|
$expectedposts['posts'][0]['tags'][1]['isstandard'] = (bool) $expectedposts['posts'][0]['tags'][1]['isstandard'];
|
|
|
|
|
|
|
|
|
|
$expectedposts['posts'][] = array(
|
|
|
|
|
'id' => $discussion1reply1->id,
|
|
|
|
|
'discussion' => $discussion1reply1->discussion,
|
|
|
|
|
'parent' => $discussion1reply1->parent,
|
|
|
|
|
'userid' => (int) $discussion1reply1->userid,
|
|
|
|
|
'created' => $discussion1reply1->created,
|
|
|
|
|
'modified' => $discussion1reply1->modified,
|
|
|
|
|
'mailed' => $discussion1reply1->mailed,
|
|
|
|
|
'subject' => $discussion1reply1->subject,
|
|
|
|
|
'message' => file_rewrite_pluginfile_urls($discussion1reply1->message, 'pluginfile.php',
|
|
|
|
|
$forum1context->id, 'mod_forum', 'post', $discussion1reply1->id),
|
|
|
|
|
'messageformat' => 1, // This value is usually changed by external_format_text() function.
|
|
|
|
|
'messagetrust' => $discussion1reply1->messagetrust,
|
|
|
|
|
'attachment' => $discussion1reply1->attachment,
|
|
|
|
|
'messageinlinefiles' => array(
|
|
|
|
|
array(
|
|
|
|
|
'filename' => $filename,
|
|
|
|
|
'filepath' => '/',
|
|
|
|
|
'filesize' => '27',
|
|
|
|
|
'fileurl' => moodle_url::make_webservice_pluginfile_url($forum1context->id, 'mod_forum', 'post',
|
|
|
|
|
$discussion1reply1->id, '/', $filename),
|
|
|
|
|
'timemodified' => $timepost,
|
|
|
|
|
'mimetype' => 'image/jpeg',
|
|
|
|
|
'isexternalfile' => false,
|
|
|
|
|
)
|
|
|
|
|
),
|
|
|
|
|
'totalscore' => $discussion1reply1->totalscore,
|
|
|
|
|
'mailnow' => $discussion1reply1->mailnow,
|
|
|
|
|
'children' => array($discussion1reply2->id),
|
|
|
|
|
'canreply' => true,
|
|
|
|
|
'postread' => false,
|
|
|
|
|
'userfullname' => fullname($user2),
|
|
|
|
|
'userpictureurl' => '',
|
|
|
|
|
'deleted' => false,
|
|
|
|
|
'isprivatereply' => false,
|
|
|
|
|
'tags' => array(),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Test a discussion with two additional posts (total 3 posts).
|
|
|
|
|
$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);
|
|
|
|
|
$this->assertEquals(3, count($posts['posts']));
|
|
|
|
|
|
|
|
|
|
// Generate here the pictures because we need to wait to the external function to init the theme.
|
|
|
|
|
$userpicture = new user_picture($user3);
|
|
|
|
|
$userpicture->size = 1; // Size f1.
|
|
|
|
|
$expectedposts['posts'][0]['userpictureurl'] = $userpicture->get_url($PAGE)->out(false);
|
|
|
|
|
|
|
|
|
|
$userpicture = new user_picture($user2);
|
|
|
|
|
$userpicture->size = 1; // Size f1.
|
|
|
|
|
$expectedposts['posts'][1]['userpictureurl'] = $userpicture->get_url($PAGE)->out(false);
|
|
|
|
|
|
|
|
|
|
// Unset the initial discussion post.
|
|
|
|
|
array_pop($posts['posts']);
|
|
|
|
|
$this->assertEquals($expectedposts, $posts);
|
|
|
|
|
|
|
|
|
|
// Check we receive the unread count correctly on tracked forum.
|
|
|
|
|
forum_tp_count_forum_unread_posts($forum2cm, $course1, true); // Reset static cache.
|
|
|
|
|
$result = mod_forum_external::get_forums_by_courses(array($course1->id));
|
|
|
|
|
$result = external_api::clean_returnvalue(mod_forum_external::get_forums_by_courses_returns(), $result);
|
|
|
|
|
foreach ($result as $f) {
|
|
|
|
|
if ($f['id'] == $forum2->id) {
|
|
|
|
|
$this->assertEquals(1, $f['unreadpostscount']);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test discussion without additional posts. There should be only one post (the one created by the discussion).
|
|
|
|
|
$posts = mod_forum_external::get_forum_discussion_posts($discussion2->id, 'modified', 'DESC');
|
|
|
|
|
$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']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check we receive 0 unread posts.
|
|
|
|
|
forum_tp_count_forum_unread_posts($forum2cm, $course1, true); // Reset static cache.
|
|
|
|
|
$result = mod_forum_external::get_forums_by_courses(array($course1->id));
|
|
|
|
|
$result = external_api::clean_returnvalue(mod_forum_external::get_forums_by_courses_returns(), $result);
|
|
|
|
|
foreach ($result as $f) {
|
|
|
|
|
if ($f['id'] == $forum2->id) {
|
|
|
|
|
$this->assertEquals(0, $f['unreadpostscount']);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test get forum posts
|
|
|
|
|
*
|
|
|
|
@@ -851,152 +604,6 @@ class mod_forum_external_testcase extends externallib_advanced_testcase {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test get forum posts
|
|
|
|
|
*/
|
|
|
|
|
public function test_mod_forum_get_forum_discussion_posts_deleted() {
|
|
|
|
|
global $CFG, $PAGE;
|
|
|
|
|
|
|
|
|
|
$this->resetAfterTest(true);
|
|
|
|
|
$generator = self::getDataGenerator()->get_plugin_generator('mod_forum');
|
|
|
|
|
|
|
|
|
|
// Create a course and enrol some users in it.
|
|
|
|
|
$course1 = self::getDataGenerator()->create_course();
|
|
|
|
|
|
|
|
|
|
// Create users.
|
|
|
|
|
$user1 = self::getDataGenerator()->create_user();
|
|
|
|
|
$this->getDataGenerator()->enrol_user($user1->id, $course1->id);
|
|
|
|
|
$user2 = self::getDataGenerator()->create_user();
|
|
|
|
|
$this->getDataGenerator()->enrol_user($user2->id, $course1->id);
|
|
|
|
|
|
|
|
|
|
// Set the first created user to the test user.
|
|
|
|
|
self::setUser($user1);
|
|
|
|
|
|
|
|
|
|
// Create test data.
|
|
|
|
|
$forum1 = self::getDataGenerator()->create_module('forum', (object) [
|
|
|
|
|
'course' => $course1->id,
|
|
|
|
|
]);
|
|
|
|
|
$forum1context = context_module::instance($forum1->cmid);
|
|
|
|
|
|
|
|
|
|
// Add discussions to the forum.
|
|
|
|
|
$discussion = $generator->create_discussion((object) [
|
|
|
|
|
'course' => $course1->id,
|
|
|
|
|
'userid' => $user1->id,
|
|
|
|
|
'forum' => $forum1->id,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$discussion2 = $generator->create_discussion((object) [
|
|
|
|
|
'course' => $course1->id,
|
|
|
|
|
'userid' => $user2->id,
|
|
|
|
|
'forum' => $forum1->id,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
// Add replies to the discussion.
|
|
|
|
|
$discussionreply1 = $generator->create_post((object) [
|
|
|
|
|
'discussion' => $discussion->id,
|
|
|
|
|
'parent' => $discussion->firstpost,
|
|
|
|
|
'userid' => $user2->id,
|
|
|
|
|
]);
|
|
|
|
|
$discussionreply2 = $generator->create_post((object) [
|
|
|
|
|
'discussion' => $discussion->id,
|
|
|
|
|
'parent' => $discussionreply1->id,
|
|
|
|
|
'userid' => $user2->id,
|
|
|
|
|
'subject' => '',
|
|
|
|
|
'message' => '',
|
|
|
|
|
'messageformat' => FORMAT_PLAIN,
|
|
|
|
|
'deleted' => 1,
|
|
|
|
|
]);
|
|
|
|
|
$discussionreply3 = $generator->create_post((object) [
|
|
|
|
|
'discussion' => $discussion->id,
|
|
|
|
|
'parent' => $discussion->firstpost,
|
|
|
|
|
'userid' => $user2->id,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
// Test where some posts have been marked as deleted.
|
|
|
|
|
$posts = mod_forum_external::get_forum_discussion_posts($discussion->id, 'modified', 'DESC');
|
|
|
|
|
$posts = external_api::clean_returnvalue(mod_forum_external::get_forum_discussion_posts_returns(), $posts);
|
|
|
|
|
$deletedsubject = get_string('privacy:request:delete:post:subject', 'mod_forum');
|
|
|
|
|
$deletedmessage = get_string('privacy:request:delete:post:message', 'mod_forum');
|
|
|
|
|
|
|
|
|
|
foreach ($posts['posts'] as $post) {
|
|
|
|
|
if ($post['id'] == $discussionreply2->id) {
|
|
|
|
|
$this->assertTrue($post['deleted']);
|
|
|
|
|
$this->assertEquals($deletedsubject, $post['subject']);
|
|
|
|
|
$this->assertEquals($deletedmessage, $post['message']);
|
|
|
|
|
} else {
|
|
|
|
|
$this->assertFalse($post['deleted']);
|
|
|
|
|
$this->assertNotEquals($deletedsubject, $post['subject']);
|
|
|
|
|
$this->assertNotEquals($deletedmessage, $post['message']);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test get forum posts (qanda forum)
|
|
|
|
|
*/
|
|
|
|
|
public function test_mod_forum_get_forum_discussion_posts_qanda() {
|
|
|
|
|
global $CFG, $DB;
|
|
|
|
|
|
|
|
|
|
$this->resetAfterTest(true);
|
|
|
|
|
|
|
|
|
|
$record = new stdClass();
|
|
|
|
|
$user1 = self::getDataGenerator()->create_user($record);
|
|
|
|
|
$user2 = self::getDataGenerator()->create_user();
|
|
|
|
|
|
|
|
|
|
// Set the first created user to the test user.
|
|
|
|
|
self::setUser($user1);
|
|
|
|
|
|
|
|
|
|
// Create course to add the module.
|
|
|
|
|
$course1 = self::getDataGenerator()->create_course();
|
|
|
|
|
$this->getDataGenerator()->enrol_user($user1->id, $course1->id);
|
|
|
|
|
$this->getDataGenerator()->enrol_user($user2->id, $course1->id);
|
|
|
|
|
|
|
|
|
|
// Forum with tracking off.
|
|
|
|
|
$record = new stdClass();
|
|
|
|
|
$record->course = $course1->id;
|
|
|
|
|
$record->type = 'qanda';
|
|
|
|
|
$forum1 = self::getDataGenerator()->create_module('forum', $record);
|
|
|
|
|
$forum1context = context_module::instance($forum1->cmid);
|
|
|
|
|
|
|
|
|
|
// Add discussions to the forums.
|
|
|
|
|
$record = new stdClass();
|
|
|
|
|
$record->course = $course1->id;
|
|
|
|
|
$record->userid = $user2->id;
|
|
|
|
|
$record->forum = $forum1->id;
|
|
|
|
|
$discussion1 = self::getDataGenerator()->get_plugin_generator('mod_forum')->create_discussion($record);
|
|
|
|
|
|
|
|
|
|
// Add 1 reply (not the actual user).
|
|
|
|
|
$record = new stdClass();
|
|
|
|
|
$record->discussion = $discussion1->id;
|
|
|
|
|
$record->parent = $discussion1->firstpost;
|
|
|
|
|
$record->userid = $user2->id;
|
|
|
|
|
$discussion1reply1 = self::getDataGenerator()->get_plugin_generator('mod_forum')->create_post($record);
|
|
|
|
|
|
|
|
|
|
// We still see only the original post.
|
|
|
|
|
$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);
|
|
|
|
|
$this->assertEquals(1, count($posts['posts']));
|
|
|
|
|
|
|
|
|
|
// Add a new reply, the user is going to be able to see only the original post and their new post.
|
|
|
|
|
$record = new stdClass();
|
|
|
|
|
$record->discussion = $discussion1->id;
|
|
|
|
|
$record->parent = $discussion1->firstpost;
|
|
|
|
|
$record->userid = $user1->id;
|
|
|
|
|
$discussion1reply2 = self::getDataGenerator()->get_plugin_generator('mod_forum')->create_post($record);
|
|
|
|
|
|
|
|
|
|
$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);
|
|
|
|
|
$this->assertEquals(2, count($posts['posts']));
|
|
|
|
|
|
|
|
|
|
// Now, we can fake the time of the user post, so he can se the rest of the discussion posts.
|
|
|
|
|
$discussion1reply2->created -= $CFG->maxeditingtime * 2;
|
|
|
|
|
$DB->update_record('forum_posts', $discussion1reply2);
|
|
|
|
|
|
|
|
|
|
$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);
|
|
|
|
|
$this->assertEquals(3, count($posts['posts']));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test get forum discussions paginated
|
|
|
|
|
*/
|
|
|
|
@@ -1597,8 +1204,8 @@ class mod_forum_external_testcase extends externallib_advanced_testcase {
|
|
|
|
|
$createdpost = mod_forum_external::add_discussion_post($discussion->firstpost, 'some subject', 'some text here...');
|
|
|
|
|
$createdpost = external_api::clean_returnvalue(mod_forum_external::add_discussion_post_returns(), $createdpost);
|
|
|
|
|
|
|
|
|
|
$posts = mod_forum_external::get_forum_discussion_posts($discussion->id);
|
|
|
|
|
$posts = external_api::clean_returnvalue(mod_forum_external::get_forum_discussion_posts_returns(), $posts);
|
|
|
|
|
$posts = mod_forum_external::get_discussion_posts($discussion->id, 'modified', 'ASC');
|
|
|
|
|
$posts = external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_returns(), $posts);
|
|
|
|
|
// We receive the discussion and the post.
|
|
|
|
|
$this->assertEquals(2, count($posts['posts']));
|
|
|
|
|
|
|
|
|
@@ -1676,16 +1283,16 @@ class mod_forum_external_testcase extends externallib_advanced_testcase {
|
|
|
|
|
$dummytext, $options);
|
|
|
|
|
$createdpost = external_api::clean_returnvalue(mod_forum_external::add_discussion_post_returns(), $createdpost);
|
|
|
|
|
|
|
|
|
|
$posts = mod_forum_external::get_forum_discussion_posts($discussion->id);
|
|
|
|
|
$posts = external_api::clean_returnvalue(mod_forum_external::get_forum_discussion_posts_returns(), $posts);
|
|
|
|
|
$posts = mod_forum_external::get_discussion_posts($discussion->id, 'modified', 'ASC');
|
|
|
|
|
$posts = external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_returns(), $posts);
|
|
|
|
|
// We receive the discussion and the post.
|
|
|
|
|
// Can't guarantee order of posts during tests.
|
|
|
|
|
$postfound = false;
|
|
|
|
|
foreach ($posts['posts'] as $thispost) {
|
|
|
|
|
if ($createdpost['postid'] == $thispost['id']) {
|
|
|
|
|
$this->assertEquals($createdpost['postid'], $thispost['id']);
|
|
|
|
|
$this->assertEquals($thispost['attachment'], 1, "There should be a non-inline attachment");
|
|
|
|
|
$this->assertCount(1, $thispost['attachments'], "There should be 1 attachment");
|
|
|
|
|
$this->assertCount(1, $thispost['attachments']);
|
|
|
|
|
$this->assertEquals('attachment.txt', $thispost['attachments'][0]['filename']);
|
|
|
|
|
$this->assertEquals($thispost['attachments'][0]['filename'], $attachfilename, "There should be 1 attachment");
|
|
|
|
|
$this->assertStringContainsString('pluginfile.php', $thispost['message']);
|
|
|
|
|
$postfound = true;
|
|
|
|
@@ -1751,8 +1358,8 @@ class mod_forum_external_testcase extends externallib_advanced_testcase {
|
|
|
|
|
// Add a discussion post in a forum discussion where the user is not subscribed (auto-subscribe preference enabled).
|
|
|
|
|
mod_forum_external::add_discussion_post($discussion1->firstpost, 'some subject', 'some text here...');
|
|
|
|
|
|
|
|
|
|
$posts = mod_forum_external::get_forum_discussion_posts($discussion1->id);
|
|
|
|
|
$posts = external_api::clean_returnvalue(mod_forum_external::get_forum_discussion_posts_returns(), $posts);
|
|
|
|
|
$posts = mod_forum_external::get_discussion_posts($discussion1->id, 'modified', 'ASC');
|
|
|
|
|
$posts = external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_returns(), $posts);
|
|
|
|
|
// We receive the discussion and the post.
|
|
|
|
|
$this->assertEquals(2, count($posts['posts']));
|
|
|
|
|
// The user should be subscribed to the discussion after adding a discussion post.
|
|
|
|
@@ -1764,8 +1371,8 @@ class mod_forum_external_testcase extends externallib_advanced_testcase {
|
|
|
|
|
// Add a discussion post in a forum discussion where the user is subscribed (auto-subscribe preference disabled).
|
|
|
|
|
mod_forum_external::add_discussion_post($discussion1->firstpost, 'some subject 1', 'some text here 1...');
|
|
|
|
|
|
|
|
|
|
$posts = mod_forum_external::get_forum_discussion_posts($discussion1->id);
|
|
|
|
|
$posts = external_api::clean_returnvalue(mod_forum_external::get_forum_discussion_posts_returns(), $posts);
|
|
|
|
|
$posts = mod_forum_external::get_discussion_posts($discussion1->id, 'modified', 'ASC');
|
|
|
|
|
$posts = external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_returns(), $posts);
|
|
|
|
|
// We receive the discussion and the post.
|
|
|
|
|
$this->assertEquals(3, count($posts['posts']));
|
|
|
|
|
// The user should still be subscribed to the discussion after adding a discussion post.
|
|
|
|
@@ -1775,8 +1382,8 @@ class mod_forum_external_testcase extends externallib_advanced_testcase {
|
|
|
|
|
// Add a discussion post in a forum discussion where the user is not subscribed (auto-subscribe preference disabled).
|
|
|
|
|
mod_forum_external::add_discussion_post($discussion2->firstpost, 'some subject 2', 'some text here 2...');
|
|
|
|
|
|
|
|
|
|
$posts = mod_forum_external::get_forum_discussion_posts($discussion2->id);
|
|
|
|
|
$posts = external_api::clean_returnvalue(mod_forum_external::get_forum_discussion_posts_returns(), $posts);
|
|
|
|
|
$posts = mod_forum_external::get_discussion_posts($discussion2->id, 'modified', 'ASC');
|
|
|
|
|
$posts = external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_returns(), $posts);
|
|
|
|
|
// We receive the discussion and the post.
|
|
|
|
|
$this->assertEquals(2, count($posts['posts']));
|
|
|
|
|
// The user should still not be subscribed to the discussion after adding a discussion post.
|
|
|
|
@@ -1791,8 +1398,8 @@ class mod_forum_external_testcase extends externallib_advanced_testcase {
|
|
|
|
|
mod_forum_external::add_discussion_post($discussion2->firstpost, 'some subject 2', 'some text here 2...',
|
|
|
|
|
$options);
|
|
|
|
|
|
|
|
|
|
$posts = mod_forum_external::get_forum_discussion_posts($discussion2->id);
|
|
|
|
|
$posts = external_api::clean_returnvalue(mod_forum_external::get_forum_discussion_posts_returns(), $posts);
|
|
|
|
|
$posts = mod_forum_external::get_discussion_posts($discussion2->id, 'modified', 'ASC');
|
|
|
|
|
$posts = external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_returns(), $posts);
|
|
|
|
|
// We receive the discussion and the post.
|
|
|
|
|
$this->assertEquals(3, count($posts['posts']));
|
|
|
|
|
// The user should now be subscribed to the discussion after adding a discussion post.
|
|
|
|
@@ -2139,9 +1746,9 @@ class mod_forum_external_testcase extends externallib_advanced_testcase {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test get forum posts discussions including rating information.
|
|
|
|
|
* Test get posts discussions including rating information.
|
|
|
|
|
*/
|
|
|
|
|
public function test_mod_forum_get_forum_discussion_rating_information() {
|
|
|
|
|
public function test_mod_forum_get_discussion_rating_information() {
|
|
|
|
|
global $DB, $CFG;
|
|
|
|
|
require_once($CFG->dirroot . '/rating/lib.php');
|
|
|
|
|
|
|
|
|
@@ -2209,8 +1816,8 @@ class mod_forum_external_testcase extends externallib_advanced_testcase {
|
|
|
|
|
|
|
|
|
|
// Retrieve the rating for the post as student.
|
|
|
|
|
$this->setUser($user1);
|
|
|
|
|
$posts = mod_forum_external::get_forum_discussion_posts($discussion->id);
|
|
|
|
|
$posts = external_api::clean_returnvalue(mod_forum_external::get_forum_discussion_posts_returns(), $posts);
|
|
|
|
|
$posts = mod_forum_external::get_discussion_posts($discussion->id, 'id', 'DESC');
|
|
|
|
|
$posts = external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_returns(), $posts);
|
|
|
|
|
$this->assertCount(1, $posts['ratinginfo']['ratings']);
|
|
|
|
|
$this->assertTrue($posts['ratinginfo']['ratings'][0]['canviewaggregate']);
|
|
|
|
|
$this->assertFalse($posts['ratinginfo']['canviewall']);
|
|
|
|
@@ -2220,8 +1827,8 @@ class mod_forum_external_testcase extends externallib_advanced_testcase {
|
|
|
|
|
|
|
|
|
|
// Retrieve the rating for the post as teacher.
|
|
|
|
|
$this->setUser($teacher);
|
|
|
|
|
$posts = mod_forum_external::get_forum_discussion_posts($discussion->id);
|
|
|
|
|
$posts = external_api::clean_returnvalue(mod_forum_external::get_forum_discussion_posts_returns(), $posts);
|
|
|
|
|
$posts = mod_forum_external::get_discussion_posts($discussion->id, 'id', 'DESC');
|
|
|
|
|
$posts = external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_returns(), $posts);
|
|
|
|
|
$this->assertCount(1, $posts['ratinginfo']['ratings']);
|
|
|
|
|
$this->assertTrue($posts['ratinginfo']['ratings'][0]['canviewaggregate']);
|
|
|
|
|
$this->assertTrue($posts['ratinginfo']['canviewall']);
|
|
|
|
@@ -2340,29 +1947,29 @@ class mod_forum_external_testcase extends externallib_advanced_testcase {
|
|
|
|
|
|
|
|
|
|
// The teacher will receive their private reply.
|
|
|
|
|
self::setUser($teacher1);
|
|
|
|
|
$posts = mod_forum_external::get_forum_discussion_posts($discussion->id);
|
|
|
|
|
$posts = external_api::clean_returnvalue(mod_forum_external::get_forum_discussion_posts_returns(), $posts);
|
|
|
|
|
$posts = mod_forum_external::get_discussion_posts($discussion->id, 'id', 'DESC');
|
|
|
|
|
$posts = external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_returns(), $posts);
|
|
|
|
|
$this->assertEquals(2, count($posts['posts']));
|
|
|
|
|
$this->assertTrue($posts['posts'][0]['isprivatereply']);
|
|
|
|
|
|
|
|
|
|
// Another teacher on the course will also receive the private reply.
|
|
|
|
|
self::setUser($teacher2);
|
|
|
|
|
$posts = mod_forum_external::get_forum_discussion_posts($discussion->id);
|
|
|
|
|
$posts = external_api::clean_returnvalue(mod_forum_external::get_forum_discussion_posts_returns(), $posts);
|
|
|
|
|
$posts = mod_forum_external::get_discussion_posts($discussion->id, 'id', 'DESC');
|
|
|
|
|
$posts = external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_returns(), $posts);
|
|
|
|
|
$this->assertEquals(2, count($posts['posts']));
|
|
|
|
|
$this->assertTrue($posts['posts'][0]['isprivatereply']);
|
|
|
|
|
|
|
|
|
|
// The student will receive the private reply.
|
|
|
|
|
self::setUser($student1);
|
|
|
|
|
$posts = mod_forum_external::get_forum_discussion_posts($discussion->id);
|
|
|
|
|
$posts = external_api::clean_returnvalue(mod_forum_external::get_forum_discussion_posts_returns(), $posts);
|
|
|
|
|
$posts = mod_forum_external::get_discussion_posts($discussion->id, 'id', 'DESC');
|
|
|
|
|
$posts = external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_returns(), $posts);
|
|
|
|
|
$this->assertEquals(2, count($posts['posts']));
|
|
|
|
|
$this->assertTrue($posts['posts'][0]['isprivatereply']);
|
|
|
|
|
|
|
|
|
|
// Another student will not receive the private reply.
|
|
|
|
|
self::setUser($student2);
|
|
|
|
|
$posts = mod_forum_external::get_forum_discussion_posts($discussion->id);
|
|
|
|
|
$posts = external_api::clean_returnvalue(mod_forum_external::get_forum_discussion_posts_returns(), $posts);
|
|
|
|
|
$posts = mod_forum_external::get_discussion_posts($discussion->id, 'id', 'ASC');
|
|
|
|
|
$posts = external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_returns(), $posts);
|
|
|
|
|
$this->assertEquals(1, count($posts['posts']));
|
|
|
|
|
$this->assertFalse($posts['posts'][0]['isprivatereply']);
|
|
|
|
|
|
|
|
|
@@ -2427,16 +2034,14 @@ class mod_forum_external_testcase extends externallib_advanced_testcase {
|
|
|
|
|
$this->assertEquals($cleantext, $discussions['discussions'][1]['message']);
|
|
|
|
|
|
|
|
|
|
// Get posts now.
|
|
|
|
|
$posts = mod_forum_external::get_forum_discussion_posts($discussion2->id);
|
|
|
|
|
$posts = external_api::clean_returnvalue(mod_forum_external::get_forum_discussion_posts_returns(), $posts);
|
|
|
|
|
$posts = mod_forum_external::get_discussion_posts($discussion2->id, 'modified', 'DESC');
|
|
|
|
|
$posts = external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_returns(), $posts);
|
|
|
|
|
// Admin message is fully trusted.
|
|
|
|
|
$this->assertEquals(1, $posts['posts'][0]['messagetrust']);
|
|
|
|
|
$this->assertEquals($dangeroustext, $posts['posts'][0]['message']);
|
|
|
|
|
|
|
|
|
|
$posts = mod_forum_external::get_forum_discussion_posts($discussion1->id);
|
|
|
|
|
$posts = external_api::clean_returnvalue(mod_forum_external::get_forum_discussion_posts_returns(), $posts);
|
|
|
|
|
$posts = mod_forum_external::get_discussion_posts($discussion1->id, 'modified', 'ASC');
|
|
|
|
|
$posts = external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_returns(), $posts);
|
|
|
|
|
// Student message is not trusted.
|
|
|
|
|
$this->assertEquals(0, $posts['posts'][0]['messagetrust']);
|
|
|
|
|
$this->assertEquals($cleantext, $posts['posts'][0]['message']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -2490,16 +2095,14 @@ class mod_forum_external_testcase extends externallib_advanced_testcase {
|
|
|
|
|
$this->assertEquals($cleantext, $discussions['discussions'][1]['message']);
|
|
|
|
|
|
|
|
|
|
// Get posts now.
|
|
|
|
|
$posts = mod_forum_external::get_forum_discussion_posts($discussion2->id);
|
|
|
|
|
$posts = external_api::clean_returnvalue(mod_forum_external::get_forum_discussion_posts_returns(), $posts);
|
|
|
|
|
$posts = mod_forum_external::get_discussion_posts($discussion2->id, 'modified', 'ASC');
|
|
|
|
|
$posts = external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_returns(), $posts);
|
|
|
|
|
// Admin message is not trusted because enabletrusttext is disabled.
|
|
|
|
|
$this->assertEquals(0, $posts['posts'][0]['messagetrust']);
|
|
|
|
|
$this->assertEquals($cleantext, $posts['posts'][0]['message']);
|
|
|
|
|
|
|
|
|
|
$posts = mod_forum_external::get_forum_discussion_posts($discussion1->id);
|
|
|
|
|
$posts = external_api::clean_returnvalue(mod_forum_external::get_forum_discussion_posts_returns(), $posts);
|
|
|
|
|
$posts = mod_forum_external::get_discussion_posts($discussion1->id, 'modified', 'ASC');
|
|
|
|
|
$posts = external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_returns(), $posts);
|
|
|
|
|
// Student message is not trusted.
|
|
|
|
|
$this->assertEquals(0, $posts['posts'][0]['messagetrust']);
|
|
|
|
|
$this->assertEquals($cleantext, $posts['posts'][0]['message']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -3324,16 +2927,14 @@ class mod_forum_external_testcase extends externallib_advanced_testcase {
|
|
|
|
|
$this->assertFalse(\mod_forum\subscriptions::is_subscribed($user->id, $forum, $discussion->id, $cm));
|
|
|
|
|
|
|
|
|
|
// Get the post from WS.
|
|
|
|
|
$result = mod_forum_external::get_forum_discussion_posts($discussion->id);
|
|
|
|
|
$result = external_api::clean_returnvalue(mod_forum_external::get_forum_discussion_posts_returns(), $result);
|
|
|
|
|
$result = mod_forum_external::get_discussion_posts($discussion->id, 'modified', 'ASC');
|
|
|
|
|
$result = external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_returns(), $result);
|
|
|
|
|
$found = false;
|
|
|
|
|
foreach ($result['posts'] as $post) {
|
|
|
|
|
if ($post['id'] == $newpost->id) {
|
|
|
|
|
$this->assertEquals($newpost->subject, $post['subject']);
|
|
|
|
|
$this->assertEquals($message, $post['message']);
|
|
|
|
|
$this->assertEquals($messageformat, $post['messageformat']);
|
|
|
|
|
$this->assertCount(1, $post['messageinlinefiles']);
|
|
|
|
|
$this->assertEquals('fakeimage.png', $post['messageinlinefiles'][0]['filename']);
|
|
|
|
|
$this->assertCount(1, $post['attachments']);
|
|
|
|
|
$this->assertEquals('faketxt.txt', $post['attachments'][0]['filename']);
|
|
|
|
|
$found = true;
|
|
|
|
|