/** * 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); }