Skip to content

Commit

Permalink
MDL-53313 tool_lp: Add data generators for course module competencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Frederic Massart committed Apr 18, 2016
1 parent d9a0d1f commit c5e89aa
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
23 changes: 23 additions & 0 deletions admin/tool/lp/tests/generator/lib.php
Expand Up @@ -26,6 +26,7 @@
use tool_lp\competency;
use tool_lp\competency_framework;
use tool_lp\course_competency;
use tool_lp\course_module_competency;
use tool_lp\external;
use tool_lp\plan;
use tool_lp\related_competency;
Expand Down Expand Up @@ -442,6 +443,28 @@ public function create_course_competency($record = null) {
return $cc;
}

/**
* Create a new course module competency.
*
* @param array|stdClass $record
* @return course_module_competency
*/
public function create_course_module_competency($record = null) {
$record = (object) $record;

if (!isset($record->cmid)) {
throw new coding_exception('The cmid value is required.');
}
if (!isset($record->competencyid)) {
throw new coding_exception('The competencyid value is required.');
}

$cc = new course_module_competency(0, $record);
$cc->create();

return $cc;
}

/**
* Create a new user_evidence.
*
Expand Down
22 changes: 22 additions & 0 deletions admin/tool/lp/tests/generator_test.php
Expand Up @@ -26,6 +26,7 @@
use tool_lp\competency;
use tool_lp\competency_framework;
use tool_lp\course_competency;
use tool_lp\course_module_competency;
use tool_lp\plan;
use tool_lp\related_competency;
use tool_lp\template;
Expand Down Expand Up @@ -234,5 +235,26 @@ public function test_create_course_competency() {
$this->assertInstanceOf('\tool_lp\course_competency', $rc);
}

public function test_create_course_module_competency() {
$this->resetAfterTest(true);

$lpg = $this->getDataGenerator()->get_plugin_generator('tool_lp');
$course1 = $this->getDataGenerator()->create_course();
$cm1 = $this->getDataGenerator()->create_module('forum', array('course' => $course1->id));
$cm2 = $this->getDataGenerator()->create_module('forum', array('course' => $course1->id));
$framework = $lpg->create_framework();
$c1 = $lpg->create_competency(array('competencyframeworkid' => $framework->get_id()));
$c2 = $lpg->create_competency(array('competencyframeworkid' => $framework->get_id()));
$c3 = $lpg->create_competency(array('competencyframeworkid' => $framework->get_id()));
$this->assertEquals(0, course_module_competency::count_records());
$rc = $lpg->create_course_module_competency(array('competencyid' => $c1->get_id(), 'cmid' => $cm1->cmid));
$rc = $lpg->create_course_module_competency(array('competencyid' => $c2->get_id(), 'cmid' => $cm1->cmid));
$this->assertEquals(2, course_module_competency::count_records(array('cmid' => $cm1->cmid)));
$this->assertEquals(0, course_module_competency::count_records(array('cmid' => $cm2->cmid)));
$rc = $lpg->create_course_module_competency(array('competencyid' => $c3->get_id(), 'cmid' => $cm2->cmid));
$this->assertEquals(1, course_module_competency::count_records(array('cmid' => $cm2->cmid)));
$this->assertInstanceOf('\tool_lp\course_module_competency', $rc);
}

}

0 comments on commit c5e89aa

Please sign in to comment.