|
| 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 mod_forum\grades\gradeitems. |
| 19 | + * |
| 20 | + * @package mod_hsuforum |
| 21 | + * @category test |
| 22 | + * @copyright 2020 Open LMS |
| 23 | + * @license http://www.gnu.org/copyleft/gpl.html GNU Public License |
| 24 | + */ |
| 25 | + |
| 26 | +declare(strict_types = 1); |
| 27 | + |
| 28 | +namespace tests\mod_hsuforum\grades; |
| 29 | + |
| 30 | +use advanced_testcase; |
| 31 | +use core_grades\component_gradeitems; |
| 32 | +use coding_exception; |
| 33 | + |
| 34 | +/** |
| 35 | + * Unit tests for mod_hsuforum\grades\gradeitems. |
| 36 | + * |
| 37 | + * @package mod_hsuforum |
| 38 | + * @category test |
| 39 | + * @copyright 2020 Open LMS |
| 40 | + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
| 41 | + */ |
| 42 | +class gradeitems_test extends advanced_testcase |
| 43 | +{ |
| 44 | + |
| 45 | + /** |
| 46 | + * Ensure that the mappings are present and correct. |
| 47 | + */ |
| 48 | + public function test_get_itemname_mapping_for_component(): void |
| 49 | + { |
| 50 | + $mappings = component_gradeitems::get_itemname_mapping_for_component('mod_hsuforum'); |
| 51 | + $this->assertIsArray($mappings); |
| 52 | + $this->assertCount(1, $mappings); |
| 53 | + $this->assertArraySubset([0 => 'posts'], $mappings); |
| 54 | + } |
| 55 | + |
| 56 | + /** |
| 57 | + * Ensure that the advanced grading only applies to the relevant items. |
| 58 | + */ |
| 59 | + public function test_get_advancedgrading_itemnames_for_component(): void |
| 60 | + { |
| 61 | + $mappings = component_gradeitems::get_advancedgrading_itemnames_for_component('mod_hsuforum'); |
| 62 | + $this->assertIsArray($mappings); |
| 63 | + $this->assertCount(1, $mappings); |
| 64 | + $this->assertContains('posts', $mappings); |
| 65 | + } |
| 66 | + |
| 67 | + /** |
| 68 | + * Ensure that the correct items are identified by is_advancedgrading_itemname. |
| 69 | + * |
| 70 | + * @dataProvider is_advancedgrading_itemname_provider |
| 71 | + * @param string $itemname |
| 72 | + * @param bool $expected |
| 73 | + */ |
| 74 | + public function test_is_advancedgrading_itemname(string $itemname, bool $expected): void |
| 75 | + { |
| 76 | + $this->assertEquals( |
| 77 | + $expected, |
| 78 | + component_gradeitems::is_advancedgrading_itemname('mod_hsuforum', $itemname) |
| 79 | + ); |
| 80 | + } |
| 81 | + |
| 82 | + /** |
| 83 | + * Data provider for tests of is_advancedgrading_itemname. |
| 84 | + * |
| 85 | + * @return array |
| 86 | + */ |
| 87 | + public function is_advancedgrading_itemname_provider(): array |
| 88 | + { |
| 89 | + return [ |
| 90 | + 'Whole forum grading is advanced' => [ |
| 91 | + 'posts', |
| 92 | + true, |
| 93 | + ], |
| 94 | + ]; |
| 95 | + } |
| 96 | +} |
0 commit comments