diff -r ac3dc090e987 -r f2a40bbc27f6 server/src/tests/libraries/Mappers/CocoonTextRdfMapperTest.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/server/src/tests/libraries/Mappers/CocoonTextRdfMapperTest.php Tue Nov 17 13:11:55 2015 +0100 @@ -0,0 +1,203 @@ + << . + @prefix owl: . + @prefix xsd: . + @prefix fn: . + @prefix rdfs: . + @prefix sesame: . + @prefix v: . + a ; + "Voilà pourquoi le bernard-l'hermite, aujourd'hui, se cache dans les coquilles vides qu'il trouve, alors que le crabe de cocotier n'a pas honte de se promener tout nu."@fr ; + "text/xml"^^ ; + "primary_text"^^ , , "narrative"^^ ; + ; + ; + ; + ; + "Copyright (c) Moyse-Faurie, Claire" ; + "The two hermit crabs and the coconut crab"@en ; + , ; + "Freely available for non-commercial use" ; + ; + , ; + "NC"^^ , "New Caledonia, Ohnyat (Ouvéa)" ; + "2011-02-05"^^ ; + "2011-02-05T23:22:23+01:00"^^ ; + "Idakote, Félicien" ; + ; + "Les deux bernard-l'hermite et le crabe de cocotier"@fr ; + "Moyse-Faurie, Claire" ; + "2002-02-20"^^ ; + . +EOT + ]; + + const TEST_INPUT_ID = "crdo-UVE_MOCIKA_SOUND"; + const TEST_GRAPH_URI = "http://purl.org/poi/corpusdelaparole.huma-num.fr/crdo-UVE_MOCIKA_SOUND"; + const TEST_CHO_URI = "http://purl.org/poi/crdo.vjf.cnrs.fr/crdo-UVE_MOCIKA_SOUND"; + + + private $inputGraphes = []; + private $resGraphes = []; + private $mappers = []; + + function __construct(string $name = null) { + parent::__construct($name); + } + + public function setUp() { + parent::setUp(); + + foreach(CocoonTextRdfMapperTest::TEST_INPUT_DOCS as $key => $inputDoc) { + $this->inputGraphes[$key] = new Graph("http://purl.org/poi/crdo.vjf.cnrs.fr/crdo-UVE_MOCIKA", $inputDoc); + $this->mappers[$key] = new CocoonTextRdfMapper($this->inputGraphes[$key]); + $this->mappers[$key]->mapGraph(); + $this->resGraphes[$key] = $this->mappers[$key]->getOutputGraphes()["http://purl.org/poi/crdo.vjf.cnrs.fr/crdo-UVE_MOCIKA_SOUND"]; + } + } + + public function tearDown() { + parent::tearDown(); + } + + /** + * Just test that the construct and setup are ok + * + * @return void + */ + public function testInit() + { + $this->assertTrue(true); + } + + /** + * Test that the returned graph has the same uri that the original. + * + * @return void + */ + public function testUri() { + + echo $this->resGraphes['BASE']->serialise('turtle'); + //echo var_export($this->resGraphes['BASE']->toRdfPhp()); + + $this->assertNotNull($this->resGraphes['BASE']); + $this->assertEquals(CocoonTextRdfMapperTest::TEST_GRAPH_URI, $this->resGraphes['BASE']->getUri(), "URIS must be translated"); + } + + /** + * Test that the return graph has one ore:Aggregation resource + * + * @return void + */ + public function testAggregationResource() { + + $resources = $this->resGraphes['BASE']->allOfType('ore:Aggregation'); + + $this->assertCount(1, $resources, "Must found only one resources of type ore:Aggregation"); + $this->assertEquals(CocoonTextRdfMapperTest::TEST_GRAPH_URI,$resources[0]->getUri()); + } + + /** + * Test providedCHO uri. + * + * @return void + */ + public function testProvidedChoURI() { + $resources = $this->resGraphes['BASE']->allOfType('edm:ProvidedCHO'); + + $this->assertCount(1, $resources, "Must found only one resources of type edm:ProvidedCHO"); + $this->assertEquals(CocoonTextRdfMapperTest::TEST_CHO_URI,$resources[0]->getUri()); + } + + /** + * Test taht the returned graph does not have a http://purl.org/dc/dcmitype/Sound type + * + * @return void + */ + public function testType() { + //"primary_text"^^ , , "narrative"^^ ; + $providedCHO = $this->resGraphes['BASE']->get('edm:ProvidedCHO', '^rdf:type'); + + $this->assertNotNull($providedCHO); + + $this->assertEmpty($providedCHO->all($this->resGraphes['BASE']->resource('http://purl.org/dc/elements/1.1/type'), 'resource'), 'Should not find dc element:type value as resource'); + $this->assertcount(2, $providedCHO->all($this->resGraphes['BASE']->resource('http://purl.org/dc/elements/1.1/type')), 'but should find 2 literals'); + + $expResMap = [ + 'primary_text' => 'http://www.language-archives.org/OLAC/1.1/linguistic-type', + 'narrative' => 'http://www.language-archives.org/OLAC/1.1/discourse-type' + ]; + + $dcTypeList = $providedCHO->all($this->resGraphes['BASE']->resource('http://purl.org/dc/elements/1.1/type')); + foreach ($dcTypeList as $dcType) { + $this->assertInstanceOf('EasyRdf\Literal', $dcType, "dc type must be a literal"); + $this->assertArrayHasKey($dcType->getValue(),$expResMap, 'Value must be in expected result Map'); + $this->assertEquals($expResMap[$dcType->getValue()], $dcType->getDatatypeUri()); + } + } + + /** + * Test that the web resources + * + * @return void + */ + public function testWebResources() { + + $resources = $this->resGraphes['BASE']->allOfType('edm:WebResources'); + + $this->assertCount(2, $resources, "Must found three webresources"); + + $aggregation = $this->resGraphes['BASE']->resource(CocoonTextRdfMapperTest::TEST_GRAPH_URI); + + foreach ($resources as $wres) { + $mimetypes = $wres->all($this->resGraphes['BASE']->resource('http://purl.org/dc/elements/1.1/format')); + $this->assertCount(1, $mimetypes, "Must find one mimetype."); + $mimetype = $mimetypes[0]; + $this->assertInstanceOf("EasyRdf\Literal", $mimetype, "mimetype must be literal"); + $this->assertEquals("dc:IMT",$mimetype->getDatatype()); + } + } + + /** + * Test that the web resources + * + * @return void + */ + public function testWebResourcesDate() { + + $resources = $this->resGraphes['BASE']->allOfType('edm:WebResources'); + + foreach ($resources as $wres) { + $this->assertFalse($wres->hasProperty("http://purl.org/dc/terms/available"),"web resource must not have http://purl.org/dc/terms/available"); + $this->assertFalse($wres->hasProperty("http://purl.org/dc/terms/modified"),"web resource must not have http://purl.org/dc/terms/modified"); + $this->assertTrue($wres->hasProperty("http://purl.org/dc/terms/issued"), "Must have http://purl.org/dc/terms/issued"); + + $issued = $wres->getLiteral('dc:issued'); + // "2014-12-05T15:00:19+01:00"^^ ; + $this->assertInstanceOf('EasyRdf\Literal', $issued, "issued value must be a literal"); + $this->assertEquals('http://purl.org/dc/terms/W3CDTF', $issued->getDatatypeUri(), "issued datatype uri must be a http://purl.org/dc/terms/W3CDTF"); + $this->assertEquals('2011-02-05T23:22:23+01:00', $issued->getValue(), "Value must be 2014-12-05T15:00:19+01:00"); + + } + + } + + +}