diff --git a/VERSIONS_HOTLINE/85026 b/VERSIONS_HOTLINE/85026 new file mode 100644 index 0000000000000000000000000000000000000000..0cc5aa1dad77ca8785860c1e66ab492bc2a46923 --- /dev/null +++ b/VERSIONS_HOTLINE/85026 @@ -0,0 +1,2 @@ + - ticket #85026 : Administration : ajout d'une valeur par défaut dans le formulaire de rattachement d'un panier à un domaine. + \ No newline at end of file diff --git a/application/modules/admin/controllers/CatalogueController.php b/application/modules/admin/controllers/CatalogueController.php index 59e586a3a2105f6dac1e59856eae05a101c1b91d..536fcb5aba3a2ee6db85ebc4f5806a7b2e87ae22 100644 --- a/application/modules/admin/controllers/CatalogueController.php +++ b/application/modules/admin/controllers/CatalogueController.php @@ -200,34 +200,37 @@ class Admin_CatalogueController extends ZendAfi_Controller_Action { if (!$catalogue = Class_Catalogue::find((int)$this->_getParam("id_catalogue"))) return $this->_redirect("admin/catalogue/index"); - if ($this->_request->isPost()) { - $panier = Class_PanierNotice::find($this->_request->getPost('id_panier')); - $catalogue->addPanierNotice($panier)->save(); - $panier->addCatalogue($catalogue)->save(); - $panier->index(); - $this->_helper->notify($this->_('Panier "%s" ajouté', $panier->getLibelle())); - $this->_redirect('admin/catalogue/paniers/id_catalogue/' . $catalogue->getId()); - return; - } - if ($id_panier_to_remove = (int)$this->_getParam('remove')) { $panier = Class_PanierNotice::find($id_panier_to_remove); $catalogue->removePanierNotice($panier)->save(); $panier->removeCatalogue($catalogue)->save(); $this->_helper->notify($this->_('Panier "%s" retiré', $panier->getLibelle())); - $this->_redirect('admin/catalogue/paniers/id_catalogue/' . $catalogue->getId()); + return $this->_redirect('admin/catalogue/paniers/id_catalogue/' . $catalogue->getId()); + } + + if (!$this->_request->isPost()) { + $this->view->form_paniers = $this->formAjoutPanier($catalogue); + $this->view->catalogue = $catalogue; + $this->view->titre = $this->_('Paniers du domaine: %s', $catalogue->getLibelle()); return; } - $this->view->form_paniers = $this->formAjoutPanier($catalogue); - $this->view->catalogue = $catalogue; - $this->view->titre = $this->_('Paniers du domaine: %s', $catalogue->getLibelle()); + if (!$panier = Class_PanierNotice::find((int)$this->_request->getPost('id_panier'))) { + $this->_helper->notify($this->_('Aucun panier sélectionné pour ajout')); + return $this->_redirect('admin/catalogue/paniers/id_catalogue/' . $catalogue->getId()); + } + + $catalogue->addPanierNotice($panier)->save(); + $panier->addCatalogue($catalogue)->save(); + $panier->index(); + $this->_helper->notify($this->_('Panier "%s" ajouté', $panier->getLibelle())); + $this->_redirect('admin/catalogue/paniers/id_catalogue/' . $catalogue->getId()); } protected function formAjoutPanier($catalogue) { - $options = []; + $options = ['' => $this->_('Veuiller sélectionner un panier')]; $paniers = Class_PanierNotice::findAllBelongsToAdmin(); foreach($paniers as $panier) $options[$panier->getId()] = $panier->getLibelleForAdmins(); diff --git a/tests/application/modules/admin/controllers/CatalogueControllerTest.php b/tests/application/modules/admin/controllers/CatalogueControllerTest.php index 0d36513e06fea794e300202cc04087031c7391d4..a8127f7474198b9c1ce2b5c27759cb24c9a70a8f 100644 --- a/tests/application/modules/admin/controllers/CatalogueControllerTest.php +++ b/tests/application/modules/admin/controllers/CatalogueControllerTest.php @@ -1357,12 +1357,20 @@ class CatalogueControllerPaniersHistoireTest extends AdminCatalogueControllerTes public function pageShouldContainsLinkToPreview() { $this->assertXPath('//a[contains(@href, "/recherche/simple/id_catalogue/100")]'); } + + + /** @test */ + public function defaultOptionShouldPresent() { + $this->assertXpathContentContains('//option', 'Veuiller sélectionner un panier'); + } } -class CatalogueControllerPaniersHistoirePostPanierSelectionSenorTest extends AdminCatalogueControllerTestCase { +class CatalogueControllerPaniersHistoirePostPanierSelectionSenorTest + extends AdminCatalogueControllerTestCase { + public function setUp() { parent::setUp(); @@ -1399,6 +1407,31 @@ class CatalogueControllerPaniersHistoirePostPanierSelectionSenorTest extends Adm +class CatalogueControllerPaniersHistoirePostPanierSelectionEmptyTest + extends AdminCatalogueControllerTestCase { + + public function setUp() { + parent::setUp(); + + $this->postDispatch('/admin/catalogue/paniers/id_catalogue/100', + ['id_panier' => '']); + } + + + /** @test */ + public function answerShouldRedirectToCataloguePanier100() { + $this->assertRedirectTo('/admin/catalogue/paniers/id_catalogue/100'); + } + + + /** @test */ + public function messageShouldBeAucunPanierSelectionnePourAjout() { + $this->assertFlashMessengerContentContains('Aucun panier sélectionné pour ajout'); + } +} + + + class CatalogueControllerPaniersHistoireRemovePanierJeunesseTest extends AdminCatalogueControllerTestCase { public function setUp() {