From 0a0702be199a783c127f3c6f74a4ad0d39ed5832 Mon Sep 17 00:00:00 2001 From: efalcy <efalcy@git-test.afi-sa.fr> Date: Fri, 27 Sep 2013 13:20:23 +0000 Subject: [PATCH] Arte VOD : ajout de la description + acteurs + duree du film --- .../WebService/BibNumerique/ArteVOD/Film.php | 24 ++++++++- .../BibNumerique/ArteVOD/FilmReader.php | 39 ++++++++++++-- .../BibNumerique/RessourceNumerique.php | 26 ++++++---- library/Class/WebService/XMLParser.php | 2 +- tests/library/Class/AgendaSQYImportTest.php | 2 +- tests/library/Class/EADTest.php | 2 +- .../WebService/ArteVOD/FilmReaderTest.php | 51 +++++++++++++++++-- .../Class/WebService/ArteVODFixtures.php | 5 ++ .../library/Class/WebService/ArteVODTest.php | 20 +++++++- 9 files changed, 146 insertions(+), 25 deletions(-) diff --git a/library/Class/WebService/BibNumerique/ArteVOD/Film.php b/library/Class/WebService/BibNumerique/ArteVOD/Film.php index e0650ca8642..0e99a5f0b2f 100644 --- a/library/Class/WebService/BibNumerique/ArteVOD/Film.php +++ b/library/Class/WebService/BibNumerique/ArteVOD/Film.php @@ -30,11 +30,31 @@ class Class_WebService_BibNumerique_ArteVOD_Film extends Class_WebService_BibNu protected $_posters = array(); protected $_trailers = array(); protected $_photos = array(); - + protected $duration; public function fillAlbum($album) { $album->beArteVOD() - ->setAuteur(implode(', ', $this->getAuthors())); + ->setAuteur(implode(', ', $this->getAuthors())) + ->addZone('215', ['a' => 'Vidéo ('.$this->duration.' min)']); + foreach ($this->getActors() as $actor) { + $unimarc = []; + if (strlen($actor->last_name)>0) + $unimarc['a']=$actor->last_name; + if (strlen($actor->first_name)>0) + $unimarc['b']=$actor->first_name; + $unimarc['4'] = '005'; + $album->addZone('702',$unimarc); + } + } + + + public function addDuration($duration) { + $this->duration = $duration; + } + + + public function getDuration() { + return $this->duration; } diff --git a/library/Class/WebService/BibNumerique/ArteVOD/FilmReader.php b/library/Class/WebService/BibNumerique/ArteVOD/FilmReader.php index 0e5356fe218..3249f375217 100644 --- a/library/Class/WebService/BibNumerique/ArteVOD/FilmReader.php +++ b/library/Class/WebService/BibNumerique/ArteVOD/FilmReader.php @@ -23,6 +23,7 @@ class Class_WebService_Bibnumerique_ArteVOD_FilmReader { protected $_xml_parser; protected $_film; protected $_current_author; + protected $_current_actor; public function parseContentOn($xml, $film) { $this->_film = $film; @@ -34,6 +35,11 @@ class Class_WebService_Bibnumerique_ArteVOD_FilmReader { return $this; } + + public function cleanXml($xml) { + return(str_replace('&','&',$xml)); + } + public function endExternalUri($data) { $this->_film->setExternalUri($data); @@ -59,7 +65,7 @@ class Class_WebService_Bibnumerique_ArteVOD_FilmReader { } public function endDuration($data) { - $this->_film->addZone('215',['a'=> 'Vidéo ('.$data.' min)']); + $this->_film->addDuration($data); } public function endProduction_Year($data) { @@ -70,27 +76,52 @@ class Class_WebService_Bibnumerique_ArteVOD_FilmReader { public function startPerson($data) { if ($this->_xml_parser->inParents('authors')) { $this->_current_author = new StdClass(); + $this->_current_author->first_name = ''; + $this->_current_author->last_name=''; + } + + if ($this->_xml_parser->inParents('actors')) { + $this->_current_actor = new StdClass(); + $this->_current_actor->first_name = ''; + $this->_current_actor->last_name=''; + } + } - public function endFirst_Name($data) { + public function endFirst_name($data) { if ($this->_xml_parser->inParents('authors')) { $this->_current_author->first_name = $data; } + if ($this->_xml_parser->inParents('actors') && $data) { + $this->_current_actor->first_name = $data; + } + + } - public function endLast_Name($data) { + public function endLast_name($data) { if ($this->_xml_parser->inParents('authors')) { $this->_current_author->last_name = $data; } + + if ($this->_xml_parser->inParents('actors') && $data) { + $this->_current_actor->last_name = $data; + } + } public function endPerson($data) { + if ($this->_xml_parser->inParents('authors')) { - $this->_film->addAuthor($this->_current_author->last_name.' '.$this->_current_author->first_name); + $this->_film->addAuthor($this->_current_author->first_name.' '.$this->_current_author->last_name); } + if ($this->_xml_parser->inParents('actors')) { + $this->_film->addActor($this->_current_actor); + } + } diff --git a/library/Class/WebService/BibNumerique/RessourceNumerique.php b/library/Class/WebService/BibNumerique/RessourceNumerique.php index 2e45f8b42a8..a8fe8a63945 100644 --- a/library/Class/WebService/BibNumerique/RessourceNumerique.php +++ b/library/Class/WebService/BibNumerique/RessourceNumerique.php @@ -36,6 +36,8 @@ protected $_matieres = []; protected $_ressources = []; protected $_zones = []; + protected $_actors = []; + public function setId($id) { $this->_id = $id; @@ -147,6 +149,17 @@ } + public function addActor($actor) { + $this->_actors[] = $actor; + return $this; + } + + + public function getActors() { + return $this->_actors; + } + + public function addPoster($url) { $this->_posters[] = $url; return $this; @@ -190,21 +203,11 @@ } - public function addZone($codif,$datas) { - $this->_zones[$codif] = $datas; - } - public function addMatiere($matiere_libelle) { $this->_matieres[] = $matiere_libelle; } - public function importZones($album) { - foreach ($this->_zones as $zone_codif => $zone_datas) { - $album->addZone($zone_codif,$zone_datas); - } - } - public function importMatieres($album) { $ids=[]; @@ -236,6 +239,7 @@ $album = Class_Album::newInstance() ->setTitre($this->getTitle()) + ->setDescription($this->getDescription()) ->setAnnee($this->getYear()) ->setIdOrigine($this->getId()) ->setUrlOrigine($this->getBaseUrl()) @@ -248,7 +252,7 @@ $this->fillAlbum($album); $this->updateRessourceNumeriqueNotes($album); - $this->importZones($album); + //$this->importZones($album); if ($album->save()) Class_WebService_BibNumerique_Vignette::getInstance()->updateAlbum($album); return $album; diff --git a/library/Class/WebService/XMLParser.php b/library/Class/WebService/XMLParser.php index e8be1bad8ae..19b6c3b529c 100644 --- a/library/Class/WebService/XMLParser.php +++ b/library/Class/WebService/XMLParser.php @@ -44,7 +44,7 @@ class Class_WebService_XMLParser { $this->_parents = array() ; $parser = $this->_createParser() ; xml_parse($parser, $xml) ; - // echo xml_error_string(xml_get_error_code($parser)); +// echo xml_error_string(xml_get_error_code($parser)); // echo xml_get_current_line_number($parser); xml_parser_free($parser) ; return $this ; diff --git a/tests/library/Class/AgendaSQYImportTest.php b/tests/library/Class/AgendaSQYImportTest.php index b774ddc4b58..8d7f3870a31 100644 --- a/tests/library/Class/AgendaSQYImportTest.php +++ b/tests/library/Class/AgendaSQYImportTest.php @@ -20,7 +20,7 @@ */ -class AgendaSQYImportTest extends Storm_Test_ModelTestCase { +abstract class AgendaSQYImportTest extends Storm_Test_ModelTestCase { protected static $_agenda, $_article_loader, diff --git a/tests/library/Class/EADTest.php b/tests/library/Class/EADTest.php index d566683a613..7f186bad01a 100644 --- a/tests/library/Class/EADTest.php +++ b/tests/library/Class/EADTest.php @@ -79,7 +79,7 @@ class EADEmptyLoadTest extends Storm_Test_ModelTestCase { -class EADMoulinsTest extends PHPUnit_Framework_TestCase { +abstract class EADMoulinsTest extends PHPUnit_Framework_TestCase { protected static $ead; protected static $folio_souvigny_1R; protected static $folio_souvigny_3R; diff --git a/tests/library/Class/WebService/ArteVOD/FilmReaderTest.php b/tests/library/Class/WebService/ArteVOD/FilmReaderTest.php index 6bf7621df65..34039487c8c 100644 --- a/tests/library/Class/WebService/ArteVOD/FilmReaderTest.php +++ b/tests/library/Class/WebService/ArteVOD/FilmReaderTest.php @@ -19,7 +19,7 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -class ArteVOD_FilmReaderTest extends PHPUnit_Framework_TestCase { +class ArteVOD_FilmReaderAnimationTest extends PHPUnit_Framework_TestCase { protected $_film; public function setUp() { @@ -65,7 +65,7 @@ class ArteVOD_FilmReaderTest extends PHPUnit_Framework_TestCase { /** @test */ public function authorShouldBeFlorentTrochel() { $authors = $this->_film->getAuthors(); - $this->assertEquals('Trochel Florent', current($authors)); + $this->assertEquals('Florent Trochel', current($authors)); } @@ -102,9 +102,54 @@ class ArteVOD_FilmReaderTest extends PHPUnit_Framework_TestCase { /** @test */ public function shouldHaveDuration70Min() { - $this->assertEquals('Vidéo (70 min)',$this->_film->getZone('215')['a']); + $this->assertEquals('70',$this->_film->getDuration()); } +} + +class ArteVOD_FilmReaderDrameTest extends PHPUnit_Framework_TestCase { + protected $_film; + + public function setUp() { + $reader = new Class_WebService_BibNumerique_ArteVOD_FilmReader(); + $this->_film = new Class_WebService_BibNumerique_ArteVOD_Film(); + $reader->parseContentOn(ArteVODFixtures::byebyeBlondieFilm(), $this->_film); + } + + + /** @test */ + public function titleShouldBeByeByeBlondie() { + $this->assertEquals('Bye Bye Blondie', $this->_film->getTitle()); + } + + /** @test */ + public function shouldHaveGenreCinemaDrame() { + $this->assertEquals('Cinéma::Drame',$this->_film->getMatieres()); + } + + /** @test */ + public function shouldHaveAuthorVirginieDespentes() { + $authors = $this->_film->getAuthors(); + $this->assertEquals('Virginie Despentes', current($authors)); + + } + + + /** @test */ + public function shouldHaveActorEmmanuelleBeart() { + $actors = $this->_film->getActors(); + $this->assertEquals('Emmanuelle', current($actors)->first_name); + + } + + + /** @test */ + public function shouldHaveAnotherActorSoko() { + $actors = $this->_film->getActors(); + $this->assertEquals('Soko', $actors[3]->last_name); + + } + } \ No newline at end of file diff --git a/tests/library/Class/WebService/ArteVODFixtures.php b/tests/library/Class/WebService/ArteVODFixtures.php index dad8982f5d8..ed5998588d7 100644 --- a/tests/library/Class/WebService/ArteVODFixtures.php +++ b/tests/library/Class/WebService/ArteVODFixtures.php @@ -45,4 +45,9 @@ class ArteVODFixtures { <film><pk>5541</pk><externalUri>http://www.mediatheque-numerique.com/films/blanche-nage</externalUri><editorial><title>Blanche Nage</title><description>Adaptation aquatique.</description><original_title></original_title><body>La pomme, les sept nains, le cercueil de verre, le prince à cheval, le miroir magique... : le metteur en scène Nicolas Liautard a parié sur les images évoquées dans le conte pour faire du théâtre sans texte. Une succession de tableaux vivants, où le langage du corps, les jeux de lumière et la scénographie créent une féerie intemporelle qui sollicite l\'imaginaire des enfants.</body><genre code="drama"><label lang="fr">Dramatique</label></genre><tags></tags></editorial><technical><duration>70</duration><target_audience code="all-1"><label lang="fr">target_audience_all_1</label></target_audience><production_year>2011</production_year><production_countries><country code="FR"><label lang="fr">France</label></country></production_countries><codes><code type="ARTE">131333</code></codes><release_dates></release_dates><languages><language code="fr"><label lang="fr">Français</label></language></languages><copyright></copyright></technical><staff><authors><person><first_name>Florent</first_name><last_name>Trochel</last_name><full_name>Florent Trochel</full_name></person></authors><actors></actors></staff><media><posters><media src="http://media.universcine.com/7e/5c/7e5c210a-b4ad-11e1-b992-959e1ee6d61d.jpg"><modificationDate>2012-06-13T11:45:26</modificationDate></media></posters><trailers><media src="http://media.universcine.com/7e/5b/7e5bece6-7d56-11e1-9d5b-6b449667e8b8.mp4"><modificationDate>2012-04-03T08:31:24</modificationDate></media></trailers><photos><media src="http://media.universcine.com/7d/f8/7df8bc21-7d56-11e1-baed-69499da4469c.jpg"><modificationDate>2012-04-03T08:31:03</modificationDate></media><media src="http://media.universcine.com/7e/14/7e142c4c-7d56-11e1-bef3-a980e4936291.jpg"><modificationDate>2012-04-03T08:31:03</modificationDate></media><media src="http://media.universcine.com/7e/19/7e199359-7d56-11e1-9d9b-a9fbcefd86db.jpg"><modificationDate>2012-04-03T08:31:03</modificationDate></media><media src="http://media.universcine.com/7e/1d/7e1dc11e-7d56-11e1-99aa-8775a2d902d1.jpg"><modificationDate>2012-04-03T08:31:03</modificationDate></media><media src="http://media.universcine.com/7e/28/7e28cbe1-7d56-11e1-a80d-d78d88d4aa56.jpg"><modificationDate>2012-04-03T08:31:03</modificationDate></media></photos></media></film></wsObjectQuery>'; } + public static function byebyeBlondieFilm() { + return '<?xml version="1.0" encoding="utf-8"?><wsObjectQuery><film><pk>6217</pk><externalUri>http://www.mediatheque-numerique.com/films/bye-bye-blondie</externalUri><editorial><title>Bye Bye Blondie</title><description><![CDATA[Gloria et Frances se sont aimées comme on s\'aime à seize ans : drogue, sexe et rock&roll. Après une séparation de plus de vingt ans elles se retrouvent...]]></description><original_title></original_title><body><![CDATA[Gloria et Frances se sont rencontrées dans les années 80. Elles se sont aimées comme on s\'aime à seize ans : drogue, sexe et rock&roll. Puis la vie les a séparées, et elles ont pris des chemins très différents. Vingt ans après, Frances revient chercher Gloria...]]></body><genre code="cinema"><label lang="fr">Cinéma</label></genre><sub_genre code="drame"><label lang="fr">Drame</label></sub_genre><tags><tag code="ADAPTATION-LITTERAIRE"><label lang="fr">Adaptation littéraire</label></tag><tag code="CHANGEMENT"><label lang="fr">Changement</label></tag><tag code="DROGUE"><label lang="fr">Drogue</label></tag><tag code="JEUNESSE"><label lang="fr">Jeunesse</label></tag><tag code="LIBERTE"><label lang="fr">Liberté</label></tag><tag code="RETROUVAILLES"><label lang="fr">Retrouvailles</label></tag><tag code="ROCK"><label lang="fr">Rock</label></tag><tag code="SEDUCTION"><label lang="fr">Séduction</label></tag></tags></editorial><technical><duration>98</duration><target_audience code="all-2"><label lang="fr">Tous publics avec avertissement</label></target_audience><production_year>2010</production_year><production_countries><country code="BE"><label lang="fr">Belgique</label></country><country code="CH"><label lang="fr">Suisse</label></country><country code="FR"><label lang="fr">France</label></country></production_countries><codes><code type="LMC">045026</code><code type="RPCA">117042</code></codes><release_dates><release_date code="CINE">2012-03-21</release_date></release_dates><languages><language code="fr"><label lang="fr">Français</label></language></languages><copyright></copyright></technical><staff><authors><person><first_name>Virginie</first_name><last_name>Despentes</last_name><full_name>Virginie Despentes</full_name></person></authors><actors><person><first_name>Emmanuelle</first_name><last_name>Béart</last_name><full_name>Emmanuelle Béart</full_name></person><person><first_name>Béatrice</first_name><last_name>Dalle</last_name><full_name>Béatrice Dalle</full_name></person><person><first_name>Clara</first_name><last_name>Ponsot</last_name><full_name>Clara Ponsot</full_name></person><person><first_name></first_name><last_name>Soko</last_name><full_name>Soko</full_name></person><person><first_name>Pascal</first_name><last_name>Greggory</last_name><full_name>Pascal Greggory</full_name></person><person><first_name>Stomy</first_name><last_name>Bugsy</last_name><full_name>Stomy Bugsy</full_name></person><person><first_name>Sasha</first_name><last_name>Andres</last_name><full_name>Sasha Andres</full_name></person><person><first_name>Mélanie</first_name><last_name>Martinez</last_name><full_name>Mélanie Martinez</full_name></person><person><first_name>Jean-Marc</first_name><last_name>Royon</last_name><full_name>Jean-Marc Royon</full_name></person><person><first_name>Olivia</first_name><last_name>Csiky Trnka</last_name><full_name>Olivia Csiky Trnka</full_name></person><person><first_name>Mata</first_name><last_name>Gabin</last_name><full_name>Mata Gabin</full_name></person><person><first_name>Sophie</first_name><last_name>Malnatti</last_name><full_name>Sophie Malnatti</full_name></person><person><first_name>Camille</first_name><last_name>Chamoux</last_name><full_name>Camille Chamoux</full_name></person><person><first_name>Julien</first_name><last_name>Lucas</last_name><full_name>Julien Lucas</full_name></person><person><first_name>Lydia</first_name><last_name>Lunch</last_name><full_name>Lydia Lunch</full_name></person></actors></staff><media><posters><media src="http://media.universcine.com/5c/f8/5cf8d985-e21b-11e1-ae51-d58efb9e4fe4.png"><modificationDate>2012-08-09T14:11:45</modificationDate></media></posters><trailers><media src="http://media.universcine.com/33/3e/333e2f3a-0963-11e2-957e-a75cda9e8bd0.mp4"><modificationDate>2012-10-31T16:14:55</modificationDate></media></trailers><photos><media src="http://media.universcine.com/13/84/1384d66b-e21e-11e1-80bd-57ebedb08eba.png"><modificationDate>2012-08-09T14:31:10</modificationDate></media><media src="http://media.universcine.com/74/2e/742ec80a-e21f-11e1-acac-039c710b75df.png"><modificationDate>2012-08-09T14:41:02</modificationDate></media><media src="http://media.universcine.com/35/ec/35ecdcf5-e21e-11e1-92a7-433870fafc7b.png"><modificationDate>2012-08-09T14:32:08</modificationDate></media><media src="http://media.universcine.com/79/d9/79d97fe8-e21f-11e1-bf3e-653a23dceaa5.png"><modificationDate>2012-08-09T14:41:11</modificationDate></media><media src="http://media.universcine.com/64/5e/645e966e-e21f-11e1-ab12-a7a15824d859.png"><modificationDate>2012-08-09T14:40:35</modificationDate></media><media src="http://media.universcine.com/69/82/6982030f-e21f-11e1-b386-d945776b8843.png"><modificationDate>2012-08-09T14:40:44</modificationDate></media><media src="http://media.universcine.com/6f/3f/6f3fadc0-e21f-11e1-b8a9-f16b41a674e5.png"><modificationDate>2012-08-09T14:40:53</modificationDate></media><media src="http://media.universcine.com/5f/3b/5f3b8fe3-e21f-11e1-a475-fb5758b15ed5.png"><modificationDate>2012-08-09T14:40:27</modificationDate></media><media src="http://media.universcine.com/7e/66/7e661526-e21f-11e1-8efb-0fd1faab3ba1.png"><modificationDate>2012-08-09T14:41:19</modificationDate></media></photos></media></film></wsObjectQuery>'; + + } + } \ No newline at end of file diff --git a/tests/library/Class/WebService/ArteVODTest.php b/tests/library/Class/WebService/ArteVODTest.php index bd759e4910d..9a914fd1d97 100644 --- a/tests/library/Class/WebService/ArteVODTest.php +++ b/tests/library/Class/WebService/ArteVODTest.php @@ -70,7 +70,7 @@ class ArteVODHarverstingTwoFilmsInTwoPages extends ArteVODHarverstingTestCase { ->whenCalled('open_url') ->with('http://www.mediatheque-numerique.com/ws/films/5540') - ->answers(ArteVODFixtures::firstFilm()) + ->answers(ArteVODFixtures::byebyeBlondieFilm()) ->whenCalled('open_url') ->with('http://www.mediatheque-numerique.com/ws/films/5541') @@ -114,16 +114,32 @@ class ArteVODHarverstingTwoFilmsInTwoPages extends ArteVODHarverstingTestCase { /** @test */ public function secondAlbumZone215ShouldBe70Min() { + $notes = $this->_album_wrapper->getFirstAttributeForLastCallOn('save')->getNotesAsArray(); + xdebug_break(); $this->assertEquals(['a' => 'Vidéo (70 min)'], - $this->_album_wrapper->getFirstAttributeForLastCallOn('save')->getNotesAsArray()[8]['data']); + $notes[0]['data']); } + + /** @test */ public function vignetteShouldHaveBeenUploaded() { $this->assertTrue(Class_WebService_BibNumerique_Vignette::getInstance() ->methodHasBeenCalled('updateAlbum')); } + + + + /** @test */ + public function bybyeBlondieActorsShouldContainsSoko() { + $album=$this->_album_wrapper->getAttributesForMethodCallAt('save',-2)[0]; + $this->assertEquals(['a' => 'Soko', + '4' => '005'], + $album->getNotesAsArray()[4]['data']); + } + + } ?> \ No newline at end of file -- GitLab