Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 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 310 and 311] [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 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 discussion forum 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\forum as forum_entity;
  28  use mod_forum\local\exporters\forum as forum_exporter;
  29  
  30  /**
  31   * The discussion forum 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_exporters_forum_testcase extends advanced_testcase {
  38      /**
  39       * Test the export function returns expected values.
  40       */
  41      public function test_export() {
  42          global $PAGE;
  43          $this->resetAfterTest();
  44  
  45          $renderer = $PAGE->get_renderer('core');
  46          $datagenerator = $this->getDataGenerator();
  47          $user = $datagenerator->create_user();
  48          $course = $datagenerator->create_course();
  49          $forum = $datagenerator->create_module('forum', [
  50              'course' => $course->id,
  51              'groupmode' => VISIBLEGROUPS
  52          ]);
  53          $coursemodule = get_coursemodule_from_instance('forum', $forum->id);
  54          $context = context_module::instance($coursemodule->id);
  55          $entityfactory = \mod_forum\local\container::get_entity_factory();
  56          $forum = $entityfactory->get_forum_from_stdclass($forum, $context, $coursemodule, $course);
  57  
  58          $exporter = new forum_exporter($forum, [
  59              'legacydatamapperfactory' => \mod_forum\local\container::get_legacy_data_mapper_factory(),
  60              'urlfactory' => \mod_forum\local\container::get_url_factory(),
  61              'capabilitymanager' => (\mod_forum\local\container::get_manager_factory())->get_capability_manager($forum),
  62              'user' => $user,
  63              'currentgroup' => null,
  64              'vaultfactory' => \mod_forum\local\container::get_vault_factory()
  65          ]);
  66  
  67          $exportedforum = $exporter->export($renderer);
  68  
  69          $this->assertEquals($forum->get_id(), $exportedforum->id);
  70          $this->assertEquals(VISIBLEGROUPS, $exportedforum->state['groupmode']);
  71          $this->assertEquals(false, $exportedforum->userstate['tracked']);
  72          $this->assertEquals(false, $exportedforum->capabilities['viewdiscussions']);
  73          $this->assertEquals(false, $exportedforum->capabilities['create']);
  74          $this->assertEquals(false, $exportedforum->capabilities['subscribe']);
  75          $this->assertNotEquals(null, $exportedforum->urls['create']);
  76          $this->assertNotEquals(null, $exportedforum->urls['markasread']);
  77      }
  78  }