diff --git a/VERSIONS_HOTLINE/86773 b/VERSIONS_HOTLINE/86773 new file mode 100644 index 0000000000000000000000000000000000000000..7ea0853bb806ebd43b3731ff0b8a7d08dbcbe0d3 --- /dev/null +++ b/VERSIONS_HOTLINE/86773 @@ -0,0 +1 @@ + - ticket #86773 : Le parametrage d'un tableau d'exemplaire d'un profil enfant ne se sauvegarde pas . \ No newline at end of file diff --git a/application/modules/admin/controllers/ModulesnoticeController.php b/application/modules/admin/controllers/ModulesnoticeController.php index 06164e8d4ddde319920496f6cd5e7e62fc3f3e24..f2a187822c0a821737bf0b8a28f8d65b884760d6 100644 --- a/application/modules/admin/controllers/ModulesnoticeController.php +++ b/application/modules/admin/controllers/ModulesnoticeController.php @@ -24,7 +24,8 @@ class Admin_ModulesnoticeController extends ZendAfi_Controller_Action { public function exemplairesAction() { $this->view->titre = $this->view->_('Propriété du bloc des exemplaires'); - $profil = Class_Profil::getCurrentProfil(); + $profil = $this->_getParam('id_profil') ? + Class_Profil::find($this->_getParam('id_profil')) : Class_Profil::getCurrentProfil(); $preferences = $profil->getItemsSettings(); $params = array_merge($preferences, $this->_request->getPost()); @@ -37,8 +38,21 @@ class Admin_ModulesnoticeController extends ZendAfi_Controller_Action { if (!$this->_request->isPost() || !$form->isValid($params)) return; - $profil->setItemsSettings($params)->save(); - $this->_helper->notify($this->_('Profil : %s sauvegardé', $profil->getLibelle())); + $profil + ->setItemsSettings($params) + ->save(); + + $errors = $profil->getErrors(); + + if ($parent = $profil->getParentProfil()) { + $parent->save(); + + $errors = array_merge($errors, $parent->getErrors()); + } + + $errors + ? $this->_helper->notify(implode('<br/>', $errors)) + : $this->_helper->notify($this->_('Profil : %s sauvegardé', $profil->getLibelle())); return $this->isPopupRequest() ? $this->_javascriptRedirectToReferrer() diff --git a/library/Class/Profil.php b/library/Class/Profil.php index ad4c9bf0b487049ec642a990c983f4901935f862..59ffd0610309f58970986e97fa037a79b4152201 100644 --- a/library/Class/Profil.php +++ b/library/Class/Profil.php @@ -1120,6 +1120,7 @@ class Class_Profil extends Storm_Model_Abstract { $cfg = ZendAfi_Filters_Serialize::serialize($string_or_array); else $cfg = $string_or_array; + return $this->_set($cfg_name, $cfg); } @@ -1360,8 +1361,7 @@ class Class_Profil extends Storm_Model_Abstract { if (in_array($field, self::getCfgSiteKeys())) { return $this->setCfgSiteParam($field, $value); } - else - return parent::_set($field, $value); + return parent::_set($field, $value); } @@ -1376,7 +1376,8 @@ class Class_Profil extends Storm_Model_Abstract { $this->setLargeurDivision2(0); $this->checkAttribute('libelle', - $this->getLibelle(), $this->_('Le libellé est obligatoire.')); + $this->getLibelle(), + $this->_('Le libellé est obligatoire.')); $this->checkAttribute('size_site_scale', $this->getSizeSiteScale()!="px" or $this->getLargeurSite() >= 800 and $this->getLargeurSite() <= 2000, @@ -1868,7 +1869,6 @@ class Class_Profil extends Storm_Model_Abstract { if ($this->hasParentProfil()) $this->getParentProfil()->save(); - return $this; } diff --git a/tests/application/modules/admin/controllers/ModulesnoticeControllerTest.php b/tests/application/modules/admin/controllers/ModulesnoticeControllerTest.php index 0c2e9ebd99462bdd0ac1a24395b6fb037ad9d165..b01fa547b8d918f479b553dd17b189d05abb7f02 100644 --- a/tests/application/modules/admin/controllers/ModulesnoticeControllerTest.php +++ b/tests/application/modules/admin/controllers/ModulesnoticeControllerTest.php @@ -93,22 +93,75 @@ class ModulesnoticeControllerExemplairesWithAnnexTest extends Admin_AbstractCont /** @test */ public function annecyShouldBeSelectable() { - $this->assertXPathContentContains('//ul/li', 'Annecy'); + $this->assertXPathContentContains('//ul/li', 'Annecy',$this->_response->getBody()); + } + + +} + + + +class ModulesnoticeControllerExemplairesPostWithErrorsTest extends Admin_AbstractControllerTestCase { + protected $_storm_default_to_volatile = true; + + + public function setUp() { + parent::setUp(); + $this->fixture('Class_Profil', + ['id' => 2, + 'parent_id' => 1, + 'libelle' => 'Cran/Accueil']) + ->setLibelle(''); + Class_Profil::find(1)->setLargeurSite(1); + + $this->postDispatch('/admin/modulesnotice/exemplaires/id_profil/2', []); + } + + + /** @test */ + public function pageShouldNotifyMissingLabel() { + $this->assertFlashMessengerContentContains('Le libellé est obligatoire'); + } + + + /** @test */ + public function pageShouldNotifyPageWidthNotValid() { + $this->assertFlashMessengerContentContains('La largeur du site doit'); } } + class ModulesnoticeControllerExemplairesPostTest extends Admin_AbstractControllerTestCase { protected $_storm_default_to_volatile = true; public function setUp() { parent::setUp(); + $profil_cran = $this->fixture('Class_Profil', + ['id' => 2, + 'parent_id' => 1, + 'libelle' => 'Cran/Accueil']); + + + $config = Class_Profil::find(1)->getCfgNoticeAsArray(); + $config['exemplaires']['annexe'] = '1'; + $config['exemplaires']['bib'] = '0'; + $config['exemplaires']['emplacement'] = '0'; + $config['exemplaires']['order_by'] = 'b'; + $config['exemplaires']['en_pret'] = 'en pret'; + Class_Profil::find(1) + ->setCfgNotice($config) + ->assertSave(); + + $this->postDispatch('/admin/modulesnotice/exemplaires/id_profil/2', - ['order_by' => 'a', + ['en_pret' => 'emprunté', + 'order_by' => 'a', 'order_direction' => 'ASC', 'grouper' => 0, - 'libraries' => ''], + 'libraries' => '', + 'emplacement' => 1], true); } @@ -120,13 +173,32 @@ class ModulesnoticeControllerExemplairesPostTest extends Admin_AbstractControlle /** @test */ - public function profilItemsSettingsShouldHaveBeenUpdated() { - $this->assertEquals('a', Class_Profil::getCurrentProfil()->getItemsSettings()['order_by']); + public function childProfilTwoItemsSettingsShouldHaveOrderByA() { + $this->assertEquals('a', Class_Profil::find(2)->getItemsSettings()['order_by']); + } + + + /** @test */ + public function parentProfilOneItemsSettingsShouldHaveOrderByA() { + $this->assertEquals('a', Class_Profil::find(1)->getItemsSettings()['order_by']); + } + + + /** @test */ + public function profilItemsShouldHaveEmplacement1() { + $this->assertEquals('1', Class_Profil::getCurrentProfil()->getItemsSettings()['emplacement']); } /** @test */ public function flashMessengerShouldCintainsProfilUpdated() { - $this->assertFlashMessengerContentContains('Profil : AFI sauvegardé'); + $this->assertFlashMessengerContentContains('Profil : Cran/Accueil sauvegardé'); + } + + + /** @test */ + public function enPretShouldEqualEmprunte() { + $this->assertEquals('emprunté', + Class_Profil::find(1)->getItemsSettings()['en_pret']); } } \ No newline at end of file