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\response;
18
 
19
use core\tests\router\route_testcase;
20
use GuzzleHttp\Psr7\ServerRequest;
21
 
22
/**
23
 * Tests for the view_response response type.
24
 *
25
 * @package    core
26
 * @copyright  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\response\view_response
29
 */
30
final class view_response_test extends route_testcase {
31
    public function test_defaults(): void {
32
        $response = new response();
33
 
34
        // The default status code is 200.
35
        $this->assertSame(200, $response->get_status_code());
36
    }
37
 
38
    public function test_get_response(): void {
39
        global $OUTPUT;
40
 
41
        $request = new ServerRequest('GET', 'http://example.com');
42
 
43
        $response = new view_response(
44
            template: 'core/welcome',
45
            parameters: [
46
                'welcomemessage' => 'Hello, everybody!',
47
            ],
48
            request: $request,
49
        );
50
 
51
        $this->assertEquals('core/welcome', $response->get_template_name());
52
        $this->assertEquals(
53
            ['welcomemessage' => 'Hello, everybody!'],
54
            $response->get_parameters(),
55
        );
56
 
57
        $this->assertEquals($request, $response->get_request());
58
        $this->assertEquals(
59
            $OUTPUT->render_from_template('core/welcome', ['welcomemessage' => 'Hello, everybody!']),
60
            $response->get_response($this->get_router()->get_response_factory())->getBody(),
61
        );
62
    }
63
}