Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

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

   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\post as post_entity;
  20  
  21  /**
  22   * The post entity tests.
  23   *
  24   * @package    mod_forum
  25   * @copyright  2019 Ryan Wyllie <ryan@moodle.com>
  26   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  27   */
  28  class entities_post_test extends \advanced_testcase {
  29      /**
  30       * Test the entity returns expected values.
  31       */
  32      public function test_entity() {
  33          $this->resetAfterTest();
  34  
  35          $owner = $this->getDataGenerator()->create_user();
  36          $notowner = $this->getDataGenerator()->create_user();
  37          $past = time() - 10;
  38          $post = new post_entity(
  39              4,
  40              1,
  41              0,
  42              $owner->id,
  43              $past,
  44              $past,
  45              true,
  46              'post subject',
  47              'post message',
  48              FORMAT_MOODLE,
  49              true,
  50              false,
  51              0,
  52              false,
  53              false,
  54              false,
  55              null,
  56              null
  57          );
  58  
  59          $this->assertEquals(4, $post->get_id());
  60          $this->assertEquals(1, $post->get_discussion_id());
  61          $this->assertEquals(0, $post->get_parent_id());
  62          $this->assertEquals(false, $post->has_parent());
  63          $this->assertEquals($owner->id, $post->get_author_id());
  64          $this->assertEquals($past, $post->get_time_created());
  65          $this->assertEquals($past, $post->get_time_modified());
  66          $this->assertEquals(true, $post->has_been_mailed());
  67          $this->assertEquals('post subject', $post->get_subject());
  68          $this->assertEquals('post message', $post->get_message());
  69          $this->assertEquals(FORMAT_MOODLE, $post->get_message_format());
  70          $this->assertEquals(true, $post->is_message_trusted());
  71          $this->assertEquals(false, $post->has_attachments());
  72          $this->assertEquals(0, $post->get_total_score());
  73          $this->assertEquals(false, $post->should_mail_now());
  74          $this->assertEquals(false, $post->is_deleted());
  75          $this->assertTrue($post->get_age() >= 10);
  76          $this->assertEquals(true, $post->is_owned_by_user($owner));
  77          $this->assertEquals(false, $post->is_owned_by_user($notowner));
  78      }
  79  }