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_external; 18 19 /** 20 * Unit tests for core_external\external_settings. 21 * 22 * @package core_external 23 * @category test 24 * @copyright 2022 Andrew Lyons <andrew@nicols.co.uk> 25 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License 26 * @covers \core_external\external_settings 27 */ 28 class external_settings_test extends \advanced_testcase { 29 /** 30 * Reset the singleton between tests. 31 */ 32 public function tearDown(): void { 33 external_settings::reset(); 34 } 35 36 /** 37 * Tests for external_settings class. 38 * 39 * @covers \core_external\external_settings::get_instance 40 */ 41 public function test_external_settings(): void { 42 $settings = external_settings::get_instance(); 43 $this->assertInstanceOf(external_settings::class, $settings); 44 } 45 46 /** 47 * Check external_settings defaults. 48 * 49 * @covers \core_external\external_settings::get_instance 50 */ 51 public function test_external_settings_defaults(): void { 52 $settings = external_settings::get_instance(); 53 $currentraw = $settings->get_raw(); 54 $currentfilter = $settings->get_filter(); 55 $currentfile = $settings->get_file(); 56 $currentfileurl = $settings->get_fileurl(); 57 $this->assertInstanceOf(external_settings::class, $settings); 58 59 // Check apis. 60 $settings->set_file('plugin.php'); 61 $this->assertEquals('plugin.php', $settings->get_file()); 62 $settings->set_filter(false); 63 $this->assertFalse($settings->get_filter()); 64 $settings->set_fileurl(false); 65 $this->assertFalse($settings->get_fileurl()); 66 $settings->set_raw(true); 67 $this->assertTrue($settings->get_raw()); 68 } 69 70 /** 71 * Check external_settings file API calls. 72 * 73 * @covers \core_external\external_settings::set_file 74 * @covers \core_external\external_settings::get_file 75 */ 76 public function test_external_settings_set_file(): void { 77 $settings = external_settings::get_instance(); 78 79 $settings->set_file('plugin.php'); 80 $this->assertEquals('plugin.php', $settings->get_file()); 81 } 82 83 /** 84 * Check external_settings filter API calls. 85 * 86 * @covers \core_external\external_settings::set_filter 87 * @covers \core_external\external_settings::get_filter 88 */ 89 public function test_external_settings_set_filter(): void { 90 $settings = external_settings::get_instance(); 91 92 $settings->set_filter(false); 93 $this->assertFalse($settings->get_filter()); 94 } 95 96 /** 97 * Check external_settings file API calls. 98 * 99 * @covers \core_external\external_settings::set_fileurl 100 * @covers \core_external\external_settings::get_fileurl 101 */ 102 public function test_external_settings_set_fileurl(): void { 103 $settings = external_settings::get_instance(); 104 105 $settings->set_fileurl(false); 106 $this->assertFalse($settings->get_fileurl()); 107 } 108 109 /** 110 * Check external_settings raw API calls. 111 * 112 * @covers \core_external\external_settings::set_raw 113 * @covers \core_external\external_settings::get_raw 114 */ 115 public function test_external_settings_set_raw(): void { 116 $settings = external_settings::get_instance(); 117 $settings->set_raw(true); 118 $this->assertTrue($settings->get_raw()); 119 } 120 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body