diff --git a/VERSIONS_HOTLINE/122926 b/VERSIONS_HOTLINE/122926 new file mode 100644 index 0000000000000000000000000000000000000000..0f6475c6ebb11d1e94af6d6dda4fa240c1b14e76 --- /dev/null +++ b/VERSIONS_HOTLINE/122926 @@ -0,0 +1 @@ + - ticket #122926 : Magasin de thèmes : Amélioration du bouton réserver de la page notice. \ No newline at end of file diff --git a/library/templates/Chili/View/RenderRecord/RenderItems.php b/library/templates/Chili/View/RenderRecord/RenderItems.php index a8c1f6c407d28cc3b1fdda7e5b91f6b0807c7b8d..62c48defc6ca58734c9afb21ab37d8272a29b6e0 100644 --- a/library/templates/Chili/View/RenderRecord/RenderItems.php +++ b/library/templates/Chili/View/RenderRecord/RenderItems.php @@ -22,15 +22,13 @@ class Chili_View_RenderRecord_RenderItems extends Intonation_View_RenderRecord_RenderItems { protected function _hookForMoreHtml($items) { - if ( ! $first_item = reset($items)) - return ''; + if ( ! $first_item = $this->_getFirstHoldableItem($items)) + return $this->_noHoldableItem(); if ( ! $record = $first_item->getNotice()) - return ''; + return $this->_noHoldableItem(); - $hold = new Intonation_Library_Link(['Url' => $this->view->url(['controller' => 'abonne', - 'action' => 'reserver', - 'record_id' => $record->getId()]), + $hold = new Intonation_Library_Link(['Url' => $first_item->getHoldLink(), 'Text' => $this->_('Réserver'), 'Image' => (Class_Template::current() ->getIco($this->view, @@ -42,5 +40,21 @@ class Chili_View_RenderRecord_RenderItems extends Intonation_View_RenderRecord_R return $this->view->div(['class' => 'items_hold_link'], $this->view->tagAction($hold)); + + } + + + protected function _noHoldableItem() { + return $this->view->div(['class' => 'items_hold_link no_holdable_item'], + $this->_('Réservation impossible, pas d\'exemplaire réservable')); + } + + + protected function _getFirstHoldableItem($items) { + return (new Storm_Collection($items)) + ->detect( function($item) + { + return $item->getHoldLink(); + } ); } } diff --git a/tests/scenarios/Templates/ChiliItemsTest.php b/tests/scenarios/Templates/ChiliItemsTest.php index 3ad805d527b2fdc052f06b3bc2ec4a3f1cca2841..a8cdd847239551339efa557aa1a495cecb0958d1 100644 --- a/tests/scenarios/Templates/ChiliItemsTest.php +++ b/tests/scenarios/Templates/ChiliItemsTest.php @@ -45,7 +45,47 @@ class ChiliItemsDispatchTest extends AbstractControllerTestCase { /** @test */ public function pageShouldContainsLinkToHold() { - $this->assertXPathContentContains('//div[@class="items_hold_link col-12 p-3 my-3 text-center"]//a[contains(@href, "abonne/reserver")]', + $this->assertXPathContentContains('//div[@class="items_hold_link col-12 p-3 my-3 text-center"]//a[contains(@href, "/recherche/reservation/id_int_bib/0/id_bib/0/id_notice/2")]', utf8_encode('Réserver')); } } + + + + +class ChiliItemsNoHoldableItemsDispatchTest extends AbstractControllerTestCase { + protected $_storm_default_to_volatile = true; + + + public function setUp() { + parent::setUp(); + + $this->_buildTemplateProfil(['id' => 3, + 'template' => 'CHILI']); + + $this->fixture('Class_Notice', + ['id' => 2, + ]); + + $this->fixture('Class_Exemplaire', + ['id' => 1, + 'id_notice' => 2, + 'id_bib' => 1 + ]); + + $this->fixture('Class_Bib', + ['id' => 1, + 'libelle' => 'Montmin', + 'interdire_resa' => 1 + ]); + + $this->dispatch('noticeajax/items-resources/id/2'); + } + + + /** @test */ + public function pageShouldContainsNoHoldableItemMessage() { + $this->assertXPathContentContains('//div[@class="items_hold_link no_holdable_item col-12 p-3 my-3 text-center"]', + utf8_encode('Réservation impossible, pas d\'exemplaire réservable')); + } +}