Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

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