Exemplo n.º 1
0
 /**
  * External function plan_request_review.
  *
  * @param int $id The plan ID.
  * @return boolean
  */
 public static function plan_request_review($id)
 {
     $params = self::validate_parameters(self::plan_request_review_parameters(), array('id' => $id));
     $plan = api::read_plan($id);
     self::validate_context($plan->get_context());
     return api::plan_request_review($plan);
 }
Exemplo n.º 2
0
 /**
  * Testing requesting the review of a plan.
  */
 public function test_plan_request_review()
 {
     $data = $this->setup_workflow_data();
     $dg = $data['dg'];
     $lpg = $data['lpg'];
     $user = $data['user'];
     $reviewer = $data['reviewer'];
     $otheruser = $data['otheruser'];
     $plan = $data['plan'];
     $tplplan = $data['tplplan'];
     $this->assertEquals(plan::STATUS_DRAFT, $plan->get_status());
     $this->assertEquals(plan::STATUS_DRAFT, $tplplan->get_status());
     // Foreign user cannot do anything.
     $this->setUser($otheruser);
     try {
         api::plan_request_review($plan);
         $this->fail('The user can not read the plan.');
     } catch (required_capability_exception $e) {
         $this->assertEquals('nopermissions', $e->errorcode);
     }
     // Can not change a plan based on a template.
     $this->setUser($user);
     try {
         api::plan_request_review($tplplan);
         $this->fail('The plan is based on a template.');
     } catch (coding_exception $e) {
         $this->assertRegExp('/Template plans cannot be reviewed./', $e->getMessage());
     }
     // Can not send for review when not draft.
     $this->setUser($user);
     $plan->set_status(plan::STATUS_WAITING_FOR_REVIEW);
     try {
         api::plan_request_review($plan);
         $this->fail('The plan cannot be sent for review at this stage.');
     } catch (coding_exception $e) {
         $this->assertRegExp('/The plan cannot be sent for review at this stage./', $e->getMessage());
     }
     // Can not send for review when not draft.
     $this->setUser($user);
     $plan->set_status(plan::STATUS_ACTIVE);
     try {
         api::plan_request_review($plan);
         $this->fail('The plan cannot be sent for review at this stage.');
     } catch (coding_exception $e) {
         $this->assertRegExp('/The plan cannot be sent for review at this stage./', $e->getMessage());
     }
     // Can not send for review when not draft.
     $this->setUser($user);
     $plan->set_status(plan::STATUS_IN_REVIEW);
     try {
         api::plan_request_review($plan);
         $this->fail('The plan cannot be sent for review at this stage.');
     } catch (coding_exception $e) {
         $this->assertRegExp('/The plan cannot be sent for review at this stage./', $e->getMessage());
     }
     // Can not send for review when not draft.
     $this->setUser($user);
     $plan->set_status(plan::STATUS_COMPLETE);
     try {
         api::plan_request_review($plan);
         $this->fail('The plan cannot be sent for review at this stage.');
     } catch (coding_exception $e) {
         $this->assertRegExp('/The plan cannot be sent for review at this stage./', $e->getMessage());
     }
     // Sending for review as a reviewer.
     $this->setUser($reviewer);
     $plan->set_status(plan::STATUS_DRAFT);
     try {
         api::plan_request_review($plan);
         $this->fail('The user can not request a review.');
     } catch (required_capability_exception $e) {
         $this->assertEquals('nopermissions', $e->errorcode);
     }
     // Sending for review.
     $this->setUser($user);
     api::plan_request_review($plan);
     $plan->read();
     $this->assertEquals(plan::STATUS_WAITING_FOR_REVIEW, $plan->get_status());
     // Sending for review by ID.
     $plan->set_status(plan::STATUS_DRAFT);
     $plan->update();
     api::plan_request_review($plan->get_id());
     $plan->read();
     $this->assertEquals(plan::STATUS_WAITING_FOR_REVIEW, $plan->get_status());
 }
Exemplo n.º 3
0
 /**
  * Test the plan review requested event.
  *
  */
 public function test_plan_review_requested()
 {
     $this->resetAfterTest(true);
     $this->setAdminUser();
     $dg = $this->getDataGenerator();
     $lpg = $this->getDataGenerator()->get_plugin_generator('core_competency');
     $user1 = $dg->create_user();
     $plan = $lpg->create_plan(array('userid' => $user1->id));
     $planid = $plan->get_id();
     $contextid = $plan->get_context()->id;
     // Trigger and capture the event.
     $sink = $this->redirectEvents();
     $result = api::plan_request_review($plan->get_id());
     $this->assertTrue($result);
     // Get our event event.
     $events = $sink->get_events();
     $event = reset($events);
     $this->assertInstanceOf('\\core\\event\\competency_plan_review_requested', $event);
     $this->assertEquals($planid, $event->objectid);
     $this->assertEquals($contextid, $event->contextid);
     $this->assertEquals($plan->get_userid(), $event->relateduserid);
     $this->assertEventContextNotUsed($event);
     $this->assertDebuggingNotCalled();
 }