diff --git a/tests/application/modules/admin/controllers/SitothequeControllerTest.php b/tests/application/modules/admin/controllers/SitothequeControllerTest.php index e38c8e9b860bfaf03a358ba6275eaadab37ab4b1..84ec9bbe4e94fea407b75acdc1c5b2cbd28bcbd1 100644 --- a/tests/application/modules/admin/controllers/SitothequeControllerTest.php +++ b/tests/application/modules/admin/controllers/SitothequeControllerTest.php @@ -27,67 +27,43 @@ abstract class SitothequeControllerTestCase extends Admin_AbstractControllerTest parent::setUp(); $this->setupDomaines(); - $categorie_informations = Class_SitothequeCategorie::newInstanceWithId(2, - ['libelle' => 'Informations', - 'id_site' => 3]) - ->setSousCategories([]) - ->setSitotheques([Class_Sitotheque::newInstanceWithId(22, - ['titre' => 'Le Canard', - 'url' => 'http://www.canard.fr', - 'description' => 'indépendant', - 'domaine_ids' => [10]]), - - $this->_le_monde = Class_Sitotheque::newInstanceWithId(23, - ['titre' => 'Le Monde', - 'url' => 'http://www.monde.fr'])]); - - - $bib_annecy = Class_Bib::newInstanceWithId(3, ['libelle' => 'Annecy']) - ->setSitothequeCategories([$categorie_informations]); - - Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Bib') - ->whenCalled('findAllBy') - ->with(['order' => 'libelle']) - ->answers([$bib_annecy]) - - ->whenCalled('findAll') - ->answers([$bib_annecy]); + $categorie_informations = $this->fixture('Class_SitothequeCategorie', + ['id' => 2, + 'libelle' => 'Informations', + 'id_site' => 3, + 'sous_categories' => [], + 'sitotheques' => [ + $this->fixture('Class_Sitotheque', + ['id' => 22, + 'titre' => 'Le Canard', + 'url' => 'http://www.canard.fr', + 'description' => 'indépendant', + 'domaine_ids' => [10]]), + + $this->_le_monde = $this->fixture('Class_Sitotheque', + ['id' => 23, + 'titre' => 'Le Monde', + 'url' => 'http://www.monde.fr'])] + ]); + + + $bib_annecy = $this->fixture('Class_Bib', + ['id' => 3, + 'libelle' => 'Annecy', + 'sitotheque_categories' => [$categorie_informations]]); Class_Bib::getPortail()->setSitothequeCategories([]); - - - Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Sitotheque') - ->whenCalled('save')->answers(true) - ->whenCalled('delete')->answers(true); - - Storm_Test_ObjectWrapper::onLoaderOfModel('Class_SitothequeCategorie') - ->whenCalled('save')->answers(true) - ->whenCalled('delete')->answers(true) - - ->whenCalled('findAllBy') - ->with(['id_site' => 3, - 'order' => 'libelle']) - ->answers([$categorie_informations]); } public function setupDomaines() { - $domaine_histoire = Class_Catalogue::newInstanceWithId(10, - ['libelle' => 'Histoire', - 'sous_domaines' => []]); - - $domaine_informations = Class_Catalogue::newInstanceWithId(66, - ['libelle' => 'Informations', - 'sous_domaines' => []]); + $this->fixture('Class_Catalogue', ['id' => 10, + 'libelle' => 'Histoire', + 'sous_domaines' => []]); - Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Catalogue') - ->whenCalled('findAllBy') - ->answers([$domaine_histoire]) - - ->whenCalled('findFirstBy') - ->with(['parent_id' => null, - 'libelle' => 'Informations']) - ->answers($domaine_informations); + $this->fixture('Class_Catalogue', ['id' => 66, + 'libelle' => 'Informations', + 'sous_domaines' => []]); } } @@ -239,7 +215,6 @@ class SitothequeControllerPostAddActionTest extends SitothequeControllerTestCase public function setUp() { parent::setUp(); - Class_Sitotheque::whenCalled('save')->willDo(function($site) {$site->setId(25);}); $this->postDispatch('/admin/sito/sitoadd/id_cat/2', ['titre' => 'google', 'url' => 'http://www.google.fr', @@ -249,15 +224,14 @@ class SitothequeControllerPostAddActionTest extends SitothequeControllerTestCase /** @test */ - public function anwersShouldRedirectToSitoEdit25() { - $this->assertRedirectTo('/admin/sito/sitoedit/id/25'); + public function anwersShouldRedirectToSitoEdit24() { + $this->assertRedirectTo('/admin/sito/sitoedit/id/24'); } /** @test */ public function sitoShouldNotHaveIdItems() { - $new_site = Class_Sitotheque::getFirstAttributeForLastCallOn('save'); - $this->assertTrue($new_site->isAttributeEmpty('id_items')); + $this->assertTrue(Class_Sitotheque::find(24)->isAttributeEmpty('id_items')); } } @@ -285,6 +259,8 @@ class SitothequeControllerSitoPostEditLeMondeTest extends SitothequeControllerTe $this->postDispatch('/admin/sito/sitoedit/id/23', ['titre' => 'Times'], true); + Class_Sitotheque::clearCache(); + $this->_le_monde = Class_Sitotheque::find(23); } @@ -294,12 +270,6 @@ class SitothequeControllerSitoPostEditLeMondeTest extends SitothequeControllerTe } - /** @test */ - public function siteShouldHaveBeenSaved() { - $this->assertTrue(Class_Sitotheque::methodHasBeenCalled('save')); - } - - /** @test */ public function anwersShouldRedirectToSitoEdit23() { $this->assertRedirectTo('/admin/sito/sitoedit/id/23'); @@ -318,7 +288,7 @@ class SitothequeControllerSitoDeleteLeMondeTest extends SitothequeControllerTest /** @test */ public function siteShouldHaveBeenDeleted() { - $this->assertTrue(Class_Sitotheque::methodHasBeenCalled('delete')); + $this->assertEmpty(Class_Sitotheque::find(23)); } @@ -383,6 +353,7 @@ class SitothequeControllerPostEditCategorieInformationsTest extends SitothequeCo $this->postDispatch('/admin/sito/catedit/id/2', ['libelle' => 'News'], true); + Class_SitothequeCategorie::clearCache(); } @@ -390,12 +361,6 @@ class SitothequeControllerPostEditCategorieInformationsTest extends SitothequeCo public function libelleShouldBeNews() { $this->assertEquals('News', Class_SitothequeCategorie::find(2)->getLibelle()); } - - - /** @test */ - public function categorieShouldHaveBeenSaved() { - $this->assertTrue(Class_SitothequeCategorie::methodHasBeenCalled('save')); - } } @@ -448,18 +413,11 @@ class SitothequeControllerPostAddCategorieNationalesTest extends SitothequeContr public function setUp() { parent::setUp(); - Class_SitothequeCategorie::whenCalled('save') - ->willDo( - function($cat) { - $cat->setId(5)->cache(); - return true; - }); - $this->postDispatch('/admin/sito/catadd/id/2', ['libelle' => 'Nationales'], true); - $this->_new_cat = Class_SitothequeCategorie::find(5); + $this->_new_cat = Class_SitothequeCategorie::find(3); } @@ -467,12 +425,6 @@ class SitothequeControllerPostAddCategorieNationalesTest extends SitothequeContr public function libelleShouldBeNationales() { $this->assertEquals('Nationales', $this->_new_cat->getLibelle()); } - - - /** @test */ - public function categorieShouldHaveBeenSaved() { - $this->assertTrue(Class_SitothequeCategorie::methodHasBeenCalled('save')); - } } @@ -484,18 +436,11 @@ class SitothequeControllerPostAddCategorieInBibTest extends SitothequeController public function setUp() { parent::setUp(); - Class_SitothequeCategorie::whenCalled('save') - ->willDo( - function($cat) { - $cat->setId(5)->cache(); - return true; - }); - $this->postDispatch('/admin/sito/catadd/id_bib/5', ['libelle' => 'Dans la bib'], true); - $this->_new_cat = Class_SitothequeCategorie::find(5); + $this->_new_cat = Class_SitothequeCategorie::find(3); } @@ -523,7 +468,7 @@ class SitothequeControllerDeleteCategorieInformationsTest extends SitothequeCont /** @test */ public function categorieShouldHaveBeenDeleted() { - $this->assertTrue(Class_SitothequeCategorie::methodHasBeenCalled('delete')); + $this->assertEmpty(Class_SitothequeCategorie::find(2)); } }