/** * Test for data_connector::deleteResourceLink(). */ public function test_delete_resource_link() { $dc = new data_connector(); $consumer = new ToolConsumer(null, $dc); $consumer->name = 'testconsumername'; $consumer->setKey('TestKey'); $consumer->secret = 'testsecret'; $consumer->save(); $title = 'testcontexttitle'; $settings = ['a', 'b', 'c']; $lticontextid = 'testlticontextid'; $context = Context::fromConsumer($consumer, $lticontextid); $context->title = $title; $context->settings = $settings; // Save the context. $this->assertTrue($dc->saveContext($context)); $resourcelink = ResourceLink::fromConsumer($consumer, 'testresourcelinkid'); $resourcelink->setContextId($context->getRecordId()); $resourcelink->save(); $resourcelinkchild = ResourceLink::fromConsumer($consumer, 'testresourcelinkchildid'); $resourcelinkchild->primaryResourceLinkId = $resourcelink->getRecordId(); $resourcelinkchild->shareApproved = true; $resourcelinkchild->setContextId($context->getRecordId()); $resourcelinkchild->save(); $resourcelinksharekey = new ResourceLinkShareKey($resourcelink); $resourcelinksharekey->save(); $user = User::fromResourceLink($resourcelink, ''); $user->ltiResultSourcedId = 'testLtiResultSourcedId'; $dc->saveUser($user); $this->assertTrue($dc->deleteResourceLink($resourcelink)); // Resource link properties should have been reset. $this->assertEmpty($resourcelink->title); $this->assertEmpty($resourcelink->getSettings()); $this->assertNull($resourcelink->groupSets); $this->assertNull($resourcelink->groups); $this->assertNull($resourcelink->primaryResourceLinkId); $this->assertNull($resourcelink->shareApproved); $this->assertNull($resourcelink->created); $this->assertNull($resourcelink->updated); // Share key record record should have been deleted. $this->assertFalse($dc->loadResourceLinkShareKey($resourcelinksharekey)); // Resource link record should have been deleted. $this->assertFalse($dc->loadResourceLink($resourcelink)); // Child resource link should still exist and its primaryResourceLinkId attribute should have been set to null. $this->assertTrue($dc->loadResourceLink($resourcelinkchild)); $this->assertNull($resourcelinkchild->primaryResourceLinkId); }
/** * 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)); }