diff -r 009efee954f7 -r 17f10b56c079 server/src/tests/Models/WebResourceTest.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/server/src/tests/Models/WebResourceTest.php Thu Jun 02 18:24:19 2016 +0200 @@ -0,0 +1,202 @@ + << . + @prefix rdfs: . + @prefix sesame: . + @prefix owl: . + @prefix xsd: . + @prefix fn: . + + a ; + "application/xml"^^ ; + "Freely available for non-commercial use" ; + "2010-11-17"^^ ; + "2013-11-04T22:20:07+01:00"^^ ; + ; + . + +EOT + ,'http://cocoon.huma-num.fr/data/archi/masters/372593.wav' => << . + @prefix rdfs: . + @prefix sesame: . + @prefix owl: . + @prefix xsd: . + @prefix fn: . + + a ; + "audio/x-wav"^^ ; + "Freely available for non-commercial use" ; + "2010-11-17"^^ ; + "PT48M26S" ; + "2013-10-12T14:35:57+02:00"^^ ; + . +EOT + ,"http://cocoon.huma-num.fr/data/cfpp2000/Ozgur_Kilic_H_32_alii_3e-2.mp3" => << . + @prefix rdfs: . + @prefix sesame: . + @prefix owl: . + @prefix xsd: . + @prefix fn: . + + <%1\$scrdo-CFPP2000_35_SOUND> a ; + ; + "Langage et langues : description, théorisation, transmission" ; + , , ; + ; + ; + "Corpus de la Parole"@fr ; + . + + a ; + "Freely available for non-commercial use" ; + "2010-11-17"^^ ; + "PT48M26S" ; + "2013-10-12T14:35:57+02:00"^^ ; + ; + , "Tanguy, Noalig" , "Chevrier, Michel" , "Kiliç, Ozgur" , "Salvegas, Etienne" , "du-Breuil-de-Pont-en-Auge, Augustin" , "du-Breuil-de-Pont-en-Auge, Benoît" ; + "Enregistrement issu du Corpus de Français Parlé Parisien des années 2000 (CFPP2000)"@fr , "Quartier(s) concerné(s) : Paris 3e, et 20e (pour l'âge adulte); Anonymisation : Noalig TANGUY;"@fr ; + "ark:/87895/1.17-375004" , "%2\$scrdo-CFPP2000_35_SOUNDid" , "oai:crdo.vjf.cnrs.fr:crdo-CFPP2000_35" , "Cote producteur: [03-01] Ozgur_Kilic_H_32_alii_3e"@fr , "ark:/87895/1.17-372593" , "oai:crdo.vjf.cnrs.fr:crdo-CFPP2000_35_SOUND" ; + ; + ; + , "anthropological_linguistics"^^ , "lexicography"^^ , "phonetics"^^ , , , , "general_linguistics"^^ , , "text_and_corpus_linguistics"^^ , "Français"@fr , , "phonology"^^ , "semantics"^^ , "sociolinguistics"^^ , "syntax"^^ , "typology"^^ , , , "discourse_analysis"^^ , "historical_linguistics"^^ , "language_documentation"^^ , , , , , , "mathematical_linguistics"^^ ; + "Entretien de Ozgur Kiliç 2"@fr ; + , , , "primary_text"^^ , , "narrative"^^ , "report"^^ , "unintelligible_speech"^^ ; + "2013-10-12"^^ ; + [ + a ; + owl:sameAs ; + "FR"^^ , "France, Île-de-France, Paris, Université Sorbonne Nouvelle Paris 3, site Censier"@fr , "Domicile de Ozgur Kiliç"@fr , "France, Île-de-France, Paris 20"@fr + ]; + , ; + ; + ; + "Tanguy, Noalig" ; + "Quartier concerné : 3e"@fr ; + "Chevrier, Michel" , "Kiliç, Ozgur" , "Salvegas, Etienne" , "du-Breuil-de-Pont-en-Auge, Augustin" , "du-Breuil-de-Pont-en-Auge, Benoît" ; + . + + + a ; + "application/xml"^^ ; + "Freely available for non-commercial use" ; + "2010-11-17"^^ ; + "2013-11-04T22:20:07+01:00"^^ ; + ; + . + + a ; + "audio/x-wav"^^ ; + "Freely available for non-commercial use" ; + "2010-11-17"^^ ; + "PT48M26S" ; + "2013-10-12T14:35:57+02:00"^^ ; + . + + a ; + "audio/mpeg"^^ ; + "Freely available for non-commercial use" ; + "2010-11-17"^^ ; + "PT48M26S" ; + "2013-10-12T14:35:57+02:00"^^ ; + ; + . + + a ; + "audio/x-wav"^^ ; + "Freely available for non-commercial use" ; + "2010-11-17"^^ ; + "PT48M26S" ; + "2013-10-12T14:35:57+02:00"^^ ; + ; + . +EOT + ]; + + public function getMockWebResource(...$contructorArgs) { + return m::mock("CorpusParole\Models\WebResource", $contructorArgs) + ->makePartial() + ->shouldAllowMockingProtectedMethods() + ->shouldReceive('jsonSerializeExtra') + ->andReturn(['extra' => 'fields']) + ->shouldReceive('doClearMemoizationCache'); + + } + + + public function setUp() { + + parent::setup(); + $this->graphs = []; + foreach(self::TEST_DOCS as $uri => $ttl) { + $this->graphs[$uri] = new EasyRdf\Graph($uri, sprintf($ttl, config('corpusparole.corpus_doc_id_base_uri'), config('corpusparole.corpus_id_scheme'))); + } + } + + public function testConstructor() { + + $this->assertNotNull($this->graphs, 'Graphs shoud not be null'); + + $webResource = $this->getMockWebResource('http://cocoon.huma-num.fr/exist/crdo/cfpp2000/fra/Ozgur_Kilic_H_32_alii_3e-2.xml', $this->graphs['http://cocoon.huma-num.fr/exist/crdo/cfpp2000/fra/Ozgur_Kilic_H_32_alii_3e-2.xml'])->getMock(); + + $this->assertNotNull($webResource); + } + + public function testUrl() { + $webResource = $this->getMockWebResource('http://cocoon.huma-num.fr/exist/crdo/cfpp2000/fra/Ozgur_Kilic_H_32_alii_3e-2.xml', $this->graphs['http://cocoon.huma-num.fr/exist/crdo/cfpp2000/fra/Ozgur_Kilic_H_32_alii_3e-2.xml'])->getMock(); + $this->assertEquals('http://cocoon.huma-num.fr/exist/crdo/cfpp2000/fra/Ozgur_Kilic_H_32_alii_3e-2.xml', $webResource->getUrl(), 'URL should be http://cocoon.huma-num.fr/exist/crdo/cfpp2000/fra/Ozgur_Kilic_H_32_alii_3e-2.xml'); + } + + public function testGetFormat() { + $webResource = $this->getMockWebResource('http://cocoon.huma-num.fr/exist/crdo/cfpp2000/fra/Ozgur_Kilic_H_32_alii_3e-2.xml', $this->graphs['http://cocoon.huma-num.fr/exist/crdo/cfpp2000/fra/Ozgur_Kilic_H_32_alii_3e-2.xml'])->getMock(); + $this->assertEquals("application/xml", $webResource->getFormat(), "Format should be application/xml"); + } + + public function testJsonSerialize() { + $webResource = $this->getMockWebResource('http://cocoon.huma-num.fr/exist/crdo/cfpp2000/fra/Ozgur_Kilic_H_32_alii_3e-2.xml', $this->graphs['http://cocoon.huma-num.fr/exist/crdo/cfpp2000/fra/Ozgur_Kilic_H_32_alii_3e-2.xml'])->getMock(); + + $json = $webResource->jsonSerialize(); + $this->assertTrue(is_array($json), "must be an array"); + $this->assertEquals( + [ + 'url' => "http://cocoon.huma-num.fr/exist/crdo/cfpp2000/fra/Ozgur_Kilic_H_32_alii_3e-2.xml", + "format" => "application/xml", + "extra" => "fields" + ], + $json + ); + } + + public function testJsonSerializeFullDoc() { + $webResource = $this->getMockWebResource("http://cocoon.huma-num.fr/data/cfpp2000/Ozgur_Kilic_H_32_alii_3e-2.mp3", $this->graphs["http://cocoon.huma-num.fr/data/cfpp2000/Ozgur_Kilic_H_32_alii_3e-2.mp3"])->getMock(); + + $json = $webResource->jsonSerialize(); + $this->assertTrue(is_array($json), "must be an array"); + $this->assertEquals( + [ + 'url' => "http://cocoon.huma-num.fr/data/cfpp2000/Ozgur_Kilic_H_32_alii_3e-2.mp3", + "format" => "audio/mpeg", + "extra" => "fields" + ], + $json + ); + } + + public function tearDown() { + m::close(); + } + +}