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.
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.

/**
 * External function test for prepare_entry.
 *
 * @package    mod_glossary
 * @category   external
 * @since      Moodle 3.10
 * @copyright  2020 Juan Leyva <juan@moodle.com>
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */

namespace mod_glossary\external;

defined('MOODLE_INTERNAL') || die();

global $CFG;
require_once($CFG->dirroot . '/webservice/tests/helpers.php');

< use external_api;
> use core_external\external_api;
use externallib_advanced_testcase;
< use mod_glossary_external; < use context_module; < use context_user; < use external_util;
/** * External function test for prepare_entry. * * @package mod_glossary * @copyright 2020 Juan Leyva <juan@moodle.com> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class prepare_entry_testcase extends externallib_advanced_testcase { /** * test_prepare_entry */ public function test_prepare_entry() { global $USER; $this->resetAfterTest(true); $course = $this->getDataGenerator()->create_course(); $glossary = $this->getDataGenerator()->create_module('glossary', ['course' => $course->id]); $gg = $this->getDataGenerator()->get_plugin_generator('mod_glossary'); $this->setAdminUser(); $aliases = ['alias1', 'alias2']; $entry = $gg->create_content( $glossary, ['approved' => 1, 'userid' => $USER->id], $aliases ); $cat1 = $gg->create_category($glossary, [], [$entry]); $gg->create_category($glossary); $return = prepare_entry::execute($entry->id); $return = external_api::clean_returnvalue(prepare_entry::execute_returns(), $return); $this->assertNotEmpty($return['inlineattachmentsid']); $this->assertNotEmpty($return['attachmentsid']); $this->assertEquals($aliases, $return['aliases']); $this->assertEquals([$cat1->id], $return['categories']); $this->assertCount(2, $return['areas']); $this->assertNotEmpty($return['areas'][0]['options']); $this->assertNotEmpty($return['areas'][1]['options']); } }