diff --git a/.gitattributes b/.gitattributes index 13ec9a9d4590d3b2d715c0d17ab1a0ab4de3dbf5..5a6773195424ba0f081d17af49cc4dca1d0d03b7 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 ca23a077cbbe0d6a73030b2df193ecb5fc84ad5c..53c9a564d256ee99cf6f6a74d17b5374394707c2 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 a53551c56efeb0ffc3bf2cc45602c7149603f2af..a3fb85d4cbd1007f8f7f501474026eb91a63d9d0 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 8702752a745411b2f31be62e2eb13af83c65e27b..f39b9efd608d140d90cde8996b71211e4fd3cf39 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 Binary files /dev/null and b/public/admin/images/ico/duplicate_cfg_modules.png differ diff --git a/tests/application/modules/admin/controllers/ProfilControllerIndexTest.php b/tests/application/modules/admin/controllers/ProfilControllerIndexTest.php index 4205d63879a19f6f2623c4caa8db8cd6784e4cc6..3112bfb8b8bed36cb8462b8b8aa4aa362856beee 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 01f74bd6a674a89edb3763a97dbd49340dbf3ae6..8f5e1669a5f3a91dfebad8294ec1e7e6e40150fc 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 7c4343eb69dbe97f7dfe60c39056b4dfbcc4f241..f3b91f5a54adf8bf2a81e249438de1521c9edc5e 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