diff --git a/library/Class/PanierNotice.php b/library/Class/PanierNotice.php index ad54242e17032534c9d879c9de294b096a55ab7e..5ff30caa41debdf9ce181b505b24eac28825ebd6 100644 --- a/library/Class/PanierNotice.php +++ b/library/Class/PanierNotice.php @@ -48,13 +48,12 @@ class PanierNoticeLoader extends Storm_Model_Loader { public function findAllWithCatalogue() { - $this->user = Class_Users::getIdentity(); - - return array_filter( + $ids = array_filter( array_unique( array_map( - function($association) {return $association->getPanierNotice();}, + function($association) {return $association->getIdPanier();}, Class_PanierNoticeCatalogue::findAll()))); + return Class_PanierNotice::findAllBy(['id' => $ids]); } diff --git a/tests/application/modules/admin/controllers/MenusControllerTest.php b/tests/application/modules/admin/controllers/MenusControllerTest.php index d122e917fba5a23382f262068e340f8b6c9f0457..9858bcf35ee3a1fffa95d6335534ce2d8b603633 100644 --- a/tests/application/modules/admin/controllers/MenusControllerTest.php +++ b/tests/application/modules/admin/controllers/MenusControllerTest.php @@ -16,16 +16,18 @@ * * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * along with BOKEH; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ require_once 'AdminAbstractControllerTestCase.php'; abstract class Admin_MenusControllerProfilJazzTestCase extends Admin_AbstractControllerTestCase { - protected $_profil_jazz; + protected + $_storm_default_to_volatile = true, + $_profil_jazz; public function setUp() { - parent::setUp(); + parent::setUp(); $cfg_menus = ['H' => ['libelle' => 'Menu horizontal', 'picto' => 'vide.gif', @@ -68,7 +70,7 @@ abstract class Admin_MenusControllerProfilJazzTestCase extends Admin_AbstractCon 'libelle' => 'Libelle du catalogue', 'preferences' => ['titre' => 'Titre du catalogue'], 'picto' => 'vide.gif' ] - + ], ], @@ -87,8 +89,8 @@ abstract class Admin_MenusControllerProfilJazzTestCase extends Admin_AbstractCon class Admin_MenusControllerProfilJazzIndexActionTest extends Admin_MenusControllerProfilJazzTestCase { public function setUp() { - parent::setUp(); - + parent::setUp(); + $this->dispatch('admin/menus/index?'. http_build_query(array('id_profil' => '5', 'id_bib' => 'null', @@ -149,7 +151,7 @@ class Admin_MenusControllerEditMenuBibNumTest extends Admin_AbstractControllerTe ->setParentId(4) ->setSousCategories(array()) ->setLibelle('BD') - ->setAlbums(array( + ->setAlbums(array( $fitzgerald = Class_Album::getLoader() ->newInstanceWithId(421) ->setCatId(42) @@ -160,7 +162,7 @@ class Admin_MenusControllerEditMenuBibNumTest extends Admin_AbstractControllerTe ->setCatId(42) ->setTitre('Armstrong') )) - ) + ) ); @@ -173,7 +175,7 @@ class Admin_MenusControllerEditMenuBibNumTest extends Admin_AbstractControllerTe ->answers(array($fitzgerald, $armstrong)); } - + public function setUp() { parent::setUp(); $this->createBibNum(); @@ -196,16 +198,16 @@ class Admin_MenusControllerEditMenuBibNumTest extends Admin_AbstractControllerTe /** @test */ function albumSelectShouldContainsFitzgerald() { - $this->assertXPathContentContains("//select[@id='album_id']//option[@value='421']", - "Jazz>BD>Fitzgerald", + $this->assertXPathContentContains("//select[@id='album_id']//option[@value='421']", + "Jazz>BD>Fitzgerald", $this->_response->getBody()); } /** @test */ function albumSelectShouldContainsArmstrong() { - $this->assertXPathContentContains("//select//option[@value='422'][@selected='selected']", - "Jazz>BD>Armstrong", + $this->assertXPathContentContains("//select//option[@value='422'][@selected='selected']", + "Jazz>BD>Armstrong", $this->_response->getBody()); } @@ -216,6 +218,9 @@ class Admin_MenusControllerEditMenuBibNumTest extends Admin_AbstractControllerTe } } + + + class Admin_MenusControllerEditMenuAlbumLinkTest extends Admin_AbstractControllerTestCase { public function setUp() { parent::setUp(); @@ -231,10 +236,10 @@ class Admin_MenusControllerEditMenuAlbumLinkTest extends Admin_AbstractControlle 'libelle' => 'Lien vers un album', 'picto' => 'book.png', 'preferences' => 'album_id=421'))); - + } - + /** @test */ public function linkAlbumWithoutCategoryShouldReturnCategoryNotClassified() { $this->assertXPathContentContains('//div', 'non classé', $this->_response->getBody()); @@ -324,7 +329,7 @@ class Admin_MenusControllerProfilJazzPostCalendrierActionTest extends Admin_Menu /** @test */ public function responseShouldBeContainsMajProprietesTitleAgenda() { - $this->assertContains('parent.retourMajProprietes("3","Agenda","vide.gif","titre=Agenda|nb_events=10")', + $this->assertContains('parent.retourMajProprietes("3","Agenda","vide.gif","titre=Agenda|nb_events=10")', $this->_response->getBody()); } } @@ -337,6 +342,9 @@ class Admin_MenusControllerProfilJazzPostCatalogueActionTest extends Admin_Menus public function setUp() { parent::setUp(); + Storm_Test_ObjectWrapper::onLoaderOfModel('Class_PanierNotice') + ->whenCalled('findAllBelongsToAdmin')->answers([]); + $this->postDispatch('admin/menus/catalogue?'.http_build_query(['id_module' => 7, 'id_profil' => 5, 'type_menu' => 'CATALOGUE']), @@ -345,7 +353,7 @@ class Admin_MenusControllerProfilJazzPostCatalogueActionTest extends Admin_Menus /** @test */ public function responseShouldBeContainsNouveaute() { - $this->assertContains('parent.retourMajProprietes("7","Nouveauté","vide.gif","titre=Titre du catalogue', + $this->assertContains('parent.retourMajProprietes("7","Nouveauté","vide.gif","titre=Titre du catalogue', $this->_response->getBody()); } } @@ -357,13 +365,31 @@ class Admin_MenusControllerProfilJazzEditCatalogueActionTest extends Admin_Menus public function setUp() { parent::setUp(); - $panier_bd = Class_PanierNotice::newInstanceWithId(1, ['libelle' => 'bd']); - $panier_romans = Class_PanierNotice::newInstanceWithId(2, ['libelle' => 'romans']); - $panier_musique = Class_PanierNotice::newInstanceWithId(3, ['libelle' => 'musique']); - + $panier_bd = $this->fixture('Class_PanierNotice', + ['id' => 1, + 'libelle' => 'bd']); + + $panier_romans = $this->fixture('Class_PanierNotice', + ['id' => 2, + 'libelle' => 'romans']); + + $panier_musique = $this->fixture('Class_PanierNotice', + ['id' => 3, + 'libelle' => 'musique']); + + $panier_autres = $this->fixture('Class_PanierNotice', + ['id' => 4, + 'libelle' => 'autres']); + + + $this->fixture('Class_Catalogue', + ['id' => 9, + 'libelle' => 'Domaine livres', + 'panier_notices' => [$panier_romans, $panier_bd]]); + Class_Users::getIdentity()->setPaniers([$panier_bd]); + Storm_Test_ObjectWrapper::onLoaderOfModel('Class_PanierNotice') - ->whenCalled('findAllWithCatalogue')->answers([$panier_bd, $panier_romans]) ->whenCalled('findAllBelongsToAdmin')->answers([$panier_musique]); $this->dispatch('admin/menus/catalogue?'.http_build_query(['id_module' => 7, @@ -388,9 +414,15 @@ class Admin_MenusControllerProfilJazzEditCatalogueActionTest extends Admin_Menus /** @test */ public function selectIdPanierShouldContainsPanierMusique() { - $this->assertXPathContentContains('//select[@name="id_panier"]/option[@value="3"]', + $this->assertXPathContentContains('//select[@name="id_panier"]/option[@value="3"]', 'musique'); } + + + /** @test */ + public function selectIdPanierShouldNotContainsPanierAutres() { + $this->assertNotXPath('//select[@name="id_panier"]/option[@value="4"]'); + } } ?> \ No newline at end of file diff --git a/tests/application/modules/opac/controllers/PanierControllerTest.php b/tests/application/modules/opac/controllers/PanierControllerTest.php index d6777afc4119f19faad7070cb9313b0d1b32c6c0..63e2c5738d0da22a3d49bce87e674ab3f5468d0f 100644 --- a/tests/application/modules/opac/controllers/PanierControllerTest.php +++ b/tests/application/modules/opac/controllers/PanierControllerTest.php @@ -1382,16 +1382,15 @@ class PanierControllerEditActionAsAbonneTest extends AbstractControllerTestCase class PanierControllerEditActionAsAdminTest extends AbstractControllerTestCase { + protected + $_storm_default_to_volatile = true; + public function setup() { parent::setup(); Class_Users::beVolatile(); Class_PanierNotice::beVolatile(); - Storm_Test_ObjectWrapper::onLoaderOfModel('Class_PanierNotice') - ->whenCalled('findAllWithCatalogue') - ->answers([]); - $roger = Class_Users::newInstanceWithId(23, ['pseudo' => 'RogerL', 'nom' => 'plou', 'login' => 'man', @@ -1432,17 +1431,12 @@ class PanierControllerEditActionAsAdminTest extends AbstractControllerTestCase { class PanierControllerEditActionAsContributeurWithOutRightForAccessDomaineTest extends AbstractControllerTestCase { + protected + $_storm_default_to_volatile = true; + public function setup() { parent::setup(); - Class_Users::beVolatile(); - Class_PanierNotice::beVolatile(); - Class_UserGroup::beVolatile(); - - Storm_Test_ObjectWrapper::onLoaderOfModel('Class_PanierNotice') - ->whenCalled('findAllWithCatalogue') - ->answers([]); - $roger = Class_Users::newInstanceWithId(23, ['pseudo' => 'RogerL', 'nom' => 'plou', 'login' => 'man', diff --git a/tests/library/ZendAfi/View/Helper/Accueil/PanierTest.php b/tests/library/ZendAfi/View/Helper/Accueil/PanierTest.php index 80529c25dc5210e146dc80eecb37a78b01c203b2..9add766864f3eeaad7ebb83849e0daf8eec0e902 100644 --- a/tests/library/ZendAfi/View/Helper/Accueil/PanierTest.php +++ b/tests/library/ZendAfi/View/Helper/Accueil/PanierTest.php @@ -16,15 +16,13 @@ * * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * along with BOKEH; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -require_once 'library/ZendAfi/View/Helper/ViewHelperTestCase.php'; - - abstract class AbstractPanierHelperTest extends ViewHelperTestCase { - - protected $_tom; + protected + $_tom, + $_storm_default_to_volatile = true; public function setup() { parent:: setup(); @@ -33,12 +31,12 @@ abstract class AbstractPanierHelperTest extends ViewHelperTestCase { ZendAfi_Auth::getInstance()->logUser($this->_tom); - $this->_helper = - new ZendAfi_View_Helper_Accueil_Panier(5, + $this->_helper = + new ZendAfi_View_Helper_Accueil_Panier(5, ['type_module' => 'PANIER', 'division' => '1', 'preferences' => ['titre' => 'Panier']] ); - + $this->_helper->setView(new ZendAfi_Controller_Action_Helper_View()); } @@ -46,7 +44,7 @@ abstract class AbstractPanierHelperTest extends ViewHelperTestCase { -class PanierTestWithConnectedUser extends AbstractPanierHelperTest { +class PanierTestWithConnectedUser extends AbstractPanierHelperTest { public function setUp() { parent::setUp(); $this->_html = $this->_helper->getBoite(); @@ -68,39 +66,53 @@ class PanierTestWithConnectedUser extends AbstractPanierHelperTest { -class PanierTestWithConnectedUserPanierNoticesFromUserAndNoCurrentPanier extends AbstractPanierHelperTest { + +abstract class PanierTestWithConnectedUserTestCase extends AbstractPanierHelperTest { public function setUp() { parent::setUp(); - $cuisiner_la_pomme = - Class_Notice::newInstanceWithId(18, - ['titre_principal' => 'Cuisiner la pomme', - 'clef_alpha' => 'cuisiner la pomme']); - $cuisiner_la_poire = - Class_Notice::newInstanceWithId(19, - ['titre_principal' => 'Cuisiner la poire', - 'clef_alpha' => 'cuisiner la poire']); + $cuisiner_la_pomme = $this->fixture('Class_Notice', + ['id' => 18, + 'titre_principal' => 'Cuisiner la pomme', + 'auteur_principal' => 'Tom Apple', + 'clef_alpha' => 'CUISINER-LA-POMME']); + + $cuisiner_la_poire = $this->fixture('Class_Notice', + ['id' => 19, + 'titre_principal' => 'Cuisiner la poire', + 'auteur_principal' => 'Tom Pear', + 'clef_alpha' => 'CUISINER-LA-POIRE']); + + $panier_cuisine = $this->fixture('Class_PanierNotice', + ['id' => 987, + 'libelle' => 'Panier cuisine']); + $panier_cuisine + ->addNotice($cuisiner_la_pomme) + ->addNotice($cuisiner_la_poire) + ->assertSave(); - $panier_cuisine = - Class_PanierNotice::newInstanceWithId(987, ['libelle' => 'Panier cuisine']) - ->setNotices([$cuisiner_la_pomme, $cuisiner_la_poire]); + $catalogue_adultes = $this->fixture('Class_Catalogue', + ['id' => 6, + 'libelle' => 'Adultes']); - $catalogue_adultes = Class_Catalogue::newInstanceWithId(6,['libelle' => 'Adultes']); + $panier_romans = $this->fixture('Class_PanierNotice', + ['id' => 666, + 'libelle' => 'Romans', + 'catalogues' => [$catalogue_adultes]]); + } +} - $panier_romans = Class_PanierNotice::newInstanceWithId(666, ['libelle' => 'Romans', - 'catalogues' => [$catalogue_adultes]]); - $this->_tom->setPaniers([$panier_cuisine]); - Storm_Test_ObjectWrapper::onLoaderOfModel('Class_PanierNotice') - ->whenCalled('findAllWithCatalogue') - ->answers([$panier_romans]); +class PanierTestWithConnectedUserPanierNoticesFromUserAndNoCurrentPanier extends PanierTestWithConnectedUserTestCase { + public function setUp() { + parent::setUp(); $this->_html = $this->_helper->getBoite(); } - + /** @test **/ public function actionBarShouldNotContainsShareAction() { $this->assertNotXPath($this->_html, '//div[@class="panier-action-bar"]/ul/li//input[contains(@value,"recherche/simple/")]'); @@ -116,54 +128,31 @@ class PanierTestWithConnectedUserPanierNoticesFromUserAndNoCurrentPanier extends -class PanierTestWithConnectedUserAndCurrentPanierWithNotice extends AbstractPanierHelperTest { +class PanierTestWithConnectedUserAndCurrentPanierWithNotice extends PanierTestWithConnectedUserTestCase { public function setUp() { parent::setUp(); - $cuisiner_la_pomme = - Class_Notice::newInstanceWithId(18, - ['titre_principal' => 'Cuisiner la pomme', - 'auteur_principal' => 'Tom Apple', - 'clef_alpha' => 'CUISINER-LA-POMME']); - $cuisiner_la_poire = - Class_Notice::newInstanceWithId(19, - ['titre_principal' => 'Cuisiner la poire', - 'auteur_principal' => 'Tom Pear', - 'clef_alpha' => 'CUISINER-LA-POIRE']); - - $panier_cuisine = - Class_PanierNotice::newInstanceWithId(987, ['libelle' => 'Panier cuisine']) - ->addNotice($cuisiner_la_pomme) - ->addNotice($cuisiner_la_poire); - - Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Notice') - ->whenCalled('findAllBy') - ->answers([$cuisiner_la_pomme, $cuisiner_la_poire]); - - $this->_tom - ->setPaniers([$panier_cuisine]) - ->setPanierCourant($panier_cuisine); + $this->_tom->setPanierCourant(Class_PanierNotice::find(987)); $this->_html = $this->_helper->getBoite(); } - + /** @test **/ public function boitePanierShouldDisplayPanierCuisinerLaPomme() { - $this->assertXPathContentContains($this->_html, '//tbody/tr[1]', 'Cuisiner la pomme', $this->_html); + $this->assertXPathContentContains($this->_html, '//tbody/tr[2]', 'Cuisiner la pomme', $this->_html); } - + /** @test **/ public function boitePanierShouldDisplayPanierCuisinerLaPommeByTomApple() { - $this->assertXPathContentContains($this->_html, '//tbody/tr[1]', 'Tom Apple', $this->_html); + $this->assertXPathContentContains($this->_html, '//tbody/tr[2]', 'Tom Apple', $this->_html); } - /** @test **/ public function boitePanierShouldDisplayPanierCuisinerLaPoire() { - $this->assertXPathContentContains($this->_html, '//tbody/tr[2]', 'Cuisiner la poire', $this->_html); + $this->assertXPathContentContains($this->_html, '//tbody/tr[1]', 'Cuisiner la poire', $this->_html); } @@ -177,7 +166,7 @@ class PanierTestWithConnectedUserAndCurrentPanierWithNotice extends AbstractPani public function rowShouldContainsDelAction() { $this->assertXPath($this->_html, '//tbody/tr//a[contains(@href,"/paniersupprimernotice/id_panier/987/id_notice/18/redirect/referer")]'); } - + /** @test **/ public function actionBarShouldContainsAfficherAsResultatDeRechercheAction() {