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\response;
18
 
19
use core\router\schema\response\payload_response;
20
use core\router\schema\specification;
21
use core\tests\router\route_testcase;
22
use GuzzleHttp\Psr7\ServerRequest;
23
use invalid_parameter_exception;
24
 
25
/**
26
 * Tests for the path parameter.
27
 *
28
 * @package    core
29
 * @copyright  Andrew Lyons <andrew@nicols.co.uk>
30
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
31
 * @covers     \core\router\response\exception_response
32
 * @covers     \core\router\response\invalid_parameter_response
33
 */
34
final class invalid_parameter_response_test extends route_testcase {
35
    public function test_basics(): void {
36
        $this->assertIsInt(invalid_parameter_response::get_exception_status_code());
37
        $this->assertEquals(400, invalid_parameter_response::get_exception_status_code());
38
    }
39
 
40
    public function test_get_response(): void {
41
        $exception = new invalid_parameter_exception('Someone made a booboo');
42
        $request = new ServerRequest('GET', '/example');
43
 
44
        $payload = invalid_parameter_response::get_response($request, $exception);
45
        $this->assertInstanceOf(payload_response::class, $payload);
46
 
47
        $response = $payload->get_response($this->get_router()->get_response_factory());
48
        $this->assertInstanceOf(\Psr\Http\Message\ResponseInterface::class, $response);
49
        $this->assertEquals(400, $response->getStatusCode());
50
 
51
        $this->assertStringContainsString(
52
            'Someone made a booboo',
53
            (string) $response->getBody(),
54
        );
55
    }
56
 
57
    public function test_openapi_description(): void {
58
        $response = new invalid_parameter_response();
59
        $openapi = $response->get_openapi_description(new specification());
60
 
61
        // The OpenAPI description should be present.
62
        // Note: We do not need to test the value of it. Doing so just reduces maintainability.
63
        $this->assertIsString($openapi->description);
64
    }
65
}