From 90a42b95848c2b34f72906199f4f47b4d29c23ed Mon Sep 17 00:00:00 2001
From: gloas <gloas@afi-loas.afi-sa.net>
Date: Thu, 27 Feb 2014 18:30:31 +0100
Subject: [PATCH] rel #12091 adding domain select to domain widget settings

---
 .../Form/Configuration/DomainWidget.php       | 27 ++++++++--
 .../ZendAfi/Form/Decorator/DomainSelect.php   | 29 +++++++++++
 library/ZendAfi/Form/Element/DomainSelect.php | 52 +++++++++++++++++++
 .../controllers/AccueilControllerTest.php     | 47 +++++++++++++++--
 4 files changed, 146 insertions(+), 9 deletions(-)
 create mode 100644 library/ZendAfi/Form/Decorator/DomainSelect.php
 create mode 100644 library/ZendAfi/Form/Element/DomainSelect.php

diff --git a/library/ZendAfi/Form/Configuration/DomainWidget.php b/library/ZendAfi/Form/Configuration/DomainWidget.php
index bc3c57dd863..7fc041bb3ad 100644
--- a/library/ZendAfi/Form/Configuration/DomainWidget.php
+++ b/library/ZendAfi/Form/Configuration/DomainWidget.php
@@ -27,11 +27,17 @@ class ZendAfi_Form_Configuration_DomainWidget extends ZendAfi_Form {
 		$form = new self();
 		$form
 			->populate($module_settings)
-			->addDisplayGroup(['title',
+			->addToWith('domain_select', $module_settings['root_domain_id'])
+			->addDisplayGroup(['titre',
 												 'boite'],
 												'Base',
-												['legend' => $form->_('Généralités')]);
-		
+												['legend' => $form->_('Généralités')])
+			->addDisplayGroup(['domain_select'],
+												'advanced',
+												['legend' => $form->_('Avancés')])
+			->addDisplayGroup(['submit'],
+												'submit',
+												['legend' => '']);		
 		return $form;
 	}
 
@@ -42,7 +48,7 @@ class ZendAfi_Form_Configuration_DomainWidget extends ZendAfi_Form {
 			->setAttrib('id', 
 									'configuration_domainBrowser')
 			->addElement('text', 
-									 'title', 
+									 'titre', 
 									 ['label' => $this->_('Titre'),
 										'size' => $this->_text_size])
 			->addElement('select',
@@ -50,7 +56,18 @@ class ZendAfi_Form_Configuration_DomainWidget extends ZendAfi_Form {
 									 ['label' => $this->_('Style de boite'),
 										'multiOptions' => (
 											new Class_Profil_Templates(
-												Class_Profil::getCurrentProfil()))->toArray()]);
+												Class_Profil::getCurrentProfil()))->toArray()])
+			->addElement('domainSelect',
+									 'domain_select')	
+			->addElement('submit', 
+									 'submit', 
+									 ['label' => $this->_('Valider')]);
+	}
+
+	
+	public function addToWith($element, $item_id) {
+		$this->$element->setItem(Class_Catalogue::find($item_id));
+		return $this;
 	}
 } 
 ?>
