See Release Notes
Long Term Support Release
Differences Between: [Versions 401 and 402] [Versions 401 and 403]
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 mod_lti\external; 18 19 defined('MOODLE_INTERNAL') || die(); 20 21 global $CFG; 22 23 require_once($CFG->dirroot . '/mod/lti/tests/mod_lti_testcase.php'); 24 25 /** 26 * PHPUnit tests for get_tool_types_and_proxies external function. 27 * 28 * @package mod_lti 29 * @author Andrew Madden <andrewmadden@catalyst-au.net> 30 * @copyright 2021 Catalyst IT 31 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 32 */ 33 class get_tool_types_and_proxies_test extends \mod_lti_testcase { 34 35 /** 36 * This method runs before every test. 37 */ 38 public function setUp(): void { 39 $this->resetAfterTest(); 40 $this->setAdminUser(); 41 } 42 43 /** 44 * Test get_tool_types_and_proxies. 45 */ 46 public function test_mod_lti_get_tool_types_and_proxies() { 47 $proxy = $this->generate_tool_proxy(1); 48 $this->generate_tool_type(1, $proxy->id); 49 50 $data = get_tool_types_and_proxies::execute(0, false, 50, 0); 51 $data = \external_api::clean_returnvalue(get_tool_types_and_proxies::execute_returns(), $data); 52 53 $this->assertCount(1, $data['types']); 54 $type = $data['types'][0]; 55 $this->assertEquals('Test tool 1', $type['name']); 56 $this->assertEquals('Example description 1', $type['description']); 57 $this->assertCount(1, $data['proxies']); 58 $proxy = $data['proxies'][0]; 59 $this->assertEquals('Test proxy 1', $proxy['name']); 60 $this->assertEquals(50, $data['limit']); 61 $this->assertEquals(0, $data['offset']); 62 } 63 64 /** 65 * Test get_tool_types_and_proxies with multiple pages of tool types. 66 */ 67 public function test_mod_lti_get_tool_types_and_proxies_with_multiple_pages() { 68 for ($i = 0; $i < 3; $i++) { 69 $proxy = $this->generate_tool_proxy($i); 70 $this->generate_tool_type($i, $proxy->id); 71 } 72 73 $data = get_tool_types_and_proxies::execute(0, false, 5, 0); 74 $data = \external_api::clean_returnvalue(get_tool_types_and_proxies::execute_returns(), $data); 75 76 $this->assertCount(2, $data['types']); 77 $this->assertCount(3, $data['proxies']); 78 $this->assertEquals(5, $data['limit']); 79 $this->assertEquals(0, $data['offset']); 80 } 81 82 /** 83 * Test get_tool_types_and_proxies with multiple pages of tool types and offset. 84 */ 85 public function test_mod_lti_get_tool_types_and_proxies_with_multiple_pages_last_page() { 86 for ($i = 0; $i < 6; $i++) { 87 $proxy = $this->generate_tool_proxy($i); 88 $this->generate_tool_type($i, $proxy->id); 89 } 90 91 $data = get_tool_types_and_proxies::execute(0, false, 5, 10); 92 $data = \external_api::clean_returnvalue(get_tool_types_and_proxies::execute_returns(), $data); 93 94 $this->assertCount(2, $data['types']); 95 $this->assertCount(0, $data['proxies']); 96 $this->assertEquals(5, $data['limit']); 97 $this->assertEquals(10, $data['offset']); 98 } 99 100 /** 101 * Test get_tool_types_and_proxies without pagination. 102 */ 103 public function test_mod_lti_get_tool_types_and_proxies_without_pagination() { 104 for ($i = 0; $i < 10; $i++) { 105 $proxy = $this->generate_tool_proxy($i); 106 $this->generate_tool_type($i, $proxy->id); 107 } 108 109 $data = get_tool_types_and_proxies::execute(0, false, 0, 0); 110 $data = \external_api::clean_returnvalue(get_tool_types_and_proxies::execute_returns(), $data); 111 112 $this->assertCount(10, $data['types']); 113 $this->assertCount(10, $data['proxies']); 114 } 115 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body