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 * Course module competency persistent class tests.
19 *
20 * @package    core_competency
21 * @copyright  2019 Damyon Wiese
22 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24
25defined('MOODLE_INTERNAL') || die();
26global $CFG;
27
28use core_competency\course_module_competency;
29
30/**
31 * Course module competency persistent testcase.
32 *
33 * @package    core_competency
34 * @copyright  2019 Damyon Wiese
35 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36 */
37class core_competency_course_module_competency_testcase extends advanced_testcase {
38
39    public function test_count_competencies() {
40        global $CFG, $DB;
41
42        $this->resetAfterTest(true);
43        $dg = $this->getDataGenerator();
44        $lpg = $dg->get_plugin_generator('core_competency');
45
46        $c1 = $dg->create_course();
47        $u1 = $dg->create_user();
48        $u2 = $dg->create_user();
49
50        $framework = $lpg->create_framework();
51        $comp1 = $lpg->create_competency(array('competencyframeworkid' => $framework->get('id')));   // In C1, and C2.
52        $comp2 = $lpg->create_competency(array('competencyframeworkid' => $framework->get('id')));   // In C2.
53        $lpg->create_course_competency(array('competencyid' => $comp1->get('id'), 'courseid' => $c1->id));
54        $lpg->create_course_competency(array('competencyid' => $comp2->get('id'), 'courseid' => $c1->id));
55
56        $assign1a = $dg->create_module('assign', ['course' => $c1]);
57        $assign1b = $dg->create_module('assign', ['course' => $c1]);
58        $cmc1a = $lpg->create_course_module_competency(['competencyid' => $comp1->get('id'), 'cmid' => $assign1a->cmid]);
59        $cmc1b = $lpg->create_course_module_competency(['competencyid' => $comp1->get('id'), 'cmid' => $assign1b->cmid]);
60        $cmc2b = $lpg->create_course_module_competency(['competencyid' => $comp2->get('id'), 'cmid' => $assign1b->cmid]);
61
62        // Enrol the user 1 in C1.
63        $dg->enrol_user($u1->id, $c1->id);
64
65        $all = course_module_competency::list_course_module_competencies($assign1a->cmid);
66        $this->assertEquals(course_module_competency::count_competencies($assign1a->cmid), count($all));
67
68        $all = course_module_competency::list_course_module_competencies($assign1b->cmid);
69        $this->assertEquals(course_module_competency::count_competencies($assign1b->cmid), count($all));
70    }
71
72}
73