diff --git a/application/modules/admin/controllers/AlbumController.php b/application/modules/admin/controllers/AlbumController.php index 0feb05be36b53b070e308bc05eed3869f1b533cf..7790e06209e8c78221bead46ee3102cbf1479f3f 100644 --- a/application/modules/admin/controllers/AlbumController.php +++ b/application/modules/admin/controllers/AlbumController.php @@ -160,15 +160,13 @@ class Admin_AlbumController extends ZendAfi_Controller_Action { public function addalbumtoAction() { - if (!$categorie = Class_AlbumCategorie::find((int)$this->_getParam('id'))) { - $this->_redirect('admin/album'); - return; - } + $categorie = ''; + $title = 'Ajouter un album'; + if ($categorie = Class_AlbumCategorie::find((int)$this->_getParam('id'))) + $title .= ' dans la collection "' . $categorie->getLibelle() . '"'; $this->_renderAlbumForm( - Class_Album::newInstance()->setCategorie($categorie), - 'Ajouter un album dans la collection "' . $categorie->getLibelle() . '"' - ); + Class_Album::newInstance()->setCategorie($categorie), $title); } diff --git a/library/ZendAfi/Form/Album.php b/library/ZendAfi/Form/Album.php index c3d7f4f6adc6996e213a71711f8bd133a8bfcf57..b073c6435a05910edac1054d16f749f1ca333685 100644 --- a/library/ZendAfi/Form/Album.php +++ b/library/ZendAfi/Form/Album.php @@ -146,7 +146,10 @@ class ZendAfi_Form_Album extends ZendAfi_Form { 'style' => 'width:440px;']) ->addElement('select', 'cat_id', ['label' => $this->_('Catégorie'), - 'multiOptions' => Class_AlbumCategorie::getAllLibelles()]) + 'multiOptions' => ['' => $this->_('Choisissez une catégorie')] + + Class_AlbumCategorie::getAllLibelles(), + 'required' => true, + 'allowEmpty' => false]) ->addElement('checkbox', 'visible', ['label' => $this->_('Visible')]) diff --git a/tests/application/modules/admin/controllers/AlbumControllerTest.php b/tests/application/modules/admin/controllers/AlbumControllerTest.php index 3097862887d8574370f20b19e5cf04129093fd45..a0282a21b7f21b7f8a9a3c25349b75d6052d6d9a 100644 --- a/tests/application/modules/admin/controllers/AlbumControllerTest.php +++ b/tests/application/modules/admin/controllers/AlbumControllerTest.php @@ -710,6 +710,53 @@ class Admin_AlbumControllerAddAlbumToPatrimoineTest extends Admin_AlbumControlle + +class Admin_AlbumControllerAddAlbumFromFrontEnd extends Admin_AlbumControllerTestCase { + public function setUp() { + parent::setUp(); + $this->dispatch('/admin/album/add_album_to/id/0'); + } + + + /** @test */ + public function actionShouldNotBeRedirected() { + $this->assertNotRedirect('/admin/album'); + } + + + /** @test */ + public function titleShouldBeAjouterUnAlbum() { + $this->assertXPathContentRegex('//h1', "/^Ajouter un album$/"); + } + + + /** @test */ + public function fieldCatIdShouldBeEmpty() { + $this->assertXPath('//form[@id="album"]//select[@name="cat_id"]/option[1][@value=""]'); + } + +} + + + +class Admin_AlbumControllerPostAlbumIronMaidenWithoutCategory extends Admin_AlbumControllerTestCase { + public function setUp() { + parent::setUp(); + + $this->postDispatch('/admin/album/add_album_to/id/0', + ['titre' => 'Iron Maiden', + 'sous_titre' => 'The Number of the Beast']); + } + + + /** @test */ + public function errorMessageShouldBePresent() { + $this->assertXPathContentContains('//ul[@class="errors"]/li', 'Une valeur est requise'); + } +} + + + abstract class Admin_AlbumControllerPostAlbumRenaissanceToPatrimoineTestCase extends Admin_AlbumControllerTestCase { public function setUp() { parent::setUp(); @@ -832,6 +879,7 @@ class Admin_AlbumControllerPostAlbumRenaissanceToPatrimoineTest $this->postDispatch('/admin/album/add_album_to/id/38', ['titre' => 'Renaissance', 'sous_titre' => 'Ze Renaissance', + 'cat_id' => 38, 'description' => 'Oeuvres majeures sous François 1er', 'nature_doc' => '2;3', 'type_doc_id' => '102', @@ -1129,6 +1177,7 @@ class Admin_AlbumControllerEditAlbumMesBDPostFrbrDeleteTest extends Admin_AlbumC $this->postDispatch('/admin/album/edit_album/id/43', ['titre' => 'Renaissance', 'sous_titre' => 'Ze Renaissance', + 'cat_id' => 2, 'description' => 'Oeuvres majeures sous François 1er', 'nature_doc' => '2;3', 'type_doc_id' => '102', @@ -1176,6 +1225,7 @@ class Admin_AlbumControllerEditAlbumMesBDPostFrbrModifyTest extends Admin_AlbumC $this->postDispatch('/admin/album/edit_album/id/43', ['titre' => 'Renaissance', 'sous_titre' => 'Ze Renaissance', + 'cat_id' => 2, 'description' => 'Oeuvres majeures sous François 1er', 'nature_doc' => '2;3', 'type_doc_id' => '102', @@ -1290,13 +1340,13 @@ class Admin_AlbumControllerEditAlbumMesBDTest extends Admin_AlbumControllerEditA /** @test */ public function formShouldHaveAComboToSelectCategorie() { - $this->assertXPathContentContains("//form//select[@name='cat_id']/option[1][@value=2]", 'Favoris'); + $this->assertXPathContentContains("//form//select[@name='cat_id']/option[2][@value=2]", 'Favoris'); } /** @test */ public function comboCategoriesShouldDisplayFullPath() { - $this->assertXPathContentContains("//form//select[@name='cat_id']/option[2][@value=6]", 'Favoris>Adulte'); + $this->assertXPathContentContains("//form//select[@name='cat_id']/option[3][@value=6]", 'Favoris>Adulte'); } @@ -1563,6 +1613,7 @@ class Admin_AlbumControllerPostEditAlbumMesBDTest extends Admin_AlbumControllerT Storm_Cache::setDefaultZendCache($this->cache_mock); $this->postDispatch('/admin/album/edit_album/id/43', ['titre' => 'Mes BD', + 'cat_id' => 2, 'description' => "Les préférées de l'année", 'tags' => 'selection', 'type_doc_id' => 201,