From 20fc712b70d87e28c05a50c549d872b51fca59f5 Mon Sep 17 00:00:00 2001
From: efalcy <efalcy@afi-sa.fr>
Date: Mon, 29 Jun 2015 18:22:26 +0200
Subject: [PATCH] apply sort selected when sorting domains on search result

---
 library/Class/CriteresRecherche.php                        | 5 ++---
 .../modules/opac/controllers/RechercheControllerTest.php   | 7 +++++++
 tests/library/Class/MoteurRechercheTest.php                | 5 ++---
 3 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/library/Class/CriteresRecherche.php b/library/Class/CriteresRecherche.php
index 921abb85f3a..92f7f16d517 100644
--- a/library/Class/CriteresRecherche.php
+++ b/library/Class/CriteresRecherche.php
@@ -276,10 +276,9 @@ class Class_CriteresRecherche {
 
 
 	public function getTri() {
-		$tri = $this->getParam('tri', 0);
-		if (0 == $tri && $this->isRechercheCatalogue())
+		$tri = urldecode($this->getParam('tri', ''));
+		if ('' === $tri && $this->isRechercheCatalogue())
 			return self::SORT_PUBLICATION;
-
 		return isset($this->getListeTris()[$tri]) ? $tri : '*';
 	}
 
diff --git a/tests/application/modules/opac/controllers/RechercheControllerTest.php b/tests/application/modules/opac/controllers/RechercheControllerTest.php
index 7f4d1b11825..d054ecfc63c 100644
--- a/tests/application/modules/opac/controllers/RechercheControllerTest.php
+++ b/tests/application/modules/opac/controllers/RechercheControllerTest.php
@@ -1834,6 +1834,13 @@ class RechercheControllerSimpleActionWithCatalogueAndDomainBrowserWidgetTest ext
 	}
 
 
+	/** @test **/
+	public function onRechercheSimpleCatalogue3IdModule9OrderByTitreShouldBeOrderByTitle() {
+		$this->dispatch('/recherche/simple/id_catalogue/3/id_module/9/tri/alpha_titre', true);
+		$this->assertXPath('//select[@name="tri"]//option[@value="alpha_titre"][@selected="selected"]');
+	}
+
+
   /** @test */
 	public function onRechercheSimpleCatalogue3IdModule9BreadcrumbShouldBeDisplayed() {
 		$this->dispatch('/recherche/simple/id_catalogue/3/id_module/9', true);
diff --git a/tests/library/Class/MoteurRechercheTest.php b/tests/library/Class/MoteurRechercheTest.php
index edd341acc34..f7722683079 100644
--- a/tests/library/Class/MoteurRechercheTest.php
+++ b/tests/library/Class/MoteurRechercheTest.php
@@ -869,7 +869,7 @@ class MoteurRechercheWithCatalogueAndParamsTest extends MoteurRechercheWithCatal
 
   /** @test */
 	public function requestShouldUseProfilSettings() {
-		$this->assertEquals('Select id_notice from notices Where ((date_creation >\'2014-12-23\' and MATCH(facettes) AGAINST(\'+(T1 T4)\' IN BOOLEAN MODE)) or MATCH(facettes) AGAINST(\'Q5\' IN BOOLEAN MODE)) and MATCH(facettes) AGAINST(\'+P4* +(Y2,4,1)\' IN BOOLEAN MODE) order by annee desc', $this->request['req_liste']);
+		$this->assertEquals('Select id_notice from notices Where ((date_creation >\'2014-12-23\' and MATCH(facettes) AGAINST(\'+(T1 T4)\' IN BOOLEAN MODE)) or MATCH(facettes) AGAINST(\'Q5\' IN BOOLEAN MODE)) and MATCH(facettes) AGAINST(\'+P4* +(Y2,4,1)\' IN BOOLEAN MODE) order by date_creation desc', $this->request['req_liste']);
 	}
 }
 
@@ -888,7 +888,7 @@ class MoteurRechercheWithCatalogueAndUrlParamsTest extends MoteurRechercheWithCa
 
 		$criteres_recherche =
 			(new Class_CriteresRecherche())->setParams(['id_catalogue' => 5,
-																									'tri' => 'date_creation+desc',
+																									'tri' => 'annee+desc',
 																									'facettes' =>'T1-T10',
 																									'facette' => 'T5']);
 
@@ -926,7 +926,6 @@ class MoteurRechercheWithCatalogueWithNoSettingsAndUrlParamsTest extends MoteurR
 
 		$criteres_recherche =
 			(new Class_CriteresRecherche())->setParams(['id_catalogue' => 5,
-																									'tri' => 'date_creation+desc',
 																									'facettes' =>'T4-T8']);
 
 		$this->request = (new Class_MoteurRecherche())->lancerRecherche($criteres_recherche);
-- 
GitLab