Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1441 ariadna 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 core\router\schema;
18
use core\tests\router\route_testcase;
19
 
20
/**
21
 * Tests for examples.
22
 *
23
 * @package    core
24
 * @copyright  Andrew Lyons <andrew@nicols.co.uk>
25
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26
 * @covers     \core\router\schema\example
27
 * @covers     \core\router\schema\openapi_base
28
 */
29
final class example_test extends route_testcase {
30
    public function test_value(): void {
31
        $example = new example(
32
            name: 'First example',
33
            value: 'This is a value',
34
        );
35
        $schema = $example->get_openapi_schema(new specification());
36
        $this->assertEquals(
37
            'This is a value',
38
            $schema->value,
39
        );
40
        $this->assertObjectNotHasProperty('externalValue', $schema);
41
    }
42
 
43
    public function test_externalvalue(): void {
44
        $example = new example(
45
            name: 'First example',
46
            externalvalue: 'https://example.com/example/value'
47
        );
48
        $schema = $example->get_openapi_schema(new specification());
49
        $this->assertObjectNotHasProperty('value', $schema);
50
        $this->assertEquals(
51
            'https://example.com/example/value',
52
            $schema->externalValue,
53
        );
54
    }
55
 
56
    public function test_value_or_externalvalue(): void {
57
        $this->expectException(\coding_exception::class);
58
        new example(
59
            name: 'First example',
60
            value: 'This is a value',
61
            externalvalue: 'This is an external value',
62
        );
63
    }
64
 
65
    public function test_basics(): void {
66
        $example = new example(
67
            name: 'First example',
68
            summary: 'This is a summary',
69
            description: 'This is a description',
70
            value: 'This is a value',
71
        );
72
 
73
        $schema = $example->get_openapi_schema(new specification());
74
 
75
        $this->assertEquals('First example', $example->get_name());
76
        $this->assertEquals('This is a summary', $schema->summary);
77
        $this->assertEquals('This is a description', $schema->description);
78
    }
79
 
80
    public function test_referenced_object(): void {
81
        $object = new class (
82
            name: 'example',
83
            value: 'Some value',
84
        ) extends example implements referenced_object {
85
        };
86
 
87
        $schema = $object->get_openapi_description(new specification());
88
        $this->assertObjectNotHasProperty('$ref', $schema);
89
        $this->assertObjectHasProperty('value', $schema);
90
 
91
        $reference = $object->get_openapi_schema(new specification());
92
        $this->assertObjectNotHasProperty('value', $reference);
93
        $this->assertObjectHasProperty('$ref', $reference);
94
    }
95
}