public function testSearchDocumentsRegenerateWhenDefinedPredicateChanged()
 {
     // First make a change that affects a search document
     $tripod = $this->getMock('\\Tripod\\Mongo\\Driver', array('getSearchIndexer', 'getDataUpdater'), array('CBD_testing', 'tripod_php_testing', array('defaultContext' => 'http://talisaspire.com/', 'async' => array(OP_VIEWS => true, OP_TABLES => true, OP_SEARCH => false))));
     $tripodUpdate = $this->getMock('\\Tripod\\Mongo\\Updates', array('storeChanges'), array($tripod, array('defaultContext' => 'http://talisaspire.com/', 'async' => array(OP_VIEWS => true, OP_TABLES => true, OP_SEARCH => false))));
     $labeller = new \Tripod\Mongo\Labeller();
     $subjectsAndPredicatesOfChange = array($labeller->uri_to_alias("http://talisaspire.com/authors/1") => array("foaf:name"));
     $tripodUpdate->expects($this->atLeastOnce())->method('storeChanges')->will($this->returnValue(array("subjectsAndPredicatesOfChange" => $subjectsAndPredicatesOfChange, "transaction_id" => "t1234")));
     $tripod->expects($this->atLeastOnce())->method('getDataUpdater')->will($this->returnValue($tripodUpdate));
     $searchIndexer = $this->getMock('\\Tripod\\Mongo\\Composites\\SearchIndexer', array('getSearchProvider', 'getImpactedSubjects'), array($tripod));
     $searchProvider = $this->getMock('\\Tripod\\Mongo\\MongoSearchProvider', array('deleteDocument', 'indexDocument'), array($tripod));
     $searchProvider->expects($this->exactly(3))->method('deleteDocument')->with($this->matchesRegularExpression("/http:\\/\\/talisaspire\\.com\\/resources\\/doc(1|2|3)\$/"), 'http://talisaspire.com/', $this->equalTo(array('i_search_resource')));
     $searchProvider->expects($this->exactly(3))->method('indexDocument');
     $searchIndexer->expects($this->atLeastOnce())->method('getSearchProvider')->will($this->returnValue($searchProvider));
     $impactedSubjects = array($this->getMockBuilder('\\Tripod\\Mongo\\ImpactedSubject')->setConstructorArgs(array(array(_ID_RESOURCE => 'http://talisaspire.com/resources/doc1', _ID_CONTEXT => 'http://talisaspire.com/'), OP_SEARCH, 'tripod_php_testing', 'CBD_testing', array('i_search_resource')))->setMethods(array('getTripod'))->getMock(), $this->getMockBuilder('\\Tripod\\Mongo\\ImpactedSubject')->setConstructorArgs(array(array(_ID_RESOURCE => 'http://talisaspire.com/resources/doc2', _ID_CONTEXT => 'http://talisaspire.com/'), OP_SEARCH, 'tripod_php_testing', 'CBD_testing', array('i_search_resource')))->setMethods(array('getTripod'))->getMock(), $this->getMockBuilder('\\Tripod\\Mongo\\ImpactedSubject')->setConstructorArgs(array(array(_ID_RESOURCE => 'http://talisaspire.com/resources/doc3', _ID_CONTEXT => 'http://talisaspire.com/'), OP_SEARCH, 'tripod_php_testing', 'CBD_testing', array('i_search_resource')))->setMethods(array('getTripod'))->getMock());
     $impactedSubjects[0]->expects($this->once())->method('getTripod')->will($this->returnValue($tripod));
     $impactedSubjects[1]->expects($this->once())->method('getTripod')->will($this->returnValue($tripod));
     $impactedSubjects[2]->expects($this->once())->method('getTripod')->will($this->returnValue($tripod));
     $searchIndexer->expects($this->once())->method('getImpactedSubjects')->with($subjectsAndPredicatesOfChange, 'http://talisaspire.com/')->will($this->returnValue($impactedSubjects));
     $tripod->expects($this->atLeastOnce())->method('getSearchIndexer')->will($this->returnValue($searchIndexer));
     $g1 = $tripod->describeResource("http://talisaspire.com/authors/1");
     $g2 = $tripod->describeResource("http://talisaspire.com/authors/1");
     $g2->add_literal_triple("http://talisaspire.com/authors/1", $g2->qname_to_uri("foaf:name"), "Bill Shakespeare");
     $tripod->saveChanges($g1, $g2);
     // Now make a change that affects a different search document - Create new document
     $tripod = $this->getMock('\\Tripod\\Mongo\\Driver', array('getSearchIndexer'), array('CBD_testing', 'tripod_php_testing', array('defaultContext' => 'http://talisaspire.com/', 'async' => array(OP_VIEWS => true, OP_TABLES => true, OP_SEARCH => false))));
     $searchIndexer = $this->getMock('\\Tripod\\Mongo\\Composites\\SearchIndexer', array('getSearchProvider', 'getImpactedSubjects'), array($tripod));
     $searchProvider = $this->getMock('\\Tripod\\Mongo\\MongoSearchProvider', array('deleteDocument', 'indexDocument'), array($tripod));
     $searchProvider->expects($this->exactly(1))->method('deleteDocument')->with($this->equalTo("http://talisaspire.com/lists/1234"), 'http://talisaspire.com/', $this->isEmpty());
     $searchProvider->expects($this->exactly(1))->method('indexDocument');
     $searchIndexer->expects($this->atLeastOnce())->method('getSearchProvider')->will($this->returnValue($searchProvider));
     $impactedSubject = $this->getMockBuilder('\\Tripod\\Mongo\\ImpactedSubject')->setConstructorArgs(array(array(_ID_RESOURCE => 'http://talisaspire.com/lists/1234', _ID_CONTEXT => 'http://talisaspire.com/'), OP_SEARCH, 'tripod_php_testing', 'CBD_testing'))->setMethods(array('getTripod'))->getMock();
     $impactedSubject->expects($this->once())->method('getTripod')->will($this->returnValue($tripod));
     $searchIndexer->expects($this->once())->method('getImpactedSubjects')->will($this->returnValue(array($impactedSubject)));
     $tripod->expects($this->atLeastOnce())->method('getSearchIndexer')->will($this->returnValue($searchIndexer));
     $list = new \Tripod\ExtendedGraph();
     $list->add_resource_triple("http://talisaspire.com/lists/1234", RDF_TYPE, "http://purl.org/vocab/resourcelist/schema#List");
     $list->add_literal_triple("http://talisaspire.com/lists/1234", "http://rdfs.org/sioc/spec/name", "Testing list");
     $tripod->saveChanges(new \Tripod\ExtendedGraph(), $list);
     // Regen our search docs for real since this step was overridden in the stub
     $this->tripod->getSearchIndexer()->generateAndIndexSearchDocuments("http://talisaspire.com/lists/1234", "http://talisaspire.com/", 'CBD_testing');
     // Now make a change to the last document
     $tripod = $this->getMock('\\Tripod\\Mongo\\Driver', array('getSearchIndexer'), array('CBD_testing', 'tripod_php_testing', array('defaultContext' => 'http://talisaspire.com/', 'async' => array(OP_VIEWS => true, OP_TABLES => true, OP_SEARCH => false))));
     $searchIndexer = $this->getMock('\\Tripod\\Mongo\\Composites\\SearchIndexer', array('getSearchProvider', 'getImpactedSubjects'), array($tripod));
     $searchProvider = $this->getMock('\\Tripod\\Mongo\\MongoSearchProvider', array('deleteDocument', 'indexDocument'), array($tripod));
     $impactedSubject = $this->getMockBuilder('\\Tripod\\Mongo\\ImpactedSubject')->setConstructorArgs(array(array(_ID_RESOURCE => 'http://talisaspire.com/lists/1234', _ID_CONTEXT => 'http://talisaspire.com/'), OP_SEARCH, 'tripod_php_testing', 'CBD_testing', array('i_search_list')))->setMethods(array('getTripod'))->getMock();
     $impactedSubject->expects($this->once())->method('getTripod')->will($this->returnValue($tripod));
     $searchProvider->expects($this->exactly(1))->method('deleteDocument')->with($this->equalTo("http://talisaspire.com/lists/1234"), 'http://talisaspire.com/', array('i_search_list'));
     $searchProvider->expects($this->exactly(1))->method('indexDocument');
     $searchIndexer->expects($this->atLeastOnce())->method('getSearchProvider')->will($this->returnValue($searchProvider));
     $searchIndexer->expects($this->once())->method('getImpactedSubjects')->will($this->returnValue(array($impactedSubject)));
     $tripod->expects($this->atLeastOnce())->method('getSearchIndexer')->will($this->returnValue($searchIndexer));
     $oldList = $tripod->describeResource("http://talisaspire.com/lists/1234");
     $list = $tripod->describeResource("http://talisaspire.com/lists/1234");
     /** @var ExtendedGraph $list */
     $list->remove_property_values("http://talisaspire.com/lists/1234", "http://rdfs.org/sioc/spec/name");
     $list->add_literal_triple("http://talisaspire.com/lists/1234", "http://rdfs.org/sioc/spec/name", "IMPROVED testing list");
     $tripod->saveChanges($oldList, $list);
     // Regen our search docs for real since this step was overridden in the stub again
     $this->tripod->getSearchIndexer()->generateAndIndexSearchDocuments("http://talisaspire.com/lists/1234", "http://talisaspire.com/", 'CBD_testing');
 }
 public function testCreateJobSpecifyQueue()
 {
     $labeller = new \Tripod\Mongo\Labeller();
     $subjectsAndPredicatesOfChange = array($labeller->uri_to_alias('http://example.com/1') => array('rdf:type', 'spec:name'), $labeller->uri_to_alias('http://example.com/2') => array('rdf:type', 'dct:title', 'dct:subject'));
     $jobData = array('changes' => $subjectsAndPredicatesOfChange, 'operations' => array(OP_SEARCH), 'tripodConfig' => \Tripod\Mongo\Config::getConfig(), 'storeName' => 'tripod_php_testing', 'podName' => 'CBD_testing', 'contextAlias' => 'http://talisaspire.com/');
     $queueName = \Tripod\Mongo\Config::getDiscoverQueueName() . '::TRIPOD_TESTING_QUEUE_' . uniqid();
     /** @var \Tripod\Mongo\Jobs\DiscoverImpactedSubjects|PHPUnit_Framework_MockObject_MockObject $discoverImpactedSubjects */
     $discoverImpactedSubjects = $this->getMockBuilder('\\Tripod\\Mongo\\Jobs\\DiscoverImpactedSubjects')->setMethods(array('submitJob'))->setMockClassName('MockDiscoverImpactedSubjects')->getMock();
     $discoverImpactedSubjects->expects($this->once())->method('submitJob')->with($queueName, 'MockDiscoverImpactedSubjects', $jobData);
     $discoverImpactedSubjects->createJob($jobData, $queueName);
 }
 /**
  * Test that a change to a resource that isn't covered by a viewspec or in an impact index still triggers the discover
  * impacted subjects operation and returns nothing
  */
 public function testResourceUpdateNotCoveredBySpecStillTriggersOperations()
 {
     $context = 'http://talisaspire.com/';
     $labeller = new \Tripod\Mongo\Labeller();
     // First add a graph
     $originalGraph = new \Tripod\ExtendedGraph();
     $uri1 = 'http://example.com/resources/' . uniqid();
     $originalGraph->add_resource_triple($uri1, RDF_TYPE, $labeller->qname_to_uri('bibo:Document'));
     $originalGraph->add_literal_triple($uri1, $labeller->qname_to_uri('dct:title'), 'How to speak American like a native');
     $originalGraph->add_literal_triple($uri1, $labeller->qname_to_uri('dct:subject'), 'Languages -- \'Murrican');
     $originalSubjectsAndPredicatesOfChange = array($labeller->uri_to_alias($uri1) => array('rdf:type', 'dct:title', 'dct:subject'));
     $updatedSubjectsAndPredicatesOfChange = array($labeller->uri_to_alias($uri1) => array('dct:subject'));
     /** @var \Tripod\Mongo\Driver|PHPUnit_Framework_MockObject_MockObject $mockTripod */
     $mockTripod = $this->getMock('\\Tripod\\Mongo\\Driver', array('getDataUpdater', 'getComposite'), array('CBD_testing', 'tripod_php_testing', array('defaultContext' => $context, OP_ASYNC => array(OP_TABLES => true, OP_VIEWS => false, OP_SEARCH => true))));
     $mockTripodUpdates = $this->getMock('\\Tripod\\Mongo\\Updates', array('processSyncOperations', 'queueAsyncOperations'), array($mockTripod, array(OP_ASYNC => array(OP_TABLES => true, OP_VIEWS => false, OP_SEARCH => true))));
     $mockViews = $this->getMock('\\Tripod\\Mongo\\Composites\\Views', array('generateViewsForResourcesOfType'), array('tripod_php_testing', \Tripod\Mongo\Config::getInstance()->getCollectionForCBD('tripod_php_testing', 'CBD_testing'), $context));
     $mockTripod->expects($this->exactly(2))->method('getDataUpdater')->will($this->returnValue($mockTripodUpdates));
     $mockTripod->expects($this->exactly(2))->method('getComposite')->with(OP_VIEWS)->will($this->returnValue($mockViews));
     $mockTripodUpdates->expects($this->exactly(2))->method('processSyncOperations')->withConsecutive(array($this->equalTo($originalSubjectsAndPredicatesOfChange), $this->equalTo($context)), array($this->equalTo($updatedSubjectsAndPredicatesOfChange), $this->equalTo($context)));
     $mockTripodUpdates->expects($this->exactly(2))->method('queueAsyncOperations')->withConsecutive(array($this->equalTo($originalSubjectsAndPredicatesOfChange), $this->equalTo($context)), array($this->equalTo($updatedSubjectsAndPredicatesOfChange), $this->equalTo($context)));
     $mockViews->expects($this->never())->method('generateViewsForResourcesOfType');
     $mockTripod->saveChanges(new \Tripod\ExtendedGraph(), $originalGraph);
     /** @var \Tripod\Mongo\Composites\Views $view */
     $view = $mockTripod->getComposite(OP_VIEWS);
     $this->assertInstanceOf('\\Tripod\\Mongo\\Composites\\Views', $view);
     $impactedSubjects = $view->getImpactedSubjects($originalSubjectsAndPredicatesOfChange, $context);
     $this->assertEmpty($impactedSubjects);
     $newGraph = $originalGraph->get_subject_subgraph($uri1);
     $newGraph->replace_literal_triple($uri1, $labeller->qname_to_uri('dct:subject'), 'Languages -- \'Murrican', 'Languages -- English, American');
     $mockTripod->saveChanges($originalGraph, $newGraph);
     /** @var \Tripod\Mongo\Composites\Views $view */
     $view = $mockTripod->getComposite(OP_VIEWS);
     $this->assertInstanceOf('\\Tripod\\Mongo\\Composites\\Views', $view);
     $impactedSubjects = $view->getImpactedSubjects($updatedSubjectsAndPredicatesOfChange, $context);
     $this->assertEmpty($impactedSubjects);
 }
 public function testRemoveTableSpecDoesNotAffectInvalidation()
 {
     foreach (\Tripod\Mongo\Config::getInstance()->getTableSpecifications($this->tripod->getStoreName()) as $specId => $spec) {
         $this->generateTableRows($specId);
     }
     $context = 'http://talisaspire.com/';
     $uri = "http://talisaspire.com/works/4d101f63c10a6";
     $collection = \Tripod\Mongo\Config::getInstance()->getCollectionForTable('tripod_php_testing', 't_resource');
     $this->assertGreaterThan(0, $collection->count(array('_id.type' => 't_resource', 'value._impactIndex' => array(_ID_RESOURCE => $uri, _ID_CONTEXT => $context))));
     $config = \Tripod\Mongo\Config::getConfig();
     unset($config['stores']['tripod_php_testing']['table_specifications'][0]);
     \Tripod\Mongo\Config::setConfig($config);
     /** @var PHPUnit_Framework_MockObject_MockObject|\Tripod\Mongo\Driver $mockTripod */
     $mockTripod = $this->getMockBuilder('\\Tripod\\Mongo\\Driver')->setMethods(array('getComposite'))->setConstructorArgs(array('CBD_testing', 'tripod_php_testing', array('defaultContext' => $context, OP_ASYNC => array(OP_VIEWS => true, OP_TABLES => false, OP_SEARCH => true))))->getMock();
     $mockTables = $this->getMockBuilder('\\Tripod\\Mongo\\Composites\\Tables')->setMethods(array('update'))->setConstructorArgs(array('tripod_php_testing', \Tripod\Mongo\Config::getInstance()->getCollectionForCBD('tripod_php_testing', 'CBD_testing'), $context))->getMock();
     $labeller = new \Tripod\Mongo\Labeller();
     $mockTripod->expects($this->once())->method('getComposite')->with(OP_TABLES)->will($this->returnValue($mockTables));
     $mockTables->expects($this->never())->method('update');
     $originalGraph = $mockTripod->describeResource($uri);
     $updatedGraph = $originalGraph->get_subject_subgraph($uri);
     $updatedGraph->add_literal_triple($uri, $labeller->qname_to_uri('dct:description'), 'Physics textbook');
     $mockTripod->saveChanges($originalGraph, $updatedGraph);
     // The table row should still be there, even if the tablespec no longer exists
     $this->assertGreaterThan(0, $collection->count(array('_id.type' => 't_resource', 'value._impactIndex' => array(_ID_RESOURCE => $uri, _ID_CONTEXT => $context))));
 }
 public function testSpecifyQueueForAsyncOperations()
 {
     $uri_1 = "http://example.com/1";
     $uri_2 = "http://example.com/2";
     $oG = new \Tripod\Mongo\MongoGraph();
     $oG->add_resource_triple($uri_1, $oG->qname_to_uri("rdf:type"), $oG->qname_to_uri("acorn:Resource"));
     $oG->add_resource_triple($uri_2, $oG->qname_to_uri("rdf:type"), $oG->qname_to_uri("acorn:Resource"));
     // a delete and an update
     $nG = new \Tripod\Mongo\MongoGraph();
     $nG->add_graph($oG);
     $nG->add_literal_triple($uri_1, $nG->qname_to_uri("searchterms:title"), "wibble");
     $nG->remove_resource_triple($uri_2, $oG->qname_to_uri("rdf:type"), "http://foo/bar#Class2");
     /** @var \Tripod\Mongo\Driver|PHPUnit_Framework_MockObject_MockObject $mockTripod */
     $mockTripod = $this->getMock('\\Tripod\\Mongo\\Driver', array('getComposite', 'getDataUpdater'), array('CBD_testing', 'tripod_php_testing', array('defaultContext' => 'http://talisaspire.com/')));
     $queueName = 'TRIPOD_TESTING_QUEUE_' . uniqid();
     $mockTripodUpdates = $this->getMock('\\Tripod\\Mongo\\Updates', array('storeChanges', 'getDiscoverImpactedSubjects'), array($mockTripod, array(OP_ASYNC => array(OP_TABLES => true, OP_VIEWS => false, OP_SEARCH => true, 'queue' => $queueName))));
     $mockViews = $this->getMock('\\Tripod\\Mongo\\Composites\\Views', array('getImpactedSubjects', 'update'), array('tripod_php_testing', \Tripod\Mongo\Config::getInstance()->getCollectionForCBD('tripod_php_testing', 'CBD_testing'), 'http://talisaspire.com/'));
     $mockDiscoverImpactedSubjects = $this->getMockBuilder('\\Tripod\\Mongo\\Jobs\\DiscoverImpactedSubjects')->setMethods(array('createJob'))->getMock();
     $impactedViewSubjects = array($this->getMockBuilder('\\Tripod\\Mongo\\ImpactedSubject')->setConstructorArgs(array(array(_ID_RESOURCE => $uri_1, _ID_CONTEXT => 'http://talisaspire.com'), OP_VIEWS, 'tripod_php_testing', 'CBD_testing'))->setMethods(array('update'))->getMock(), $this->getMockBuilder('\\Tripod\\Mongo\\ImpactedSubject')->setConstructorArgs(array(array(_ID_RESOURCE => $uri_2, _ID_CONTEXT => 'http://talisaspire.com'), OP_VIEWS, 'tripod_php_testing', 'CBD_testing'))->setMethods(array('update'))->getMock());
     $labeller = new \Tripod\Mongo\Labeller();
     $subjectsAndPredicatesOfChange = array($labeller->uri_to_alias($uri_1) => array('searchterms:title'), $labeller->uri_to_alias($uri_2) => array('rdf:type'));
     $jobData = array('changes' => $subjectsAndPredicatesOfChange, 'operations' => array(OP_TABLES, OP_SEARCH), 'tripodConfig' => \Tripod\Mongo\Config::getConfig(), 'storeName' => 'tripod_php_testing', 'podName' => 'CBD_testing', 'contextAlias' => 'http://talisaspire.com/', 'queue' => $queueName, 'statsConfig' => array());
     // getComposite() should only be called if there are synchronous operations
     $mockTripod->expects($this->once())->method('getComposite')->with(OP_VIEWS)->will($this->returnValue($mockViews));
     $mockTripodUpdates->expects($this->once())->method('getDiscoverImpactedSubjects')->will($this->returnValue($mockDiscoverImpactedSubjects));
     $mockTripodUpdates->expects($this->once())->method('storeChanges')->will($this->returnValue(array("subjectsAndPredicatesOfChange" => $subjectsAndPredicatesOfChange, "transaction_id" => "t1234")));
     $mockTripod->expects($this->once())->method('getDataUpdater')->will($this->returnValue($mockTripodUpdates));
     $mockViews->expects($this->once())->method('getImpactedSubjects')->will($this->returnValue($impactedViewSubjects));
     // This shouldn't be called because ImpactedSubject->update has been mocked and isn't doing anything
     $mockViews->expects($this->never())->method('update');
     $impactedViewSubjects[0]->expects($this->once())->method('update');
     $impactedViewSubjects[1]->expects($this->once())->method('update');
     $mockDiscoverImpactedSubjects->expects($this->once())->method('createJob')->with($jobData, $queueName);
     $mockTripod->saveChanges($oG, $nG, "http://talisaspire.com/");
 }
 public function testTransactionLogIsWrittenToCorrectDBAndCollection()
 {
     $storeName = 'tripod_php_testing';
     $newConfig = \Tripod\Mongo\Config::getConfig();
     $newConfig['transaction_log']['database'] = 'tripod_php_testing_transaction_log';
     $newConfig['transaction_log']['collection'] = 'transaction_log';
     \Tripod\Mongo\Config::setConfig($newConfig);
     $config = \Tripod\Mongo\Config::getInstance();
     // Clear out any old data
     $tlogDB = $config->getTransactionLogDatabase();
     $tlogDB->drop();
     // Make sure the dbs do not exist
     $transactionConnInfo = $newConfig['data_sources'][$newConfig['transaction_log']['data_source']];
     $options = isset($transactionConnInfo['replicaSet']) && !empty($transactionConnInfo['replicaSet']) ? array('replicaSet' => $transactionConnInfo['replicaSet']) : array();
     $transactionMongo = new Client($transactionConnInfo['connection'], $options);
     $transactionDbInfo = $transactionMongo->listDatabases();
     foreach ($transactionDbInfo as $db) {
         $this->assertNotEquals($db->getName(), $newConfig['transaction_log']['database']);
     }
     $tqueuesConnInfo = $newConfig['data_sources'][$newConfig['transaction_log']['data_source']];
     $options = isset($tqueuesConnInfo['replicaSet']) && !empty($tqueuesConnInfo['replicaSet']) ? array('replicaSet' => $tqueuesConnInfo['replicaSet']) : array();
     $queuesMongo = new Client($tqueuesConnInfo['connection'], $options);
     $queuesDbInfo = $queuesMongo->listDatabases();
     foreach ($queuesDbInfo as $db) {
         $this->assertNotEquals($db->getName(), $newConfig['transaction_log']['database']);
     }
     // Start adding some data
     $this->tripod = new \Tripod\Mongo\Driver('CBD_testing', $storeName, array(OP_ASYNC => array(OP_VIEWS => true, OP_TABLES => false, OP_SEARCH => false)));
     $this->loadResourceDataViaTripod();
     $graph = new \Tripod\Mongo\MongoGraph();
     $subject = 'http://example.com/' . uniqid();
     $labeller = new \Tripod\Mongo\Labeller();
     $graph->add_resource_triple($subject, RDF_TYPE, $labeller->qname_to_uri('foaf:Person'));
     $graph->add_literal_triple($subject, FOAF_NAME, "Anne Example");
     $this->tripod->saveChanges(new \Tripod\ExtendedGraph(), $graph);
     $newGraph = $this->tripod->describeResource($subject);
     $newGraph->add_literal_triple($subject, $labeller->qname_to_uri('foaf:email'), '*****@*****.**');
     $this->tripod->saveChanges($graph, $newGraph);
     // Make sure the dbs do now exist
     $transactionDbInfo = $transactionMongo->listDatabases();
     $transactionDbExists = false;
     foreach ($transactionDbInfo as $db) {
         if ($db->getName() === $newConfig['transaction_log']['database']) {
             $transactionDbExists = true;
         }
     }
     $this->assertTrue($transactionDbExists);
     // Make sure the data in the dbs look right
     $transactionColletion = $transactionMongo->selectCollection($newConfig['transaction_log']['database'], $newConfig['transaction_log']['collection']);
     $transactionCount = $transactionColletion->count();
     $transactionExampleDocument = $transactionColletion->findOne();
     $this->assertEquals(24, $transactionCount);
     $this->assertContains('transaction_', $transactionExampleDocument["_id"]);
 }
 /**
  * @param string $subject
  * @param string $transaction_id
  */
 protected function lockDocument($subject, $transaction_id)
 {
     $collection = \Tripod\Mongo\Config::getInstance()->getCollectionForLocks('tripod_php_testing');
     $labeller = new \Tripod\Mongo\Labeller();
     $doc = array('_id' => array(_ID_RESOURCE => $labeller->uri_to_alias($subject), _ID_CONTEXT => \Tripod\Mongo\Config::getInstance()->getDefaultContextAlias()), _LOCKED_FOR_TRANS => $transaction_id, _LOCKED_FOR_TRANS_TS => \Tripod\Mongo\DateUtil::getMongoDate());
     $collection->insertOne($doc, array("w" => 1));
 }
 public function testDeleteResourceCreatesImpactedSubjects()
 {
     $uri = 'http://example.com/resources/' . uniqid();
     $labeller = new Tripod\Mongo\Labeller();
     $uriAlias = $labeller->uri_to_alias($uri);
     $creatorUri = 'http://example.com/identities/oscar-wilde';
     $creatorUriAlias = $labeller->uri_to_alias($creatorUri);
     $graph = new \Tripod\ExtendedGraph();
     $graph->add_resource_triple($uri, RDF_TYPE, $labeller->qname_to_uri('acorn:Resource'));
     $graph->add_resource_triple($uri, RDF_TYPE, $labeller->qname_to_uri('bibo:Book'));
     $graph->add_literal_triple($uri, $labeller->qname_to_uri('dct:title'), 'The Importance of Being Earnest');
     $graph->add_literal_triple($uri, $labeller->qname_to_uri('dct:subject'), 'Plays -- Satire');
     $graph->add_resource_triple($uri, $labeller->qname_to_uri('dct:creator'), $creatorUri);
     $uri2 = 'http://example.com/resources/' . uniqid();
     $uriAlias2 = $labeller->uri_to_alias($uri2);
     $graph2 = new \Tripod\ExtendedGraph();
     $graph2->add_resource_triple($uri2, RDF_TYPE, $labeller->qname_to_uri('acorn:Resource'));
     $graph2->add_resource_triple($uri2, RDF_TYPE, $labeller->qname_to_uri('bibo:Book'));
     $graph2->add_literal_triple($uri2, $labeller->qname_to_uri('dct:title'), 'The Picture of Dorian Gray');
     $graph2->add_literal_triple($uri2, $labeller->qname_to_uri('dct:subject'), 'Portraits -- Fiction');
     $graph2->add_resource_triple($uri2, $labeller->qname_to_uri('dct:creator'), $creatorUri);
     $graph3 = new \Tripod\ExtendedGraph();
     $graph3->add_resource_triple($creatorUri, RDF_TYPE, $labeller->qname_to_uri('foaf:Person'));
     $graph3->add_literal_triple($creatorUri, $labeller->qname_to_uri('foaf:name'), 'Oscar Wilde');
     // Save the graphs and ensure that table rows are generated
     $tripod = new \Tripod\Mongo\Driver($this->defaultPodName, $this->defaultStoreName, array('defaultContext' => $this->defaultContext, OP_ASYNC => array(OP_VIEWS => false, OP_TABLES => false, OP_SEARCH => false)));
     // Save the author graph first so the joins work
     $tripod->saveChanges(new \Tripod\ExtendedGraph(), $graph3);
     $tripod->saveChanges(new \Tripod\ExtendedGraph(), $graph);
     $collection = \Tripod\Mongo\Config::getInstance()->getCollectionForSearchDocument($this->defaultStoreName, 'i_search_resource');
     $query = array(_ID_KEY => array(_ID_RESOURCE => $uriAlias, _ID_CONTEXT => $this->defaultContext, _ID_TYPE => 'i_search_resource'));
     $this->assertEquals(1, $collection->count($query));
     $tripod->saveChanges(new \Tripod\ExtendedGraph(), $graph2);
     $query[_ID_KEY][_ID_RESOURCE] = $uriAlias2;
     $this->assertEquals(1, $collection->count($query));
     $impactQuery = array(_ID_KEY . '.' . _ID_TYPE => 'i_search_resource', '_impactIndex' => array(_ID_RESOURCE => $creatorUriAlias, _ID_CONTEXT => $this->defaultContext), 'result.author' => 'Oscar Wilde');
     $this->assertEquals(2, $collection->count($impactQuery));
     /** @var \Tripod\Mongo\Driver|PHPUnit_Framework_MockObject_MockObject $mockTripod */
     $mockTripod = $this->getMockBuilder('\\Tripod\\Mongo\\Driver')->setMethods(array('getDataUpdater'))->setConstructorArgs(array($this->defaultPodName, $this->defaultStoreName, array('defaultContext' => $this->defaultContext, OP_ASYNC => array(OP_VIEWS => false, OP_TABLES => false, OP_SEARCH => false))))->getMock();
     $mockTripodUpdates = $this->getMockBuilder('\\Tripod\\Mongo\\Updates')->setConstructorArgs(array($mockTripod, array('defaultContext' => $this->defaultContext, OP_ASYNC => array(OP_VIEWS => false, OP_TABLES => false, OP_SEARCH => false))))->setMethods(array('processSyncOperations'))->getMock();
     $mockTripod->expects($this->once())->method('getDataUpdater')->will($this->returnValue($mockTripodUpdates));
     $expectedSubjectsAndPredicatesOfChange = array($creatorUriAlias => array('rdf:type', 'foaf:name'));
     $mockTripodUpdates->expects($this->once())->method('processSyncOperations')->with($expectedSubjectsAndPredicatesOfChange, $this->defaultContext);
     // Delete creator resource
     $mockTripod->saveChanges($graph3, new \Tripod\ExtendedGraph());
     $deletedGraph = $mockTripod->describeResource($creatorUri);
     $this->assertTrue($deletedGraph->is_empty());
     // Manually walk through the tables operation
     /** @var \Tripod\Mongo\Composites\SearchIndexer $search */
     $search = $mockTripod->getComposite(OP_SEARCH);
     $expectedImpactedSubjects = array(new \Tripod\Mongo\ImpactedSubject(array(_ID_RESOURCE => $uriAlias, _ID_CONTEXT => $this->defaultContext), OP_SEARCH, $this->defaultStoreName, $this->defaultPodName, array('i_search_resource')), new \Tripod\Mongo\ImpactedSubject(array(_ID_RESOURCE => $uriAlias2, _ID_CONTEXT => $this->defaultContext), OP_SEARCH, $this->defaultStoreName, $this->defaultPodName, array('i_search_resource')));
     $this->assertEquals($expectedImpactedSubjects, $search->getImpactedSubjects($expectedSubjectsAndPredicatesOfChange, $this->defaultContext));
     foreach ($expectedImpactedSubjects as $subject) {
         $search->update($subject);
     }
     $query = array(_ID_KEY => array(_ID_RESOURCE => $uriAlias, _ID_CONTEXT => $this->defaultContext, _ID_TYPE => 'i_search_resource'));
     $this->assertEquals(1, $collection->count($query));
     $query[_ID_KEY][_ID_RESOURCE] = $uriAlias2;
     $this->assertEquals(1, $collection->count($query));
     // Deleted resource will still be impact indexes because join still exists
     $impactQuery = array(_ID_KEY . '.' . _ID_TYPE => 'i_search_resource', '_impactIndex' => array(_ID_RESOURCE => $creatorUriAlias, _ID_CONTEXT => $this->defaultContext));
     $this->assertEquals(2, $collection->count($impactQuery));
     // But the document should have been regenerated without the value
     $impactQuery['result.author'] = 'Oscar Wilde';
     $this->assertEquals(0, $collection->count($impactQuery));
 }