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  use mod_forum\local\entities\author as author_entity;
  20  use mod_forum\local\entities\discussion as discussion_entity;
  21  use mod_forum\local\entities\discussion_summary as discussion_summary_entity;
  22  use mod_forum\local\entities\post as post_entity;
  23  
  24  /**
  25   * The discussion_summary entity tests.
  26   *
  27   * @package    mod_forum
  28   * @copyright  2019 Ryan Wyllie <ryan@moodle.com>
  29   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  30   */
  31  class entities_discussion_summary_test extends \advanced_testcase {
  32      /**
  33       * Test the entity returns expected values.
  34       */
  35      public function test_entity() {
  36          $this->resetAfterTest();
  37  
  38          $firstauthor = new author_entity(
  39              1,
  40              2,
  41              'test',
  42              'person',
  43              'test person',
  44              'test@example.com',
  45              false
  46          );
  47          $lastauthor = new author_entity(
  48              2,
  49              3,
  50              'test 2',
  51              'person 2',
  52              'test 2 person 2',
  53              'test2@example.com',
  54              false
  55          );
  56          $discussion = new discussion_entity(
  57              1,
  58              1,
  59              1,
  60              'test discussion',
  61              1,
  62              1,
  63              0,
  64              false,
  65              time(),
  66              time(),
  67              0,
  68              0,
  69              false,
  70              0
  71          );
  72          $firstpost = new post_entity(
  73              1,
  74              1,
  75              0,
  76              1,
  77              time(),
  78              time(),
  79              true,
  80              'post subject',
  81              'post message',
  82              1,
  83              true,
  84              false,
  85              0,
  86              false,
  87              false,
  88              false,
  89              null,
  90              null
  91          );
  92  
  93          $discussionsummary = new discussion_summary_entity($discussion, $firstpost, $firstauthor, $lastauthor);
  94  
  95          $this->assertEquals($discussion, $discussionsummary->get_discussion());
  96          $this->assertEquals($firstauthor, $discussionsummary->get_first_post_author());
  97          $this->assertEquals($lastauthor, $discussionsummary->get_latest_post_author());
  98          $this->assertEquals($firstpost, $discussionsummary->get_first_post());
  99      }
 100  }