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  /**
  20   * The author vault tests.
  21   *
  22   * @package    mod_forum
  23   * @copyright  2019 Ryan Wyllie <ryan@moodle.com>
  24   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  25   */
  26  class vaults_author_test extends \advanced_testcase {
  27      /**
  28       * Test get_from_id.
  29       */
  30      public function test_get_from_id() {
  31          $this->resetAfterTest();
  32  
  33          $user = $this->getDataGenerator()->create_user();
  34          $vaultfactory = \mod_forum\local\container::get_vault_factory();
  35          $authorvault = $vaultfactory->get_author_vault();
  36  
  37          $author = $authorvault->get_from_id($user->id);
  38  
  39          $this->assertEquals($user->id, $author->get_id());
  40      }
  41  
  42      /**
  43       * Test get_context_ids_for_author_ids.
  44       */
  45      public function test_get_context_ids_for_author_ids() {
  46          $this->resetAfterTest();
  47  
  48          $user1 = $this->getDataGenerator()->create_user();
  49          $user2 = $this->getDataGenerator()->create_user();
  50          $user3 = $this->getDataGenerator()->create_user();
  51          $userid1 = $user1->id;
  52          $userid2 = $user2->id;
  53          $userid3 = $user3->id;
  54          $fakeuserid = $user3->id + 1000;
  55          $vaultfactory = \mod_forum\local\container::get_vault_factory();
  56          $authorvault = $vaultfactory->get_author_vault();
  57          $user1context = \context_user::instance($user1->id);
  58          $user2context = \context_user::instance($user2->id);
  59          $user3context = \context_user::instance($user3->id);
  60          $user1contextid = $user1context->id;
  61          $user2contextid = $user2context->id;
  62          $user3contextid = $user3context->id;
  63          $fakeusercontextid = null;
  64          $userids = [$userid1, $userid2, $userid3, $fakeuserid];
  65  
  66          $expected = [
  67              $userid1 => $user1contextid,
  68              $userid2 => $user2contextid,
  69              $userid3 => $user3contextid,
  70              $fakeuserid => $fakeusercontextid
  71          ];
  72  
  73          $this->assertEquals($expected, $authorvault->get_context_ids_for_author_ids($userids));
  74      }
  75  }