public function test_delete_plans() { $this->setUser($this->creator); $syscontext = context_system::instance(); $plan1 = $this->create_plan(1, $this->user->id, 0, plan::STATUS_ACTIVE, 0); $plan2 = $this->create_plan(2, $this->user->id, 0, plan::STATUS_ACTIVE, 0); $plan3 = $this->create_plan(3, $this->creator->id, 0, plan::STATUS_ACTIVE, 0); $this->assertTrue(external::delete_plan($plan1->id)); unassign_capability('moodle/competency:planmanage', $this->creatorrole, $syscontext->id); accesslib_clear_all_caches_for_unit_testing(); try { external::delete_plan($plan2->id); $this->fail('Exception expected due to not permissions to manage plans'); } catch (moodle_exception $e) { $this->assertEquals('nopermissions', $e->errorcode); } $this->setUser($this->user); // Can not delete plans created by other users. try { external::delete_plan($plan2->id); $this->fail('Exception expected due to not permissions to manage plans'); } catch (moodle_exception $e) { $this->assertEquals('nopermissions', $e->errorcode); } assign_capability('moodle/competency:planmanageown', CAP_ALLOW, $this->userrole, $syscontext->id); accesslib_clear_all_caches_for_unit_testing(); $this->assertTrue(external::delete_plan($plan2->id)); // Can not delete plans created for other users. try { external::delete_plan($plan3->id); $this->fail('Exception expected due to not permissions to manage plans'); } catch (moodle_exception $e) { $this->assertEquals('nopermissions', $e->errorcode); } $plan4 = $this->create_plan(4, $this->user->id, 0, plan::STATUS_ACTIVE, 0); $this->assertTrue(external::delete_plan($plan4->id)); }