See Release Notes
Long Term Support Release
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 enrol_lti\local\ltiadvantage\lib; 18 19 /** 20 * Tests for the http_response class. 21 * 22 * @package enrol_lti 23 * @copyright 2022 Jake Dallimore <jrhdallimore@gmail.com> 24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 25 * @coversDefaultClass \enrol_lti\local\ltiadvantage\lib\http_response 26 */ 27 class http_response_test extends \basic_testcase { 28 29 /** 30 * Test constructor and getters for a range of inputs. 31 * 32 * @dataProvider response_data_provider 33 * @param array $payload the array of header and body payload data. 34 * @param int $status the int status of the http response. 35 * @covers ::__construct 36 */ 37 public function test_response(array $payload, int $status) { 38 $response = new http_response($payload, $status); 39 $this->assertEquals($payload['headers'], $response->getHeaders()); 40 $this->assertEquals($payload['body'], $response->getBody()); 41 $this->assertEquals($status, $response->getStatusCode()); 42 } 43 44 /** 45 * Data provider for testing http_response instances. 46 * 47 * @return array the test case data. 48 */ 49 public function response_data_provider() { 50 return [ 51 'valid headers and body' => [ 52 'payload' => [ 53 'headers' => ['Content-Type' => 'application/json'], 54 'body' => '{"something": true}' 55 ], 56 'httpstatus' => 200 57 ], 58 'valid headers with empty body' => [ 59 'payload' => [ 60 'headers' => ['Content-Type' => 'application/json'], 61 'body' => '' 62 ], 63 'httpstatus' => 200 64 ], 65 'valid, no headers or body' => [ 66 'payload' => [ 67 'headers' => [], 68 'body' => '' 69 ], 70 'httpstatus' => 200 71 ], 72 'valid headers, empty body, non-200 response status' => [ 73 'payload' => [ 74 'headers' => ['httpstatus' => 'HTTP/1.1 401 Unauthorised: message ', 'Content-Type' => 'application/json'], 75 'body' => '' 76 ], 77 'httpstatus' => 401 78 ] 79 ]; 80 } 81 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body