\ No newline at end of file
diff --git a/library/ZendAfi/Form/Decorator/DomainSelect.php b/library/ZendAfi/Form/Decorator/DomainSelect.php
new file mode 100644
index 00000000000..ea08c71cd0f
--- /dev/null
+++ b/library/ZendAfi/Form/Decorator/DomainSelect.php
@@ -0,0 +1,29 @@
+<?php
+/**
+ * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved.
+ *
+ * AFI-OPAC 2.0 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).
+ *
+ * AFI-OPAC 2.0 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 AFI-OPAC 2.0; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA 
+ */
+
+
+
+class ZendAfi_Form_Decorator_DomainSelect extends Zend_Form_Decorator_Abstract {
+	public function render($content) {
+		return $this->_element->getView()->domaineSelect($this->_element->getItem());
+	}
+}
+?>
diff --git a/library/ZendAfi/Form/Element/DomainSelect.php b/library/ZendAfi/Form/Element/DomainSelect.php
new file mode 100644
index 00000000000..bb344a94570
--- /dev/null
+++ b/library/ZendAfi/Form/Element/DomainSelect.php
@@ -0,0 +1,52 @@
+<?php
+/**
+ * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved.
+ *
+ * AFI-OPAC 2.0 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).
+ *
+ * AFI-OPAC 2.0 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 AFI-OPAC 2.0; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA 
+ */
+
+
+
+class ZendAfi_Form_Element_DomainSelect extends Zend_Form_Element {
+	/*
+	 * @param item user of Trait_HasManyDomaines
+	 */
+	protected $_item;
+
+	public function __construct($spec, $options=null) {
+		parent::__construct($spec, $options);
+		$decorators = $this->_decorators;
+		$this->_decorators = ['DomainSelect' => new ZendAfi_Form_Decorator_DomainSelect()];
+
+		foreach ($decorators as $name => $value)
+			$this->_decorators[$name] = $value;
+		$this->removeDecorator('ViewHelper');
+
+	}
+
+
+	public function setItem($item) {
+		$this->_item = $item;
+		return $this;
+	}
+
+
+	public function getItem() {
+		return $this->_item;
+	}
+}
+?>
\ No newline at end of file
diff --git a/tests/application/modules/admin/controllers/AccueilControllerTest.php b/tests/application/modules/admin/controllers/AccueilControllerTest.php
index 9ead2e48d4e..324e4e80819 100644
--- a/tests/application/modules/admin/controllers/AccueilControllerTest.php
+++ b/tests/application/modules/admin/controllers/AccueilControllerTest.php
@@ -799,8 +799,7 @@ class AccueilControllerWidgetDomainConfigurationTest extends Admin_AbstractContr
 		$domain_widget = ['type_module' => 'DOMAIN_BROWSER',
 											'division' => 1,
 											'id_module' => 5,
-											'preferences' => ['title' => 'Mes domaines',
-																				'boite' => 'boite_vide',
+											'preferences' => ['boite' => 'boite_vide',
 																				'root_domain_id' => '1']];
 
 		Class_Profil::getCurrentProfil()
@@ -812,14 +811,54 @@ class AccueilControllerWidgetDomainConfigurationTest extends Admin_AbstractContr
 
 	/** @test **/
 	public function inputTitleWidgetShouldBeDisplay() {
-		$this->assertXpath('//input[@name="title"][@value="Mes domaines"]');
+		$this->assertXpath('//input[@name="titre"][@value="Domaines"]');
 	}
 
 
-		/** @test **/
+	/** @test **/
 	public function inputWidgetSkinShouldBeDisplay() {
 		$this->assertXpath('//select[@name="boite"]/option[@selected="selected"][@value="boite_vide"]');
 	}
+
+
+	/** @test */
+	public function submitButtonShouldBeDisplayed() {
+		$this->assertXPath('//input[@type="submit"]');
+	}
+
+
+	/** @test */
+	public function inputRootDomaineIdShouldBeDisplayed() {
+		$this->assertXPath('//input[@name="domaine_ids"]');
+	}
+}
+
+
+
+
+class AccueilControllerWidgetDomainPostConfigurationTest extends Admin_AbstractControllerTestCase {
+
+	public function setup() {
+		parent::setup();
+		
+		$domain_widget = ['type_module' => 'DOMAIN_BROWSER',
+											'division' => 1,
+											'id_module' => 5,
+											'preferences' => ['boite' => 'boite_vide',
+																				'root_domain_id' => '1']];
+
+		Class_Profil::getCurrentProfil()
+			->setLibelle('Adulte')
+			->updateModuleConfigAccueil(5, $domain_widget);
+
+		$this->postDispatch('/admin/accueil/domain-browser?config=accueil&id_profil=2&id_module=5&type_module=DOMAIN_BROWSER', ['titre' =>'Mes Domaines']);
+	}
+
+
+	/** @test */
+	public function newWidgetTitleShouldBeMesDomaines() {
+		$this->assertEquals('Mes Domaines', Class_Profil::getCurrentProfil()->getModuleAccueilConfig(5)['preferences']['titre']);
+	}
 }
 
 ?>
\ No newline at end of file
-- 
GitLab