diff --git a/library/Class/Album.php b/library/Class/Album.php index 7ab8ae6b20d1c28a689b85c7a7b62a49466dc92e..69b1e9029d6c2e94affbac791ff4a7ed7bd7c4f2 100644 --- a/library/Class/Album.php +++ b/library/Class/Album.php @@ -1234,9 +1234,13 @@ class Class_Album extends Storm_Model_Abstract { * @return string */ public function getPoster() { - if ($posters_url = $this->getUnimarc856Values('poster')) - return $posters_url[0]; - return ''; + if (!$posters_url = $this->getUnimarc856Values('poster')) + return ''; + + foreach($posters_url as $url) + if (false !== strpos($url, 'small')) return $url; + + return $posters_url[0]; } diff --git a/library/Class/WebService/BibNumerique/Dilicom/ONIXFile.php b/library/Class/WebService/BibNumerique/Dilicom/ONIXFile.php index 49187aedc304548de0ac597cec8c1e30725d0e2a..d29fc6e2a34caf4f2fd2775efe8e5b183ab031a7 100644 --- a/library/Class/WebService/BibNumerique/Dilicom/ONIXFile.php +++ b/library/Class/WebService/BibNumerique/Dilicom/ONIXFile.php @@ -27,7 +27,8 @@ class Class_WebService_BibNumerique_Dilicom_ONIXFile { PRODUCT_TYPE_ID_ISBN_13 = '15', PUBLISHING_DATE_ROLE_PUBLISHING_DATE = '01', TEXT_TYPE_DESCRIPTION = '03', - LANG_ROLE_TEXT_LANG = '01'; + LANG_ROLE_TEXT_LANG = '01', + RESOURCE_CONTENT_TYPE_FRONT_COVER = '01'; protected $_parser, @@ -36,6 +37,7 @@ class Class_WebService_BibNumerique_Dilicom_ONIXFile { $_current_text_type, $_current_product_id_type, $_current_product_id_value, + $_current_resource_content_type, $_current_language_role, $_tag_mapping = ['B203' => 'TitleText', 'B221' => 'ProductIDType', @@ -48,7 +50,9 @@ class Class_WebService_BibNumerique_Dilicom_ONIXFile { 'X426' => 'TextType', 'D104' => 'Text', 'B253' => 'LanguageRole', - 'B252' => 'LanguageCode']; + 'B252' => 'LanguageCode', + 'X435' => 'ResourceLink', + 'X436' => 'ResourceContentType']; public function __construct() { @@ -165,5 +169,16 @@ class Class_WebService_BibNumerique_Dilicom_ONIXFile { if ($this->_current_language_role == self::LANG_ROLE_TEXT_LANG) $this->_book->setIdLangue($content); } + + + public function endResourceContentType($content) { + $this->_current_resource_content_type = $content; + } + + + public function endResourceLink($content) { + if ($this->_current_resource_content_type === self::RESOURCE_CONTENT_TYPE_FRONT_COVER) + $this->_book->addPoster($content); + } } ?> \ No newline at end of file diff --git a/library/Class/WebService/BibNumerique/Vignette.php b/library/Class/WebService/BibNumerique/Vignette.php index 15b36083083c761735b834721ddfcdcac0a894cd..501f9cab8e06ac3820eebe97ce335a22096d77f0 100644 --- a/library/Class/WebService/BibNumerique/Vignette.php +++ b/library/Class/WebService/BibNumerique/Vignette.php @@ -16,7 +16,7 @@ * * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * along with BOKEH; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ class Class_WebService_BibNumerique_Vignette extends Class_WebService_Abstract { diff --git a/tests/library/Class/WebService/Dilicom/PNBOffersParserTest.php b/tests/library/Class/WebService/Dilicom/PNBOffersParserTest.php index 2a5b6637a53262e09d0c73490e8d3c09d9ccd6b3..d570555437eabddbf1f45d17e612f58f2a1d1485 100644 --- a/tests/library/Class/WebService/Dilicom/PNBOffersParserTest.php +++ b/tests/library/Class/WebService/Dilicom/PNBOffersParserTest.php @@ -26,12 +26,18 @@ class DilicomPNBOfferParserTest extends Storm_Test_ModelTestCase { $xmlpath = realpath(dirname(__FILE__)) . '/fixtures/full_pnb_666_20150220T150017Z.xml'; $xml = file_get_contents($xmlpath); + $this->_http_client = Storm_Test_ObjectWrapper::mock() + ->whenCalled('open_url') + ->answers(''); + Class_WebService_Abstract::setDefaultHttpClient($this->_http_client); + Storm_Model_Loader::defaultToVolatile(); $this->_books = Class_WebService_BibNumerique_Dilicom_PNBOffersFile::booksFromXML($xml); } public function tearDown() { Storm_Model_Loader::defaultToDb(); + Class_WebService_Abstract::setDefaultHttpClient(null); parent::tearDown(); } @@ -46,9 +52,33 @@ class DilicomPNBOfferParserTest extends Storm_Test_ModelTestCase { public function firstAlbumShouldBePlusJamaisSansElle() { $album = $this->_books[0]->import(); $this->assertEquals('Plus jamais sans elle', $album->getTitre()); + return $album; + } + + + /** @test */ + public function firstBookPostersShouldContainsFrontCoverDotJpg() { + $this->assertContains('https://assets.edenlivres.fr/assets/publications/23416/medias/front_cover.jpg', + $this->_books[0]->getPosters()); } + /** @test */ + public function firstBookPostersShouldContainsFrontCoverSmallDotJpg() { + $this->assertContains('http://assets.edenlivres.fr/assets/publications/23416/cover/small.jpg', + $this->_books[0]->getPosters()); + } + + + /** @test */ + public function firstAlbumDownloadedThumbnailShouldBeSmallDotJpg() { + $this->_books[0]->import(); + $this->assertTrue($this->_http_client->methodHasBeenCalledWithParams('open_url', + ['http://assets.edenlivres.fr/assets/publications/23416/cover/small.jpg'])); + } + + + /** @test */ public function secondAlbumShouldBeJournalDunDegonfle() { $album = $this->_books[1]->import();