server/src/tests/Repositories/DocumentRepositoryTest.php
changeset 168 17f10b56c079
parent 143 023b6d467566
child 277 bd4bc1db4f40
--- a/server/src/tests/Repositories/DocumentRepositoryTest.php	Thu Jun 02 18:16:17 2016 +0200
+++ b/server/src/tests/Repositories/DocumentRepositoryTest.php	Thu Jun 02 18:24:19 2016 +0200
@@ -5,6 +5,8 @@
 use CorpusParole\Repositories\RdfDocumentRepository;
 use CorpusParole\Libraries\Sparql\SparqlClient;
 use CorpusParole\Models\Document;
+use CorpusParole\Models\DocumentResult;
+
 
 use Mockery as m;
 
@@ -108,7 +110,7 @@
         $this->assertCount(1, $res, "Should have 1 doc in res");
         $resDoc = $res[0];
 
-        $this->assertInstanceOf(Document::class, $resDoc, "Res doc must be a Document");
+        $this->assertInstanceOf(DocumentResult::class, $resDoc, "Res doc must be a Document");
         $this->assertEquals(config('corpusparole.corpus_id_scheme').'crdo-ALA_738', $resDoc->getId(), "id must be crdo...");
         $this->assertEquals($expectedId, $resDoc->getUri(), 'url must be ...');
         $this->assertNotNull($resDoc->getGraph(), 'Graph must be not null');
@@ -132,6 +134,24 @@
         $this->assertTrue(EasyRdf\Isomorphic::isomorphic($res->getGraph(), new EasyRdf\Graph($expectedId, sprintf(DocumentRepositoryTest::TEST_DOC, config('corpusparole.corpus_doc_id_base_uri')))));
     }
 
+    public function testGetShort() {
+
+        $expectedId = $this->corpusDocIdBaseUri.'crdo-ALA_738';
+        $returnedGraph = new EasyRdf\Graph($expectedId, sprintf(DocumentRepositoryTest::TEST_DOC, config('corpusparole.corpus_doc_id_base_uri')));
+
+        $sparqlClientMock = m::mock('CorpusParole\Libraries\Sparql\SparqlClient');
+        $sparqlClientMock->shouldReceive('query')->with(\Hamcrest\Text\StringContains::containsString($expectedId))
+            ->andReturn($returnedGraph);
+        $documentRepository = $this->app->make('CorpusParole\Repositories\RdfDocumentRepository', [$sparqlClientMock]);
+
+        $res = $documentRepository->get('crdo-ALA_738', true);
+
+        $this->assertInstanceOf(DocumentResult::class, $res, "Result must be of type DocumentResult");
+        $this->assertEquals(config('corpusparole.corpus_id_scheme').'crdo-ALA_738', $res->getId(), 'id should be crdo-ALA_738' );
+        $this->assertNotNull($res->getGraph(), "Graph shoul not be null");
+        $this->assertTrue(EasyRdf\Isomorphic::isomorphic($res->getGraph(), new EasyRdf\Graph($expectedId, sprintf(DocumentRepositoryTest::TEST_DOC, config('corpusparole.corpus_doc_id_base_uri')))));
+    }
+
     public function testSave() {
 
         $sparqlClientMock = m::mock('CorpusParole\Libraries\Sparql\SparqlClient', function($mock) {