/** * Test that we can remove related competencies. * * @return void */ public function test_remove_related_competency() { $this->setUser($this->creator); $lpg = $this->getDataGenerator()->get_plugin_generator('core_competency'); $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())); $rc1 = $lpg->create_related_competency(array('competencyid' => $c1->get_id(), 'relatedcompetencyid' => $c2->get_id())); $rc2 = $lpg->create_related_competency(array('competencyid' => $c2->get_id(), 'relatedcompetencyid' => $c3->get_id())); $this->assertEquals(2, related_competency::count_records()); // Returns false when the relation does not exist. $result = external::remove_related_competency($c1->get_id(), $c3->get_id()); $result = external_api::clean_returnvalue(external::remove_related_competency_returns(), $result); $this->assertFalse($result); // Returns true on success. $result = external::remove_related_competency($c2->get_id(), $c3->get_id()); $result = external_api::clean_returnvalue(external::remove_related_competency_returns(), $result); $this->assertTrue($result); $this->assertEquals(1, related_competency::count_records()); // We don't need to specify competencyid and relatedcompetencyid in the right order. $result = external::remove_related_competency($c2->get_id(), $c1->get_id()); $result = external_api::clean_returnvalue(external::remove_related_competency_returns(), $result); $this->assertTrue($result); $this->assertEquals(0, related_competency::count_records()); }