Línea 28... |
Línea 28... |
28 |
* @package mod_forum
|
28 |
* @package mod_forum
|
29 |
* @copyright 2019 Ryan Wyllie <ryan@moodle.com>
|
29 |
* @copyright 2019 Ryan Wyllie <ryan@moodle.com>
|
30 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
30 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
31 |
* @coversDefaultClass \mod_forum\local\vaults\post
|
31 |
* @coversDefaultClass \mod_forum\local\vaults\post
|
32 |
*/
|
32 |
*/
|
33 |
class vaults_post_test extends \advanced_testcase {
|
33 |
final class vaults_post_test extends \advanced_testcase {
|
34 |
// Make use of the test generator trait.
|
34 |
// Make use of the test generator trait.
|
35 |
use mod_forum_tests_generator_trait;
|
35 |
use mod_forum_tests_generator_trait;
|
Línea 36... |
Línea 36... |
36 |
|
36 |
|
37 |
/** @var \mod_forum\local\vaults\post */
|
37 |
/** @var \mod_forum\local\vaults\post */
|
Línea 38... |
Línea 38... |
38 |
private $vault;
|
38 |
private $vault;
|
39 |
|
39 |
|
40 |
/**
|
40 |
/**
|
41 |
* Set up function for tests.
|
41 |
* Set up function for tests.
|
- |
|
42 |
*/
|
42 |
*/
|
43 |
public function setUp(): void {
|
43 |
public function setUp(): void {
|
44 |
parent::setUp();
|
44 |
$vaultfactory = \mod_forum\local\container::get_vault_factory();
|
45 |
$vaultfactory = \mod_forum\local\container::get_vault_factory();
|
Línea 45... |
Línea 46... |
45 |
$this->vault = $vaultfactory->get_post_vault();
|
46 |
$this->vault = $vaultfactory->get_post_vault();
|
46 |
}
|
47 |
}
|
47 |
|
48 |
|
48 |
/**
|
49 |
/**
|
49 |
* Teardown for all tests.
|
50 |
* Teardown for all tests.
|
- |
|
51 |
*/
|
50 |
*/
|
52 |
public function tearDown(): void {
|
Línea 51... |
Línea 53... |
51 |
public function tearDown(): void {
|
53 |
unset($this->vault);
|
52 |
unset($this->vault);
|
54 |
parent::tearDown();
|
53 |
}
|
55 |
}
|
Línea 789... |
Línea 791... |
789 |
|
791 |
|
790 |
$datagenerator = $this->getDataGenerator();
|
792 |
$datagenerator = $this->getDataGenerator();
|
791 |
$course = $datagenerator->create_course();
|
793 |
$course = $datagenerator->create_course();
|
792 |
[$teacher, $otherteacher] = $this->helper_create_users($course, 2, 'teacher');
|
794 |
[$teacher, $otherteacher] = $this->helper_create_users($course, 2, 'teacher');
|
- |
|
795 |
[$user, $user2] = $this->helper_create_users($course, 2, 'student');
|
793 |
[$user, $user2] = $this->helper_create_users($course, 2, 'student');
|
796 |
$now = time();
|
794 |
$forum = $datagenerator->create_module('forum', ['course' => $course->id]);
|
797 |
$forum = $datagenerator->create_module('forum', ['course' => $course->id]);
|
795 |
[$discussion1, $post1] = $this->helper_post_to_forum($forum, $user);
|
798 |
[$discussion1, $post1] = $this->helper_post_to_forum($forum, $user);
|
796 |
$post2 = $this->helper_reply_to_post($post1, $user);
|
799 |
$post2 = $this->helper_reply_to_post($post1, $user, ['created' => $now + 100]);
|
797 |
$post3 = $this->helper_reply_to_post($post1, $user);
|
800 |
$post3 = $this->helper_reply_to_post($post1, $user, ['created' => $now + 101]);
|
798 |
$post4 = $this->helper_reply_to_post($post2, $user);
|
801 |
$post4 = $this->helper_reply_to_post($post2, $user, ['created' => $now + 102]);
|
799 |
[$discussion2, $post5] = $this->helper_post_to_forum($forum, $user);
|
802 |
[$discussion2, $post5] = $this->helper_post_to_forum($forum, $user);
|
- |
|
803 |
$post6 = $this->helper_reply_to_post($post5, $user);
|
- |
|
804 |
$post7 = $this->helper_reply_to_post($post5, $user);
|
800 |
$post6 = $this->helper_reply_to_post($post5, $user);
|
805 |
$post8 = $this->helper_reply_to_post($post6, $user);
|
801 |
[$discussion3, $post7] = $this->helper_post_to_forum($forum, $user);
|
806 |
[$discussion3, $post9] = $this->helper_post_to_forum($forum, $user);
|
802 |
$post8 = $this->helper_post_to_discussion($forum, $discussion3, $teacher, [
|
807 |
$post10 = $this->helper_post_to_discussion($forum, $discussion3, $teacher, [
|
803 |
'privatereplyto' => $user->id,
|
808 |
'privatereplyto' => $user->id,
|
Línea 804... |
Línea 809... |
804 |
]);
|
809 |
]);
|
805 |
|
810 |
|
Línea 809... |
Línea 814... |
809 |
|
814 |
|
810 |
$ids = $this->vault->get_latest_posts_for_discussion_ids($user,
|
815 |
$ids = $this->vault->get_latest_posts_for_discussion_ids($user,
|
811 |
[$discussion1->id, $discussion2->id], false);
|
816 |
[$discussion1->id, $discussion2->id], false);
|
812 |
$this->assertCount(2, $ids);
|
817 |
$this->assertCount(2, $ids);
|
813 |
$this->assertEquals($post4->id, $ids[$discussion1->id]->get_id());
|
818 |
$this->assertEquals($post4->id, $ids[$discussion1->id]->get_id());
|
Línea 814... |
Línea 819... |
814 |
$this->assertEquals($post6->id, $ids[$discussion2->id]->get_id());
|
819 |
$this->assertEquals($post8->id, $ids[$discussion2->id]->get_id());
|
815 |
|
820 |
|
816 |
$ids = $this->vault->get_latest_posts_for_discussion_ids($user,
|
821 |
$ids = $this->vault->get_latest_posts_for_discussion_ids($user,
|
817 |
[$discussion1->id, $discussion2->id, $discussion3->id], false);
|
822 |
[$discussion1->id, $discussion2->id, $discussion3->id], false);
|
818 |
$this->assertCount(3, $ids);
|
823 |
$this->assertCount(3, $ids);
|
819 |
$this->assertEquals($post4->id, $ids[$discussion1->id]->get_id());
|
824 |
$this->assertEquals($post4->id, $ids[$discussion1->id]->get_id());
|
Línea 820... |
Línea 825... |
820 |
$this->assertEquals($post6->id, $ids[$discussion2->id]->get_id());
|
825 |
$this->assertEquals($post8->id, $ids[$discussion2->id]->get_id());
|
821 |
$this->assertEquals($post8->id, $ids[$discussion3->id]->get_id());
|
826 |
$this->assertEquals($post10->id, $ids[$discussion3->id]->get_id());
|
822 |
|
827 |
|
823 |
// Checks the user who doesn't have access to the private reply.
|
828 |
// Checks the user who doesn't have access to the private reply.
|
824 |
$ids = $this->vault->get_latest_posts_for_discussion_ids($user2,
|
829 |
$ids = $this->vault->get_latest_posts_for_discussion_ids($user2,
|
825 |
[$discussion1->id, $discussion2->id, $discussion3->id], false);
|
830 |
[$discussion1->id, $discussion2->id, $discussion3->id], false);
|
826 |
$this->assertCount(3, $ids);
|
831 |
$this->assertCount(3, $ids);
|
Línea 827... |
Línea 832... |
827 |
$this->assertEquals($post4->id, $ids[$discussion1->id]->get_id());
|
832 |
$this->assertEquals($post4->id, $ids[$discussion1->id]->get_id());
|
828 |
$this->assertEquals($post6->id, $ids[$discussion2->id]->get_id());
|
833 |
$this->assertEquals($post8->id, $ids[$discussion2->id]->get_id());
|
829 |
$this->assertEquals($post7->id, $ids[$discussion3->id]->get_id());
|
834 |
$this->assertEquals($post9->id, $ids[$discussion3->id]->get_id());
|
830 |
|
835 |
|
831 |
// Checks the user with the private reply to.
|
836 |
// Checks the user with the private reply to.
|
832 |
$ids = $this->vault->get_latest_posts_for_discussion_ids($user, [
|
837 |
$ids = $this->vault->get_latest_posts_for_discussion_ids($user, [
|
833 |
$discussion1->id,
|
838 |
$discussion1->id,
|
834 |
$discussion2->id,
|
839 |
$discussion2->id,
|
835 |
$discussion3->id,
|
840 |
$discussion3->id,
|
836 |
$discussion3->id + 1000
|
841 |
$discussion3->id + 1000
|
837 |
], false);
|
842 |
], false);
|
838 |
$this->assertCount(3, $ids);
|
843 |
$this->assertCount(3, $ids);
|
Línea 839... |
Línea 844... |
839 |
$this->assertEquals($post4->id, $ids[$discussion1->id]->get_id());
|
844 |
$this->assertEquals($post4->id, $ids[$discussion1->id]->get_id());
|
840 |
$this->assertEquals($post6->id, $ids[$discussion2->id]->get_id());
|
845 |
$this->assertEquals($post8->id, $ids[$discussion2->id]->get_id());
|
841 |
$this->assertEquals($post8->id, $ids[$discussion3->id]->get_id());
|
846 |
$this->assertEquals($post10->id, $ids[$discussion3->id]->get_id());
|
Línea 867... |
Línea 872... |
867 |
|
872 |
|
868 |
$datagenerator = $this->getDataGenerator();
|
873 |
$datagenerator = $this->getDataGenerator();
|
869 |
$user = $datagenerator->create_user();
|
874 |
$user = $datagenerator->create_user();
|
870 |
$course = $datagenerator->create_course();
|
875 |
$course = $datagenerator->create_course();
|
- |
|
876 |
$forum = $datagenerator->create_module('forum', ['course' => $course->id]);
|
871 |
$forum = $datagenerator->create_module('forum', ['course' => $course->id]);
|
877 |
$now = time();
|
872 |
[$discussion1, $post1] = $this->helper_post_to_forum($forum, $user);
|
878 |
[$discussion1, $post1] = $this->helper_post_to_forum($forum, $user);
|
873 |
$post2 = $this->helper_reply_to_post($post1, $user);
|
879 |
$post2 = $this->helper_reply_to_post($post1, $user, ['created' => $now + 100]);
|
874 |
$post3 = $this->helper_reply_to_post($post1, $user);
|
880 |
$post3 = $this->helper_reply_to_post($post1, $user, ['created' => $now + 101]);
|
875 |
$post4 = $this->helper_reply_to_post($post2, $user);
|
881 |
$post4 = $this->helper_reply_to_post($post2, $user, ['created' => $now + 102]);
|
876 |
[$discussion2, $post5] = $this->helper_post_to_forum($forum, $user);
|
882 |
[$discussion2, $post5] = $this->helper_post_to_forum($forum, $user);
|
- |
|
883 |
$post6 = $this->helper_reply_to_post($post5, $user);
|
- |
|
884 |
$post7 = $this->helper_reply_to_post($post5, $user);
|
877 |
$post6 = $this->helper_reply_to_post($post5, $user);
|
885 |
$post8 = $this->helper_reply_to_post($post6, $user);
|
Línea 878... |
Línea 886... |
878 |
[$discussion3, $post7] = $this->helper_post_to_forum($forum, $user);
|
886 |
[$discussion3, $post9] = $this->helper_post_to_forum($forum, $user);
|
879 |
|
887 |
|
880 |
$firstposts = $this->vault->get_first_post_for_discussion_ids([$discussion1->id]);
|
888 |
$firstposts = $this->vault->get_first_post_for_discussion_ids([$discussion1->id]);
|
Línea 888... |
Línea 896... |
888 |
|
896 |
|
889 |
$firstposts = $this->vault->get_first_post_for_discussion_ids([$discussion1->id, $discussion2->id, $discussion3->id]);
|
897 |
$firstposts = $this->vault->get_first_post_for_discussion_ids([$discussion1->id, $discussion2->id, $discussion3->id]);
|
890 |
$this->assertCount(3, $firstposts);
|
898 |
$this->assertCount(3, $firstposts);
|
891 |
$this->assertEquals($post1->id, $firstposts[$post1->id]->get_id());
|
899 |
$this->assertEquals($post1->id, $firstposts[$post1->id]->get_id());
|
892 |
$this->assertEquals($post5->id, $firstposts[$post5->id]->get_id());
|
900 |
$this->assertEquals($post5->id, $firstposts[$post5->id]->get_id());
|
Línea 893... |
Línea 901... |
893 |
$this->assertEquals($post7->id, $firstposts[$post7->id]->get_id());
|
901 |
$this->assertEquals($post9->id, $firstposts[$post9->id]->get_id());
|
894 |
|
902 |
|
895 |
$firstposts = $this->vault->get_first_post_for_discussion_ids([
|
903 |
$firstposts = $this->vault->get_first_post_for_discussion_ids([
|
896 |
$discussion1->id,
|
904 |
$discussion1->id,
|
897 |
$discussion2->id,
|
905 |
$discussion2->id,
|
898 |
$discussion3->id,
|
906 |
$discussion3->id,
|
899 |
$discussion3->id + 1000
|
907 |
$discussion3->id + 1000
|
900 |
]);
|
908 |
]);
|
901 |
$this->assertCount(3, $firstposts);
|
909 |
$this->assertCount(3, $firstposts);
|
902 |
$this->assertEquals($post1->id, $firstposts[$post1->id]->get_id());
|
910 |
$this->assertEquals($post1->id, $firstposts[$post1->id]->get_id());
|
903 |
$this->assertEquals($post5->id, $firstposts[$post5->id]->get_id());
|
911 |
$this->assertEquals($post5->id, $firstposts[$post5->id]->get_id());
|
Línea 904... |
Línea 912... |
904 |
$this->assertEquals($post7->id, $firstposts[$post7->id]->get_id());
|
912 |
$this->assertEquals($post9->id, $firstposts[$post9->id]->get_id());
|
905 |
}
|
913 |
}
|
906 |
|
914 |
|