diff --git a/library/Class/Catalogue.php b/library/Class/Catalogue.php index ab69bdf2486677a8bcd1c4067b760af92fdc0528..87b0960c50562295acefb3a4166db2430777fe5b 100644 --- a/library/Class/Catalogue.php +++ b/library/Class/Catalogue.php @@ -705,7 +705,7 @@ class Class_Catalogue extends Storm_Model_Abstract { // liste des catalogues pour une combo //------------------------------------------------------------------------------- static function getCataloguesForCombo() { - $liste = []; + $liste = ['']; $catalogues = Class_Catalogue::findTopCatalogues(); foreach($catalogues as $catalogue) { self::addCataloguePathAndChildrenTo($catalogue, $liste); diff --git a/tests/application/modules/admin/controllers/NewsletterControllerTest.php b/tests/application/modules/admin/controllers/NewsletterControllerTest.php index c08f524a65da54d738a8c716a3e3a614f209a426..6248008a3cad8cfa62ef01c8137c037011013630 100644 --- a/tests/application/modules/admin/controllers/NewsletterControllerTest.php +++ b/tests/application/modules/admin/controllers/NewsletterControllerTest.php @@ -186,30 +186,40 @@ class Admin_NewsletterControllerAddActionWithCataloguesTest extends Admin_Newsle public function setUp() { parent::setUp(); - $this->mock_sql = $this->getSqlMock(); - - $this->mock_sql - ->expects($this->any()) - ->method('fetchAll') - ->with("select * from catalogue order by libelle") - ->will($this->returnValue(array(array('ID_CATALOGUE' => 2, - 'LIBELLE' => 'Jazz'), - array('ID_CATALOGUE' => 5, - 'LIBELLE' => 'BD')))); + $histoire = Class_Catalogue::newInstanceWithId(100, + [ 'libelle' => 'Histoire', + 'sous_domaines' => [ + Class_Catalogue::newInstanceWithId(200, [ 'libelle' => 'Politique', + 'parent_id' => 100]), + + Class_Catalogue::newInstanceWithId(300, [ 'libelle'=>'Moyen-age', + 'parent_id' => 100])] + ]); + + Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Catalogue') + ->whenCalled('findAllBy') + ->with(['where' => 'parent_id is null', + 'order' => 'libelle']) + ->answers([$histoire]); $this->dispatch('/admin/newsletter/add'); } /** @test */ - function catalogueJazzShouldBeAnOption() { - $this->assertXPathContentContains("//select[@id='id_catalogue']/option[@value='2']", 'Jazz'); + function catalogueHistoireShouldBeAnOption() { + $this->assertXPathContentContains("//select[@id='id_catalogue']/option[@value='100']", 'Histoire'); } /** @test */ - function catalogueBDShouldBeAnOption() { - $this->assertXPathContentContains("//select[@id='id_catalogue']/option[@value='5']", 'BD'); + function catalogueMoyenAgeShouldBeAnOption() { + $this->assertXPathContentContains("//select[@id='id_catalogue']/option[@value='300']", 'Moyen-age'); + } + + /** @test */ + function emptyCatalogueShouldBeAnOption() { + $this->assertXPath("//select[@id='id_catalogue']/option[@value='0']"); } }