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