diff -r 95dfb40ff3d2 -r dd6b3adde73b server/src/tests/libraries/Mappers/CocoonTextRdfMapperTest.php --- a/server/src/tests/libraries/Mappers/CocoonTextRdfMapperTest.php Tue Apr 12 13:42:04 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,291 +0,0 @@ - << . - @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_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(); - - $this->testGraphUri = config('corpusparole.corpus_doc_id_base_uri').CocoonTextRdfMapperTest::TEST_INPUT_ID; - 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($this->testGraphUri, $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($this->testGraphUri,$resources[0]->getUri()); - } - - /** - * Test providedCHO identifier. - * - * @return void - */ - public function testProvidedChoId() { - $resources = $this->resGraphes['BASE']->allOfType('edm:ProvidedCHO'); - - $this->assertCount(1, $resources, "Must found only one resources of type edm:ProvidedCHO"); - $providedCHO = $resources[0]; - - $identifier = $providedCHO->getLiteral(''); - - $this->assertInstanceOf('EasyRdf\Literal', $identifier, "identifier value must be a literal"); - $this->assertEquals(config('corpusparole.corpus_id_scheme') . CocoonTextRdfMapperTest::TEST_INPUT_ID, $identifier->getValue(), "Value must be equals to ".config('corpusparole.corpus_id_scheme').CocoonTextRdfMapperTest::TEST_INPUT_ID); - - } - - public function testRightsWebResourceIdentity() { - $properties = [ - "http://purl.org/dc/elements/1.1/rights", - 'http://purl.org/dc/terms/license', - ]; - - $webResourceList = $this->resGraphes['BASE']->all('edm:WebResource', '^rdf:type'); - $sourceNode = $this->inputGraphes['BASE']->get('http://crdo.risc.cnrs.fr/schemas/Resource', '^rdf:type'); - - foreach ($webResourceList as $webResource) { - foreach ($properties as $prop) { - $outputValuesStr = []; - foreach($webResource->all($this->resGraphes['BASE']->resource($prop)) as $outputValue) { - array_push($outputValuesStr, strval($outputValue)); - } - $this->assertNotEmpty($outputValuesStr, "we must found some values to test $prop"); - foreach ($sourceNode->all($this->inputGraphes['BASE']->resource($prop)) as $value) { - $this->assertContains(strval($value), $outputValuesStr, "$prop not found in output graph"); - } - } - } - } - - public function testRightsWebResourceTrim() { - $properties = [ - 'http://purl.org/dc/terms/accessRights', - ]; - - $webResourceList = $this->resGraphes['BASE']->all('edm:WebResource', '^rdf:type'); - $sourceNode = $this->inputGraphes['BASE']->get('http://crdo.risc.cnrs.fr/schemas/Resource', '^rdf:type'); - - foreach ($webResourceList as $webResource) { - foreach ($properties as $prop) { - $outputValuesStr = []; - foreach($webResource->all($this->resGraphes['BASE']->resource($prop)) as $outputValue) { - array_push($outputValuesStr, strval($outputValue)); - } - $this->assertNotEmpty($outputValuesStr, "we must found some values to test $prop"); - foreach ($sourceNode->all($this->inputGraphes['BASE']->resource($prop)) as $value) { - $this->assertContains(trim(strval($value)), $outputValuesStr, "$prop not found in output graph"); - } - } - } - } - - - /** - * 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 that 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->assertcount(3, $providedCHO->all($this->resGraphes['BASE']->resource('http://purl.org/dc/elements/1.1/type')), 'but should find 2 literals'); - - $dcTypeList = $providedCHO->all($this->resGraphes['BASE']->resource('http://purl.org/dc/elements/1.1/type')); - foreach ($dcTypeList as $dcType) { - $this->assertThat( - $dcType, - $this->logicalXor( - $this->isInstanceOf(EasyRdf\Literal::class), - $this->isInstanceOf(EasyRdf\Resource::class) - ) - ); - } - } - - /** - * Test that the web resources - * - * @return void - */ - public function testWebResources() { - - $resources = $this->resGraphes['BASE']->allOfType('edm:WebResource'); - - $this->assertCount(2, $resources, "Must found three webresource"); - - $aggregation = $this->resGraphes['BASE']->resource($this->testGraphUri); - - 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 has good date - * - * @return void - */ - public function testWebResourcesDate() { - - $resources = $this->resGraphes['BASE']->allOfType('edm:WebResource'); - - 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"); - - } - - } - - - /** - * Test that the web resources as conformsTo property - * - * @return void - */ - public function testWebResourcesConformsTo() { - - $resources = $this->resGraphes['BASE']->allOfType('edm:WebResource'); - foreach ($resources as $wres) { - - $mimetypes = $wres->all($this->resGraphes['BASE']->resource('http://purl.org/dc/elements/1.1/format')); - $mimetype = $mimetypes[0]->getValue(); - if($mimetype !== 'application/xml') { - continue; - } - $conformsTo = $wres->get(''); - $this->assertNotNull($conformsTo, "Must have a conformsTo node"); - $this->assertInstanceOf('EasyRdf\Resource', $conformsTo, "Must be a resource"); - $this->assertEquals("http://purl.org/poi/crdo.vjf.cnrs.fr/crdo-dtd_archive", $conformsTo->getUri(), "Must be http://purl.org/poi/crdo.vjf.cnrs.fr/crdo-dtd_archive"); - } - } - - -}