Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

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

   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  use mod_forum\local\entities\discussion as discussion_entity;
  20  use mod_forum\local\entities\forum as forum_entity;
  21  
  22  defined('MOODLE_INTERNAL') || die();
  23  
  24  global $CFG;
  25  require_once($CFG->dirroot . '/rating/lib.php');
  26  
  27  /**
  28   * The forum entity tests.
  29   *
  30   * @package    mod_forum
  31   * @copyright  2019 Ryan Wyllie <ryan@moodle.com>
  32   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  33   */
  34  class entities_forum_test extends \advanced_testcase {
  35      /**
  36       * Test the entity returns expected values.
  37       */
  38      public function test_entity() {
  39          $this->resetAfterTest();
  40  
  41          $time = time() - 10;
  42          $discussion = new discussion_entity(
  43              1,
  44              2,
  45              3,
  46              'test discussion',
  47              4,
  48              5,
  49              6,
  50              false,
  51              $time,
  52              $time,
  53              0,
  54              0,
  55              false,
  56              0
  57          );
  58  
  59          $past = time() - 100;
  60          $course = $this->getDataGenerator()->create_course();
  61          $forum = $this->getDataGenerator()->create_module('forum', ['course' => $course->id]);
  62          $coursemodule = get_coursemodule_from_instance('forum', $forum->id);
  63          $context = \context_module::instance($coursemodule->id);
  64          $effectivegroupmode = NOGROUPS;
  65          $id = 1;
  66          $courseid = 2;
  67          $type = 'standard';
  68          $name = 'test forum';
  69          $intro = 'this is the intro';
  70          $introformat = FORMAT_MOODLE;
  71          $assessed = RATING_AGGREGATE_NONE;
  72          $assesstimestart = 0;
  73          $assesstimefinish = 0;
  74          $scale = 0;
  75          $gradeforum = 0;
  76          $maxbytes = 200;
  77          $maxattachments = 5;
  78          $forcesubscribe = 0;
  79          $trackingtype = 1;
  80          $rsstype = 0;
  81          $rssarticles = 0;
  82          $timemodified = $past;
  83          $warnafter = 0;
  84          $blockafter = 0;
  85          $blockperiod = 0;
  86          $completiondiscussions = 0;
  87          $completionreplies = 0;
  88          $completionposts = 0;
  89          $displaywordcount = false;
  90          $lockdiscussionafter = 0;
  91          $duedate = 0;
  92          $cutoffdate = 0;
  93          $sendnotification = false;
  94          $forum = new forum_entity(
  95              $context,
  96              $coursemodule,
  97              $course,
  98              $effectivegroupmode,
  99              $id,
 100              $courseid,
 101              $type,
 102              $name,
 103              $intro,
 104              $introformat,
 105              $assessed,
 106              $assesstimestart,
 107              $assesstimefinish,
 108              $scale,
 109              $gradeforum,
 110              $sendnotification,
 111              $maxbytes,
 112              $maxattachments,
 113              $forcesubscribe,
 114              $trackingtype,
 115              $rsstype,
 116              $rssarticles,
 117              $timemodified,
 118              $warnafter,
 119              $blockafter,
 120              $blockperiod,
 121              $completiondiscussions,
 122              $completionreplies,
 123              $completionposts,
 124              $displaywordcount,
 125              $lockdiscussionafter,
 126              $duedate,
 127              $cutoffdate
 128          );
 129  
 130          $this->assertEquals($context, $forum->get_context());
 131          $this->assertEquals($coursemodule, $forum->get_course_module_record());
 132          $this->assertEquals($coursemodule, $forum->get_course_module_record());
 133          $this->assertEquals($effectivegroupmode, $forum->get_effective_group_mode());
 134          $this->assertEquals(false, $forum->is_in_group_mode());
 135          $this->assertEquals($course, $forum->get_course_record());
 136          $this->assertEquals($id, $forum->get_id());
 137          $this->assertEquals($courseid, $forum->get_course_id());
 138          $this->assertEquals($name, $forum->get_name());
 139          $this->assertEquals($intro, $forum->get_intro());
 140          $this->assertEquals($introformat, $forum->get_intro_format());
 141          $this->assertEquals($assessed, $forum->get_rating_aggregate());
 142          // Rating aggregate is set to none.
 143          $this->assertEquals(false, $forum->has_rating_aggregate());
 144          $this->assertEquals($assesstimestart, $forum->get_assess_time_start());
 145          $this->assertEquals($assesstimefinish, $forum->get_assess_time_finish());
 146          $this->assertEquals($scale, $forum->get_scale());
 147          $this->assertEquals($gradeforum, $forum->get_grade_for_forum());
 148          $this->assertEquals($maxbytes, $forum->get_max_bytes());
 149          $this->assertEquals($maxattachments, $forum->get_max_attachments());
 150          $this->assertEquals($forcesubscribe, $forum->get_subscription_mode());
 151          $this->assertEquals($trackingtype, $forum->get_tracking_type());
 152          $this->assertEquals($rsstype, $forum->get_rss_type());
 153          $this->assertEquals($rssarticles, $forum->get_rss_articles());
 154          $this->assertEquals($timemodified, $forum->get_time_modified());
 155          $this->assertEquals($warnafter, $forum->get_warn_after());
 156          $this->assertEquals($blockafter, $forum->get_block_after());
 157          $this->assertEquals($blockperiod, $forum->get_block_period());
 158          $this->assertEquals(false, $forum->has_blocking_enabled());
 159          $this->assertEquals($completiondiscussions, $forum->get_completion_discussions());
 160          $this->assertEquals($completionreplies, $forum->get_completion_replies());
 161          $this->assertEquals($completionposts, $forum->get_completion_posts());
 162          $this->assertEquals($displaywordcount, $forum->should_display_word_count());
 163          $this->assertEquals($lockdiscussionafter, $forum->get_lock_discussions_after());
 164          $this->assertEquals(false, $forum->has_lock_discussions_after());
 165          $this->assertEquals(false, $forum->is_discussion_locked($discussion));
 166          $this->assertEquals(false, $forum->has_due_date());
 167          $this->assertEquals(false, $forum->is_due_date_reached());
 168          $this->assertEquals(false, $forum->has_cutoff_date());
 169          $this->assertEquals(false, $forum->is_cutoff_date_reached());
 170      }
 171  }