Differences Between: [Versions 310 and 311] [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403]
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 * Tool LP data generator tests. 19 * 20 * @package core_competency 21 * @category test 22 * @copyright 2015 Frédéric Massart - FMCorz.net 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 use core_competency\competency; 27 use core_competency\competency_framework; 28 use core_competency\course_competency; 29 use core_competency\course_module_competency; 30 use core_competency\plan; 31 use core_competency\related_competency; 32 use core_competency\template; 33 use core_competency\template_cohort; 34 use core_competency\template_competency; 35 use core_competency\user_competency; 36 use core_competency\user_competency_plan; 37 use core_competency\plan_competency; 38 use core_competency\evidence; 39 40 defined('MOODLE_INTERNAL') || die(); 41 42 /** 43 * Tool LP data generator testcase. 44 * 45 * @package core_competency 46 * @category test 47 * @copyright 2015 Frédéric Massart - FMCorz.net 48 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 49 */ 50 class core_competency_generator_testcase extends advanced_testcase { 51 52 public function test_create_framework() { 53 $this->resetAfterTest(true); 54 55 $lpg = $this->getDataGenerator()->get_plugin_generator('core_competency'); 56 $this->assertEquals(0, competency_framework::count_records()); 57 $framework = $lpg->create_framework(); 58 $framework = $lpg->create_framework(); 59 $this->assertEquals(2, competency_framework::count_records()); 60 $this->assertInstanceOf('\core_competency\competency_framework', $framework); 61 } 62 63 public function test_create_competency() { 64 $this->resetAfterTest(true); 65 66 $lpg = $this->getDataGenerator()->get_plugin_generator('core_competency'); 67 $framework = $lpg->create_framework(); 68 $this->assertEquals(0, competency::count_records()); 69 $competency = $lpg->create_competency(array('competencyframeworkid' => $framework->get('id'))); 70 $competency = $lpg->create_competency(array('competencyframeworkid' => $framework->get('id'))); 71 $this->assertEquals(2, competency::count_records()); 72 $this->assertInstanceOf('\core_competency\competency', $competency); 73 } 74 75 public function test_create_related_competency() { 76 $this->resetAfterTest(true); 77 78 $lpg = $this->getDataGenerator()->get_plugin_generator('core_competency'); 79 $framework = $lpg->create_framework(); 80 $c1 = $lpg->create_competency(array('competencyframeworkid' => $framework->get('id'))); 81 $c2 = $lpg->create_competency(array('competencyframeworkid' => $framework->get('id'))); 82 $c3 = $lpg->create_competency(array('competencyframeworkid' => $framework->get('id'))); 83 $this->assertEquals(0, related_competency::count_records()); 84 $rc = $lpg->create_related_competency(array('competencyid' => $c1->get('id'), 'relatedcompetencyid' => $c2->get('id'))); 85 $rc = $lpg->create_related_competency(array('competencyid' => $c2->get('id'), 'relatedcompetencyid' => $c3->get('id'))); 86 $this->assertEquals(2, related_competency::count_records()); 87 $this->assertInstanceOf('\core_competency\related_competency', $rc); 88 } 89 90 public function test_create_plan() { 91 $this->resetAfterTest(true); 92 93 $user = $this->getDataGenerator()->create_user(); 94 $lpg = $this->getDataGenerator()->get_plugin_generator('core_competency'); 95 $this->assertEquals(0, plan::count_records()); 96 $plan = $lpg->create_plan(array('userid' => $user->id)); 97 $this->assertEquals(1, plan::count_records()); 98 $this->assertInstanceOf('\core_competency\plan', $plan); 99 } 100 101 public function test_create_user_competency() { 102 $this->resetAfterTest(true); 103 104 $user = $this->getDataGenerator()->create_user(); 105 $lpg = $this->getDataGenerator()->get_plugin_generator('core_competency'); 106 $framework = $lpg->create_framework(); 107 $c1 = $lpg->create_competency(array('competencyframeworkid' => $framework->get('id'))); 108 $c2 = $lpg->create_competency(array('competencyframeworkid' => $framework->get('id'))); 109 $c3 = $lpg->create_competency(array('competencyframeworkid' => $framework->get('id'))); 110 $this->assertEquals(0, user_competency::count_records()); 111 $rc = $lpg->create_user_competency(array('userid' => $user->id, 'competencyid' => $c1->get('id'))); 112 $rc = $lpg->create_user_competency(array('userid' => $user->id, 'competencyid' => $c2->get('id'))); 113 $this->assertEquals(2, user_competency::count_records()); 114 $this->assertInstanceOf('\core_competency\user_competency', $rc); 115 } 116 117 public function test_create_user_competency_plan() { 118 $this->resetAfterTest(true); 119 120 $user = $this->getDataGenerator()->create_user(); 121 $lpg = $this->getDataGenerator()->get_plugin_generator('core_competency'); 122 $framework = $lpg->create_framework(); 123 $c1 = $lpg->create_competency(array('competencyframeworkid' => $framework->get('id'))); 124 $c2 = $lpg->create_competency(array('competencyframeworkid' => $framework->get('id'))); 125 $plan = $lpg->create_plan(array('userid' => $user->id)); 126 $this->assertEquals(0, user_competency_plan::count_records()); 127 $ucp = $lpg->create_user_competency_plan(array( 128 'userid' => $user->id, 129 'competencyid' => $c1->get('id'), 130 'planid' => $plan->get('id') 131 )); 132 $ucp = $lpg->create_user_competency_plan(array( 133 'userid' => $user->id, 134 'competencyid' => $c2->get('id'), 135 'planid' => $plan->get('id') 136 )); 137 $this->assertEquals(2, user_competency_plan::count_records()); 138 $this->assertInstanceOf('\core_competency\user_competency_plan', $ucp); 139 } 140 141 public function test_create_template() { 142 $this->resetAfterTest(true); 143 144 $lpg = $this->getDataGenerator()->get_plugin_generator('core_competency'); 145 $this->assertEquals(0, template::count_records()); 146 $template = $lpg->create_template(); 147 $template = $lpg->create_template(); 148 $this->assertEquals(2, template::count_records()); 149 $this->assertInstanceOf('\core_competency\template', $template); 150 } 151 152 public function test_create_template_competency() { 153 $this->resetAfterTest(true); 154 $lpg = $this->getDataGenerator()->get_plugin_generator('core_competency'); 155 156 $this->assertEquals(0, template_competency::count_records()); 157 $framework = $lpg->create_framework(); 158 $c1 = $lpg->create_competency(array('competencyframeworkid' => $framework->get('id'))); 159 $c2 = $lpg->create_competency(array('competencyframeworkid' => $framework->get('id'))); 160 $template = $lpg->create_template(); 161 $relation = $lpg->create_template_competency(array('competencyid' => $c1->get('id'), 'templateid' => $template->get('id'))); 162 $relation = $lpg->create_template_competency(array('competencyid' => $c2->get('id'), 'templateid' => $template->get('id'))); 163 $this->assertEquals(2, template_competency::count_records()); 164 $this->assertInstanceOf('\core_competency\template_competency', $relation); 165 } 166 167 public function test_create_plan_competency() { 168 $this->resetAfterTest(true); 169 $user = $this->getDataGenerator()->create_user(); 170 $lpg = $this->getDataGenerator()->get_plugin_generator('core_competency'); 171 172 $framework = $lpg->create_framework(); 173 $c1 = $lpg->create_competency(array('competencyframeworkid' => $framework->get('id'))); 174 $c2 = $lpg->create_competency(array('competencyframeworkid' => $framework->get('id'))); 175 176 $plan = $lpg->create_plan(array('userid' => $user->id)); 177 178 $pc1 = $lpg->create_plan_competency(array('planid' => $plan->get('id'), 'competencyid' => $c1->get('id'))); 179 $pc2 = $lpg->create_plan_competency(array('planid' => $plan->get('id'), 'competencyid' => $c2->get('id'))); 180 181 $this->assertEquals(2, plan_competency::count_records()); 182 $this->assertInstanceOf('\core_competency\plan_competency', $pc1); 183 $this->assertInstanceOf('\core_competency\plan_competency', $pc2); 184 $this->assertEquals($plan->get('id'), $pc1->get('planid')); 185 } 186 187 public function test_create_template_cohort() { 188 $this->resetAfterTest(true); 189 190 $lpg = $this->getDataGenerator()->get_plugin_generator('core_competency'); 191 $c1 = $this->getDataGenerator()->create_cohort(); 192 $c2 = $this->getDataGenerator()->create_cohort(); 193 $t1 = $lpg->create_template(); 194 $this->assertEquals(0, template_cohort::count_records()); 195 $tc = $lpg->create_template_cohort(array('templateid' => $t1->get('id'), 'cohortid' => $c1->id)); 196 $this->assertEquals(1, template_cohort::count_records()); 197 $tc = $lpg->create_template_cohort(array('templateid' => $t1->get('id'), 'cohortid' => $c2->id)); 198 $this->assertEquals(2, template_cohort::count_records()); 199 $this->assertInstanceOf('\core_competency\template_cohort', $tc); 200 } 201 202 public function test_create_evidence() { 203 $this->resetAfterTest(true); 204 205 $user = $this->getDataGenerator()->create_user(); 206 $lpg = $this->getDataGenerator()->get_plugin_generator('core_competency'); 207 $framework = $lpg->create_framework(); 208 $c1 = $lpg->create_competency(array('competencyframeworkid' => $framework->get('id'))); 209 $c2 = $lpg->create_competency(array('competencyframeworkid' => $framework->get('id'))); 210 $rc1 = $lpg->create_user_competency(array('userid' => $user->id, 'competencyid' => $c1->get('id'))); 211 $rc2 = $lpg->create_user_competency(array('userid' => $user->id, 'competencyid' => $c2->get('id'))); 212 $e = $lpg->create_evidence(array('usercompetencyid' => $rc1->get('id'))); 213 $e = $lpg->create_evidence(array('usercompetencyid' => $rc2->get('id'))); 214 $this->assertEquals(2, evidence::count_records()); 215 $this->assertInstanceOf('\core_competency\evidence', $e); 216 } 217 218 public function test_create_course_competency() { 219 $this->resetAfterTest(true); 220 221 $lpg = $this->getDataGenerator()->get_plugin_generator('core_competency'); 222 $course1 = $this->getDataGenerator()->create_course(); 223 $course2 = $this->getDataGenerator()->create_course(); 224 $framework = $lpg->create_framework(); 225 $c1 = $lpg->create_competency(array('competencyframeworkid' => $framework->get('id'))); 226 $c2 = $lpg->create_competency(array('competencyframeworkid' => $framework->get('id'))); 227 $c3 = $lpg->create_competency(array('competencyframeworkid' => $framework->get('id'))); 228 $this->assertEquals(0, course_competency::count_records()); 229 $rc = $lpg->create_course_competency(array('competencyid' => $c1->get('id'), 'courseid' => $course1->id)); 230 $rc = $lpg->create_course_competency(array('competencyid' => $c2->get('id'), 'courseid' => $course1->id)); 231 $this->assertEquals(2, course_competency::count_records(array('courseid' => $course1->id))); 232 $this->assertEquals(0, course_competency::count_records(array('courseid' => $course2->id))); 233 $rc = $lpg->create_course_competency(array('competencyid' => $c3->get('id'), 'courseid' => $course2->id)); 234 $this->assertEquals(1, course_competency::count_records(array('courseid' => $course2->id))); 235 $this->assertInstanceOf('\core_competency\course_competency', $rc); 236 } 237 238 public function test_create_course_module_competency() { 239 $this->resetAfterTest(true); 240 241 $lpg = $this->getDataGenerator()->get_plugin_generator('core_competency'); 242 $course1 = $this->getDataGenerator()->create_course(); 243 $cm1 = $this->getDataGenerator()->create_module('forum', array('course' => $course1->id)); 244 $cm2 = $this->getDataGenerator()->create_module('forum', array('course' => $course1->id)); 245 $framework = $lpg->create_framework(); 246 $c1 = $lpg->create_competency(array('competencyframeworkid' => $framework->get('id'))); 247 $c2 = $lpg->create_competency(array('competencyframeworkid' => $framework->get('id'))); 248 $c3 = $lpg->create_competency(array('competencyframeworkid' => $framework->get('id'))); 249 $this->assertEquals(0, course_module_competency::count_records()); 250 $rc = $lpg->create_course_module_competency(array('competencyid' => $c1->get('id'), 'cmid' => $cm1->cmid)); 251 $rc = $lpg->create_course_module_competency(array('competencyid' => $c2->get('id'), 'cmid' => $cm1->cmid)); 252 $this->assertEquals(2, course_module_competency::count_records(array('cmid' => $cm1->cmid))); 253 $this->assertEquals(0, course_module_competency::count_records(array('cmid' => $cm2->cmid))); 254 $rc = $lpg->create_course_module_competency(array('competencyid' => $c3->get('id'), 'cmid' => $cm2->cmid)); 255 $this->assertEquals(1, course_module_competency::count_records(array('cmid' => $cm2->cmid))); 256 $this->assertInstanceOf('\core_competency\course_module_competency', $rc); 257 } 258 259 } 260
title
Description
Body
title
Description
Body
title
Description
Body
title
Body