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 |
namespace gradingform_guide;
|
|
|
18 |
|
|
|
19 |
use gradingform_controller;
|
|
|
20 |
|
|
|
21 |
defined('MOODLE_INTERNAL') || die();
|
|
|
22 |
|
|
|
23 |
global $CFG;
|
|
|
24 |
require_once($CFG->dirroot . '/grade/grading/lib.php');
|
|
|
25 |
require_once($CFG->dirroot . '/grade/grading/form/guide/lib.php');
|
|
|
26 |
|
|
|
27 |
/**
|
|
|
28 |
* Test cases for the Marking Guide.
|
|
|
29 |
*
|
|
|
30 |
* @package gradingform_guide
|
|
|
31 |
* @category test
|
|
|
32 |
* @copyright 2015 Nikita Kalinin <nixorv@gmail.com>
|
|
|
33 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
34 |
*/
|
|
|
35 |
class guide_test extends \advanced_testcase {
|
|
|
36 |
/**
|
|
|
37 |
* Unit test to get draft instance and create new instance.
|
|
|
38 |
*/
|
11 |
efrain |
39 |
public function test_get_or_create_instance(): void {
|
1 |
efrain |
40 |
global $DB;
|
|
|
41 |
|
|
|
42 |
$this->resetAfterTest(true);
|
|
|
43 |
|
|
|
44 |
// Create fake areas.
|
|
|
45 |
$fakearea = (object)array(
|
|
|
46 |
'contextid' => 1,
|
|
|
47 |
'component' => 'mod_assign',
|
|
|
48 |
'areaname' => 'submissions',
|
|
|
49 |
'activemethod' => 'guide'
|
|
|
50 |
);
|
|
|
51 |
$fakearea1id = $DB->insert_record('grading_areas', $fakearea);
|
|
|
52 |
$fakearea->contextid = 2;
|
|
|
53 |
$fakearea2id = $DB->insert_record('grading_areas', $fakearea);
|
|
|
54 |
|
|
|
55 |
// Create fake definitions.
|
|
|
56 |
$fakedefinition = (object)array(
|
|
|
57 |
'areaid' => $fakearea1id,
|
|
|
58 |
'method' => 'guide',
|
|
|
59 |
'name' => 'fakedef',
|
|
|
60 |
'status' => gradingform_controller::DEFINITION_STATUS_READY,
|
|
|
61 |
'timecreated' => 0,
|
|
|
62 |
'usercreated' => 1,
|
|
|
63 |
'timemodified' => 0,
|
|
|
64 |
'usermodified' => 1,
|
|
|
65 |
);
|
|
|
66 |
$fakedef1id = $DB->insert_record('grading_definitions', $fakedefinition);
|
|
|
67 |
$fakedefinition->areaid = $fakearea2id;
|
|
|
68 |
$fakedef2id = $DB->insert_record('grading_definitions', $fakedefinition);
|
|
|
69 |
|
|
|
70 |
// Create fake guide instance in first area.
|
|
|
71 |
$fakeinstance = (object)array(
|
|
|
72 |
'definitionid' => $fakedef1id,
|
|
|
73 |
'raterid' => 1,
|
|
|
74 |
'itemid' => 1,
|
|
|
75 |
'rawgrade' => null,
|
|
|
76 |
'status' => 0,
|
|
|
77 |
'feedback' => null,
|
|
|
78 |
'feedbackformat' => 0,
|
|
|
79 |
'timemodified' => 0
|
|
|
80 |
);
|
|
|
81 |
$fakeinstanceid = $DB->insert_record('grading_instances', $fakeinstance);
|
|
|
82 |
|
|
|
83 |
$manager1 = get_grading_manager($fakearea1id);
|
|
|
84 |
$manager2 = get_grading_manager($fakearea2id);
|
|
|
85 |
$controller1 = $manager1->get_controller('guide');
|
|
|
86 |
$controller2 = $manager2->get_controller('guide');
|
|
|
87 |
|
|
|
88 |
$instance1 = $controller1->get_or_create_instance(0, 1, 1);
|
|
|
89 |
$instance2 = $controller2->get_or_create_instance(0, 1, 1);
|
|
|
90 |
|
|
|
91 |
// Definitions should not be the same.
|
|
|
92 |
$this->assertEquals(false, $instance1->get_data('definitionid') == $instance2->get_data('definitionid'));
|
|
|
93 |
}
|
|
|
94 |
}
|