diff --git a/VERSIONS b/VERSIONS index 7ab1be4290bba0f0d5819460444da36752a62c39..abc75ad235683076055ce1e58d84f3275ba15ebe 100644 --- a/VERSIONS +++ b/VERSIONS @@ -1,3 +1,6 @@ +- ticket #17171: L'autocomplétion en recherche simple n'est plus considérée comme expérimentale, il suffit d'activer les batchs associés. + + 18/10/2014 - v6.54.3 - ticket #16596: Corrige l'ordre de calcul des types de documents (Sous-champ 995 avant le label) diff --git a/library/ZendAfi/View/Helper/Accueil/RechSimple.php b/library/ZendAfi/View/Helper/Accueil/RechSimple.php index fa7fef7a07cd8c30a83b7e01b3bc73ea5e75bcdb..c68a6424862c3cb54d25af02c5fc813fb0eb331f 100644 --- a/library/ZendAfi/View/Helper/Accueil/RechSimple.php +++ b/library/ZendAfi/View/Helper/Accueil/RechSimple.php @@ -16,7 +16,7 @@ * * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * along with AFI-OPAC 2.0; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ class ZendAfi_View_Helper_Accueil_RechSimple extends ZendAfi_View_Helper_Accueil_Base { @@ -24,13 +24,22 @@ class ZendAfi_View_Helper_Accueil_RechSimple extends ZendAfi_View_Helper_Accueil $script_loader ->addJQueryReady('$("input.expressionRecherche").attr("x-webkit-speech","x-webkit-speech")'); - if (!defined('DEVELOPMENT')) - return; + if (!$this->_isAutocompleteEnabled()) + return $this; + $script_loader ->addOPACPluginScript('search_autocomplete/search_autocomplete') ->addJQueryReady('$("input.expressionRecherche").search_autocomplete('. $this->getAutocompleteOptions() .')'); + + return $this; } + protected function _isAutocompleteEnabled() { + $batch_types = Class_Batch::getActiveTypes(); + return in_array('AUTOCOMPLETE_RECORD_TITLE', $batch_types) || in_array('AUTOCOMPLETE_RECORD_AUTHOR', $batch_types); + } + + protected function getAutocompleteOptions() { $options = new stdClass(); $options->url = $this->view->url(['controller' => 'recherche', @@ -43,7 +52,7 @@ class ZendAfi_View_Helper_Accueil_RechSimple extends ZendAfi_View_Helper_Accueil public function getHtml() { $this->titre = $this->preferences["titre"]; - $this->contenu = $this->view->TagRechercheSimple($this->preferences, + $this->contenu = $this->view->TagRechercheSimple($this->preferences, $this->id_module, $this->division); return $this->getHtmlArray(); diff --git a/tests/library/ZendAfi/View/Helper/Accueil/RechSimpleTest.php b/tests/library/ZendAfi/View/Helper/Accueil/RechSimpleTest.php index 81af939f014562ec0de6634b02a30c85f41d8d69..03cb2b7234ec95c8b7b0a79a353fb1750b461d24 100644 --- a/tests/library/ZendAfi/View/Helper/Accueil/RechSimpleTest.php +++ b/tests/library/ZendAfi/View/Helper/Accueil/RechSimpleTest.php @@ -16,22 +16,33 @@ * * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * along with AFI-OPAC 2.0; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ require_once 'library/ZendAfi/View/Helper/ViewHelperTestCase.php'; -class ZendAfi_View_Helper_Accueil_RechSimpleTest extends ViewHelperTestCase { +abstract class ZendAfi_View_Helper_Accueil_RechSimpleTestCase extends ViewHelperTestCase { public function setup() { parent::setup(); - $helper = new ZendAfi_View_Helper_Accueil_RechSimple(1, - ['division' => 1, - 'type_module' => 'RECH_SIMPLE', - 'preferences' => [ - 'boite' => '', - 'titre' => 'Search widget']]); - - $helper->setView(new ZendAfi_Controller_Action_Helper_View()); - $this->_html = $helper->getBoite(); + $this->_helper = new ZendAfi_View_Helper_Accueil_RechSimple(1, + ['division' => 1, + 'type_module' => 'RECH_SIMPLE', + 'preferences' => [ + 'boite' => '', + 'titre' => 'Search widget']]); + + $this->_helper->setView(new ZendAfi_Controller_Action_Helper_View()); + } +} + + + + + +class ZendAfi_View_Helper_Accueil_RechSimpleWithAutocompleteTest extends ZendAfi_View_Helper_Accueil_RechSimpleTestCase { + public function setup() { + parent::setUp(); + $this->fixture('Class_Batch', ['id' => 42, 'type' => 'AUTOCOMPLETE_RECORD_TITLE']); + $this->_html = $this->_helper->getBoite(); $this->_head_script = Class_ScriptLoader::getInstance()->html(); } @@ -49,4 +60,22 @@ class ZendAfi_View_Helper_Accueil_RechSimpleTest extends ViewHelperTestCase { $this->assertXPathContentContains($this->_head_script, '//script', $expected_ajax_param); } } + + + + +class ZendAfi_View_Helper_Accueil_RechSimpleWithoutAutocompleteTest extends ZendAfi_View_Helper_Accueil_RechSimpleTestCase { + public function setup() { + parent::setUp(); + Class_Batch::beVolatile(); + $this->_html = $this->_helper->getBoite(); + $this->_head_script = Class_ScriptLoader::getInstance()->html(); + } + + + /** @test */ + public function searchAutocompleteShouldNotBeLodaed() { + $this->assertNotXPath($this->_head_script, '//script[contains(@src,"search_autocomplete.js")]'); + } +} ?> \ No newline at end of file