/** * Test for data_connector::get_resourcelink_from_context() */ public function test_get_resourcelink_from_context() { $dc = new data_connector(); $consumer = new ToolConsumer(null, $dc); $consumer->name = 'TestName'; $consumer->setKey('TestKey'); $consumer->secret = 'TestSecret'; $consumer->save(); $settings = ['a', 'b', 'c']; $lticontextid = 'testlticontextid'; $context = Context::fromConsumer($consumer, $lticontextid); $context->settings = $settings; $context->save(); // No ResourceLink associated with the Context yet. $this->assertNull($dc->get_resourcelink_from_context($context)); // Create and save ResourceLink from the Context. $resourcelink = ResourceLink::fromContext($context, 'testresourcelinkid'); $resourcelink->save(); $dc->loadResourceLink($resourcelink); // Assert that the resource link and the one fetched by get_resourcelink_from_context() are the same. $this->assertEquals($resourcelink, $dc->get_resourcelink_from_context($context)); }