Exemplo n.º 1
0
 public function testReplayTransactions_AddingAndDeleting()
 {
     $uri = 'http://example.com/resources/1';
     $g = new \Tripod\Mongo\MongoGraph();
     $g->add_literal_triple($uri, $g->qname_to_uri('searchterms:title'), 'Anything at all');
     // add the entity to the store
     $this->tripod->saveChanges(new \Tripod\ExtendedGraph(), $g, "http://talisaspire.com/");
     $this->assertDocumentVersion(array("r" => $uri, "c" => "http://talisaspire.com/"), 0);
     $this->assertEquals(1, $this->tripodTransactionLog->getTotalTransactionCount(), 'There should only be 1 transaction in the transaction log');
     // delete the entity from the store
     $this->tripod->saveChanges($g, new \Tripod\ExtendedGraph(), "http://talisaspire.com/");
     $this->assertDocumentHasBeenDeleted(array("r" => $uri, "c" => "http://talisaspire.com/"));
     $this->assertDocumentVersion(array("r" => $uri, "c" => "http://talisaspire.com/"), 1);
     $this->assertEquals(2, $this->tripodTransactionLog->getTotalTransactionCount(), 'There should only be 2 transactions in the transaction log');
     // add it again ( slightly different document for assertion)
     $g->add_literal_triple($uri, $g->qname_to_uri('searchterms:isbn'), '1234567890');
     $this->tripod->saveChanges(new \Tripod\ExtendedGraph(), $g, "http://talisaspire.com/");
     $this->assertDocumentVersion(array("r" => $uri, "c" => "http://talisaspire.com/"), 2);
     $this->assertEquals(3, $this->tripodTransactionLog->getTotalTransactionCount(), 'There should only be 3 transaction in the transaction log');
     // drop the collection so CBD collection is empty
     $this->getTripodCollection($this->tripod)->drop();
     // replay the transaction
     $this->tripod->replayTransactionLog();
     $uG = $this->tripod->describeResource($uri);
     $this->assertDocumentVersion(array("r" => $uri, "c" => "http://talisaspire.com/"), 2);
     $this->assertHasLiteralTriple($uG, $uri, $uG->qname_to_uri('searchterms:title'), 'Anything at all');
     $this->assertHasLiteralTriple($uG, $uri, $uG->qname_to_uri('searchterms:isbn'), '1234567890');
 }
Exemplo n.º 2
0
 /**
  * Test to ensure that impact index contains joined ids for resources that do not yet exist in the database (i.e.
  * allow open world model)
  * @access public
  * @return void
  */
 public function testPreviouslyUnavailableDataBecomesPresentAndTriggersTableRegen()
 {
     $this->tripodTables->generateTableRows("t_join_link");
     $rows = $this->tripodTables->getTableRows("t_join_link", array("_id.r" => "baseData:bar1234"));
     $this->assertEquals(1, $rows['head']['count']);
     $this->assertEquals("user:10103", $rows['results'][0]['authorUri']);
     // Author link should not appear because resource has not yet been created
     $this->assertArrayNotHasKey('authorLink', $rows['results'][0]);
     $uri = 'http://schemas.talis.com/2005/user/schema#10103';
     // Confirm this user does not exist
     $this->assertFalse($this->tripod->describeResource($uri)->has_triples_about($uri));
     $g = new \Tripod\Mongo\MongoGraph();
     $g->add_resource_triple($uri, $g->qname_to_uri("rdf:type"), $g->qname_to_uri("foaf:Person"));
     $g->add_literal_triple($uri, $g->qname_to_uri("foaf:name"), "A. Nonymous");
     $this->tripod->saveChanges(new \Tripod\Mongo\MongoGraph(), $g, "http://talisaspire.com/", "This resource didn't exist at join time");
     $userGraph = $this->tripod->describeResource($uri);
     $this->assertTrue($userGraph->has_triples_about($uri), "new entity we created was not saved");
     // Get our table rows again
     $rows = $this->tripodTables->getTableRows("t_join_link", array("_id.r" => "baseData:bar1234"));
     // authorLink should now be populated
     $this->assertArrayHasKey('authorLink', $rows['results'][0]);
     $this->assertEquals($uri, $rows['results'][0]['authorLink']);
 }