/** * Test we can read a competency framework with read permissions. */ public function test_read_competency_frameworks_with_read_permissions_in_category() { $this->setUser($this->creator); $insystem = $this->create_competency_framework(1, true); $incat = $this->create_competency_framework(2, false); // Switch users to someone with less permissions. $this->setUser($this->catuser); $id = $incat->id; $result = external::read_competency_framework($id); $result = (object) external_api::clean_returnvalue(external::read_competency_framework_returns(), $result); $this->assertGreaterThan(0, $result->timecreated); $this->assertGreaterThan(0, $result->timemodified); $this->assertEquals($this->creator->id, $result->usermodified); $this->assertEquals('shortname2', $result->shortname); $this->assertEquals('idnumber2', $result->idnumber); $this->assertEquals('description2', $result->description); $this->assertEquals(FORMAT_HTML, $result->descriptionformat); $this->assertEquals(2, $result->scaleid); $this->assertEquals($this->scaleconfiguration2, $result->scaleconfiguration); $this->assertEquals(true, $result->visible); // Switching to user with no permissions. try { $result = external::read_competency_framework($insystem->id); $this->fail('Current user cannot should not be able to read the framework.'); } catch (required_capability_exception $e) { // All good. } }