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