Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 310 and 311] [Versions 39 and 311]

   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  namespace mod_forum;
  18  
  19  defined('MOODLE_INTERNAL') || die();
  20  
  21  global $CFG;
  22  require_once (__DIR__ . '/generator_trait.php');
  23  require_once("{$CFG->dirroot}/mod/forum/rsslib.php");
  24  
  25  /**
  26   * Tests for the forum implementation of the RSS component.
  27   *
  28   * @package    mod_forum
  29   * @copyright  2018 Andrew Nicols <andrew@nicols.co.uk>
  30   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  31   */
  32  class rsslib_test extends \advanced_testcase {
  33      // Include the mod_forum test helpers.
  34      // This includes functions to create forums, users, discussions, and posts.
  35      use \mod_forum_tests_generator_trait;
  36  
  37      /**
  38       * Ensure that deleted posts are not included.
  39       */
  40      public function test_forum_rss_feed_discussions_sql_respect_deleted() {
  41          global $DB;
  42  
  43          $this->resetAfterTest();
  44  
  45          $course = $this->getDataGenerator()->create_course();
  46          $forum = $this->getDataGenerator()->create_module('forum', ['course' => $course->id]);
  47          $cm = get_coursemodule_from_instance('forum', $forum->id);
  48  
  49          list($user, $otheruser) = $this->helper_create_users($course, 2);
  50  
  51          // Post twice.
  52          $this->helper_post_to_forum($forum, $otheruser);
  53          list($discussion, $post) = $this->helper_post_to_forum($forum, $otheruser);
  54  
  55          list($sql, $params) = forum_rss_feed_discussions_sql($forum, $cm);
  56          $discussions = $DB->get_records_sql($sql, $params);
  57          $this->assertCount(2, $discussions);
  58  
  59          $post->deleted = 1;
  60          $DB->update_record('forum_posts', $post);
  61  
  62          list($sql, $params) = forum_rss_feed_discussions_sql($forum, $cm);
  63          $discussions = $DB->get_records_sql($sql, $params);
  64          $this->assertCount(1, $discussions);
  65      }
  66  
  67  
  68      /**
  69       * Ensure that deleted posts are not included.
  70       */
  71      public function test_forum_rss_feed_posts_sql_respect_deleted() {
  72          global $DB;
  73  
  74          $this->resetAfterTest();
  75  
  76          $course = $this->getDataGenerator()->create_course();
  77          $forum = $this->getDataGenerator()->create_module('forum', ['course' => $course->id]);
  78          $cm = get_coursemodule_from_instance('forum', $forum->id);
  79  
  80          list($user, $otheruser) = $this->helper_create_users($course, 2);
  81  
  82          // Post twice.
  83          $this->helper_post_to_forum($forum, $otheruser);
  84          list($discussion, $post) = $this->helper_post_to_forum($forum, $otheruser);
  85  
  86          list($sql, $params) = forum_rss_feed_posts_sql($forum, $cm);
  87          $posts = $DB->get_records_sql($sql, $params);
  88          $this->assertCount(2, $posts);
  89  
  90          $post->deleted = 1;
  91          $DB->update_record('forum_posts', $post);
  92  
  93          list($sql, $params) = forum_rss_feed_posts_sql($forum, $cm);
  94          $posts = $DB->get_records_sql($sql, $params);
  95          $this->assertCount(1, $posts);
  96      }
  97  }