server/src/tests/Repositories/DocumentRepositoryTest.php
changeset 168 17f10b56c079
parent 143 023b6d467566
child 277 bd4bc1db4f40
equal deleted inserted replaced
167:009efee954f7 168:17f10b56c079
     3 use Illuminate\Support\Facades\Facade;
     3 use Illuminate\Support\Facades\Facade;
     4 
     4 
     5 use CorpusParole\Repositories\RdfDocumentRepository;
     5 use CorpusParole\Repositories\RdfDocumentRepository;
     6 use CorpusParole\Libraries\Sparql\SparqlClient;
     6 use CorpusParole\Libraries\Sparql\SparqlClient;
     7 use CorpusParole\Models\Document;
     7 use CorpusParole\Models\Document;
       
     8 use CorpusParole\Models\DocumentResult;
       
     9 
     8 
    10 
     9 use Mockery as m;
    11 use Mockery as m;
    10 
    12 
    11 class DocumentRepositoryTest extends TestCase {
    13 class DocumentRepositoryTest extends TestCase {
    12 
    14 
   106         $res = $documentRepository->all();
   108         $res = $documentRepository->all();
   107 
   109 
   108         $this->assertCount(1, $res, "Should have 1 doc in res");
   110         $this->assertCount(1, $res, "Should have 1 doc in res");
   109         $resDoc = $res[0];
   111         $resDoc = $res[0];
   110 
   112 
   111         $this->assertInstanceOf(Document::class, $resDoc, "Res doc must be a Document");
   113         $this->assertInstanceOf(DocumentResult::class, $resDoc, "Res doc must be a Document");
   112         $this->assertEquals(config('corpusparole.corpus_id_scheme').'crdo-ALA_738', $resDoc->getId(), "id must be crdo...");
   114         $this->assertEquals(config('corpusparole.corpus_id_scheme').'crdo-ALA_738', $resDoc->getId(), "id must be crdo...");
   113         $this->assertEquals($expectedId, $resDoc->getUri(), 'url must be ...');
   115         $this->assertEquals($expectedId, $resDoc->getUri(), 'url must be ...');
   114         $this->assertNotNull($resDoc->getGraph(), 'Graph must be not null');
   116         $this->assertNotNull($resDoc->getGraph(), 'Graph must be not null');
   115     }
   117     }
   116 
   118 
   125         $documentRepository = $this->app->make('CorpusParole\Repositories\RdfDocumentRepository', [$sparqlClientMock]);
   127         $documentRepository = $this->app->make('CorpusParole\Repositories\RdfDocumentRepository', [$sparqlClientMock]);
   126 
   128 
   127         $res = $documentRepository->get('crdo-ALA_738');
   129         $res = $documentRepository->get('crdo-ALA_738');
   128 
   130 
   129         $this->assertInstanceOf(Document::class, $res, "Result must be of type Document");
   131         $this->assertInstanceOf(Document::class, $res, "Result must be of type Document");
       
   132         $this->assertEquals(config('corpusparole.corpus_id_scheme').'crdo-ALA_738', $res->getId(), 'id should be crdo-ALA_738' );
       
   133         $this->assertNotNull($res->getGraph(), "Graph shoul not be null");
       
   134         $this->assertTrue(EasyRdf\Isomorphic::isomorphic($res->getGraph(), new EasyRdf\Graph($expectedId, sprintf(DocumentRepositoryTest::TEST_DOC, config('corpusparole.corpus_doc_id_base_uri')))));
       
   135     }
       
   136 
       
   137     public function testGetShort() {
       
   138 
       
   139         $expectedId = $this->corpusDocIdBaseUri.'crdo-ALA_738';
       
   140         $returnedGraph = new EasyRdf\Graph($expectedId, sprintf(DocumentRepositoryTest::TEST_DOC, config('corpusparole.corpus_doc_id_base_uri')));
       
   141 
       
   142         $sparqlClientMock = m::mock('CorpusParole\Libraries\Sparql\SparqlClient');
       
   143         $sparqlClientMock->shouldReceive('query')->with(\Hamcrest\Text\StringContains::containsString($expectedId))
       
   144             ->andReturn($returnedGraph);
       
   145         $documentRepository = $this->app->make('CorpusParole\Repositories\RdfDocumentRepository', [$sparqlClientMock]);
       
   146 
       
   147         $res = $documentRepository->get('crdo-ALA_738', true);
       
   148 
       
   149         $this->assertInstanceOf(DocumentResult::class, $res, "Result must be of type DocumentResult");
   130         $this->assertEquals(config('corpusparole.corpus_id_scheme').'crdo-ALA_738', $res->getId(), 'id should be crdo-ALA_738' );
   150         $this->assertEquals(config('corpusparole.corpus_id_scheme').'crdo-ALA_738', $res->getId(), 'id should be crdo-ALA_738' );
   131         $this->assertNotNull($res->getGraph(), "Graph shoul not be null");
   151         $this->assertNotNull($res->getGraph(), "Graph shoul not be null");
   132         $this->assertTrue(EasyRdf\Isomorphic::isomorphic($res->getGraph(), new EasyRdf\Graph($expectedId, sprintf(DocumentRepositoryTest::TEST_DOC, config('corpusparole.corpus_doc_id_base_uri')))));
   152         $this->assertTrue(EasyRdf\Isomorphic::isomorphic($res->getGraph(), new EasyRdf\Graph($expectedId, sprintf(DocumentRepositoryTest::TEST_DOC, config('corpusparole.corpus_doc_id_base_uri')))));
   133     }
   153     }
   134 
   154