From 2cfc16c0ff4b9c2300a59f3e0aaf102ddffa7916 Mon Sep 17 00:00:00 2001 From: efalcy <efalcy@afi-sa.fr> Date: Thu, 16 Apr 2015 18:37:37 +0200 Subject: [PATCH] dev #23802 : Sitotheque arborescent Add option on box "sitotheque" to display by category (wip) --- .../views/scripts/accueil/sitotheque.phtml | 9 +-- .../opac/controllers/SitoController.php | 2 +- library/ZendAfi/View/Helper/Menu/Profil.php | 9 +-- .../controllers/AccueilControllerTest.php | 5 ++ .../opac/controllers/SitoControllerTest.php | 57 ++++++++++++++++++- 5 files changed, 71 insertions(+), 11 deletions(-) diff --git a/application/modules/admin/views/scripts/accueil/sitotheque.phtml b/application/modules/admin/views/scripts/accueil/sitotheque.phtml index 6f3e6e4b36c..942e6213c49 100644 --- a/application/modules/admin/views/scripts/accueil/sitotheque.phtml +++ b/application/modules/admin/views/scripts/accueil/sitotheque.phtml @@ -34,12 +34,13 @@ <td class="droite" width="90px">Type </td> <td class="gauche"> <?php - $onchange="$('.treeselect').treeselect('toggleVisibility', (this.value == '1'));"; + $onchange="$('.treeselect').treeselect('toggleVisibility', (this.value == '1' || this.value=='3'));"; echo $this->formSelect("type_aff", $this->preferences["type_aff"], - array("onchange" => $onchange), - array("1" => "Une sélection de catégories ou de sites", - "2" => "Les sites les plus récents")) + ["onchange" => $onchange], + ["1" => "Une sélection de catégories ou de sites", + "2" => "Les sites les plus récents", + "3" => "Affichage hiérarchique par catégorie"]) ?> </td> </tr> diff --git a/application/modules/opac/controllers/SitoController.php b/application/modules/opac/controllers/SitoController.php index 6700be3445c..bac17cff4f5 100644 --- a/application/modules/opac/controllers/SitoController.php +++ b/application/modules/opac/controllers/SitoController.php @@ -66,7 +66,7 @@ class SitoController extends Zend_Controller_Action { $preferences = Class_Profil::getCurrentProfil() ->getModuleAccueilPreferences($id_module, 'SITO'); - + xdebug_break(); $sites = Class_Sitotheque::getSitesFromIdsAndCategories( explode('-', $preferences['id_items']), explode('-', $preferences['id_categorie'])); diff --git a/library/ZendAfi/View/Helper/Menu/Profil.php b/library/ZendAfi/View/Helper/Menu/Profil.php index c759646e356..40e14574e35 100644 --- a/library/ZendAfi/View/Helper/Menu/Profil.php +++ b/library/ZendAfi/View/Helper/Menu/Profil.php @@ -16,14 +16,15 @@ * * 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 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ class ZendAfi_View_Helper_Menu_Profil extends ZendAfi_View_Helper_Menu_Entry { public function getBoite($li_class = '') { - return (Class_Profil::getCurrentProfil()->getId() == (int)$this->_preferences['clef_profil']) - ? parent::getBoite(trim($li_class.' selected_profil')) - : parent::getBoite($li_class); + if (isset($this->_preferences['clef_profil']) && + (Class_Profil::getCurrentProfil()->getId() == (int)$this->_preferences['clef_profil'])) + return parent::getBoite(trim($li_class.' selected_profil')); + return parent::getBoite($li_class); } } diff --git a/tests/application/modules/admin/controllers/AccueilControllerTest.php b/tests/application/modules/admin/controllers/AccueilControllerTest.php index f82c9f25adb..b9958afdbc6 100644 --- a/tests/application/modules/admin/controllers/AccueilControllerTest.php +++ b/tests/application/modules/admin/controllers/AccueilControllerTest.php @@ -296,6 +296,11 @@ class AccueilControllerConfigSitothequeWithPreferencesTest extends Admin_Abstrac public function displayOrderSelectionShouldBeChecked() { $this->assertXPath('//input[@type="radio"][@name="display_order"][@checked="checked"][@value="Selection"]'); } + +/** @test */ + public function typeHierarchicCanBeSelected() { + $this->assertXPathContentContains('//select[@id="type_aff"]//option[@value=3]','Affichage hiérarchique par catégorie'); + } } diff --git a/tests/application/modules/opac/controllers/SitoControllerTest.php b/tests/application/modules/opac/controllers/SitoControllerTest.php index 0a18cc72cc2..0b7904fdb5a 100644 --- a/tests/application/modules/opac/controllers/SitoControllerTest.php +++ b/tests/application/modules/opac/controllers/SitoControllerTest.php @@ -19,9 +19,10 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ abstract class SitoControllerTestCase extends AbstractControllerTestCase { + protected $hackers; public function setUp() { parent::setUp(); - $this->fixture('Class_SitothequeCategorie', + $this->hackers=$this->fixture('Class_SitothequeCategorie', ['id' => 3, 'libelle' => 'Hackers']); @@ -57,7 +58,59 @@ abstract class SitoControllerTestCase extends AbstractControllerTestCase { } +class SitoControllerHierarchicViewTest extends SitoControllerTestCase { + public function setUp() { + parent::setUp(); + $this->fixture('Class_SitothequeCategorie', + ['id' => 12, + 'parent_categorie' => $this->hackers, + 'libelle' => 'Collectifs' ]); + + + $this->fixture('Class_Sitotheque', + ['id' => 280, + 'id_cat' => 12, + 'titre' => 'La quadrature du net', + 'description' => 'Internet et libertés', + 'url' => 'http://laquadrature.net']); + + $this->fixture('Class_Sitotheque', + ['id' => 281, + 'id_cat' => 12, + 'titre' => 'Framasoft', + 'description' => 'Degooglisons internet', + 'url' => 'http://framasoft.org']); + + Class_Profil::getCurrentProfil() + ->setCfgAccueil([ + 'modules' => [ + '1' => [ + 'division' => '2', + 'type_module' => 'SITO', + 'preferences' => [ + 'id_categorie' => '12', + "type_aff" => "3", + 'id_items' => '280-281'] + ] + ], + 'options' => []]); + + $this->dispatch('/sito/viewselection/id_module/1', true); + + } + /** @test */ + public function LinuxFrShouldNotBeShown() { + $this->assertNotXPath('//div[@class="contenu"]//div[@class="sitotheque"]//a[@href="http://linuxfr.org"]', + $this->_response->getBody()); + } + +/** @test */ + public function FramasoftShouldBeShown() { + $this->assertNotXPath('//div[@class="contenu"]//div[@class="sitotheque"]//a[@href="http://framasoft.org"]', + $this->_response->getBody()); + } +} class SitoControllerViewRecentTest extends SitoControllerTestCase { public function setUp() { parent::setUp(); @@ -79,7 +132,7 @@ class SitoControllerViewSelectionTest extends SitoControllerTestCase { public function setUp() { parent::setUp(); - $this->dispatch('/sito/viewselection/id_module/1', true); + $this->dispatch('/sito/viewselection/id_module/1', true);; } -- GitLab