diff --git a/FEATURES/156866 b/FEATURES/156866 new file mode 100644 index 0000000000000000000000000000000000000000..e39eeb7792a52798c9e79e1e9ad4418f4f7c9ad1 --- /dev/null +++ b/FEATURES/156866 @@ -0,0 +1,10 @@ + '156866' => + ['Label' => $this->_('Remplissage automatique du formulaire de recherche avancée'), + 'Desc' => $this->_('Lorsqu\'on effectue une recherche via le formulaire de recherche avancée, le résultat de recherche affiche un bouton pour revenir au formulaire pré-rempli avec les valeurs saisies (magasin de thèmes seulement)'), + 'Image' => '', + 'Video' => '', + 'Category' => $this->_('Recherche'), + 'Right' => function($feature_description, $user) {return true;}, + 'Wiki' => 'https://wiki.bokeh-library-portal.org/index.php?title=Recherche_avanc%C3%A9e', + 'Test' => '', + 'Date' => '2022-06-15'], \ No newline at end of file diff --git a/VERSIONS_WIP/156866 b/VERSIONS_WIP/156866 new file mode 100644 index 0000000000000000000000000000000000000000..47a11bd54036487da1d296a67e98efb016a3c0ad --- /dev/null +++ b/VERSIONS_WIP/156866 @@ -0,0 +1 @@ + - fonctionnalité #156866 : Magasin de thèmes : Lorsqu'on effectue une recherche via le formulaire de recherche avancée, le résultat de recherche affiche un bouton pour revenir au formulaire pré-rempli avec les valeurs saisies \ No newline at end of file diff --git a/application/modules/opac/controllers/RechercheController.php b/application/modules/opac/controllers/RechercheController.php index df23656a12aa56cb4721a5a449d3ecd998201bf1..a1837ec342a62573009df4a4b83c8c4070d31588 100644 --- a/application/modules/opac/controllers/RechercheController.php +++ b/application/modules/opac/controllers/RechercheController.php @@ -118,7 +118,7 @@ class RechercheController extends ZendAfi_Controller_Action { ->getSearchCriteria() ->setParams($this->_request->getParams()); - $this->view->active_tab = $this->_getParam('form_id', 0); + $this->view->active_tab = $this->_getParam(Class_SearchForm_Post::FORM_ID, 0); $this->view->search_forms = Class_SearchForm::findAllByPrefs(isset($this->preferences['forms']) ? $this->preferences['forms'] diff --git a/library/Class/CriteresRecherche.php b/library/Class/CriteresRecherche.php index c8e3639dede630ef8ed1f0168c0c7152d8e7c73a..1b37e82a9c512ee09e446335b35ab3a98e7720c3 100644 --- a/library/Class/CriteresRecherche.php +++ b/library/Class/CriteresRecherche.php @@ -59,7 +59,7 @@ class Class_CriteresRecherche extends Class_CriteresRecherche_Abstract { 'operateur_editeur'=>'', 'operateur_collection'=>'', 'section' => '', - 'form_id' => '', + Class_SearchForm_Post::FORM_ID => '', 'page' => 1, 'page_size' => '', 'genre' => '', @@ -73,7 +73,8 @@ class Class_CriteresRecherche extends Class_CriteresRecherche_Abstract { 'cote_fin' => '', 'by_work' => '', 'work' => '', - 'limit' => 0]; + 'limit' => 0, + Class_SearchForm_Post::POST_CACHE_KEY => '']; public function __construct() { diff --git a/library/Class/Profil.php b/library/Class/Profil.php index f300ca7036cfc9504be243af4994904c54c92598..32c2ece5567af78639a594ff9e99010bcfa32a36 100644 --- a/library/Class/Profil.php +++ b/library/Class/Profil.php @@ -2336,7 +2336,7 @@ class Class_Profil extends Storm_Model_Abstract { } - public function getSearchResultSettings() { + public function getSearchResultSettings() : array { return $this->getConfigurationOf('recherche', 'resultat' , 'simple'); } @@ -2348,7 +2348,7 @@ class Class_Profil extends Storm_Model_Abstract { } - public function getConfigurationOf($module,$action, $action2) { + public function getConfigurationOf($module,$action, $action2) : array { $cfg = $this->getCfgModulesAsArray(); $default_cfg = (new Class_Systeme_ModulesAppli())->getValeursParDefaut($module, $action); return diff --git a/library/Class/SearchForm.php b/library/Class/SearchForm.php index 3c9912e83e1daa1a04ef01e12ac2560f3b462be9..871fa4e73b932abe25ea83d6f2c8a2e1a7b6d533 100644 --- a/library/Class/SearchForm.php +++ b/library/Class/SearchForm.php @@ -102,8 +102,8 @@ class Class_SearchForm extends Storm_Model_Abstract { } - public function getFormInstance() { - return (new Class_SearchFormWrapper($this, static::$_throw_errors))->getFormInstance(); + public function getFormInstance() : Class_SearchForm_Wrapper { + return (new Class_SearchForm_Wrapper($this, static::$_throw_errors))->getFormInstance(); } @@ -132,101 +132,3 @@ class Class_SearchForm extends Storm_Model_Abstract { return !$this->linkedModels()->isEmpty(); } } - - - - -class Class_SearchFormWrapper { - - use Trait_Translator; - - - protected - $_search_form, - $_throw_errors = false, - $_form, - $_errors = []; - - - public function __construct($search_form, $throw_errors) { - $this->_search_form = $search_form; - $this->_throw_errors = $throw_errors; - } - - - public function getFormInstance() { - if (!$this->_search_form->hasFilename()) - return $this->addError($this->_('Aucun fichier lié à ce formulaire')); - - Class_FileManager::beOpenBar(); - if (!$file = Class_FileManager::find($this->_search_form->getFilename())) - return $this->addError($this->_('Le fichier lié à ce formulaire n\'a pas été trouvé')); - - if (!$content = $file->getContent()) - return $this->addError($this->_('Le fichier lié à ce formulaire est vide ou illisible')); - - $validator = new Class_SearchForm_Validator; - if (!$validator->isValid($content)) - return $this->addError($this->_('Le fichier lié à ce formulaire n\'est pas valide : %s', $validator->getError())); - - $form = new ZendAfi_Form_AdvancedSearch(); - $form->setAttrib('data-custom-form-id', $this->_search_form->getId()); - - $runtime_error = $this->_include($file->getRealpath(), $form); - - if ($runtime_error) - return $this->addError($this->_('Le fichier lié à ce formulaire a provoqué une erreur d\'exécution : %s', - $runtime_error)); - - return $this->setForm($form); - } - - - protected function _include($path, $form) { - $includer = Class_SearchForm::getIncluder(); - - if ($this->_throw_errors) { - $includer($path, $form); - return ''; - } - - try { - $includer($path, $form); - return ''; - } catch(Exception $e) { - return $e->getMessage(); - } - } - - - public function hasError() { - return !empty($this->_errors); - } - - - public function addError($error) { - $this->_errors [] = $error; - return $this; - } - - - public function getErrors() { - return $this->_errors; - } - - - public function setForm($form) { - $this->_form = $form; - return $this; - } - - - public function getForm() { - return $this->_form; - } - - - public function isFormVisible() { - return $this->_search_form->isVisible(); - } -} \ No newline at end of file diff --git a/library/Class/SearchForm/Post.php b/library/Class/SearchForm/Post.php new file mode 100644 index 0000000000000000000000000000000000000000..6e6f3b22217ec1f3d440322237a98bcf623b2a30 --- /dev/null +++ b/library/Class/SearchForm/Post.php @@ -0,0 +1,97 @@ +<?php +/** + * Copyright (c) 2012-2022, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * BOKEH is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * 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 + */ + + +class Class_SearchForm_Post { + const + POST_CACHE_KEY = 'post', + FORM_ID = 'form_id'; + + protected Zend_Session_Abstract $_session; + + + public static function onCurrentSession() : self { + return new Class_SearchForm_Post(Zend_Registry::get('session')); + } + + + public function __construct(Zend_Session_Abstract $session) { + $this->_session = $session; + if (!$this->_session->searches) + $this->_session->searches = []; + } + + + public function withSearchFormUrlDo(Class_CriteresRecherche $search_criteria, + Closure $with_url_do) : self { + if (!$key = $search_criteria->getParam(static::POST_CACHE_KEY)) + return $this; + + if (!$post = $this->_session->searches[$key] ?? null) + return $this; + + $with_url_do(Class_Url::relative(array_filter(['controller' => 'recherche', + 'action' => 'avancee', + static::POST_CACHE_KEY => $search_criteria->getParam(static::POST_CACHE_KEY), + static::FORM_ID => $search_criteria->getParam(static::FORM_ID)]))); + return $this; + } + + + public function withRequestPostDo(Zend_Controller_Request_Abstract $request, + Closure $with_post_do) : self { + + $post = $request->getPost(); + + if (null !== $request->getParam(static::FORM_ID)) + $this->_saveAndUpdatePost($post); + + $search_params = array_diff_key( + array_merge($request->getParams(), + $post), + ['module' => '', + 'controller' => '', + 'action' => '', + 'current_module' => '']); + $with_post_do($search_params); + return $this; + } + + + protected function _saveAndUpdatePost(array &$post) : self { + if (!$post) + return $this; + + $cache_key = md5(serialize($post)); + + $this->_session->searches[$cache_key] = $post; + + $post[static::POST_CACHE_KEY] = $cache_key; + return $this; + } + + + public function loadPost(Zend_Controller_Request_Abstract $request) : array { + if (!$key = $request->getParam(static::POST_CACHE_KEY)) + return []; + return $this->_session->searches[$key] ?? []; + } +} diff --git a/library/Class/SearchForm/Wrapper.php b/library/Class/SearchForm/Wrapper.php new file mode 100644 index 0000000000000000000000000000000000000000..36ae992f8d1b86995365deb5bd51f6b056f983f0 --- /dev/null +++ b/library/Class/SearchForm/Wrapper.php @@ -0,0 +1,125 @@ +<?php +/** + * Copyright (c) 2012-2022, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * BOKEH is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * 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 + */ + +class Class_SearchForm_Wrapper { + use + Trait_Translator, + Trait_StormFileSystem; + + + protected Class_SearchForm $_search_form; + protected bool $_throw_errors = false; + protected ZendAfi_Form_AdvancedSearch $_form; + protected array $_errors = []; + + + public function __construct(Class_SearchForm $search_form, bool $throw_errors) { + $this->_search_form = $search_form; + $this->_throw_errors = $throw_errors; + } + + + public function getFormInstance() : self { + if (!$this->_search_form->hasFilename()) + return $this->addError($this->_('Aucun fichier lié à ce formulaire')); + + $filepath = $this->_getFormRealPath(); + + if (!$this->getFileSystem()->isReadable($filepath)) + return $this->addError($this->_('Le fichier lié à ce formulaire n\'a pas été trouvé')); + + if (!$content = $this->getFileSystem()->fileGetContents($filepath)) + return $this->addError($this->_('Le fichier lié à ce formulaire est vide ou illisible')); + + $validator = new Class_SearchForm_Validator; + if (!$validator->isValid($content)) + return $this->addError($this->_('Le fichier lié à ce formulaire n\'est pas valide : %s', $validator->getError())); + + $form = new ZendAfi_Form_AdvancedSearch(); + $form->setAttrib('data-custom-form-id', $this->_search_form->getId()); + + $runtime_error = $this->_include($filepath, $form); + + if ($runtime_error) + return $this->addError($this->_('Le fichier lié à ce formulaire a provoqué une erreur d\'exécution : %s', + $runtime_error)); + + return $this->setForm($form); + } + + + protected function _getFormRealPath() : string { + $filepath = $this->_search_form->getFilename(); + if ('/' === substr($filepath, 0, 1)) + $filepath = substr($filepath, 1); + + return $filepath; + } + + + protected function _include(string $path, ZendAfi_Form_AdvancedSearch $form) : string { + $includer = Class_SearchForm::getIncluder(); + + if ($this->_throw_errors) { + $includer($path, $form); + return ''; + } + + try { + $includer($path, $form); + return ''; + } catch(Exception $e) { + return $e->getMessage(); + } + } + + + public function hasError() : bool { + return !empty($this->_errors); + } + + + public function addError(string $error) : self { + $this->_errors [] = $error; + return $this; + } + + + public function getErrors() : array { + return $this->_errors; + } + + + public function setForm(ZendAfi_Form_AdvancedSearch $form) : self { + $this->_form = $form; + return $this; + } + + + public function getForm() : ZendAfi_Form_AdvancedSearch { + return $this->_form; + } + + + public function isFormVisible() : bool { + return $this->_search_form->isVisible(); + } +} diff --git a/library/ZendAfi/Controller/Action/Helper/CatalogSearch.php b/library/ZendAfi/Controller/Action/Helper/CatalogSearch.php index 9560cdc9bc761515d33b4a0148b7380bd039068a..a56564165a871411b6c64d8c6ab0316addf4cf00 100644 --- a/library/ZendAfi/Controller/Action/Helper/CatalogSearch.php +++ b/library/ZendAfi/Controller/Action/Helper/CatalogSearch.php @@ -43,25 +43,11 @@ class ZendAfi_Controller_Action_Helper_CatalogSearch || $this->_getParam('statut') == static::RESET) return $this->_redirect('opac/recherche/saisie'); - $this->_criteria = $criteria; - - $this->_preferences = (array) $this - ->_findProfile($this->_criteria) - ->getSearchResultSettings(); - - $params = array_merge($this->_request->getParams(), - $this->_request->getPost()); - $params = - array_diff_key($params, - ['module' => '', - 'controller' => '', - 'action' => '', - 'current_module' => '']); - - $this->_criteria->setParams($params, $this->_preferences); - $this->_initializeSortOrderFromUserSettingsOrUrlParams(); + $this + ->_initializeSearchCriteriasAndPreferences($criteria) + ->_initializeSortOrderFromUserSettingsOrUrlParams(); - if ($redirect_params = $this->_getRedirectParams($params)) + if ($redirect_params = $this->_getRedirectParams($this->_request->getParams())) return $this->_redirect($this->_view->url($redirect_params, null, true), ['prependBase' => false]); @@ -79,6 +65,21 @@ class ZendAfi_Controller_Action_Helper_CatalogSearch } + protected function _initializeSearchCriteriasAndPreferences(Class_CriteresRecherche $criteria) : self { + $this->_criteria = $criteria; + + $this->_preferences = $this + ->_findProfile($this->_criteria) + ->getSearchResultSettings(); + + Class_SearchForm_Post::onCurrentSession() + ->withRequestPostDo($this->_request, + fn(array $params) => $this->_criteria->setParams($params, + $this->_preferences)); + return $this; + } + + protected function _getRedirectParams(array $params) : array { $should_redirect = false; @@ -257,4 +258,4 @@ class ZendAfi_Controller_Action_Helper_CatalogSearch 'page' => $this->_getParam('page', 1), 'records' => $records]); } -} \ No newline at end of file +} diff --git a/library/ZendAfi/Form/AdvancedSearch.php b/library/ZendAfi/Form/AdvancedSearch.php index b087ad2d526c7889878594c6aa01ac419f376b8e..e49711539acaedbb2d06c8d36cd619e88abb6115 100644 --- a/library/ZendAfi/Form/AdvancedSearch.php +++ b/library/ZendAfi/Form/AdvancedSearch.php @@ -21,7 +21,18 @@ class ZendAfi_Form_AdvancedSearch extends ZendAfi_Form { - protected $_axes = []; + protected array $_axes = []; + + public function __construct($options = null) { + parent::__construct($options); + $this->_axes = ['titres' => $this->_('Titres'), + 'auteurs' => $this->_('Auteurs'), + 'matieres' => $this->_('Sujets'), + 'dewey' => $this->_('Centres d\'intérêt'), + 'editeur' => $this->_('Editeur'), + 'collection' => $this->_('Collection')]; + } + public function addElement($element, $name = null, $options = null) { parent::addElement($element, $name, $options); @@ -36,12 +47,6 @@ class ZendAfi_Form_AdvancedSearch extends ZendAfi_Form { public function loadDefaults() { $keypress = ['onkeypress' => 'if (event.keyCode == 13) { this.form.submit();return false;}']; - $this->_axes = ['titres' => $this->_('Titres'), - 'auteurs' => $this->_('Auteurs'), - 'matieres' => $this->_('Sujets'), - 'dewey' => $this->_('Centres d\'intérêt'), - 'editeur' => $this->_('Editeur'), - 'collection' => $this->_('Collection')]; foreach($this->_axes as $type => $label) $this->addElement('searchAxe', $type, ['label' => $label, @@ -114,21 +119,17 @@ class ZendAfi_Form_AdvancedSearch extends ZendAfi_Form { } - public function populate(array $datas) { + public function populate(array $datas) : self { parent::populate($datas); - foreach(array_keys($this->_axes) as $type) - $this->$type->setCompositeInputValues($datas); - - if ($this->annee) - $this->annee->setCompositeInputValues($datas); - - foreach($this->_elementsByClass(ZendAfi_Form_Element_SearchAxeMultiInput::class) as $element) + foreach($this->_elementsByClass(ZendAfi_Form_Element_CompositeValues::class) as $element) $element->setCompositeInputValues($datas); + + return $this; } - protected function _elementsByClass($class_name) { + protected function _elementsByClass(string $class_name) : array { return array_filter($this->getElements(), function($element) use($class_name) { diff --git a/library/ZendAfi/Form/Decorator/AuthorityPicker.php b/library/ZendAfi/Form/Decorator/AuthorityPicker.php index c95718ad918fa868c8d17440b9d4bc8ab27a2431..caaacc0b624e5bf029512b2642590a2208c6218f 100644 --- a/library/ZendAfi/Form/Decorator/AuthorityPicker.php +++ b/library/ZendAfi/Form/Decorator/AuthorityPicker.php @@ -53,7 +53,9 @@ pick_url:' . json_encode($view->url($this->_getParams(), null, true)) .' ->setAttribs(['onclick' => 'return false;'])) . $view->formLabel($mode_id, - $view->formCheckbox($mode_id, 1, ['checked' => true]) + $view->formCheckbox($mode_id, + 1, + ['checked' => $this->_element->getIncludeSpecificTerms()]) . ' ' . $this->_('Inclure les termes spécifiques'), ['escape' => false]) diff --git a/library/ZendAfi/Form/Element/Authority.php b/library/ZendAfi/Form/Element/Authority.php index 14b61bee7c69d750e8bce938a666147284e92dfb..b3df089e228b9f71f3a005390c8a1248d3b72370 100644 --- a/library/ZendAfi/Form/Element/Authority.php +++ b/library/ZendAfi/Form/Element/Authority.php @@ -20,12 +20,13 @@ */ -class ZendAfi_Form_Element_Authority extends Zend_Form_Element_Xhtml { +class ZendAfi_Form_Element_Authority extends Zend_Form_Element_Xhtml implements ZendAfi_Form_Element_CompositeValues { use Trait_Translator; protected $_pick_button_label, - $_reset_button_label; + $_reset_button_label, + $_include_specific_terms = true; public function __construct($spec, $options = null) { parent::__construct($spec, $options); @@ -40,31 +41,47 @@ class ZendAfi_Form_Element_Authority extends Zend_Form_Element_Xhtml { } - public function getRecordLabel() { + public function setCompositeInputValues(array $datas) : self { + if ($value = $datas[ZendAfi_Form_Decorator_AuthorityPicker::NAME_PREFIX . $this->getName()] ?? null) + $this->setValue($value); + + $this->_include_specific_terms = $datas[ZendAfi_Form_Decorator_AuthorityPicker::MODE_PREFIX . $this->getName()] ?? true; + return $this; + } + + + public function getIncludeSpecificTerms() : bool { + return $this->_include_specific_terms; + } + + + public function getRecordLabel() : string { return ($id = $this->getValue()) && ($record = Class_Notice::find($id)) ? $record->getTitrePrincipal() : ''; } - public function setPickButtonLabel($label) { + public function setPickButtonLabel(string $label) : self { $this->_pick_button_label = $label; + return $this; } - public function getPickButtonLabel() { + public function getPickButtonLabel() : string { return $this->_pick_button_label ? $this->_pick_button_label : $this->_('Choisir'); } - public function setResetButtonLabel($label) { + public function setResetButtonLabel(string $label) : self { $this->_reset_button_label = $label; + return $this; } - public function getResetButtonLabel() { + public function getResetButtonLabel() : string { return $this->_reset_button_label ? $this->_reset_button_label : $this->_('Annuler'); diff --git a/library/ZendAfi/Form/Element/CompositeValues.php b/library/ZendAfi/Form/Element/CompositeValues.php new file mode 100644 index 0000000000000000000000000000000000000000..393b4c6cf5690a9b69aa672cd640c7554bcafb46 --- /dev/null +++ b/library/ZendAfi/Form/Element/CompositeValues.php @@ -0,0 +1,25 @@ +<?php +/** + * Copyright (c) 2012-2022, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * BOKEH is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * 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 + */ + + +interface ZendAfi_Form_Element_CompositeValues { + public function setCompositeInputValues(array $datas) : self; +} diff --git a/library/ZendAfi/Form/Element/MultiInput.php b/library/ZendAfi/Form/Element/MultiInput.php index 934512560577147d627eaf287d4ffd7048d18a62..1ebeaa52868df9c242dcb1914cf5fda8c88b38e3 100644 --- a/library/ZendAfi/Form/Element/MultiInput.php +++ b/library/ZendAfi/Form/Element/MultiInput.php @@ -176,4 +176,4 @@ class ZendAfi_Form_Element_MultiInput extends Zend_Form_Element { protected function _getErrorMessages() { return $this->getErrorMessages(); } -} \ No newline at end of file +} diff --git a/library/ZendAfi/Form/Element/Range.php b/library/ZendAfi/Form/Element/Range.php index 599862f45f9f1e775c03eddab536fbabefebc79f..182335e80c59d773ce0ef2f73ef8e7e2b7f5c3f0 100644 --- a/library/ZendAfi/Form/Element/Range.php +++ b/library/ZendAfi/Form/Element/Range.php @@ -20,7 +20,8 @@ */ -class ZendAfi_Form_Element_Range extends Zend_Form_Element { +class ZendAfi_Form_Element_Range extends Zend_Form_Element implements ZendAfi_Form_Element_CompositeValues { + public function __construct($spec, $options = null) { parent::__construct($spec, $options); @@ -31,12 +32,14 @@ class ZendAfi_Form_Element_Range extends Zend_Form_Element { } - public function setCompositeInputValues($datas) { + public function setCompositeInputValues(array $datas) : self { if (array_key_exists($this->getName() . $this->getAttrib('from_suffix'), $datas)) $this->setAttrib('from_value', $datas[$this->getName() . $this->getAttrib('from_suffix')]); if (array_key_exists($this->getName() . $this->getAttrib('to_suffix'), $datas)) $this->setAttrib('to_value', $datas[$this->getName() . $this->getAttrib('to_suffix')]); + + return $this; } diff --git a/library/ZendAfi/Form/Element/SearchAxe.php b/library/ZendAfi/Form/Element/SearchAxe.php index 8bf7dcac7e54c29f0d2ce836b6196dc2c94afe7f..d6153a8a624fe844a59df81638b77ed92c600ec7 100644 --- a/library/ZendAfi/Form/Element/SearchAxe.php +++ b/library/ZendAfi/Form/Element/SearchAxe.php @@ -20,7 +20,7 @@ */ -class ZendAfi_Form_Element_SearchAxe extends Zend_Form_Element { +class ZendAfi_Form_Element_SearchAxe extends Zend_Form_Element implements ZendAfi_Form_Element_CompositeValues { public function __construct($spec, $options = null) { parent::__construct($spec, $options); @@ -37,12 +37,14 @@ class ZendAfi_Form_Element_SearchAxe extends Zend_Form_Element { } - public function setCompositeInputValues($datas) { + public function setCompositeInputValues(array $datas) : self { if (array_key_exists($this->getAttrib('input_prefix') . $this->getName(), $datas)) $this->setValue($datas[$this->getAttrib('input_prefix') . $this->getName()]); if (array_key_exists($this->getAttrib('operator_prefix') . $this->getName(), $datas)) $this->setAttrib('operator_value', $datas[$this->getAttrib('operator_prefix') . $this->getName()]); + + return $this; } diff --git a/library/ZendAfi/Form/Element/SearchAxeMultiInput.php b/library/ZendAfi/Form/Element/SearchAxeMultiInput.php index 5c4444c6e475e4d2a3886b7c2051a90d51cf7b7d..0590ee6a38f7994c1220574ba1bb497df81c2c2a 100644 --- a/library/ZendAfi/Form/Element/SearchAxeMultiInput.php +++ b/library/ZendAfi/Form/Element/SearchAxeMultiInput.php @@ -20,7 +20,7 @@ */ -class ZendAfi_Form_Element_SearchAxeMultiInput extends ZendAfi_Form_Element_MultiInput { +class ZendAfi_Form_Element_SearchAxeMultiInput extends ZendAfi_Form_Element_MultiInput implements ZendAfi_Form_Element_CompositeValues { use Trait_Translator; protected @@ -97,8 +97,9 @@ class ZendAfi_Form_Element_SearchAxeMultiInput extends ZendAfi_Form_Element_Mult } - public function setCompositeInputValues($datas) { + public function setCompositeInputValues(array $datas) : self { $this->setValues($this->_custom_multi_param->values($this, $datas)); + return $this; } diff --git a/library/ZendAfi/Form/Element/SelectDynamicFacet.php b/library/ZendAfi/Form/Element/SelectDynamicFacet.php index c0ebfb21ed39d37a26e9e2dc85bbadea26aaa883..ef7dcd11eb5556811a2696cd5cba408333d7df39 100644 --- a/library/ZendAfi/Form/Element/SelectDynamicFacet.php +++ b/library/ZendAfi/Form/Element/SelectDynamicFacet.php @@ -47,8 +47,4 @@ class ZendAfi_Form_Element_SelectDynamicFacet extends Zend_Form_Element_Select { return $options; } - - - public function setCompositeInputValues($datas) { - } } diff --git a/library/ZendAfi/View/Helper/AdvancedSearch.php b/library/ZendAfi/View/Helper/AdvancedSearch.php index d28e360f74b55929e11cfc172ce9a2ac43969e91..4c52b8a4a3b3db9b4a44b4b355f70bb71f489b7b 100644 --- a/library/ZendAfi/View/Helper/AdvancedSearch.php +++ b/library/ZendAfi/View/Helper/AdvancedSearch.php @@ -23,7 +23,7 @@ class ZendAfi_View_Helper_AdvancedSearch extends ZendAfi_View_Helper_BaseHelper { public function advancedSearch($search_forms = [], $active_tab = 0) { - if(!Class_AdminVar::isCustomSearchFormEnabled()) + if (!Class_AdminVar::isCustomSearchFormEnabled()) return $this->view->legacyAdvancedSearch(); $html = []; @@ -82,7 +82,7 @@ class ZendAfi_View_Helper_AdvancedSearch extends ZendAfi_View_Helper_BaseHelper 'controller' => 'recherche' , 'action' => 'avancee', 'statut' => 'reset', - 'form_id' => $form_id], null,true)) + Class_SearchForm_Post::FORM_ID => $form_id], null,true)) ->setText($this->_('Réinitialiser')) ->setTitle($this->_('Réinitialiser le formulaire')) ->setAttrib('class', 'bouton init')); @@ -137,12 +137,17 @@ class ZendAfi_View_Helper_AdvancedSearch extends ZendAfi_View_Helper_BaseHelper protected function _populateForm($form, $form_id) { $request = Zend_Controller_Front::getInstance()->getRequest(); - $form->populate($request->getParams()); + $params = $request->getParams(); + + if ($post = Class_SearchForm_Post::onCurrentSession()->loadPost($request)) + $params = $post; + + $form->populate($params); $url_params = ['controller' => 'recherche', 'action' => 'simple', 'titre' => $this->_('Recherche avancée'), - 'form_id' => $form_id]; + Class_SearchForm_Post::FORM_ID => $form_id]; if ($profil_redirect = Class_Profil::getCurrentProfil() ->getModulePreference('recherche', @@ -157,4 +162,4 @@ class ZendAfi_View_Helper_AdvancedSearch extends ZendAfi_View_Helper_BaseHelper true)); return $form; } -} \ No newline at end of file +} diff --git a/library/templates/Herisson/Library/Settings.php b/library/templates/Herisson/Library/Settings.php index 9eb49102fa9b3fc16703b28354a5be8796a958f6..80d59af9bad61dd094393027c9ecba23b6d4ea09 100644 --- a/library/templates/Herisson/Library/Settings.php +++ b/library/templates/Herisson/Library/Settings.php @@ -123,7 +123,8 @@ class Herisson_Library_Settings extends Intonation_Library_Settings { $hydrating_mapping['p class opened'] = 'text-white bg-success p-1 rounded d-inline-block m-0'; $hydrating_mapping['p class closed'] = 'text-white bg-danger p-1 rounded d-inline-block m-0'; - $hydrating_mapping['a class reset_criteria'] = 'btn btn-info btn-sm m-0 text-dark text-left btn-warning'; + $hydrating_mapping['a class reset_criteria'] = 'btn btn-info btn-sm m-0 text-light text-left btn-warning'; + $hydrating_mapping['a class back_to_search'] = 'btn btn-info btn-sm m-0 text-light text-left btn-warning'; $hydrating_mapping['a class active_criteria'] = 'btn btn-info btn-sm m-0 text-dark text-left btn-warning'; $hydrating_mapping['div class search_criteria_col'] = 'col-12 order-2 mb-2'; diff --git a/library/templates/Intonation/Library/Settings.php b/library/templates/Intonation/Library/Settings.php index b14ae934e1ba4def20c9f159783cea2668254dc5..30d06a945e4f9e2896fff13b290be7a4dd5a2600 100644 --- a/library/templates/Intonation/Library/Settings.php +++ b/library/templates/Intonation/Library/Settings.php @@ -219,6 +219,7 @@ class Intonation_Library_Settings extends Intonation_System_Abstract { 'button class search_submit_button' => 'order-7', 'a class active_criteria' => 'btn btn-warning btn-sm mt-2 mr-2 text-dark text-left', 'a class reset_criteria' => 'btn btn-info btn-sm mt-2 mr-2 text-dark text-left', + 'a class back_to_search' => 'btn btn-info btn-sm mt-2 mr-2 text-dark text-left', 'button class reset_search' => 'btn btn-sm btn-warning border-dark', 'div class multi_facets_submit' => 'btn btn-sm btn-primary mb-2', diff --git a/library/templates/Intonation/View/Search/HtmlCriteria.php b/library/templates/Intonation/View/Search/HtmlCriteria.php index 7bdb88620c5ae411c3f2caae496cffc46fb4c48e..8da0b3b6a9693a4ccdf0d5869cfddb00499b628e 100644 --- a/library/templates/Intonation/View/Search/HtmlCriteria.php +++ b/library/templates/Intonation/View/Search/HtmlCriteria.php @@ -39,11 +39,13 @@ class Intonation_View_Search_HtmlCriteria extends ZendAfi_View_Helper_TagCritere $this->_injectMultiFacets(); $this->_wrapCriteria(); $this->_addResetButton(); + $this->_addBackToSearchFormButton(); return $this->_cache = $this->_wrapHtml(); } + protected function _wrapCriteria() { if ( ! $this->_html) return $this; @@ -80,6 +82,25 @@ class Intonation_View_Search_HtmlCriteria extends ZendAfi_View_Helper_TagCritere } + protected function _addBackToSearchFormButton() : self { + Class_SearchForm_Post::onCurrentSession() + ->withSearchFormUrlDo($this->_criteres_recherche, + function(string $url) + { + $link = (new Intonation_Library_Link) + ->setUrl($url) + ->setImage($this->view->templateIco('edit', 'utils')) + ->setText($this->_('Retour au formulaire de recherche')) + ->setClass('back_to_search') + ->alwaysDisplayText(); + $this->_html .= $this->view->tagAction($link); + }); + + return $this; + } + + + protected function _wrapHtml() { return $this->_html ? ($this->_tag('div', $this->_html, diff --git a/tests/scenarios/AdvancedSearch/AdvancedSearchResultTest.php b/tests/scenarios/AdvancedSearch/AdvancedSearchResultTest.php index 5826944097d502e620d8d070abb12fa977c39422..cc903bebb1c5445cdb3538a54b81a8714f201336 100644 --- a/tests/scenarios/AdvancedSearch/AdvancedSearchResultTest.php +++ b/tests/scenarios/AdvancedSearch/AdvancedSearchResultTest.php @@ -21,7 +21,8 @@ class AdvancedSearchResultPostTest extends AbstractControllerTestCase { - protected $_storm_default_to_volatile = true; + protected $_post, + $_cache_key; public function setUp() { @@ -31,30 +32,31 @@ class AdvancedSearchResultPostTest extends AbstractControllerTestCase { // * entre blocks (T3-T4~T4-T3), (T3-T4~T3-T5-T4) // * entre inputs (T4.T4-T5) // * pas entre and et not + $this->_post = ['1_super_input_operator' => ['and', 'or', 'and', 'or'], + '1_super_input_axe' => ['type_doc', 'type_doc', 'section', 'section'], + '1_super_input_type_doc' => ['3', '4'], + '1_super_input_section' => ['50', '49'], + + '2_super_input_operator' => ['and', 'or', 'or'], + '2_super_input_axe' => ['type_doc', 'type_doc', 'dynamic_facet_HDOC0'], + '2_super_input_type_doc' => ['6', '7'], + '2_super_input_dynamic_facet_HDOC0' => ['DOC00001'], + + '3_super_input_operator' => ['not', 'or', 'or', 'or'], + '3_super_input_axe' => ['type_doc', 'type_doc', 'title', 'author'], + '3_super_input_type_doc' => ['5', '9'], + '3_super_input_title' => ['misérables'], + '3_super_input_author' => ['hugo'], + ]; - $this->postDispatch('/recherche/simple/titre/Recherche+avancée/form_id/0', - ['1_super_input_operator' => ['and', 'or', 'and', 'or'], - '1_super_input_axe' => ['type_doc', 'type_doc', 'section', 'section'], - '1_super_input_type_doc' => ['3', '4'], - '1_super_input_section' => ['50', '49'], - - '2_super_input_operator' => ['and', 'or', 'or'], - '2_super_input_axe' => ['type_doc', 'type_doc', 'dynamic_facet_HDOC0'], - '2_super_input_type_doc' => ['6', '7'], - '2_super_input_dynamic_facet_HDOC0' => ['DOC00001'], - - '3_super_input_operator' => ['not', 'or', 'or', 'or'], - '3_super_input_axe' => ['type_doc', 'type_doc', 'title', 'author'], - '3_super_input_type_doc' => ['5', '9'], - '3_super_input_title' => ['misérables'], - '3_super_input_author' => ['hugo'], - ]); + $this->_cache_key = md5(serialize($this->_post)); + $this->postDispatch('/recherche/simple/titre/Recherche+avancée/form_id/0',$this->_post); } /** @test */ - public function shouldRedirectWithMultiDocTypes() { - $this->assertRedirectTo('/recherche/simple/axes/a0T3-0T4%7Ea0S50-0S49.a0T6-0T7-0HDOC00001.n0T5-0T9-10mis%C3%A9rables-11hugo/titre/Recherche+avanc%C3%A9e'); + public function responseShouldRedirectWithAxesMultiDocTypesAndPostWithCacheKey() { + $this->assertRedirectTo('/recherche/simple/post/' . $this->_cache_key . '/axes/a0T3-0T4%7Ea0S50-0S49.a0T6-0T7-0HDOC00001.n0T5-0T9-10mis%C3%A9rables-11hugo/titre/Recherche+avanc%C3%A9e'); } } diff --git a/tests/scenarios/AdvancedSearch/AdvancedSearchTest.php b/tests/scenarios/AdvancedSearch/AdvancedSearchTest.php index d839d693842b600be2633f16a97a87a74270ae74..8603eb86f7f903d85edf0a12bb573f5a252d7de3 100644 --- a/tests/scenarios/AdvancedSearch/AdvancedSearchTest.php +++ b/tests/scenarios/AdvancedSearch/AdvancedSearchTest.php @@ -22,14 +22,16 @@ abstract class AdvancedSearchTestCase extends AbstractControllerTestCase { - protected $_storm_default_to_volatile = true; - - public function setUp() { parent::setUp(); $this->_prepareFixtures(); - $this->dispatch('/recherche/avancee', true); + $this->_dispatch(); + } + + + protected function _dispatch() { + $this->dispatch('/recherche/avancee'); } @@ -204,25 +206,20 @@ abstract class AdvancedSearchCustomFormSelectedTestCase extends AdvancedSearchTe Class_Profil::getCurrentProfil() ->setCfgModules(['recherche' => ['avancee' => ['forms' => '3']]]); - $this->_file_system = - $this->mock() - ->whenCalled('directoryAt')->with($this->_form_filename)->answers(false) - ->whenCalled('fileAt')->with($this->_form_filename) - ->answers((new Class_FileManager) - ->setId($this->_form_filename) - ->setRealpath($this->_form_filename) - ->setPath($this->_form_filename) - ->setName('form.php') - ->setBasename('form.php') - ->setParentPath('userfiles/forms') - ->setWritable(true)); + $this->_file_system = (new Storm_FileSystem_Volatile) + ->mkdir(ROOT_PATH) + ->cd(ROOT_PATH) + ->mkdir('userfiles/forms') + ->touch($this->_form_filename); + + Class_SearchForm_Wrapper::setFileSystem($this->_file_system); } public function tearDown() { - Class_FileManager::reset(); Class_SearchForm::setIncluder(null); Class_SearchForm::throwErrors(false); + Class_SearchForm_Wrapper::setFileSystem(null); parent::tearDown(); } @@ -294,14 +291,11 @@ class AdvancedSearchFileNotFoundCustomFormSelectedTest protected function _prepareFixtures() { parent::_prepareFixtures(); - $this->fixture('Class_SearchForm', ['id' => 3, 'filename' => $this->_form_filename]); - - $file_system = $this->mock() - ->whenCalled('directoryAt')->with($this->_form_filename)->answers(false) - ->whenCalled('fileAt')->with($this->_form_filename)->answers(false) - ; + $this->fixture(Class_SearchForm::class, + ['id' => 3, + 'filename' => $this->_form_filename]); - Class_FileManager::setFileSystem($file_system); + Class_SearchForm_Wrapper::setFileSystem(new Storm_FileSystem_Volatile); } @@ -320,11 +314,9 @@ class AdvancedSearchNotReadableCustomFormSelectedTest protected function _prepareFixtures() { parent::_prepareFixtures(); - $this->fixture('Class_SearchForm', ['id' => 3, 'filename' => $this->_form_filename]); - - $this->_file_system->whenCalled('getContent')->with($this->_form_filename)->answers(false); - - Class_FileManager::setFileSystem($this->_file_system); + $this->fixture(Class_SearchForm::class, + ['id' => 3, + 'filename' => $this->_form_filename]); } @@ -343,13 +335,13 @@ class AdvancedSearchBrokenPhpCustomFormSelectedTest protected function _prepareFixtures() { parent::_prepareFixtures(); - $this->fixture('Class_SearchForm', ['id' => 3, 'filename' => $this->_form_filename]); + $this->fixture(Class_SearchForm::class, + ['id' => 3, + 'filename' => $this->_form_filename]); $this->_file_system - ->whenCalled('getContent')->with($this->_form_filename) - ->answers('<?php will fail'); - - Class_FileManager::setFileSystem($this->_file_system); + ->filePutContents(ROOT_PATH . $this->_form_filename, + '<?php will fail'); } @@ -370,14 +362,14 @@ class AdvancedSearchForbiddenCallCustomFormSelectedTest protected function _prepareFixtures() { parent::_prepareFixtures(); - $this->fixture('Class_SearchForm', ['id' => 3, 'filename' => $this->_form_filename]); + $this->fixture(Class_SearchForm::class, + ['id' => 3, + 'filename' => $this->_form_filename]); $this->_file_system - ->whenCalled('getContent') - ->with($this->_form_filename) - ->answers('<?php Class_Users::deleteBy([]);'); + ->filePutContents(ROOT_PATH . $this->_form_filename, + '<?php Class_Users::deleteBy([]);'); - Class_FileManager::setFileSystem($this->_file_system); $this->_includer_called = false; Class_SearchForm::setIncluder(function($path) { $this->_includer_called = true; }); } @@ -403,9 +395,11 @@ class AdvancedSearchFormWithDateSelectorsTest extends AdvancedSearchCustomFormSe protected function _prepareFixtures() { parent::_prepareFixtures(); - $this->fixture('Class_SearchForm', ['id' => 3, 'filename' => $this->_form_filename]); + $this->fixture(Class_SearchForm::class, + ['id' => 3, + 'filename' => $this->_form_filename]); - $this->fixture('Class_CodifThesaurus', + $this->fixture(Class_CodifThesaurus::class, ['id' => 1, 'libelle' => 'Année de publication', 'id_thesaurus' => 'APUB', @@ -418,7 +412,7 @@ class AdvancedSearchFormWithDateSelectorsTest extends AdvancedSearchCustomFormSe ]); - $this->fixture('Class_CodifThesaurus', + $this->fixture(Class_CodifThesaurus::class, ['id' => 2, 'libelle' => 'Mois de publication', 'id_thesaurus' => 'MPUB', @@ -430,7 +424,7 @@ class AdvancedSearchFormWithDateSelectorsTest extends AdvancedSearchCustomFormSe 'rule_list_label_length' => [2] ]); - $this->fixture('Class_CodifThesaurus', + $this->fixture(Class_CodifThesaurus::class, ['id' => 3, 'libelle' => 'Jour de publication', 'id_thesaurus' => 'JPUB', @@ -442,7 +436,7 @@ class AdvancedSearchFormWithDateSelectorsTest extends AdvancedSearchCustomFormSe 'rule_list_label_length' => [2] ]); - $this->fixture('Class_CodifThesaurus', + $this->fixture(Class_CodifThesaurus::class, ['id' => 34, 'libelle' => '3', 'id_thesaurus' => 'JPUB0003', @@ -450,7 +444,7 @@ class AdvancedSearchFormWithDateSelectorsTest extends AdvancedSearchCustomFormSe 'code' => 'JPUB', ]); - $this->fixture('Class_CodifThesaurus', + $this->fixture(Class_CodifThesaurus::class, ['id' => 35, 'libelle' => '1', 'id_thesaurus' => 'JPUB0001', @@ -460,10 +454,9 @@ class AdvancedSearchFormWithDateSelectorsTest extends AdvancedSearchCustomFormSe $this->_file_system - ->whenCalled('getContent')->with($this->_form_filename) - ->answers('<?php ?>'); + ->filePutContents(ROOT_PATH . $this->_form_filename, + '<?php ?>'); - Class_FileManager::setFileSystem($this->_file_system); Class_SearchForm::setIncluder( function($path, $form) { $form @@ -511,12 +504,14 @@ class AdvancedSearchFormWithAuthoritiesCriteriaTest protected function _prepareFixtures() { parent::_prepareFixtures(); - $this->fixture('Class_SearchForm', ['id' => 3, 'filename' => $this->_form_filename]); + $this->fixture(Class_SearchForm::class, + ['id' => 3, + 'filename' => $this->_form_filename]); + $this->_file_system - ->whenCalled('getContent')->with($this->_form_filename) - ->answers('<?php ?>'); + ->filePutContents(ROOT_PATH . $this->_form_filename, + '<?php ?>'); - Class_FileManager::setFileSystem($this->_file_system); Class_SearchForm::setIncluder( function($path, $form) { $form @@ -567,49 +562,29 @@ abstract class AdvancedSearchValidCustomFormsSelectedAndPublishedTestCase $author_search_form = 'userfiles/forms/author_search_form.php'; - $this->fixture('Class_SearchForm', + $this->fixture(Class_SearchForm::class, ['id' => 3, - 'filename' => $author_search_form, + 'filename' => '/' . $author_search_form, 'visible' => 1]); $title_search_form = 'userfiles/forms/title_search_form.php'; - $this->fixture('Class_SearchForm', + $this->fixture(Class_SearchForm::class, ['id' => 9, 'filename' => $title_search_form, 'visible' => 1]); + $this + ->_file_system + ->filePutContents(ROOT_PATH . $author_search_form, + '<?php ?>') + ->filePutContents(ROOT_PATH . $title_search_form, + '<?php ?>') + ->cd(ROOT_PATH); - $this->_file_system = $this->mock() - ->whenCalled('directoryAt') - ->with($author_search_form) - ->answers(false) - - ->whenCalled('directoryAt') - ->with($title_search_form) - ->answers(false) - - ->whenCalled('fileAt') - ->with($author_search_form) - ->answers((new Class_FileManager) - ->setId($author_search_form) - ->setRealpath($author_search_form) - ->setPath($author_search_form) - ->setWritable(true)) - - ->whenCalled('fileAt') - ->with($title_search_form) - ->answers((new Class_FileManager) - ->setId($title_search_form) - ->setRealpath($title_search_form) - ->setPath($title_search_form) - ->setWritable(true)) - - ->whenCalled('getContent') - ->answers('<?php ?>'); Class_SearchForm::setIncluder( function($path, $form) use ($title_search_form, $author_search_form) { - if($path == $author_search_form) + if ($path == $author_search_form) return $form ->addElement('text', 'author_field', ['label' => 'Chercher un auteur']) ->addUniqDisplayGroup('yeah'); @@ -620,7 +595,6 @@ abstract class AdvancedSearchValidCustomFormsSelectedAndPublishedTestCase ->addUniqDisplayGroup('yeah'); }); - Class_FileManager::setFileSystem($this->_file_system); Class_Profil::getCurrentProfil() ->setCfgModules(['recherche' => ['avancee' => ['forms' => '3;9']]]); ZendAfi_Auth::getInstance()->clearIdentity(); @@ -635,13 +609,13 @@ class AdvancedSearchValidCustomFormsSelectedAndPublishedTest /** @test */ public function authorFieldShouldBePresent() { - $this->assertXPath('//input[@name="author_field"]', $this->_response->getBody()); + $this->assertXPath('//input[@name="author_field"]'); } /** @test */ public function titleFieldShouldBePresent() { - $this->assertXPath('//input[@name="title_field"]', $this->_response->getBody()); + $this->assertXPath('//input[@name="title_field"]'); } @@ -712,9 +686,6 @@ class AdvancedSearchResetSecondFormTest class AdvancedSearchFileManagerPhpFileDispatchTest extends Admin_AbstractControllerTestCase { - protected - $_storm_default_to_volatile = true; - public function setUp() { parent::setUp(); @@ -803,10 +774,6 @@ class AdvancedSearchFileManagerPhpFileDispatchTest extends Admin_AbstractControl class AdvancedSearchMultiFacetsPostDispatchTest extends Admin_AbstractControllerTestCase { - protected - $_storm_default_to_volatile = true; - - public function setUp() { parent::setUp(); $this->fixture('Class_CodifThesaurus', @@ -851,19 +818,104 @@ class AdvancedSearchMultiFacetsPostDispatchTest extends Admin_AbstractController +abstract class AdvancedSearchFormWithSearchAxeTitresAndPostCacheTestCase extends AdvancedSearchCustomFormSelectedTestCase { + protected function _prepareFixtures() { + parent::_prepareFixtures(); + + $this->fixture(Class_SearchForm::class, + ['id' => 3, + 'visible' => true, + 'filename' => $this->_form_filename]); + + $this->_file_system->filePutContents(ROOT_PATH . $this->_form_filename, + '<?php ?>'); + + Class_SearchForm::throwErrors(true); + Class_SearchForm::setIncluder( + function($path, $form) + { + $form + ->addElement('searchAxe', + 'titres', + ['label' => $form->_("Titre")]) + ->addElement('authority', + 'thesaurus', + [ + 'label' => 'Mots-clés (thésaurus) ', + 'facets' => 'HTHES', + 'tree_roots' => '415582', + ]); + }); + } +} + + + + +class AdvancedSearchFormWithSearchAxeTitresPostTest extends AdvancedSearchFormWithSearchAxeTitresAndPostCacheTestCase { + protected $_post = ['rech_titres' => 'Memento', + 'authority_thesaurus' => '15', + 'mode_authority_thesaurus' => '0']; + + protected function _dispatch() { + $this->postDispatch('/recherche/simple/form_id/1', + $this->_post); + } + + + /** @test */ + public function cacheShouldContainsPostTitresMemento() { + $this->assertEquals($this->_post, + Zend_Registry::get('session')->searches[md5(serialize($this->_post))]); + } +} + + + + +class AdvancedSearchFormWithSearchAxeTitresWithPostKeyTest extends AdvancedSearchFormWithSearchAxeTitresAndPostCacheTestCase { + protected function _dispatch() { + Zend_Registry::get('session')->searches = ['1234' => ['rech_titres' => 'Memento', + 'authority_thesaurus' => '15', + 'mode_authority_thesaurus' => '0']]; + $this->dispatch('/recherche/avancee/post/1234'); + } + + + /** @test */ + public function inputRechTitresShouldHaveValueMemento() { + $this->assertXPath('//input[@name="rech_titres"][@value="Memento"]'); + } + + + /** @test */ + public function inputAuthorityThesaurisShouldHaveValue15() { + $this->assertXPath('//input[@name="authority_thesaurus"][@value="15"]'); + } + + + /** @test */ + public function inputModeAuthorityThesaurisShouldNotBeChecked() { + $this->assertXPath('//input[@name="mode_authority_thesaurus"][@type="checkbox"][not(@checked)]'); + } +} + + + + class AdvancedSearchFormWithDeprecatedDomainsCriteriaTest extends AdvancedSearchCustomFormSelectedTestCase { protected function _prepareFixtures() { parent::_prepareFixtures(); - $this->fixture('Class_SearchForm', ['id' => 3, 'filename' => $this->_form_filename]); + $this->fixture(Class_SearchForm::class, + ['id' => 3, + 'filename' => $this->_form_filename]); - $this->_file_system - ->whenCalled('getContent')->with($this->_form_filename) - ->answers('<?php ?>'); + $this->_file_system->filePutContents(ROOT_PATH . $this->_form_filename, + '<?php ?>'); - Class_FileManager::setFileSystem($this->_file_system); Class_SearchForm::throwErrors(true); Class_SearchForm::setIncluder( function($path, $form) { @@ -1008,20 +1060,20 @@ class AdvancedSearchFormWithDeprecatedDomainsCriteriaTest + class AdvancedSearchFormMultiInputTest extends AdvancedSearchCustomFormSelectedTestCase { protected function _prepareFixtures() { parent::_prepareFixtures(); - $this->fixture('Class_SearchForm', + $this->fixture(Class_SearchForm::class, ['id' => 3, - 'filename' => $this->_form_filename]); + 'filename' => $this->_form_filename, + 'visible' => true]); - $this->_file_system - ->whenCalled('getContent')->with($this->_form_filename) - ->answers('<?php ?>'); + $this->_file_system->filePutContents(ROOT_PATH . $this->_form_filename, + '<?php ?>'); - Class_FileManager::setFileSystem($this->_file_system); Class_SearchForm::throwErrors(true); $includer = function($path, $form) { @@ -1094,9 +1146,7 @@ class AdvancedSearchFormMultiInputTest extends AdvancedSearchCustomFormSelectedT class AdvancedSearchFormUnauthorizedMultiInputTest extends AbstractControllerTestCase { protected - $_storm_default_to_volatile = true, - $_form_filename = 'userfiles/forms/form.php', - $_file_system; + $_form_filename = 'userfiles/forms/form.php'; public function setUp() { parent::setUp(); @@ -1105,26 +1155,14 @@ class AdvancedSearchFormUnauthorizedMultiInputTest extends AbstractControllerTes Class_Profil::getCurrentProfil() ->setCfgModules(['recherche' => ['avancee' => ['forms' => '3']]]); - $this->fixture('Class_SearchForm', + $this->fixture(Class_SearchForm::class, ['id' => 3, 'filename' => $this->_form_filename]); - $this->_file_system = - $this->mock() - ->whenCalled('directoryAt')->with($this->_form_filename)->answers(false) - ->whenCalled('fileAt')->with($this->_form_filename) - ->answers((new Class_FileManager) - ->setId($this->_form_filename) - ->setRealpath($this->_form_filename) - ->setPath($this->_form_filename) - ->setName('form.php') - ->setBasename('form.php') - ->setParentPath('userfiles/forms') - ->setWritable(true)) - ->whenCalled('getContent')->with($this->_form_filename) - ->answers('<?php ?>'); - - Class_FileManager::setFileSystem($this->_file_system); + Class_SearchForm_Wrapper::setFileSystem((new Storm_FileSystem_Volatile) + ->mkdir(ROOT_PATH . 'userfiles/forms') + ->cd(ROOT_PATH) + ->filePutContents($this->_form_filename, '<?php ?>')); } @@ -1167,9 +1205,6 @@ class AdvancedSearchFormUnauthorizedMultiInputTest extends AbstractControllerTes class AdvancedSearchFormWithDomainCriteriaDispatchTest extends AbstractControllerTestCase { - protected $_storm_default_to_volatile = true; - - public function setUp() { parent::setUp(); @@ -1305,8 +1340,6 @@ class AdvancedSearchFormWithDomainCriteriaDispatchTest extends AbstractControlle class AdvancedSearchAuthoritySuggestTest extends AbstractControllerTestCase { - protected $_storm_default_to_volatile = true; - /** @test */ public function onEmptyValueShouldReturnNothing() { $this->dispatch('/authority-suggest/suggest'); diff --git a/tests/scenarios/Catalog/CustomCatalogTest.php b/tests/scenarios/Catalog/CustomCatalogTest.php index a0bc6c1bf933b242670c5dc4159a4b864af69d07..c775e1898508da0b5ea8736507dcab4e60a2857b 100644 --- a/tests/scenarios/Catalog/CustomCatalogTest.php +++ b/tests/scenarios/Catalog/CustomCatalogTest.php @@ -63,24 +63,13 @@ trait CustomCatalogFixture { 'paniers' => [], 'custom_form_id' => 2]); - $this->_file_system = - $this->mock() - ->whenCalled('directoryAt')->with($this->_form_filename)->answers(false) - ->whenCalled('fileAt')->with($this->_form_filename) - ->answers((new Class_FileManager) - ->setId($this->_form_filename) - ->setRealpath($this->_form_filename) - ->setPath($this->_form_filename) - ->setName('form.php') - ->setBasename('form.php') - ->setParentPath('userfiles/forms') - ->setWritable(true)); - - $this->_file_system - ->whenCalled('getContent')->with($this->_form_filename) - ->answers('<?php ?>'); - - Class_FileManager::setFileSystem($this->_file_system); + $this->_file_system = (new Storm_FileSystem_Volatile) + ->mkdir(ROOT_PATH) + ->cd(ROOT_PATH) + ->mkdir('userfiles/forms') + ->filePutContents($this->_form_filename, '<?php ?>'); + + Class_SearchForm_Wrapper::setFileSystem($this->_file_system); Class_SearchForm::throwErrors(true); $includer = function($path, $form) { diff --git a/tests/scenarios/Templates/TemplatesSearchTest.php b/tests/scenarios/Templates/TemplatesSearchTest.php index 3b8f2709401107426dd005c2dc2a71ebc077dda5..e0276d123acb73269b9e6d04fc20766958530c69 100644 --- a/tests/scenarios/Templates/TemplatesSearchTest.php +++ b/tests/scenarios/Templates/TemplatesSearchTest.php @@ -77,7 +77,7 @@ class TemplatesSearchWithSortParameterInWidgetFromIndexPageTest extends Template class TemplatesSearchWithSortParameterInWidgetFromSearchPageWithTriParamTest extends TemplatesSearchWithSortParameterInWidgetTestCase { public function setUp() { parent::setUp(); - $this->dispatch('/recherche/simple/expressionRecherche/poire/tri/alpha_auteur+desc'); + $this->dispatch('/recherche/simple/expressionRecherche/poire/tri/alpha_auteur+desc/form_id/2'); } @@ -90,6 +90,48 @@ class TemplatesSearchWithSortParameterInWidgetFromSearchPageWithTriParamTest ext +class TemplatesSearchWithSortParameterInWidgetFromSearchPageWithPostParamsTest extends TemplatesSearchWithSortParameterInWidgetTestCase { + /** @test */ + public function withSavedPostPageShouldContainsLinkToGoBackToSearch() { + Zend_Registry::get('session')->searches = ['1234' => ['rech_titres' => 'Memento']]; + + $this->dispatch('/recherche/simple/expressionRecherche/poire/form_id/2/post/1234'); + $this->assertXPathContentContains('//a[@href="/recherche/avancee/post/1234/form_id/2"][contains(@class, "back_to_search")]', + 'Retour au formulaire de recherche'); + } + + + /** @test */ + public function withSavedPostAndNoFormIdPageShouldContainsLinkToGoBackToSearch() { + Zend_Registry::get('session')->searches = ['1234' => ['rech_titres' => 'Memento']]; + + $this->dispatch('/recherche/simple/expressionRecherche/poire/post/1234'); + $this->assertXPathContentContains('//a[@href="/recherche/avancee/post/1234"][contains(@class, "back_to_search")]', + 'Retour au formulaire de recherche'); + } + + + /** @test */ + public function withSavedEmptyPostPageShouldNotContainsLinkToGoBackToSearch() { + Zend_Registry::get('session')->searches = ['1234' => []]; + + $this->dispatch('/recherche/simple/expressionRecherche/poire/form_id/2/post/1234'); + $this->assertNotXPath('//a[contains(@class, "back_to_search")]'); + } + + + /** @test */ + public function withNoPostPageShouldNotContainsLinkToGoBackToSearch() { + Zend_Registry::get('session')->searches = 'pouet tagada tsoin tsoin'; + + $this->dispatch('/recherche/simple/expressionRecherche/poire/form_id/2/post/1234'); + $this->assertNotXPath('//a[contains(@class, "back_to_search")]'); + } +} + + + + class TemplatesDispatchIntonationSearchTest extends TemplatesIntonationTestCase { public function setUp() { parent::setUp(); @@ -157,6 +199,12 @@ class TemplatesDispatchIntonationSearchTest extends TemplatesIntonationTestCase } + /** @test */ + public function pageShouldNotContainsLinkToGoBackToSearch() { + $this->assertNotXPath('//a[contains(@class, "back_to_search")]'); + } + + /** @test */ public function searchTitleShouldBePomme() { $this->assertXPath('//main//h1[contains(@class,"content_title")][text()="Résultat pour pomme "]');