Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 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
/**
18
 * Unit tests for get_entity_generator web service
19
 *
20
 * @package   tool_behat
21
 * @copyright 2022 onwards Catalyst IT EU {@link https://catalyst-eu.net}
22
 * @author    Mark Johnson <mark.johnson@catalyst-eu.net>
23
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24
 */
25
 
26
namespace tool_behat\external;
27
 
28
/**
29
 * Tests for get_entity_generator web service
30
 *
31
 * @covers \tool_behat\external\get_entity_generator
32
 */
1441 ariadna 33
final class get_entity_generator_test extends \advanced_testcase {
1 efrain 34
 
35
    /**
36
     * Log in as admin
37
     *
38
     * @return void
39
     */
40
    public function setUp(): void {
1441 ariadna 41
        parent::setUp();
1 efrain 42
        $this->resetAfterTest();
43
        $this->setAdminUser();
44
    }
45
 
46
    /**
47
     * Get the generator for a core entity.
48
     *
49
     * @return void
50
     */
51
    public function test_execute_core_entity(): void {
52
        $generator = get_entity_generator::execute('users');
53
        $this->assertEquals(['required' => ['username']], $generator);
54
    }
55
 
56
    /**
57
     * Get the generator for the plugin entity.
58
     *
59
     * @return void
60
     */
61
    public function test_execute_plugin_entity(): void {
62
        $generator = get_entity_generator::execute('mod_book > chapters');
63
        $this->assertEquals(['required' => ['book', 'title', 'content']], $generator);
64
    }
65
 
66
    /**
67
     * Get the generator for an entity with no required fields.
68
     *
69
     * @return void
70
     */
71
    public function test_execute_no_requried(): void {
72
        $generator = get_entity_generator::execute('mod_forum > posts');
73
        $this->assertEquals(['required' => []], $generator);
74
    }
75
 
76
    /**
77
     * Attempt to get the generator for a core entity that does not exist.
78
     *
79
     * @return void
80
     */
81
    public function test_execute_invalid_entity(): void {
82
        $this->expectException('coding_exception');
83
        get_entity_generator::execute('foo');
84
    }
85
 
86
    /**
87
     * Attempt to get a generator form a plugin that does not exist.
88
     *
89
     * @return void
90
     */
91
    public function test_execute_invalid_plugin(): void {
92
        $this->expectException('coding_exception');
93
        get_entity_generator::execute('foo > bar');
94
    }
95
 
96
    /**
97
     * Attempt to get a generator for an entity that does not exist, from a plugin that does.
98
     *
99
     * @return void
100
     */
101
    public function test_execute_invalid_plugin_entity(): void {
102
        $this->expectException('coding_exception');
103
        get_entity_generator::execute('mod_book > bar');
104
    }
105
}