Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

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