Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.

Differences Between: [Versions 310 and 402] [Versions 311 and 402] [Versions 400 and 402] [Versions 401 and 402]

   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   * External function test for prepare_entry.
  19   *
  20   * @package    mod_glossary
  21   * @category   external
  22   * @since      Moodle 3.10
  23   * @copyright  2020 Juan Leyva <juan@moodle.com>
  24   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  25   */
  26  
  27  namespace mod_glossary\external;
  28  
  29  defined('MOODLE_INTERNAL') || die();
  30  
  31  global $CFG;
  32  require_once($CFG->dirroot . '/webservice/tests/helpers.php');
  33  
  34  use core_external\external_api;
  35  use externallib_advanced_testcase;
  36  
  37  /**
  38   * External function test for prepare_entry.
  39   *
  40   * @package    mod_glossary
  41   * @copyright  2020 Juan Leyva <juan@moodle.com>
  42   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  43   */
  44  class prepare_entry_testcase extends externallib_advanced_testcase {
  45  
  46      /**
  47       * test_prepare_entry
  48       */
  49      public function test_prepare_entry() {
  50          global $USER;
  51          $this->resetAfterTest(true);
  52  
  53          $course = $this->getDataGenerator()->create_course();
  54          $glossary = $this->getDataGenerator()->create_module('glossary', ['course' => $course->id]);
  55          $gg = $this->getDataGenerator()->get_plugin_generator('mod_glossary');
  56  
  57          $this->setAdminUser();
  58          $aliases = ['alias1', 'alias2'];
  59          $entry = $gg->create_content(
  60              $glossary,
  61              ['approved' => 1, 'userid' => $USER->id],
  62              $aliases
  63          );
  64  
  65          $cat1 = $gg->create_category($glossary, [], [$entry]);
  66          $gg->create_category($glossary);
  67  
  68          $return = prepare_entry::execute($entry->id);
  69          $return = external_api::clean_returnvalue(prepare_entry::execute_returns(), $return);
  70  
  71          $this->assertNotEmpty($return['inlineattachmentsid']);
  72          $this->assertNotEmpty($return['attachmentsid']);
  73          $this->assertEquals($aliases, $return['aliases']);
  74          $this->assertEquals([$cat1->id], $return['categories']);
  75          $this->assertCount(2, $return['areas']);
  76          $this->assertNotEmpty($return['areas'][0]['options']);
  77          $this->assertNotEmpty($return['areas'][1]['options']);
  78      }
  79  }