From 702e64c0f158c6a841a1eaebb2fda44f203f5c9b Mon Sep 17 00:00:00 2001 From: llaffont <llaffont@git-test.afi-sa.fr> Date: Tue, 11 Jun 2013 16:16:44 +0000 Subject: [PATCH] Profil: Ajout fonction pour appliquer la config pages portails aux autres profils #9532 --- .gitattributes | 3 +- .../admin/controllers/ProfilController.php | 7 ++ .../views/scripts/profil/_profil_row.phtml | 18 +++-- library/Class/Profil.php | 22 +++++- .../images/ico/duplicate_cfg_modules.png | Bin 0 -> 807 bytes .../controllers/ProfilControllerIndexTest.php | 29 ++++--- .../controllers/ProfilControllerTest.php | 37 ++++++++- ...MenuTest.php => DuplicateInProfilTest.php} | 72 +++++++++++++----- 8 files changed, 146 insertions(+), 42 deletions(-) create mode 100644 public/admin/images/ico/duplicate_cfg_modules.png rename tests/library/Class/{DuplicateHorizontalMenuTest.php => DuplicateInProfilTest.php} (69%) diff --git a/.gitattributes b/.gitattributes index 13ec9a9d459..5a677319542 100644 --- a/.gitattributes +++ b/.gitattributes @@ -3160,6 +3160,7 @@ public/admin/images/ico/coche_verte.gif -text public/admin/images/ico/copier.gif -text public/admin/images/ico/del.gif -text public/admin/images/ico/down.gif -text +public/admin/images/ico/duplicate_cfg_modules.png -text svneol=unset#unset public/admin/images/ico/ecran.png -text public/admin/images/ico/ecran_rouge.png -text public/admin/images/ico/edit.gif -text @@ -5784,7 +5785,7 @@ tests/library/Class/CompositeBuilderTreeTest.php -text tests/library/Class/CompositeBuilderTreeTestCase.php -text tests/library/Class/CriteresRechercheTest.php -text tests/library/Class/DecodageUnimarcTest.php -text -tests/library/Class/DuplicateHorizontalMenuTest.php -text +tests/library/Class/DuplicateInProfilTest.php -text tests/library/Class/DynamicUserGroupTest.php -text tests/library/Class/EADTest.php -text tests/library/Class/FRBR/LinkTest.php -text diff --git a/application/modules/admin/controllers/ProfilController.php b/application/modules/admin/controllers/ProfilController.php index ca23a077cbb..53c9a564d25 100644 --- a/application/modules/admin/controllers/ProfilController.php +++ b/application/modules/admin/controllers/ProfilController.php @@ -533,6 +533,13 @@ class Admin_ProfilController extends ZendAfi_Controller_Action { $this->_redirect('admin/profil/menusindex/id_profil/'.$this->id_profil); } + + public function duplicateConfigModulesAction() { + Class_Profil::find($this->id_profil)->duplicateConfigModules(); + $this->_helper->notify($this->_('Configuration des pages appliquée à tous les autres profils.')); + $this->_redirect('admin/profil'); + } + private function _splitArg($item) { $pos = strpos($item, '='); diff --git a/application/modules/admin/views/scripts/profil/_profil_row.phtml b/application/modules/admin/views/scripts/profil/_profil_row.phtml index a53551c56ef..a3fb85d4cbd 100644 --- a/application/modules/admin/views/scripts/profil/_profil_row.phtml +++ b/application/modules/admin/views/scripts/profil/_profil_row.phtml @@ -37,19 +37,23 @@ if ($this->profil->isTelephone()) { <div class="actions"> <?php - $actions = [['action' => 'edit', 'icon' => 'ico/edit.gif', 'help' => 'Modifier'], - ['action' => 'menusindex', 'icon' => 'picto/menus.png', 'help' => 'Configuration des menus'], - ['action' => 'proprietes', 'icon' => 'picto/module.gif', 'help' => 'Propriétés des modules'], - ['action' => 'deep_copy', 'icon' => 'ico/page_copy.png', 'help' => 'Dupliquer le profil'], - ['action' => 'newpage', 'icon' => 'ico/page_add.png', 'help' => 'Ajouter une page']]; + $actions = [['action' => 'edit', 'icon' => 'ico/edit.gif', 'help' => 'Modifier'], + ['action' => 'menusindex', 'icon' => 'picto/menus.png', 'help' => 'Configuration des menus'], + ['action' => 'proprietes', 'icon' => 'picto/module.gif', 'help' => 'Propriétés des modules'], + ['action' => 'deep_copy', 'icon' => 'ico/page_copy.png', 'help' => 'Dupliquer le profil'], + ['action' => 'newpage', 'icon' => 'ico/page_add.png', 'help' => 'Ajouter une page']]; foreach ($actions as $action) echo $this->tagAnchor($this->url(array('action' => $action['action'], 'id_profil' => $this->profil->getId())), '<img src="'.URL_ADMIN_IMG.$action['icon'].'" alt="'.$action['help'].'" title="'.$action['help'].'" />'); - if ($this->profil->isPortail() == 1) - echo ' '; + if ($this->profil->isPortail() == 1) { + $actions []= ['action' => 'duplicate-config-modules', 'icon' => 'ico/duplicate_cfg_modules.png', 'help' => 'Appliquer la configuration des pages aux autres profils']; + echo $this->tagAnchor($this->url(['action' => 'duplicate-config-modules', 'id_profil' => $this->profil->getId()]), + '<img src="'.URL_ADMIN_IMG.'ico/duplicate_cfg_modules.png" alt="Appliquer la configuration des pages aux autres profils" title="Appliquer la configuration des pages aux autres profils" />', + ['onclick' => 'javascript:if(!confirm(\'Attention, cela écrasera la configuration des autres profils. Continuer ?\')) return false;"']); + } else echo '<a href="'.BASE_URL.'/admin/profil/delete/id_profil/'.$this->profil->getId(). '">'. diff --git a/library/Class/Profil.php b/library/Class/Profil.php index 8702752a745..f39b9efd608 100644 --- a/library/Class/Profil.php +++ b/library/Class/Profil.php @@ -1448,16 +1448,32 @@ class Class_Profil extends Storm_Model_Abstract { } - public function duplicateHorizontalMenu() { + public function topProfilsDoAndSave($closure) { $profils = $this->getLoader()->findAllBy(['where'=> 'parent_id is null']); foreach ($profils as $profil) { if ($this->getId()==$profil->getId()) continue; - $profil->setCfgMenuHorizontal($this->getMenu('H')); + $closure($profil); $profil->save(); } - } + + public function duplicateHorizontalMenu() { + $this->topProfilsDoAndSave( + function($profil) { + $profil->setCfgMenuHorizontal($this->getMenu('H')); + } + ); + } + + + public function duplicateConfigModules() { + $this->topProfilsDoAndSave( + function($profil) { + $profil->setCfgModules($this->getCfgModules()); + } + ); + } } \ No newline at end of file diff --git a/public/admin/images/ico/duplicate_cfg_modules.png b/public/admin/images/ico/duplicate_cfg_modules.png new file mode 100644 index 0000000000000000000000000000000000000000..407f1abd0a9e00bd3f279e4b530b3420ec07f3b7 GIT binary patch literal 807 zcmV+?1K9kDP)<h;3K|Lk000e1NJLTq000mG000mO1^@s6AM^iV00006VoOIv0RI60 z0RN!9r;`8x010qNS#tmY3ljhU3ljkVnw%H_000McNliru-3AK}IV$8<)S&<X0<=j) zK~y-)eUn>ki*Xpnf8W<{ZGEL3GhsDn<}g&2vBg;$x)CE;f{|EeTbV;-#0^6tyK%*Z z(;^{)n8j(qNX8t3MYd^^%_)wVVRq<JUt86*e-~>+SUp$o&GUQTJpbn}5lh8D1uz>0 z1q%b?)a3X{iq&M5gMNu;&COmqeVr2j(;5b+rKX>rn>=saaLdS1L(Rhs5)x8a;nw3P zZI^0qrz!sh^xzRc!ZXWr4<weo*v<LYQ}_b`<d96!)KY78U7ae&G#3Ijgqw~urEER5 zEm$<#$(zo%ba}h@@a+TLeh-SQ&^N#doa`M_Hl);S%5oYuKPW*7DR{gdbP*kvI16DB z?gLN^oai0ZEvoy@uG(2;&3kZvabprDZsgo#%7Dq}F%ltyOwk|a{Alt~1w+A#(~r*J z7@Cb)n5md|lKT5@E-tS^(|pLX6n%u%4F2;7!)8MhPD%jOLe;*na=*~Ln#etn*Um&H zr{>$c7H=<jg>6JUWT2##r(d7CcUmU{h)>xyvA(UNO_X0N7ixiO2VkAPWctpGPfTOR z?=904=LjKy1q>=ZyYr>y^NE6^g~5jR4Z>0F5Qm-~7JD!37y7mRN&py(8GvllU!mnF z$p^0<{;{L6RJ3%rh(%WxiG<?`V)W5b!sq=iY&$YPGa+hT5%*8#a`M1QN|GhXaQ9Ok znU^zhwYxAyRF2I*LH?nQ-&}W}EaNp^Rw{5c^bbI>s>3A-nSeilA#9-Mdk>X47kK>8 zO;zQ&g|zUTtp0FC>$5WQPd_N=kwY>8&5to+r0h-^>m94GrQ7cTI%>3-h1Gr0|BO?O z=DaNHQu7RB21^o_V^cF}c+o<KS8IFcZ*8PK&>9OMG2SehlEw_t%X(EOD}+V3w_&m* lc{;v!3)jaUNs9exe*r$z02#<$!Mp$f002ovPDHLkV1k{GZ4Lkc literal 0 HcmV?d00001 diff --git a/tests/application/modules/admin/controllers/ProfilControllerIndexTest.php b/tests/application/modules/admin/controllers/ProfilControllerIndexTest.php index 4205d63879a..3112bfb8b8b 100644 --- a/tests/application/modules/admin/controllers/ProfilControllerIndexTest.php +++ b/tests/application/modules/admin/controllers/ProfilControllerIndexTest.php @@ -90,74 +90,74 @@ class Admin_ProfilControllerWithAdminPortailIndexTest extends Admin_ProfilContro /** @test */ public function profilJeunesseShouldBeVisible() { - $this->assertXPathContentContains("//ul[1]//li[1]//div", + $this->assertXPathContentContains("//div/ul[1]//li[1]//div", "Jeunesse"); } /** @test */ public function profilJeunessePageAccueilShouldBeVisible() { - $this->assertXPathContentContains("//ul[1]//li[1]//a[contains(@href, 'id_profil/12')]", + $this->assertXPathContentContains("//div/ul[1]//li[1]//a[contains(@href, 'id_profil/12')]", "Accueil"); } /** @test */ public function profilJeunesseIconeShouldBeEcranRouge() { - $this->assertXPath("//ul[1]//li[1]//img[contains(@src, 'ecran_rouge.png')]"); + $this->assertXPath("//div/ul[1]//li[1]//img[contains(@src, 'ecran_rouge.png')]"); } /** @test */ public function profilAdulteShouldBeVisible() { - $this->assertXPathContentContains("//ul[1]//li[1]//div", "Adulte", + $this->assertXPathContentContains("//div/ul[1]//li[1]//div", "Adulte", $this->_response->getBody()); } /** @test */ public function pageAccueilProfilAdulteShouldBeVisible() { - $this->assertXPathContentContains("//ul[1]//li[1]//a[contains(@href, 'id_profil/8')]", + $this->assertXPathContentContains("//div/ul[1]//li[1]//a[contains(@href, 'id_profil/8')]", "Accueil"); } /** @test */ function previewPageAccueilAnchorTitleShouldBeVisualisationDeLaPageAdulte() { - $this->assertXPath('//ul[1]//li[1]//a[@rel="prettyPhoto"][contains(@title, "Visualisation de la page \'Adulte\'")]', + $this->assertXPath('//div/ul[1]//li[1]//a[@rel="prettyPhoto"][contains(@title, "Visualisation de la page \'Adulte\'")]', $this->_response->getBody()); } /** @test */ public function profilAdulteIconeShouldBeEcran() { - $this->assertXPath("//ul[1]//li[1]//img[contains(@src, 'ecran.png')]"); + $this->assertXPath("//div/ul[1]//li[1]//img[contains(@src, 'ecran.png')]"); } /** @test */ public function profilPortailShouldBeVisible() { - $this->assertXPathContentContains("//ul[1]//li[2]//div", + $this->assertXPathContentContains("//div/ul[1]/li[2]/div", "Portail"); } /** @test */ public function profilPortailIconeShouldBeMap() { - $this->assertXPath("//ul[1]//li[2]//img[contains(@src, 'map.gif')]"); + $this->assertXPath("//div/ul[1]/li[2]//img[contains(@src, 'map.gif')]"); } /** @test */ public function profilSmartphoneShouldBeVisible() { - $this->assertXPathContentContains("//ul[1]//li[3]//div", + $this->assertXPathContentContains("//div/ul[1]/li[3]//div", "Smartphone"); } /** @test */ public function profilSmartphoneIconeShouldBeTelephone() { - $this->assertXPath("//ul[1]//li[3]//img[contains(@src, 'telephone.gif')]"); + $this->assertXPath("//div/ul[1]/li[3]//img[contains(@src, 'telephone.gif')]"); } @@ -167,9 +167,16 @@ class Admin_ProfilControllerWithAdminPortailIndexTest extends Admin_ProfilContro "Ajouter un profil"); } + + /** @test */ + public function profilPortailShouldHaveActionDuplicatieCfgModules() { + $this->assertXPath("//div/ul[1]/li[2]/div/a[contains(@href, 'profil/duplicate-config-modules/id_profil/1')]"); + } } + + class Admin_ProfilControllerWithAdminBibIndexTest extends Admin_ProfilControllerIndexTestCase { protected function _loginHook($account) { parent::_loginHook($account); diff --git a/tests/application/modules/admin/controllers/ProfilControllerTest.php b/tests/application/modules/admin/controllers/ProfilControllerTest.php index 01f74bd6a67..8f5e1669a5f 100644 --- a/tests/application/modules/admin/controllers/ProfilControllerTest.php +++ b/tests/application/modules/admin/controllers/ProfilControllerTest.php @@ -608,7 +608,6 @@ class Admin_ProfilControllerProfilJeunesseTestMenusIndex extends Admin_ProfilCon $this->assertXPath("//tr[@class='second']//td//a[contains(@href, 'admin/profil/duplicate-horizontal-menu/id_profil/5')]"); } - /** @test */ public function cannotDeleteMenuHorizontalLink() { $this->assertNotXPath("//tr[@class='second']//td//a[contains(@href, 'menusmaj/id_profil/5/id_menu/H/mode/delete')]"); @@ -1263,4 +1262,40 @@ class Admin_ProfilControllerDuplicateHorizontalMenuTest extends Admin_ProfilCont + + +class Admin_ProfilControllerDuplicateCfgModulesTest extends Admin_ProfilControllerProfilJeunesseWithPagesTestCase { + public function setUp() { + parent::setUp(); + Class_Profil::getLoader() + ->whenCalled('findAllBy') + ->answers([$this->other_profil = Class_Profil::newInstanceWithId(10)]); + + $this->profil_jeunesse->setCfgModules(['test']); + + $this->dispatch('/admin/profil/duplicate-config-modules/id_profil/5', true); + } + + + /** @test */ + public function cfgModulesShouldBeDuplicated() { + $this->assertEquals($this->profil_jeunesse->getCfgModules(), + $this->other_profil->getCfgModules()); + } + + + /** @test */ + public function answerShouldNotifySuccess() { + $this->assertFlashMessengerContains('Configuration des pages appliquée à tous les autres profils.'); + } + + + /** @test */ + public function responseShouldRedirectToIndexProfil() { + $this->assertRedirectTo('/admin/profil'); + } +} + + + ?> \ No newline at end of file diff --git a/tests/library/Class/DuplicateHorizontalMenuTest.php b/tests/library/Class/DuplicateInProfilTest.php similarity index 69% rename from tests/library/Class/DuplicateHorizontalMenuTest.php rename to tests/library/Class/DuplicateInProfilTest.php index 7c4343eb69d..f3b91f5a54a 100644 --- a/tests/library/Class/DuplicateHorizontalMenuTest.php +++ b/tests/library/Class/DuplicateInProfilTest.php @@ -18,16 +18,14 @@ * 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 */ -//require_once('library/Class/Profil.php'); -class DuplicateHorizontalMenuTest extends Storm_Test_ModelTestCase { + +abstract class DuplicateInProfilTestCase extends Storm_Test_ModelTestCase { protected $current_profil; public function setUp() { parent::setUp(); - $this->current_profil = Class_Profil::newInstanceWithId(1) - ->setLibelle("Profil courant") - ->setCfgMenus( + $cfg_menus = ['H' => ["libelle" => "Menu horizontal", "picto" => "vide.gif", @@ -36,9 +34,9 @@ class DuplicateHorizontalMenuTest extends Storm_Test_ModelTestCase { 'picto' => 'bookmark.png', 'preferences' => [], 'sous_menus' => [['type_menu' => 'ACCUEIL', - 'libelle' => 'Accueil', - 'picto' => 'vide.gif', - 'preferences' => []], + 'libelle' => 'Accueil', + 'picto' => 'vide.gif', + 'preferences' => []], ['type_menu' => 'URL', 'libelle' => 'Google', @@ -59,23 +57,28 @@ class DuplicateHorizontalMenuTest extends Storm_Test_ModelTestCase { ['type_menu' => 'PANIER', 'libelle' => 'Paniers de notices', 'picto' => 'vide.gif' ] - ]]]], + ]]]], 'V' => ["libelle" => "Menu vertical", "picto" => "vide.gif", "menus" => [] - ] - ] - ); - $profil1=Class_Profil::newInstanceWithId(2) - ->setLibelle("Profil 1"); - - $profil2=Class_Profil::newInstanceWithId(3) - ->setLibelle("Profil 2"); + ] + ]; + + + $cfg_modules = ['recherche' => ['viewnotice1' => ['barre_nav' => 'Notice']]]; + + $this->current_profil = Class_Profil::newInstanceWithId(1, ['libelle' => 'Profil courant', + 'cfg_menus' => $cfg_menus, + 'cfg_modules' => $cfg_modules]); + + $profil1=Class_Profil::newInstanceWithId(2, ['libelle' => 'Profil 1']); + + $profil2=Class_Profil::newInstanceWithId(3, ['libelle' => 'Profil 2']); + $this->profils[]=$profil1; $this->profils[]=$profil2; - Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Profil') ->whenCalled('save') @@ -83,7 +86,15 @@ class DuplicateHorizontalMenuTest extends Storm_Test_ModelTestCase { ->whenCalled('findAllBy') ->with(['where'=> 'parent_id is null']) ->answers($this->profils); + } +} + + + +class DuplicateInProfilHorizontalMenuTest extends DuplicateInProfilTestCase { + public function setUp() { + parent::setUp(); $this->current_profil->duplicateHorizontalMenu(); } @@ -102,11 +113,34 @@ class DuplicateHorizontalMenuTest extends Storm_Test_ModelTestCase { } + /** @test */ + public function duplicateProfilShouldSaveProfil2() { + $this->assertEquals($this->profils[1],Class_Profil::getFirstAttributeForLastCallOn('save')); + + } +} + + + + +class DuplicateInProfilConfigModulesTest extends DuplicateInProfilTestCase { + public function setUp() { + parent::setUp(); + $this->current_profil->duplicateConfigModules(); + } + + + /** @test */ + public function duplicateProfilShouldHaveBarreNavRechercheNotice() { + $this->assertEquals('Notice', $this->profils[1]->getCfgModulesPreferences('recherche', 'viewnotice', '1')['barre_nav']); + } /** @test */ public function duplicateProfilShouldSaveProfil2() { $this->assertEquals($this->profils[1],Class_Profil::getFirstAttributeForLastCallOn('save')); } +} + -} \ No newline at end of file +?> \ No newline at end of file -- GitLab