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