Skip to content

Commit 8594006

Browse files
committed
INT-15822: gradeitems class added on hsuforum to support advanced grading
1 parent bc852b6 commit 8594006

File tree

4 files changed

+171
-0
lines changed

4 files changed

+171
-0
lines changed

classes/grades/gradeitems.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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+
* Grade item mappings for the activity.
19+
*
20+
* @package mod_hsuforum
21+
* @copyright 2020 Open LMS
22+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23+
*/
24+
25+
declare(strict_types = 1);
26+
27+
namespace mod_hsuforum\grades;
28+
29+
use \core_grades\local\gradeitem\itemnumber_mapping;
30+
use \core_grades\local\gradeitem\advancedgrading_mapping as advanced_mapping;
31+
32+
/**
33+
* Grade item mappings for the activity.
34+
*
35+
* @package mod_hsuforum
36+
* @copyright 2020 Open LMS
37+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
38+
*/
39+
class gradeitems implements itemnumber_mapping, advanced_mapping {
40+
41+
/**
42+
* Return the list of grade item mappings for the forum.
43+
*
44+
* @return array
45+
*/
46+
public static function get_itemname_mapping_for_component(): array {
47+
return [
48+
0 => 'posts',
49+
];
50+
}
51+
52+
/**
53+
* Get the list of advanced grading item names for this component.
54+
*
55+
* @return array
56+
*/
57+
public static function get_advancedgrading_itemnames(): array {
58+
return [
59+
'posts',
60+
];
61+
}
62+
}

lang/en/hsuforum.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,3 +748,4 @@
748748
$string['confighiderecentposts'] = 'Set to yes to stop the display of recent forum posts on the course page.';
749749
$string['forumsubjectdeleted'] = 'This forum post has been removed';
750750
$string['forumbodydeleted'] = 'The content of this forum post has been removed and can no longer be accessed.';
751+
$string['gradeitem:posts'] = 'Posts';

tests/grades_gradeitems_test.php

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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+
}

tests/lib_test.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3626,4 +3626,16 @@ public function test_hsuforum_scale_dependency_form() {
36263626
// Dependency should not exist.
36273627
$this->assertFalse(array_search('scale', $value['assessed']['eq'][0]));
36283628
}
3629+
3630+
public function test_create_instance_with_advanced_grading () {
3631+
$this->resetAfterTest();
3632+
$this->setAdminUser();
3633+
global $CFG;
3634+
3635+
$CFG->mod_hsuforum_grading_interface = true;
3636+
$course = $this->getDataGenerator()->create_course();
3637+
// This will fail if the gradeitems class doesn't exists or is not properly setup.
3638+
$forum = $this->getDataGenerator()->create_module('hsuforum', array('course' => $course->id,
3639+
'completionreplies' => 5, 'completiondiscussions' => 2));
3640+
}
36293641
}

0 commit comments

Comments
 (0)