From 37c81fa60dc437dd3bc3dfbeff65123a90c889fc Mon Sep 17 00:00:00 2001 From: Laurent Laffont <llaffont@afi-sa.fr> Date: Tue, 2 Jan 2018 14:18:00 +0100 Subject: [PATCH] hotline #65920 kiosk widget: random option fix --- VERSIONS_HOTLINE/65920 | 1 + .../ZendAfi/View/Helper/Accueil/Kiosque.php | 21 +++-- .../opac/controllers/JavaControllerTest.php | 3 +- .../View/Helper/Accueil/KiosqueTest.php | 93 +++++++++++++++++-- 4 files changed, 104 insertions(+), 14 deletions(-) create mode 100644 VERSIONS_HOTLINE/65920 diff --git a/VERSIONS_HOTLINE/65920 b/VERSIONS_HOTLINE/65920 new file mode 100644 index 00000000000..abee31eb33f --- /dev/null +++ b/VERSIONS_HOTLINE/65920 @@ -0,0 +1 @@ + - ticket #65920 : Boites kiosque : correction de la fonction de tirage aléatoire \ No newline at end of file diff --git a/library/ZendAfi/View/Helper/Accueil/Kiosque.php b/library/ZendAfi/View/Helper/Accueil/Kiosque.php index c59660584b3..466c5edaf12 100644 --- a/library/ZendAfi/View/Helper/Accueil/Kiosque.php +++ b/library/ZendAfi/View/Helper/Accueil/Kiosque.php @@ -280,6 +280,10 @@ class ZendAfi_View_Helper_Accueil_Kiosque extends ZendAfi_View_Helper_Accueil_Ba public function getKiosqueHtml($page = 1) { + if ($this->isModeChrono() || (1 === (int)$this->preferences['aleatoire'])) + return $this->_noPagerKioskHtml(); + + $this->_nombre_notices_par_page = $this->preferences['nb_notices']; $nombre_total_notices = 0; $this->preferences['nb_notices'] = 0; @@ -296,15 +300,20 @@ class ZendAfi_View_Helper_Accueil_Kiosque extends ZendAfi_View_Helper_Accueil_Ba if(!$notices) return $this->view->tag('p',$this->view->_('Aucun résultat')); - $html = $this->renderNoticesKiosqueHtml($notices); - if (!$this->isModeChrono()) - $html = $this - ->getPagerHtml($page, + return + $this->getPagerHtml($page, $this->_nombre_notices_par_page, $nombre_total_notices) - . $html; + . + $this->renderNoticesKiosqueHtml($notices); + } + + + protected function _noPagerKioskHtml() { + if (!$records = Class_Catalogue::getNoticesByPreferences($this->preferences)) + return $this->view->tag('p',$this->view->_('Aucun résultat')); - return $html; + return $this->renderNoticesKiosqueHtml($records); } diff --git a/tests/application/modules/opac/controllers/JavaControllerTest.php b/tests/application/modules/opac/controllers/JavaControllerTest.php index 4f708a3c6fb..843de17ff8c 100644 --- a/tests/application/modules/opac/controllers/JavaControllerTest.php +++ b/tests/application/modules/opac/controllers/JavaControllerTest.php @@ -105,6 +105,7 @@ class JavaControllerWithKiosqueMurPageTest extends AbstractControllerTestCase { 'preferences' => ['style_liste' => 'mur', 'nb_notices' => 10, 'nb_analyse' => 50, + 'aleatoire' => 0, 'only_img' => 0]]]]; Class_Profil::getCurrentProfil()->setCfgAccueil($cfg_accueil); @@ -115,7 +116,7 @@ class JavaControllerWithKiosqueMurPageTest extends AbstractControllerTestCase { /** @test */ public function firstControlShouldLinkToPageOne() { - $this->assertXPath('//div[@class="controls"]/a[1][contains(@href, "java/page/no/1/id_module/1")]', $this->_response->getBody()); + $this->assertXPath('//div[@class="controls"]/a[1][contains(@href, "java/page/no/1/id_module/1")]'); } diff --git a/tests/library/ZendAfi/View/Helper/Accueil/KiosqueTest.php b/tests/library/ZendAfi/View/Helper/Accueil/KiosqueTest.php index 05f9dbef3a4..27a7021350a 100644 --- a/tests/library/ZendAfi/View/Helper/Accueil/KiosqueTest.php +++ b/tests/library/ZendAfi/View/Helper/Accueil/KiosqueTest.php @@ -21,7 +21,9 @@ abstract class ZendAfi_View_Helper_Accueil_KiosqueTestCase extends ViewHelperTestCase { - protected $_html; + protected + $_html, + $_storm_default_to_volatile = true; public function setUp() { parent::setUp(); @@ -227,11 +229,27 @@ class ZendAfi_View_Helper_Accueil_KiosqueMurWithPanierAndTriTest extends ZendAfi -class ZendAfi_View_Helper_Accueil_KiosqueChronoWithCatalogueTest extends ZendAfi_View_Helper_Accueil_KiosqueMurTestCase { - public function getExtraPreferences() { - return ['id_catalogue' => 12, - 'style_liste' => 'chrono', - 'op_hauteur' => 400]; +class ZendAfi_View_Helper_Accueil_KiosqueChronoWithCatalogueTest extends ZendAfi_View_Helper_Accueil_KiosqueTestCase { + public function getPreferences() { + return ['type_module' => 'KIOSQUE', + 'division' => 3, + 'preferences' => ['style_liste' => 'chrono', + 'id_catalogue' => 12, + 'op_hauteur' => 400, + 'aleatoire' => 0 + ] + ]; + } + + + public function setUp() { + parent::setUp(); + Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Catalogue') + ->whenCalled('getNoticesByPreferences') + ->answers($this->_notices); + + + $this->_html = $this->_helper->getKiosqueHtml(); } @@ -240,14 +258,22 @@ class ZendAfi_View_Helper_Accueil_KiosqueChronoWithCatalogueTest extends ZendAfi $this->assertXPath($this->_html, '//div[@class="liste_chrono"][contains(@id,"liste_chrono_")]'); } + /** @test */ public function heightShouldBe400() { $this->assertContains('"height":400', $this->_html); } + + + /** @test */ + public function pageShouldNotContainsPager() { + $this->assertNotXPath($this->_html, '//div[@class="controls"]'); + } } + abstract class ZendAfi_View_Helper_Accueil_KiosqueRequetesTestCase extends ZendAfi_View_Helper_Accueil_KiosqueTestCase { public function setUp() { parent::setUp(); @@ -304,7 +330,6 @@ abstract class ZendAfi_View_Helper_Accueil_KiosqueRequetesTestCase extends ZendA class ZendAfi_View_Helper_Accueil_KiosqueRequetesAsRedacteurTest extends ZendAfi_View_Helper_Accueil_KiosqueRequetesTestCase { - protected $_catalogue_cinema; public function setUp() { @@ -615,3 +640,57 @@ class ZendAfi_View_Helper_Accueil_KiosqueWithLinkedRecordsInDomainSetTest extend $this->assertEquals('select id_notice from notices Where MATCH(facettes) AGAINST(\'Q5\' IN BOOLEAN MODE) order by date_creation DESC LIMIT 0,50', $this->_request['req_liste']); } } + + + + +class ZendAfi_View_Helper_Accueil_WallKioskRandomTest extends ZendAfi_View_Helper_Accueil_KiosqueTestCase { + public function getPreferences() { + return ['type_module' => 'KIOSQUE', + 'division' => 3, + 'preferences' => ['style_liste' => 'mur', + 'id_catalogue' => 12, + 'aleatoire' => 1, + 'tri' => 1, + 'nb_notices' => 20, + 'nb_analyse' => 100] + ]; + } + + + public function setUp() { + parent::setUp(); + + Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Catalogue') + ->whenCalled('getNoticesByPreferences') + ->answers($this->_notices); + + $this->_html = $this->_helper->getKiosqueHtml(); + } + + + /** @test */ + public function htmlShouldNotContainsPager() { + $this->assertNotXPath($this->_html, '//div[@class="controls"]'); + } + + + /** @test */ + public function htmlShouldContainsTwoRecords() { + $this->assertXPathCount($this->_html, '//div[@class="liste_mur"]//div[@class="notice"]', + 2, + $this->_html); + } + + + /** @test */ + public function withoutRecordsHtmlShouldContainsNoResult() { + Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Catalogue') + ->whenCalled('getNoticesByPreferences') + ->answers([]); + + $this->assertXPathContentContains($this->_helper->getKiosqueHtml(), + '//p', + utf8_encode('Aucun résultat')); + } +} -- GitLab