diff -r 2b3247d02769 -r f55970e41793 server/src/tests/Repositories/DocumentRepositoryIntegrationTest.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/server/src/tests/Repositories/DocumentRepositoryIntegrationTest.php Mon Oct 05 17:02:10 2015 +0200 @@ -0,0 +1,173 @@ +. + @prefix rep: . + @prefix sr: . + @prefix sail: . + @prefix ms: . + + [] a rep:Repository ; + rep:repositoryID "%1\$s" ; + rdfs:label "%1\$s test repository" ; + rep:repositoryImpl [ + rep:repositoryType "openrdf:SailRepository" ; + sr:sailImpl [ + sail:sailType "openrdf:MemoryStore" ; + ms:persist false ; + ms:syncDelay 0 + ] + ]. +EOT; + + const TEST_DOC = << . + . + "Extrait des enqu\u00EAtes dialectologiques en vue de constituer un atlas linguistique de l'Alsace."@fr . + "audio/x-wav"^^ . + . + "primary_text"^^ . + "dialogue"^^ . + . + "lexicography"^^ . + "phonetics"^^ . + "anthropological_linguistics"^^ . + . + . + _:genid2d5831d84541df446694586ac2006f96042dgenid1 . + _:genid2d5831d84541df446694586ac2006f96042dgenid2 . + "Atlas linguistiques, cultures et parlers r\u00E9gionaux de France" . + "Copyright (c) D\u00E9partement de dialectologie alsacienne et mosellane de l'Universit\u00E9 de Strasbourg" . + "Atlas Linguistique et ethnographique de l'Alsace - Enquetes sur la conscience linguistique - ALA_608"@fr . + "Freely available for non-commercial use" . + . + . + . + "PT02H04M16S" . + "start=1980; end=1989; name=ann\u00E9es 80"^^ . + "France, Alsace"@fr . + "FR"^^ . + . + . + "2004-07-03"^^ . + "2014-11-04T16:25:54+01:00"^^ . + "Alsacien"@fr . + "Huck, Dominique" . + "depositor"^^ . + _:genid2d5831d84541df446694586ac2006f96042dgenid1 . + _:genid2d5831d84541df446694586ac2006f96042dgenid1 "Bothorel-Witz, Arlette" . + _:genid2d5831d84541df446694586ac2006f96042dgenid1 "interviewer"^^ . + _:genid2d5831d84541df446694586ac2006f96042dgenid2 . + _:genid2d5831d84541df446694586ac2006f96042dgenid2 "Huck, Dominique" . + _:genid2d5831d84541df446694586ac2006f96042dgenid2 "interviewer"^^ . +EOT; + + function __construct(string $name = null) { + parent::__construct($name); + $this->graph = new EasyRdf\Graph("http://purl.org/poi/crdo.vjf.cnrs.fr/crdo-ALA_608", DocumentRepositoryIntegrationTest::TEST_DOC); + } + + public function setUp() { + parent::setUp(); + + $this->httpClient = new Client(['base_uri' => config('corpusparole.sesame_base_url')]); + $this->sesameRepository = config('corpusparole.sesame_repository'); + $this->cocoonDocIdBaseUri = config('corpusparole.cocoon_doc_id_base_uri'); + + $this->documentRepository = $this->app->make('CorpusParole\Repositories\DocumentRepository'); + $uniqueid = uniqid('corpusparole', true); + $repoCreateStmt = sprintf(DocumentRepositoryIntegrationTest::REPO_CREATION_TTL, $this->sesameRepository); + $this->httpClient->delete("repositories/$this->sesameRepository", ['http_errors' => false]); + $this->httpClient->post('repositories/SYSTEM/statements', [ + 'headers' => ['Content-type' => 'application/x-turtle;charset=UTF-8'], + 'query' => ['context' => "_:$uniqueid"], + 'body' => $repoCreateStmt, + ]); + $this->httpClient->put("repositories/$this->sesameRepository/statements", [ + 'headers' => ['Content-type' => 'text/turtle;charset=UTF-8'], + 'body' => DocumentRepositoryIntegrationTest::TEST_DOC, + 'query' => ['context' => ''], + ]); + } + + public function tearDown() { + $this->httpClient->delete("repositories/$this->sesameRepository"); + parent::tearDown(); + } + + public function testAll() { + $expectedId = $this->cocoonDocIdBaseUri.'crdo-ALA_608'; + $docList = $this->documentRepository->all(); + $this->assertCount(1, $docList, "Should have one element"); + + $resDoc = $docList[0]; + + $this->assertInstanceOf(Document::class, $resDoc, "Res doc must be a Document"); + $this->assertEquals('crdo-ALA_608', $resDoc->getId(), "id must be crdo..."); + $this->assertEquals($expectedId, $resDoc->getUri(), 'url must be ...'); + $this->assertNull($resDoc->getGraph(), 'Graph must be null'); + + } + + public function testGet() { + + $expectedId = $this->cocoonDocIdBaseUri.'crdo-ALA_608'; + $returnedGraph = new EasyRdf\Graph($expectedId, DocumentRepositoryIntegrationTest::TEST_DOC); + + $res = $this->documentRepository->get('crdo-ALA_608'); + + $this->assertInstanceOf(Document::class, $res, "Result must be of type Document"); + $this->assertEquals('crdo-ALA_608', $res->getId(), 'id should be crdo-ALA_608' ); + $this->assertNotNull($res->getGraph(), "Graph shoul not be null"); + $this->assertTrue(EasyRdf\Isomorphic::isomorphic($res->getGraph(),$returnedGraph)); + } + + public function testSave() { + + $doc = new Document("http://purl.org/poi/crdo.vjf.cnrs.fr/crdo-ALA_608", $this->graph); + $doc->updateDiscourseTypes(['oratory','drama','narrative']); + + $res = $this->documentRepository->save($doc); + + $this->assertTrue($res, 'Has started a transaction'); + + $res = $this->documentRepository->get('crdo-ALA_608'); + + $discoursesTypes = $res->getDiscourseTypes(); + + $this->assertCount(3, $discoursesTypes, "types array must be of size 1"); + + $this->assertContainsOnlyInstancesOf("EasyRdf\Literal", $discoursesTypes, "Result contains only literals"); + + $newDiscoursesTypes = []; + foreach($discoursesTypes as $dt) { + array_push($newDiscoursesTypes, $dt->getValue()); + $this->assertContains($dt->getValue(),['oratory','drama','narrative'],'Value in [oratory,drama,narrative]'); + $this->assertEquals("http://www.language-archives.org/OLAC/1.1/discourse-type", $dt->getDatatypeUri(), "discourse type url"); + } + sort($newDiscoursesTypes); + $this->assertEquals(['drama', 'narrative', 'oratory'], $newDiscoursesTypes, "array type must the same"); + } + + public function testCount() { + $res = $this->documentRepository->getCount(); + + $this->assertNotNull($res, "Res should not be null"); + $this->assertSame(1, $res, "should heve only one document"); + } + + +}