diff --git a/cosmogramme/cosmozend/application/modules/cosmo/views/scripts/annexe/index.phtml b/cosmogramme/cosmozend/application/modules/cosmo/views/scripts/annexe/index.phtml index b762356521e69e8f505030a105d14d28eec1bdef..ec26368ba97c8137b032680537b70500cfe21736 100644 --- a/cosmogramme/cosmozend/application/modules/cosmo/views/scripts/annexe/index.phtml +++ b/cosmogramme/cosmozend/application/modules/cosmo/views/scripts/annexe/index.phtml @@ -2,6 +2,7 @@ echo $this->tagAnchor(['action' => 'add', 'id' => null], $this->_('Ajouter une annexe')); + echo $this->tagModelTable($this->annexes, [$this->_('Bibliothèque'), $this->_('code'), diff --git a/cosmogramme/cosmozend/tests/CosmoControllerTestCase.php b/cosmogramme/cosmozend/tests/CosmoControllerTestCase.php index a87b383cd3d74eed9c0dd167362feeca9280a8c6..7dd9690fae9bf9aefd18a964b083902257f967a9 100644 --- a/cosmogramme/cosmozend/tests/CosmoControllerTestCase.php +++ b/cosmogramme/cosmozend/tests/CosmoControllerTestCase.php @@ -55,6 +55,17 @@ abstract class CosmoControllerTestCase extends Zend_Test_PHPUnit_ControllerTestC } + public function assertRedirectTo($url, $message = '') { + $location = isset($this->response->getHeaders()[0]) + ? $this->response->getHeaders()[0]['value'] + : $this->_response->getBody(); + + return $message + ? parent::assertRedirectTo($url, $message) + : parent::assertRedirectTo($url, 'Headers location : ' . $location); + } + + public function dispatch($url = null, $throw_exceptions = false) { // redirector should not exit $redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector'); diff --git a/cosmogramme/cosmozend/tests/application/modules/cosmo/controllers/AnnexeControllerTest.php b/cosmogramme/cosmozend/tests/application/modules/cosmo/controllers/AnnexeControllerTest.php index cebf7614fe1113dabef0384677e578b7d81731a9..b4493fc28ce6ac9cb8897eae3d2627fd06b1065c 100644 --- a/cosmogramme/cosmozend/tests/application/modules/cosmo/controllers/AnnexeControllerTest.php +++ b/cosmogramme/cosmozend/tests/application/modules/cosmo/controllers/AnnexeControllerTest.php @@ -33,6 +33,10 @@ abstract class AnnexeControllerTestCase extends CosmoControllerTestCase { ['id' => 56, 'nom_court' => 'Médiathèque Annecy']); + $this->fixture('Class_Bib', + ['id' => 9999854, + 'libelle' => 'Bibliothèque de Cran-Gevrier']); + $this->fixture('Class_IntBib', ['id' => 9999854, 'nom_court' => 'Bibliothèque de Cran-Gevrier']); @@ -143,6 +147,61 @@ class AnnexeControllerEditActionTest extends AnnexeControllerTestCase { public function shouldContainsSelectWithMediathequeAnnecy() { $this->assertXPath('//form//select[@name="id_bib"]//option[2][@value="56"][@selected]'); } + + + /** @test */ + public function shouldContainsCodeACY01() { + $this->assertXPath('//form//input[@name="code"][@value="ACY-01"][@type="text"]'); + } } + + + +class AnnexeControllerPostEditActionTest extends AnnexeControllerTestCase { + + public function setUp() { + parent::setUp(); + $this->postDispatch('/cosmo/annexe/edit/id/98', + ['code' => 'ACY-010', + 'libelle' => 'same libelle', + 'id_bib' => '9999854']); + } + + + /** @test */ + public function codifAnnexeLibraryShouldBeCran() { + $this->assertEquals('Bibliothèque de Cran-Gevrier', Class_CodifAnnexe::find(98)->getLibraryLabel()); + } + + + /** @test */ + public function shouldRedirectToEdit() { + $this->assertRedirectTo('/cosmo/annexe/edit/id/98'); + } +} + + + + +class AnnexeControllerDeleteActionTest extends AnnexeControllerTestCase { + + + public function setUp() { + parent::setUp(); + $this->dispatch('/cosmo/annexe/delete/id/98', true); + } + + + /** @test */ + public function shouldDeleteIt() { + $this->assertNull(Class_CodifAnnexe::find(98)); + } + + + /** @test */ + public function shouldRedirectToIndex() { + $this->assertRedirectTo('/cosmo/annexe/index'); + } +} ?> \ No newline at end of file diff --git a/library/ZendAfi/Controller/Action.php b/library/ZendAfi/Controller/Action.php index d57e83df6bc5d0b56f9b842c3fdec7092280ae73..2a0db65e913599f812b5129f79da05c00800f628 100644 --- a/library/ZendAfi/Controller/Action.php +++ b/library/ZendAfi/Controller/Action.php @@ -130,7 +130,10 @@ class ZendAfi_Controller_Action extends Zend_Controller_Action { protected function _redirectToIndex() { - $url = '/admin/'.$this->_request->getControllerName().'/index'; + $url = sprintf('/%s/%s/index', + $this->_request->getModuleName(), + $this->_request->getControllerName()); + $closure = function($item, $value) use (&$url) { $url .= '/' . $item . '/' . $value; }; diff --git a/library/ZendAfi/Controller/Plugin/Manager/Annexe.php b/library/ZendAfi/Controller/Plugin/Manager/Annexe.php index dfdc80eb7b49d25e78fbed0c8e524c07be1d9d77..2a845497d240f496fb645c54df83685e2ffdfc15 100644 --- a/library/ZendAfi/Controller/Plugin/Manager/Annexe.php +++ b/library/ZendAfi/Controller/Plugin/Manager/Annexe.php @@ -29,7 +29,9 @@ class ZendAfi_Controller_Plugin_Manager_Annexe extends ZendAfi_Controller_Plugin ['url' => ['action' => 'delete', 'id' => $model->getId()], 'icon' => 'delete', - 'label' => $this->_('Supprimer l\'annexe %s', $model->getLibelle())]]; + 'label' => $this->_('Supprimer l\'annexe %s', $model->getLibelle()), + 'anchorOptions' => ['onclick' => sprintf('return confirm(\'%s\')', + $this->_('Etes-vous sûr de vouloir supprimer cette annexe ?'))]]]; } } ?> \ No newline at end of file diff --git a/library/ZendAfi/Controller/Plugin/Manager/Manager.php b/library/ZendAfi/Controller/Plugin/Manager/Manager.php index a2811132493150908e8ede38810506ebd4622ed1..890c1b9b6ada86ea549be3c37e103b4b9c11fa92 100644 --- a/library/ZendAfi/Controller/Plugin/Manager/Manager.php +++ b/library/ZendAfi/Controller/Plugin/Manager/Manager.php @@ -165,8 +165,10 @@ class ZendAfi_Controller_Plugin_Manager_Manager extends ZendAfi_Controller_Plugi protected function _getEditUrl($model) { - return sprintf('/admin/%s/edit/id/%s', - $this->_request->getControllerName(), $model->getId()); + return sprintf('/%s/%s/edit/id/%s', + $this->_request->getModuleName(), + $this->_request->getControllerName(), + $model->getId()); } diff --git a/library/ZendAfi/Controller/Plugin/Manager/Section.php b/library/ZendAfi/Controller/Plugin/Manager/Section.php index 2c9a966e14385bfe776e08ffdd3bfb08877b83dd..ece8c1d9788a3fc3c567af17bd9b53230ae4a5a5 100644 --- a/library/ZendAfi/Controller/Plugin/Manager/Section.php +++ b/library/ZendAfi/Controller/Plugin/Manager/Section.php @@ -32,15 +32,5 @@ class ZendAfi_Controller_Plugin_Manager_Section extends ZendAfi_Controller_Plugi 'icon' => 'delete', 'label' => $this->_('Supprimer')]]; } - - - protected function _redirectToIndex() { - $this->_redirect('/cosmo/' . $this->_request->getControllerName().'/index'); - } - - - protected function _redirectToEdit($model) { - $this->_redirect('/cosmo/' . $this->_request->getControllerName().'/edit/id/' . $model->getId()); - } } ?> \ No newline at end of file