/** * Test remove plan and the managing of archived user competencies. */ public function test_delete_plan_manage_archived_competencies() { $this->resetAfterTest(true); $dg = $this->getDataGenerator(); $lpg = $this->getDataGenerator()->get_plugin_generator('core_competency'); $syscontext = context_system::instance(); // Create user and role for the test. $user = $dg->create_user(); $managerole = $dg->create_role(array('name' => 'User manage own', 'shortname' => 'manageown')); assign_capability('moodle/competency:planmanageowndraft', CAP_ALLOW, $managerole, $syscontext->id); assign_capability('moodle/competency:planmanageown', CAP_ALLOW, $managerole, $syscontext->id); $dg->role_assign($managerole, $user->id, $syscontext->id); $this->setUser($user); // Create a framework and assign competencies. $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())); // Create completed plan with records in user_competency. $completedplan = $lpg->create_plan(array('userid' => $user->id, 'status' => \core_competency\plan::STATUS_COMPLETE)); $lpg->create_plan_competency(array('planid' => $completedplan->get_id(), 'competencyid' => $c1->get_id())); $lpg->create_plan_competency(array('planid' => $completedplan->get_id(), 'competencyid' => $c2->get_id())); $uc1 = $lpg->create_user_competency(array('userid' => $user->id, 'competencyid' => $c1->get_id())); $uc2 = $lpg->create_user_competency(array('userid' => $user->id, 'competencyid' => $c2->get_id())); $ucp1 = $lpg->create_user_competency_plan(array('userid' => $user->id, 'competencyid' => $c1->get_id(), 'planid' => $completedplan->get_id())); $ucp2 = $lpg->create_user_competency_plan(array('userid' => $user->id, 'competencyid' => $c2->get_id(), 'planid' => $completedplan->get_id())); api::delete_plan($completedplan->get_id()); // Check that achived user competencies are deleted. $this->assertEquals(0, \core_competency\plan::count_records()); $this->assertEquals(2, \core_competency\user_competency::count_records()); $this->assertEquals(0, \core_competency\user_competency_plan::count_records()); }
public function test_create_plan() { $this->resetAfterTest(true); $user = $this->getDataGenerator()->create_user(); $lpg = $this->getDataGenerator()->get_plugin_generator('core_competency'); $this->assertEquals(0, plan::count_records()); $plan = $lpg->create_plan(array('userid' => $user->id)); $this->assertEquals(1, plan::count_records()); $this->assertInstanceOf('\\core_competency\\plan', $plan); }
public function test_sync_plans_from_cohorts_with_passed_duedate() { global $DB; $this->resetAfterTest(true); $this->setAdminUser(); $dg = $this->getDataGenerator(); $lpg = $dg->get_plugin_generator('core_competency'); $user1 = $dg->create_user(); $user2 = $dg->create_user(); $cohort = $dg->create_cohort(); $tpl = $lpg->create_template(array('duedate' => time() + 1000)); $templatecohort = api::create_template_cohort($tpl->get_id(), $cohort->id); $task = \core\task\manager::get_scheduled_task('\\core\\task\\sync_plans_from_template_cohorts_task'); // Add 1 user to the cohort. cohort_add_member($cohort->id, $user1->id); // Creating plans from template cohort. $task->execute(); $this->assertEquals(1, \core_competency\plan::count_records()); // Now add another user, but this time the template will be expired. cohort_add_member($cohort->id, $user2->id); $record = $tpl->to_record(); $record->duedate = time() - 10000; $DB->update_record(\core_competency\template::TABLE, $record); $tpl->read(); $task->execute(); $this->assertEquals(1, \core_competency\plan::count_records()); // Still only one plan. // Pretend it wasn't expired. $tpl->set_duedate(time() + 100); $tpl->update(); $task->execute(); $this->assertEquals(2, \core_competency\plan::count_records()); // Now there is two. }
protected function get_other_values(renderer_base $output) { $context = $this->persistent->get_context(); return array('duedateformatted' => userdate($this->persistent->get_duedate()), 'cohortscount' => template_cohort::count_records(array('templateid' => $this->persistent->get_id())), 'planscount' => plan::count_records(array('templateid' => $this->persistent->get_id())), 'canmanage' => $this->persistent->can_manage(), 'canread' => $this->persistent->can_read(), 'contextname' => $context->get_context_name(), 'contextnamenoprefix' => $context->get_context_name(false)); }