getOntologyMock(); $class = $ontologyMock->getClass('http://fakeClass'); $class->createInstance('Fake Item', '', 'http://fakeUri'); $persistence = $ontologyMock->getPersistence(); $persistenceManager = $this->getSqlMock('tmp'); $rds = $persistenceManager->getPersistenceById('tmp'); $schema = $rds->getSchemaManager()->createSchema(); $rdsSchema = new RdsSqlSchema(); $rdsSchema->setServiceLocator($ontologyMock->getServiceLocator()); $schema = $rdsSchema->getSchema($schema); $queries = $persistence->getPlatform()->schemaToSql($schema); foreach ($queries as $query) { $persistence->query($query); } $this->storage = new TestRdsStorage([RevisionStorageInterface::OPTION_PERSISTENCE => self::PERSISTENCE_KEY]); $this->storage->setServiceLocator($ontologyMock->getServiceLocator()); } public function tearDown(): void { $this->storage = null; } public function testAddRevision() { $triples = $this->getTriplesMock(); $revision = new Revision('123', 456, time(), 'author', 'message'); $persistence = $this->storage ->getServiceLocator() ->get(PersistenceManager::SERVICE_ID) ->getPersistenceById(self::PERSISTENCE_KEY); // no any revision in the storage $count = $persistence->query('select count(*) as count from revision')->fetch()['count']; $countData = $persistence->query('select count(*) as count from revision_data')->fetch()['count']; $this->assertEquals(0, $count); $this->assertEquals(0, $countData); // adding one revision to the storage $addedRevision = $this->storage->addRevision($revision, $triples->toArray()); $count = $persistence->query('select count(*) as count from revision')->fetch()['count']; $countData = $persistence->query('select count(*) as count from revision_data')->fetch()['count']; $this->assertEquals(1, $count); $this->assertEquals(2, $countData); $this->assertEquals($revision, $addedRevision); $this->assertEquals($triples, $this->storage->getData($addedRevision)); } public function testGetRevision() { $revision = new Revision('123', 456, time(), 'author', 'message'); $this->storage->addRevision($revision, []); // returned revision is exact that was added $returnedRevision = $this->storage->getRevision('123', 456); $this->assertEquals($revision, $returnedRevision); // incorrect revision version, not found error raised $this->expectException(RevisionNotFoundException::class); $this->storage->getRevision('123', 789); } public function testGetAllRevisions() { $resourceId = '123'; $revisionOne = new Revision($resourceId, 456, time(), 'author', 'message one'); $revisionTwo = new Revision($resourceId, 789, time(), 'author', 'message two'); $revisions = [ $this->storage->addRevision($revisionOne, []), $this->storage->addRevision($revisionTwo, []), ]; $allRevisions = $this->storage->getAllRevisions($resourceId); $this->assertEquals($revisions, $allRevisions); } public function testGetData() { $triples = $this->getTriplesMock(); $revision = $this->storage->addRevision( new Revision('123', 234, time(), 'author', 'message'), $triples->toArray() ); $data = $this->storage->getData($revision); $this->assertEquals($triples, $data); } public function testGetResourcesUriByQuery() { $triples = $this->getTriplesMock(); $revision = new Revision('http://fakeUri', 456, time(), 'author', 'message'); $this->storage->addRevision($revision, $triples->toArray()); $data = $this->storage->getResourcesUriByQuery('first', [], 'my first predicate'); $this->assertEquals(['http://fakeUri'], $data); } public function testGetResourcesDataByQuery() { $triples = $this->getTriplesMock(); $revision = new Revision('http://fakeUri', 456, time(), 'author', 'message'); $this->storage->addRevision($revision, $triples->toArray()); $data = $this->storage->getResourcesDataByQuery('first', [], 'my first predicate'); $this->assertCount(1, $data); $this->assertEquals( [ 'id' => 'http://fakeUri', 'label' => 'my first object', ], $data[0] ); } public function testBuildRevisionCollection() { $dataBank = []; for ($i = 0; $i < 3; $i++) { $resourceId = '123' . $i; $version = $i; $created = time() + $i; $user = 'author ' . $i; $message = 'message ' . $i; $dataBank['data'][] = [ RdsStorage::REVISION_RESOURCE => $resourceId, RdsStorage::REVISION_VERSION => $version, RdsStorage::REVISION_CREATED => $created, RdsStorage::REVISION_USER => $user, RdsStorage::REVISION_MESSAGE => $message ]; $dataBank['revisions'][] = new Revision($resourceId, $version, $created, $user, $message); } $this->assertEquals($dataBank['revisions'], $this->storage->buildRevisionCollection($dataBank['data'])); } } class TestRdsStorage extends RdsStorage { protected function getLocalModel() { return new common_ext_Namespace(1); } protected function getLike() { return 'LIKE'; } }