MDL-53186 tool_lp: Send competencies in review from evidence interface
[moodle.git] / admin / tool / lp / tests / user_evidence_competency_test.php
CommitLineData
71cb304a
SG
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 * User evidence competency persistent class tests.
19 *
20 * @package tool_lp
21 * @copyright 2016 Serge Gauthier - <serge.gauthier.2@umontreal.ca>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24
25defined('MOODLE_INTERNAL') || die();
26global $CFG;
27
28use tool_lp\user_evidence_competency;
29
30/**
31 * User evidence competency persistent testcase.
32 *
33 * @package tool_lp
34 * @copyright 2016 Serge Gauthier - <serge.gauthier.2@umontreal.ca>
35 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36 */
37class tool_lp_user_evidene_competency_testcase extends advanced_testcase {
38
39 public function test_get_user_competencies_by_userevidenceid() {
40 global $CFG, $DB;
41
42 $this->resetAfterTest(true);
43 $dg = $this->getDataGenerator();
44 $lpg = $dg->get_plugin_generator('tool_lp');
45
46 $u1 = $dg->create_user();
47
48 // Create framework with competencies.
49 $fw = $lpg->create_framework();
50 $c1 = $lpg->create_competency(array('competencyframeworkid' => $fw->get_id()));
51 $c2 = $lpg->create_competency(array('competencyframeworkid' => $fw->get_id()));
52 $c3 = $lpg->create_competency(array('competencyframeworkid' => $fw->get_id()));
53 $c4 = $lpg->create_competency(array('competencyframeworkid' => $fw->get_id()));
54
55 // Create a plan with competencies.
56 $p1 = $lpg->create_plan(array('userid' => $u1->id));
57 $lpg->create_plan_competency(array('planid' => $p1->get_id(), 'competencyid' => $c1->get_id()));
58 $lpg->create_plan_competency(array('planid' => $p1->get_id(), 'competencyid' => $c2->get_id()));
59 $lpg->create_plan_competency(array('planid' => $p1->get_id(), 'competencyid' => $c3->get_id()));
60 $lpg->create_plan_competency(array('planid' => $p1->get_id(), 'competencyid' => $c4->get_id()));
61
62 // Create a prior learning evidence and link competencies.
63 $ue1 = $lpg->create_user_evidence(array('userid' => $u1->id));
64 $uec11 = $lpg->create_user_evidence_competency(array('userevidenceid' => $ue1->get_id(), 'competencyid' => $c1->get_id()));
65 $uec12 = $lpg->create_user_evidence_competency(array('userevidenceid' => $ue1->get_id(), 'competencyid' => $c2->get_id()));
66 $uec13 = $lpg->create_user_evidence_competency(array('userevidenceid' => $ue1->get_id(), 'competencyid' => $c3->get_id()));
67 $uc11 = $lpg->create_user_competency(array('userid' => $u1->id, 'competencyid' => $c1->get_id()));
68 $uc12 = $lpg->create_user_competency(array('userid' => $u1->id, 'competencyid' => $c2->get_id()));
69 $uc13 = $lpg->create_user_competency(array('userid' => $u1->id, 'competencyid' => $c3->get_id()));
70
71 // Create an other prior learning evidence and link competencies.
72 $ue2 = $lpg->create_user_evidence(array('userid' => $u1->id));
73 $uec22 = $lpg->create_user_evidence_competency(array('userevidenceid' => $ue2->get_id(), 'competencyid' => $c4->get_id()));
74 $uc22 = $lpg->create_user_competency(array('userid' => $u1->id, 'competencyid' => $c4->get_id()));
75
76 // Check the user competencies associated to the first prior learning evidence.
77 $ucs = user_evidence_competency::get_user_competencies_by_userevidenceid($ue1->get_id());
78 $this->assertCount(3, $ucs);
79 $uc = array_shift($ucs);
80 $this->assertEquals($uc->get_id(), $uc11->get_id());
81 $uc = array_shift($ucs);
82 $this->assertEquals($uc->get_id(), $uc12->get_id());
83 $uc = array_shift($ucs);
84 $this->assertEquals($uc->get_id(), $uc13->get_id());
85
86 // Check the user competencies associated to the second prior learning evidence.
87 $ucs = user_evidence_competency::get_user_competencies_by_userevidenceid($ue2->get_id());
88 $this->assertCount(1, $ucs);
89 $uc = array_shift($ucs);
90 $this->assertEquals($uc->get_id(), $uc22->get_id());
91 }
92}