See Release Notes
Long Term Support Release
Differences Between: [Versions 39 and 311] [Versions 39 and 400] [Versions 39 and 401] [Versions 39 and 402] [Versions 39 and 403]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * Tests for the forum implementation of the RSS component. 19 * 20 * @package mod_forum 21 * @copyright 2018 Andrew Nicols <andrew@nicols.co.uk> 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 defined('MOODLE_INTERNAL') || die(); 26 27 global $CFG; 28 require_once (__DIR__ . '/generator_trait.php'); 29 require_once("{$CFG->dirroot}/mod/forum/rsslib.php"); 30 31 /** 32 * Tests for the forum implementation of the RSS component. 33 * 34 * @copyright 2018 Andrew Nicols <andrew@nicols.co.uk> 35 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 36 */ 37 class mod_forum_rsslib_testcase extends advanced_testcase { 38 // Include the mod_forum test helpers. 39 // This includes functions to create forums, users, discussions, and posts. 40 use mod_forum_tests_generator_trait; 41 42 /** 43 * Ensure that deleted posts are not included. 44 */ 45 public function test_forum_rss_feed_discussions_sql_respect_deleted() { 46 global $DB; 47 48 $this->resetAfterTest(); 49 50 $course = $this->getDataGenerator()->create_course(); 51 $forum = $this->getDataGenerator()->create_module('forum', ['course' => $course->id]); 52 $cm = get_coursemodule_from_instance('forum', $forum->id); 53 54 list($user, $otheruser) = $this->helper_create_users($course, 2); 55 56 // Post twice. 57 $this->helper_post_to_forum($forum, $otheruser); 58 list($discussion, $post) = $this->helper_post_to_forum($forum, $otheruser); 59 60 list($sql, $params) = forum_rss_feed_discussions_sql($forum, $cm); 61 $discussions = $DB->get_records_sql($sql, $params); 62 $this->assertCount(2, $discussions); 63 64 $post->deleted = 1; 65 $DB->update_record('forum_posts', $post); 66 67 list($sql, $params) = forum_rss_feed_discussions_sql($forum, $cm); 68 $discussions = $DB->get_records_sql($sql, $params); 69 $this->assertCount(1, $discussions); 70 } 71 72 73 /** 74 * Ensure that deleted posts are not included. 75 */ 76 public function test_forum_rss_feed_posts_sql_respect_deleted() { 77 global $DB; 78 79 $this->resetAfterTest(); 80 81 $course = $this->getDataGenerator()->create_course(); 82 $forum = $this->getDataGenerator()->create_module('forum', ['course' => $course->id]); 83 $cm = get_coursemodule_from_instance('forum', $forum->id); 84 85 list($user, $otheruser) = $this->helper_create_users($course, 2); 86 87 // Post twice. 88 $this->helper_post_to_forum($forum, $otheruser); 89 list($discussion, $post) = $this->helper_post_to_forum($forum, $otheruser); 90 91 list($sql, $params) = forum_rss_feed_posts_sql($forum, $cm); 92 $posts = $DB->get_records_sql($sql, $params); 93 $this->assertCount(2, $posts); 94 95 $post->deleted = 1; 96 $DB->update_record('forum_posts', $post); 97 98 list($sql, $params) = forum_rss_feed_posts_sql($forum, $cm); 99 $posts = $DB->get_records_sql($sql, $params); 100 $this->assertCount(1, $posts); 101 } 102 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body