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 /** 18 * Unit tests for the import_handler_info class. 19 * 20 * @package tool_moodlenet 21 * @category test 22 * @copyright 2020 Jake Dallimore <jrhdallimore@gmail.com> 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 namespace tool_moodlenet\local\tests; 26 27 use tool_moodlenet\local\import_handler_info; 28 use tool_moodlenet\local\import_strategy; 29 use tool_moodlenet\local\import_strategy_file; 30 31 defined('MOODLE_INTERNAL') || die(); 32 33 /** 34 * Class tool_moodlenet_import_handler_info_testcase, providing test cases for the import_handler_info class. 35 */ 36 class tool_moodlenet_import_handler_info_testcase extends \advanced_testcase { 37 38 /** 39 * Test init and the getters. 40 * 41 * @dataProvider handler_info_data_provider 42 * @param string $modname the name of the mod. 43 * @param string $description description of the mod. 44 * @param bool $expectexception whether we expect an exception during init or not. 45 */ 46 public function test_initialisation($modname, $description, $expectexception) { 47 $this->resetAfterTest(); 48 // Skip those cases we cannot init. 49 if ($expectexception) { 50 $this->expectException(\coding_exception::class); 51 $handlerinfo = new import_handler_info($modname, $description, new import_strategy_file()); 52 } 53 54 $handlerinfo = new import_handler_info($modname, $description, new import_strategy_file()); 55 56 $this->assertEquals($modname, $handlerinfo->get_module_name()); 57 $this->assertEquals($description, $handlerinfo->get_description()); 58 $this->assertInstanceOf(import_strategy::class, $handlerinfo->get_strategy()); 59 } 60 61 62 /** 63 * Data provider for creation of import_handler_info objects. 64 * 65 * @return array the data for creation of the info object. 66 */ 67 public function handler_info_data_provider() { 68 return [ 69 'All data present' => ['label', 'Add a label to the course', false], 70 'Empty module name' => ['', 'Add a file resource to the course', true], 71 'Empty description' => ['resource', '', true], 72 73 ]; 74 } 75 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body