Esempio n. 1
0
 /**
  * Test for data_connector::getSharesResourceLink().
  */
 public function test_get_shares_resource_link()
 {
     $dc = new data_connector();
     $consumer = new ToolConsumer(null, $dc);
     $consumer->name = 'testconsumername';
     $consumer->setKey('TestKey');
     $consumer->secret = 'testsecret';
     $consumer->idScope = ToolProvider::ID_SCOPE_GLOBAL;
     $consumer->save();
     $title = 'testcontexttitle';
     $settings = ['a', 'b', 'c'];
     $lticontextid = 'testlticontextid';
     $context = Context::fromConsumer($consumer, $lticontextid);
     $context->title = $title;
     $context->settings = $settings;
     $context->save();
     $resourcelink = ResourceLink::fromConsumer($consumer, 'testresourcelinkid');
     $resourcelink->setContextId($context->getRecordId());
     $resourcelink->save();
     $shares = $dc->getSharesResourceLink($resourcelink);
     $this->assertEmpty($shares);
     $resourcelinkchild = ResourceLink::fromConsumer($consumer, 'testresourcelinkchildid');
     $resourcelinkchild->primaryResourceLinkId = $resourcelink->getRecordId();
     $resourcelinkchild->shareApproved = true;
     $resourcelinkchild->save();
     $resourcelinkchild2 = ResourceLink::fromConsumer($consumer, 'testresourcelinkchildid2');
     $resourcelinkchild2->primaryResourceLinkId = $resourcelink->getRecordId();
     $resourcelinkchild2->shareApproved = false;
     $resourcelinkchild2->save();
     $shares = $dc->getSharesResourceLink($resourcelink);
     $this->assertCount(2, $shares);
     $shareids = [$resourcelinkchild->getRecordId(), $resourcelinkchild2->getRecordId()];
     foreach ($shares as $share) {
         $this->assertTrue($share instanceof ResourceLinkShare);
         $this->assertTrue(in_array($share->resourceLinkId, $shareids));
         if ($share->resourceLinkId == $shareids[0]) {
             $this->assertTrue($share->approved);
         } else {
             $this->assertFalse($share->approved);
         }
     }
 }