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_read_receipt_collection as collection_entity;
  20  use mod_forum\local\entities\post as post_entity;
  21  
  22  /**
  23   * The post_read_receipt_collection entity tests.
  24   *
  25   * @package    mod_forum
  26   * @copyright  2019 Ryan Wyllie <ryan@moodle.com>
  27   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  28   */
  29  class entities_post_read_receipt_collection_test extends \advanced_testcase {
  30      /**
  31       * Test the entity returns expected values.
  32       */
  33      public function test_entity() {
  34          $this->resetAfterTest();
  35  
  36          $user = $this->getDataGenerator()->create_user();
  37          $missingpost = new post_entity(
  38              4,
  39              1,
  40              0,
  41              1,
  42              time(),
  43              time(),
  44              true,
  45              'post subject',
  46              'post message',
  47              1,
  48              true,
  49              false,
  50              0,
  51              false,
  52              false,
  53              false,
  54              null,
  55              null
  56          );
  57          $post = new post_entity(
  58              1,
  59              1,
  60              0,
  61              1,
  62              time(),
  63              time(),
  64              true,
  65              'post subject',
  66              'post message',
  67              1,
  68              true,
  69              false,
  70              0,
  71              false,
  72              false,
  73              false,
  74              null,
  75              null
  76          );
  77          $collection = new collection_entity([
  78              (object) [
  79                  'postid' => 1,
  80                  'userid' => $user->id + 1
  81              ],
  82              (object) [
  83                  'postid' => 1,
  84                  'userid' => $user->id
  85              ],
  86              (object) [
  87                  'postid' => 4,
  88                  'userid' => $user->id + 1
  89              ]
  90          ]);
  91  
  92          $this->assertEquals(true, $collection->has_user_read_post($user, $post));
  93          $this->assertEquals(false, $collection->has_user_read_post($user, $missingpost));
  94      }
  95  }