diff --git a/library/Class/Notice/JsonVisitor.php b/library/Class/Notice/JsonVisitor.php index c84b9530077f534641234a69b4f55378b68a0ce1..aed1d92987aadeab8664b289ab4874818ac73f3b 100644 --- a/library/Class/Notice/JsonVisitor.php +++ b/library/Class/Notice/JsonVisitor.php @@ -56,6 +56,12 @@ class Class_Notice_JsonVisitor { } + public function visitVignette($url_vignette) { + if ($url_vignette) + $this->_data->thumbnail = Class_Url::absolute($url_vignette); + } + + public function visitSerialTitle($title) { $this->_ensureArray('titles'); $this->_data->titles = array_merge($title, $this->_data->titles); @@ -64,7 +70,7 @@ class Class_Notice_JsonVisitor { public function visitTitres($titles) { - $this->_ensureArray('title'); + $this->_ensureArray('titles'); $this->_data->titles = array_merge($this->_data->titles, $titles); } diff --git a/tests/application/modules/opac/controllers/RechercheControllerJsonTest.php b/tests/application/modules/opac/controllers/RechercheControllerJsonTest.php index 64355eec9d1ce5544a08c20a0e730451be9094a5..89fbff55c074c0534a70719a7fea9b335ce931f4 100644 --- a/tests/application/modules/opac/controllers/RechercheControllerJsonTest.php +++ b/tests/application/modules/opac/controllers/RechercheControllerJsonTest.php @@ -40,9 +40,15 @@ abstract class RechercheControllerJsonTestCase extends AbstractControllerTestCas protected function _prepareSql($sql) {} + protected function _searchUrl() { return 'recherche/simple/expressionRecherche//tri/*/format/json'; } + + + protected function _unimarcFrom($file_name) { + return file_get_contents(dirname(__FILE__) . '/' . $file_name); + } } @@ -99,24 +105,38 @@ class RechercheControllerJsonEmptyResultTest extends RechercheControllerJsonTest -class RechercheControllerJsonOneResultTest extends RechercheControllerJsonTestCase { - protected $_record; +class RechercheControllerJsonWithResultTest extends RechercheControllerJsonTestCase { + protected $_first, $_second; protected function _prepareLoader($loader) { $this->fixture('Class_CodifGenre', ['id' => 3, 'libelle' => 'Science fiction']); - $record = $this->fixture('Class_Notice', + $potter = $this->fixture('Class_Notice', ['id' => 234, 'clef_alpha' => 'HARRYPOTTERALECOLEDESSORCIERS--ROWLINGJ-1-GALLIMARDJEUNESSE-2011-1', 'type_doc' => 1, - 'unimarc' => file_get_contents(dirname(__FILE__).'/harry_potter_ecole_sorciers.txt'), + 'unimarc' => $this->_unimarcFrom('harry_potter_ecole_sorciers.txt'), 'annee' => '1998', - 'facettes' => 'G3']); + 'facettes' => 'G3', + 'url_vignette' => 'http://ecx.images-amazon.com/images/I/51KVZWGHASL._SL160_.jpg', + 'url_image' => 'http://ecx.images-amazon.com/images/I/51KVZWGHASL.jpg']); + + + $rdv = $this->fixture('Class_Notice', + ['id' => 10141532, + 'clef_alpha' => 'RENDEZVOUSAKIRUNA--ANNANOVIONDARROUSSINJEANPIERRESOULISANASTASIOSLJUNGMARKCLAESBODNIAKIMHENRY---2012-104', + 'type_doc' => 104, + 'unimarc' => $this->_unimarcFrom('rdv_a_kiruna.txt'), + 'annee' => '2012', + 'facettes' => 'T104 A62646 A19260 A77257 A77258 A77259 A44958 A77260 A77261 A77262 A77263 A77264 A56926 A77265 A77266 A77267 A77268 M4566 M12096 Lfre Z39 Z20 Z21 Z22 Z7 Z34 Z64 Z154 Z59', + 'url_vignette' => BASE_URL .'/userfiles/album/154191/thumb_154191_e7bcedba-743a-11e2-a43d-fb3bf58b5f60.png', + 'url_image' => 'http://media.universcine.com/e7/bc/e7bcedba-743a-11e2-a43d-fb3bf58b5f60.png']); + $loader->whenCalled('findAllByRequeteRecherche') ->with('Select id_notice from notices', 10, 1) - ->answers([$record]) + ->answers([$potter, $rdv]) ->beStrict(); } @@ -124,7 +144,7 @@ class RechercheControllerJsonOneResultTest extends RechercheControllerJsonTestCa protected function _prepareSql($sql) { $sql->whenCalled('fetchOne') ->with('Select count(*) from notices') - ->answers(1) + ->answers(2) ->whenCalled('execute') ->answers(true) @@ -134,26 +154,27 @@ class RechercheControllerJsonOneResultTest extends RechercheControllerJsonTestCa public function setUp() { parent::setUp(); - $this->_record = $this->_json->records[0]; + $this->_first = $this->_json->records[0]; + $this->_second= $this->_json->records[1]; } /** @test */ public function totalShouldBeOne() { - $this->assertEquals(1, $this->_json->total); + $this->assertEquals(2, $this->_json->total); } /** @test */ public function recordsShouldContainsOneResult() { - $this->assertEquals(1, count($this->_json->records)); + $this->assertEquals(2, count($this->_json->records)); } /** @test */ public function identifierShouldBeAsExpected() { $this->assertEquals('HARRYPOTTERALECOLEDESSORCIERS--ROWLINGJ-1-GALLIMARDJEUNESSE-2011-1', - $this->_record->identifier); + $this->_first->identifier); } @@ -163,91 +184,106 @@ class RechercheControllerJsonOneResultTest extends RechercheControllerJsonTestCa 'action' => 'viewnotice', 'clef' => 'HARRYPOTTERALECOLEDESSORCIERS--ROWLINGJ-1-GALLIMARDJEUNESSE-2011-1', 'id' => 234], null, true), - $this->_record->permalink); + $this->_first->permalink); } /** @test */ public function typeCodeShouldBeOne() { - $this->assertEquals(1, $this->_record->type->code); + $this->assertEquals(1, $this->_first->type->code); } /** @test */ public function typeLabelShouldBeLivres() { - $this->assertEquals('Livres', $this->_record->type->label); + $this->assertEquals('Livres', $this->_first->type->label); + } + + + /** @test */ + public function firstThumbnailShouldBePresent() { + $this->assertEquals('http://ecx.images-amazon.com/images/I/51KVZWGHASL._SL160_.jpg', + $this->_first->thumbnail); + } + + + /** @test */ + public function secondThumbnailShouldBePresentAndAbsolute() { + $this->assertEquals(ROOT_URL . BASE_URL + . '/userfiles/album/154191/thumb_154191_e7bcedba-743a-11e2-a43d-fb3bf58b5f60.png', + $this->_second->thumbnail); } /** @test */ public function firstTitleShouldBeHarryPotter() { - $this->assertEquals('Harry Potter', $this->_record->titles[0]); + $this->assertEquals('Harry Potter', $this->_first->titles[0]); } /** @test */ public function secondTitleShouldBeALEcoleDesSorciers() { - $this->assertEquals('A l\'école des sorciers', $this->_record->titles[1]); + $this->assertEquals('A l\'école des sorciers', $this->_first->titles[1]); } /** @test */ public function serialTitleShouldBeHarryPotter() { - $this->assertEquals('Harry Potter', $this->_record->serial); + $this->assertEquals('Harry Potter', $this->_first->serial); } /** @test */ public function shouldHave2Creators() { - $this->assertEquals(2, count($this->_record->creators)); + $this->assertEquals(2, count($this->_first->creators)); } /** @test */ public function firstCreatorShouldBeJKRowling() { - $this->assertEquals('Rowling|Joanne Kathleen', $this->_record->creators[0]); + $this->assertEquals('Rowling|Joanne Kathleen', $this->_first->creators[0]); } /** @test */ public function secondCreatorShouldBeJFMenard() { - $this->assertEquals('Ménard|Jean-François', $this->_record->creators[1]); + $this->assertEquals('Ménard|Jean-François', $this->_first->creators[1]); } /** @test */ public function firstPublishersShouldBeGallimardJeunesse() { - $this->assertEquals('Gallimard Jeunesse (Paris)', $this->_record->publishers[0]); + $this->assertEquals('Gallimard Jeunesse (Paris)', $this->_first->publishers[0]); } /** @test */ public function dateShouldBe1998() { - $this->assertEquals('1998', $this->_record->date); + $this->assertEquals('1998', $this->_first->date); } /** @test */ public function volumeShouldBeOne() { - $this->assertEquals('1', $this->_record->volume); + $this->assertEquals('1', $this->_first->volume); } /** @test */ public function languageShouldNotBePresent() { - $this->assertFalse(property_exists($this->_record, 'language')); + $this->assertFalse(property_exists($this->_first, 'language')); } /** @test */ public function descriptionShouldNotBePresent() { - $this->assertFalse(property_exists($this->_record, 'description')); + $this->assertFalse(property_exists($this->_first, 'description')); } /** @test */ public function firstCollectionShouldBeFolioJunior() { - $this->assertEquals('Folio junior', $this->_record->collections[0]); + $this->assertEquals('Folio junior', $this->_first->collections[0]); } @@ -304,6 +340,6 @@ class RechercheControllerJsonOneResultTest extends RechercheControllerJsonTestCa protected function classifAt($position) { - return $this->_record->classifications[$position]; + return $this->_first->classifications[$position]; } } \ No newline at end of file