Пример #1
0
 /**
  * Delete a competency
  *
  * @param int $id The competency id
  * @return boolean
  */
 public static function delete_competency($id)
 {
     $params = self::validate_parameters(self::delete_competency_parameters(), array('id' => $id));
     $competency = api::read_competency($params['id']);
     $context = $competency->get_context();
     self::validate_context($context);
     return api::delete_competency($params['id']);
 }
Пример #2
0
 public function test_delete_competency_used_in_course()
 {
     $this->resetAfterTest(true);
     $dg = $this->getDataGenerator();
     $lpg = $dg->get_plugin_generator('core_competency');
     $this->setAdminUser();
     $cat1 = $dg->create_category();
     $course = $dg->create_course(array('category' => $cat1->id));
     $f1 = $lpg->create_framework();
     $c1 = $lpg->create_competency(array('competencyframeworkid' => $f1->get_id()));
     $c2 = $lpg->create_competency(array('competencyframeworkid' => $f1->get_id()));
     $c1a = $lpg->create_competency(array('competencyframeworkid' => $f1->get_id(), 'parentid' => $c1->get_id()));
     $c1b = $lpg->create_competency(array('competencyframeworkid' => $f1->get_id(), 'parentid' => $c1a->get_id()));
     $c11b = $lpg->create_competency(array('competencyframeworkid' => $f1->get_id(), 'parentid' => $c1b->get_id()));
     $c12b = $lpg->create_competency(array('competencyframeworkid' => $f1->get_id(), 'parentid' => $c1b->get_id()));
     // Add competency to course.
     $cc = $lpg->create_course_competency(array('courseid' => $course->id, 'competencyid' => $c11b->get_id()));
     // We can not delete a competency if the competency or competencies children is linked to a course.
     $this->assertFalse(api::delete_competency($c1a->get_id()));
     // We can delete the competency if we remove the competency from course.
     $cc->delete();
     $this->assertTrue(api::delete_competency($c1a->get_id()));
     $this->assertFalse(competency::record_exists($c1a->get_id()));
     $this->assertFalse(competency::record_exists($c1b->get_id()));
     $this->assertFalse(competency::record_exists($c11b->get_id()));
     $this->assertFalse(competency::record_exists($c12b->get_id()));
 }
Пример #3
0
 /**
  * Test the competency deleted event.
  *
  */
 public function test_competency_deleted()
 {
     $this->resetAfterTest(true);
     $this->setAdminUser();
     $lpg = $this->getDataGenerator()->get_plugin_generator('core_competency');
     $f1 = $lpg->create_framework();
     $c1 = $lpg->create_competency(array('competencyframeworkid' => $f1->get_id()));
     $c1id = $c1->get_id();
     $contextid = $c1->get_context()->id;
     // Trigger and capture the event.
     $sink = $this->redirectEvents();
     // Delete competency should trigger a deleted event.
     api::delete_competency($c1id);
     // Get our event event.
     $events = $sink->get_events();
     $event = reset($events);
     $this->assertInstanceOf('\\core\\event\\competency_deleted', $event);
     $this->assertEquals($c1id, $event->objectid);
     $this->assertEquals($contextid, $event->contextid);
     $this->assertEventContextNotUsed($event);
     $this->assertDebuggingNotCalled();
 }