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\objects;
|
|
|
18 |
|
|
|
19 |
use core\router\schema\specification;
|
|
|
20 |
use core\tests\router\route_testcase;
|
|
|
21 |
|
|
|
22 |
/**
|
|
|
23 |
* Tests for a stacktrace.
|
|
|
24 |
*
|
|
|
25 |
* @package core
|
|
|
26 |
* @copyright 2023 Andrew Lyons <andrew@nicols.co.uk>
|
|
|
27 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
28 |
* @covers \core\router\schema\objects\stacktrace
|
|
|
29 |
* @covers \core\router\schema\objects\type_base
|
|
|
30 |
*/
|
|
|
31 |
final class stacktrace_test extends route_testcase {
|
|
|
32 |
public function test_referenced_object(): void {
|
|
|
33 |
$object = new stacktrace();
|
|
|
34 |
|
|
|
35 |
$schema = $object->get_openapi_description(new specification());
|
|
|
36 |
$this->assertObjectNotHasProperty('$ref', $schema);
|
|
|
37 |
$this->assertObjectHasProperty('type', $schema);
|
|
|
38 |
$this->assertObjectHasProperty('items', $schema);
|
|
|
39 |
$this->assertObjectHasProperty('examples', $schema);
|
|
|
40 |
$this->assertEquals('array', $schema->type);
|
|
|
41 |
|
|
|
42 |
$reference = $object->get_openapi_schema(new specification());
|
|
|
43 |
$this->assertObjectNotHasProperty('type', $reference);
|
|
|
44 |
$this->assertObjectHasProperty('$ref', $reference);
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
public function test_validation(): void {
|
|
|
48 |
$object = new stacktrace();
|
|
|
49 |
|
|
|
50 |
// This should return whatever was input.
|
|
|
51 |
$data = $object->validate_data([
|
|
|
52 |
'example' => 123,
|
|
|
53 |
'other' => 321,
|
|
|
54 |
]);
|
|
|
55 |
|
|
|
56 |
$this->assertCount(2, $data);
|
|
|
57 |
$this->assertEquals([
|
|
|
58 |
'example' => 123,
|
|
|
59 |
'other' => 321,
|
|
|
60 |
], $data);
|
|
|
61 |
}
|
|
|
62 |
}
|