From 7ce1b07a72964928cd3b115c9a92300fde5e6900 Mon Sep 17 00:00:00 2001 From: Henri-Damien LAURENT <hdlaurent@afi-sa.fr> Date: Thu, 6 Oct 2022 09:50:26 +0000 Subject: [PATCH] hotline#163882 : [MT] Search : Fix error 500 on corrupted page_size_data --- library/Class/CriteresRecherche.php | 4 +-- library/Class/CriteresRecherche/Abstract.php | 4 +-- library/Class/MoteurRecherche/Result.php | 4 +-- library/Class/User/Settings.php | 8 ++--- .../Templates/TemplatesUserSettingsTest.php | 33 +++++++++++++++++++ 5 files changed, 43 insertions(+), 10 deletions(-) diff --git a/library/Class/CriteresRecherche.php b/library/Class/CriteresRecherche.php index 7db0d071bac..d8b5dc30b78 100644 --- a/library/Class/CriteresRecherche.php +++ b/library/Class/CriteresRecherche.php @@ -1008,8 +1008,8 @@ class Class_CriteresRecherche extends Class_CriteresRecherche_Abstract { } - public function getPageSize() { - if ($size = $this->getParam('page_size')) + public function getPageSize() : int { + if ($size = (int) $this->getParam('page_size')) return $size; if ($user_page_size = (new Class_User_Settings(Class_Users::getIdentity()))->getSearchPageSize()) diff --git a/library/Class/CriteresRecherche/Abstract.php b/library/Class/CriteresRecherche/Abstract.php index 3f1288a066c..2afa02fad30 100644 --- a/library/Class/CriteresRecherche/Abstract.php +++ b/library/Class/CriteresRecherche/Abstract.php @@ -163,8 +163,8 @@ abstract class Class_CriteresRecherche_Abstract { } - public function getPageSize() { - return $this->getParam('page_size', + public function getPageSize() : int { + return (int) $this->getParam('page_size', $this->_default_page_size); } diff --git a/library/Class/MoteurRecherche/Result.php b/library/Class/MoteurRecherche/Result.php index af4912deb2f..1776d975ab9 100644 --- a/library/Class/MoteurRecherche/Result.php +++ b/library/Class/MoteurRecherche/Result.php @@ -238,7 +238,7 @@ class Class_MoteurRecherche_Result { } - public function getRecordsCount() { + public function getRecordsCount() : int { return count($this->fetchAllRecordsIds()); } @@ -315,7 +315,7 @@ class Class_MoteurRecherche_ResultWork extends Class_MoteurRecherche_Result { } - public function getRecordsCount() { + public function getRecordsCount() : int { $this->fetchAllRecordsIds(); return count($this->_works); } diff --git a/library/Class/User/Settings.php b/library/Class/User/Settings.php index 7e4ef16eaec..5eb97151f05 100644 --- a/library/Class/User/Settings.php +++ b/library/Class/User/Settings.php @@ -288,7 +288,7 @@ class Class_User_Settings { protected function _saveUserWithLib($id) : self { - if ($id === $this->get(Class_User_Setting::BOOKMARKED_LIBRARIES)) + if ((int) $id === (int) $this->get(Class_User_Setting::BOOKMARKED_LIBRARIES)) return $this; $this->set(Class_User_Setting::BOOKMARKED_LIBRARIES, [$id]); @@ -364,12 +364,12 @@ class Class_User_Settings { } - public function getSearchPageSize() { - return $this->get(Class_User_Setting::SEARCH_PAGE_SIZE); + public function getSearchPageSize() : int { + return (int) $this->get(Class_User_Setting::SEARCH_PAGE_SIZE); } - public function setSearchPageSize($size) { + public function setSearchPageSize(int $size) { return $this->set(Class_User_Setting::SEARCH_PAGE_SIZE, $size); } diff --git a/tests/scenarios/Templates/TemplatesUserSettingsTest.php b/tests/scenarios/Templates/TemplatesUserSettingsTest.php index 01eeba821b0..fc1eef148c7 100644 --- a/tests/scenarios/Templates/TemplatesUserSettingsTest.php +++ b/tests/scenarios/Templates/TemplatesUserSettingsTest.php @@ -370,3 +370,36 @@ class TemplatesUserSettingsSearchSaveChiliAndDomainBDAndWidgetDomainTest extends Zend_Registry::get('sql')->getFirstAttributeForLastCallOn('fetchAll')); } } + + + + +class TemplateUserSettingsWithCorruptedDataTest extends AbstractControllerTestCase { + public function setUp() { + parent::setUp(); + $this->_buildTemplateProfil(['id' => 1]); + + $john = $this->fixture(Class_Users::class, + ['id' => 5, + 'login' => 'John', + 'password' => 'motdepasse', + 'settings' => 'a:5:{s:11:"library_ids";s:0:"";s:12:"search_order";s:35:"date_creation desc, alpha_titre asc";s:13:"search_layout";s:1:"3";s:16:"search_page_size";s:12:"kreversi.png";s:13:"profile_image";s:41:"public/opac/images/abonnes/read_black.png";}' + ]); + ZendAfi_Auth::getInstance()->logUser($john); + + $this->fixture(Class_Notice::class, + ['id' => 1]); + + Zend_Registry::set('sql', $this->mock() + ->whenCalled('fetchAll') + ->answers([[1,'']])); + + $this->dispatch('/recherche/pomme'); + } + + + /** @test */ + public function pageSizeShouldBeTen() { + $this->assertXPathContentContains('//div[@class="selector_widget"]//form//select[contains(@onchange, "page_size/\'+value")]/option[@value=10][@selected]', 10); + } +} -- GitLab