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