Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 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 310 and 311] [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 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 discussion_summary 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  use mod_forum\local\entities\author as author_entity;
  28  use mod_forum\local\entities\discussion as discussion_entity;
  29  use mod_forum\local\entities\discussion_summary as discussion_summary_entity;
  30  use mod_forum\local\entities\post as post_entity;
  31  
  32  /**
  33   * The discussion_summary entity tests.
  34   *
  35   * @package    mod_forum
  36   * @copyright  2019 Ryan Wyllie <ryan@moodle.com>
  37   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  38   */
  39  class mod_forum_entities_discussion_summary_testcase extends advanced_testcase {
  40      /**
  41       * Test the entity returns expected values.
  42       */
  43      public function test_entity() {
  44          $this->resetAfterTest();
  45  
  46          $firstauthor = new author_entity(
  47              1,
  48              2,
  49              'test',
  50              'person',
  51              'test person',
  52              'test@example.com',
  53              false
  54          );
  55          $lastauthor = new author_entity(
  56              2,
  57              3,
  58              'test 2',
  59              'person 2',
  60              'test 2 person 2',
  61              'test2@example.com',
  62              false
  63          );
  64          $discussion = new discussion_entity(
  65              1,
  66              1,
  67              1,
  68              'test discussion',
  69              1,
  70              1,
  71              0,
  72              false,
  73              time(),
  74              time(),
  75              0,
  76              0,
  77              false,
  78              0
  79          );
  80          $firstpost = new post_entity(
  81              1,
  82              1,
  83              0,
  84              1,
  85              time(),
  86              time(),
  87              true,
  88              'post subject',
  89              'post message',
  90              1,
  91              true,
  92              false,
  93              0,
  94              false,
  95              false,
  96              false,
  97              null,
  98              null
  99          );
 100  
 101          $discussionsummary = new discussion_summary_entity($discussion, $firstpost, $firstauthor, $lastauthor);
 102  
 103          $this->assertEquals($discussion, $discussionsummary->get_discussion());
 104          $this->assertEquals($firstauthor, $discussionsummary->get_first_post_author());
 105          $this->assertEquals($lastauthor, $discussionsummary->get_latest_post_author());
 106          $this->assertEquals($firstpost, $discussionsummary->get_first_post());
 107      }
 108  }