From 0ad2a557601c16e8d3a26b9429395964a550faf9 Mon Sep 17 00:00:00 2001 From: efalcy <efalcy@git-test.afi-sa.fr> Date: Tue, 6 Nov 2012 14:28:19 +0000 Subject: [PATCH] Boite "Lettre d'informations" (Newsletter) --- .gitattributes | 4 + .../admin/controllers/AccueilController.php | 4 + .../views/scripts/accueil/newsletters.phtml | 24 ++++ .../opac/controllers/AbonneController.php | 73 ++++++++++- categories.org | 3 + library/Class/Systeme/ModulesAccueil.php | 7 +- .../Systeme/ModulesAccueil/Newsletters.php | 43 ++++++ library/Class/Users.php | 1 + library/ZendAfi/Controller/Action.php | 4 + .../View/Helper/Accueil/Newsletters.php | 73 +++++++++++ public/opac/css/global.css | 4 +- .../ProfilControllerPageAccueilTest.php | 65 ++++++++- .../AbonneControllerNewslettersTest.php | 123 ++++++++++++------ .../ProfilOptionsControllerTest.php | 14 +- .../View/Helper/Accueil/NewslettersTest.php | 111 ++++++++++++++++ 15 files changed, 509 insertions(+), 44 deletions(-) create mode 100644 application/modules/admin/views/scripts/accueil/newsletters.phtml create mode 100644 library/Class/Systeme/ModulesAccueil/Newsletters.php create mode 100644 library/ZendAfi/View/Helper/Accueil/Newsletters.php create mode 100644 tests/library/ZendAfi/View/Helper/Accueil/NewslettersTest.php diff --git a/.gitattributes b/.gitattributes index e72754b08bd..5a2226c06ac 100644 --- a/.gitattributes +++ b/.gitattributes @@ -332,6 +332,7 @@ application/modules/admin/views/scripts/accueil/langue.phtml -text application/modules/admin/views/scripts/accueil/login.phtml -text application/modules/admin/views/scripts/accueil/menuvertical.phtml -text application/modules/admin/views/scripts/accueil/news.phtml -text +application/modules/admin/views/scripts/accueil/newsletters.phtml -text application/modules/admin/views/scripts/accueil/prets.phtml -text application/modules/admin/views/scripts/accueil/rechguidee.phtml -text application/modules/admin/views/scripts/accueil/rechsimple.phtml -text @@ -1857,6 +1858,7 @@ library/Class/Systeme/ModulesAccueil/Langue.php -text library/Class/Systeme/ModulesAccueil/Login.php -text library/Class/Systeme/ModulesAccueil/MenuVertical.php -text library/Class/Systeme/ModulesAccueil/News.php -text +library/Class/Systeme/ModulesAccueil/Newsletters.php -text library/Class/Systeme/ModulesAccueil/Null.php -text library/Class/Systeme/ModulesAccueil/Prets.php -text library/Class/Systeme/ModulesAccueil/RechercheGuidee.php -text @@ -2070,6 +2072,7 @@ library/ZendAfi/View/Helper/Accueil/Langue.php -text library/ZendAfi/View/Helper/Accueil/Login.php -text library/ZendAfi/View/Helper/Accueil/MenuVertical.php -text library/ZendAfi/View/Helper/Accueil/News.php -text +library/ZendAfi/View/Helper/Accueil/Newsletters.php -text library/ZendAfi/View/Helper/Accueil/Prets.php -text library/ZendAfi/View/Helper/Accueil/RechGuidee.php -text library/ZendAfi/View/Helper/Accueil/RechSimple.php -text @@ -4599,6 +4602,7 @@ tests/library/ZendAfi/View/Helper/Accueil/CritiquesTest.php -text tests/library/ZendAfi/View/Helper/Accueil/LangueTest.php -text tests/library/ZendAfi/View/Helper/Accueil/MenuVerticalTest.php -text tests/library/ZendAfi/View/Helper/Accueil/NewsTest.php -text +tests/library/ZendAfi/View/Helper/Accueil/NewslettersTest.php -text tests/library/ZendAfi/View/Helper/Accueil/PretsTest.php -text tests/library/ZendAfi/View/Helper/Accueil/ReservationsTest.php -text tests/library/ZendAfi/View/Helper/Accueil/RssTest.php -text diff --git a/application/modules/admin/controllers/AccueilController.php b/application/modules/admin/controllers/AccueilController.php index eb92ac65bd7..4723be34620 100644 --- a/application/modules/admin/controllers/AccueilController.php +++ b/application/modules/admin/controllers/AccueilController.php @@ -144,6 +144,10 @@ class Admin_AccueilController extends Zend_Controller_Action { $this->_simpleAction(); } + public function newslettersAction() { + $this->_simpleAction(); + } + public function bibliothequeNumeriqueAction() { if (1 == $this->_getParam('styles_reload')) { $this->view->preferences = $this->_request->getPost(); diff --git a/application/modules/admin/views/scripts/accueil/newsletters.phtml b/application/modules/admin/views/scripts/accueil/newsletters.phtml new file mode 100644 index 00000000000..08e8f72ea63 --- /dev/null +++ b/application/modules/admin/views/scripts/accueil/newsletters.phtml @@ -0,0 +1,24 @@ +<center> +<h1>Propriétés du module Lettres d'informations</h1><br> +<div class="formTable"> + <form method="post" action="<?php echo $this->url ?>"> + + <fieldset> + <legend>Affichage</legend> + <table cellspacing="2"> + + <tr> + <td class="droite">Style de boite </td> + <td class="gauche"><?php echo $this->combo_templates ?></td> + </tr> + <tr> + <td class="droite">Titre de la boite </td> + <td class="gauche"><input type="text" name="titre" size="52" value="<?php print($this->preferences["titre"]); ?>"></td> + </tr> + + </table> + </fieldset> + + <?php echo $this->formSubmit("Valider","Valider",array("class" => "bouton")) ?> + </form> + </div> diff --git a/application/modules/opac/controllers/AbonneController.php b/application/modules/opac/controllers/AbonneController.php index 782577dbfce..b3820d480d7 100644 --- a/application/modules/opac/controllers/AbonneController.php +++ b/application/modules/opac/controllers/AbonneController.php @@ -18,12 +18,13 @@ * along with AFI-OPAC 2.0; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -class AbonneController extends Zend_Controller_Action { +class AbonneController extends ZendAfi_Controller_Action { use Trait_Translator; protected $_user = null; // Le user connecté public function init() { + parent::init(); if ("authenticate" == $this->getRequest()->getActionName()) return; @@ -91,6 +92,47 @@ class AbonneController extends Zend_Controller_Action { } + public function subscribeNewsletterAction() { + $this->_stayOnPage(); + + if (!$newsletter = Class_Newsletter::find((int)$this->_getParam('id'))) { + $this->_helper->notify('Newsletter non trouvée'); + return; + } + + + $this->_user->addNewsletter($newsletter); + + if ($this->_user->save()) { + $this->_helper->notify(sprintf('Vous êtes inscrit à la liste de diffusion: %s', + $newsletter->getTitre())); + }; + + } + + + public function unsubscribeNewsletterAction() { + + $this->_stayOnPage(); + if (!$newsletter = Class_Newsletter::find((int)$this->_getParam('id'))) { + $this->_helper->notify('Newsletter non trouvée'); + return; + } + + + $this->_user->removeNewsletter($newsletter); + + if ($this->_user->save()) { + $this->_helper->notify(sprintf('Vous êtes désinscrit de la liste de diffusion: %s', + $newsletter->getTitre())); + }; + + + + } + + + public function detailsessionAction() { if (!$session = Class_SessionFormation::getLoader()->find((int)$this->_getParam('id'))) $this->_redirect('/abonne/formations'); @@ -429,6 +471,35 @@ class AbonneController extends Zend_Controller_Action { } + public function newslettersAction() { + + /* $newsletters = array(); + + $newsletters_id = $this->_request->getParam('subscriptions', array()); + foreach($newsletters_id as $nl_id) + $newsletters []= Class_Newsletter::getLoader()->find($nl_id); + + $this->_user + ->setNewsletters($newsletters) */ + + } + + + public function subscribeAction() { + + /* $newsletters = array(); + + $newsletters_id = $this->_request->getParam('subscriptions', array()); + foreach($newsletters_id as $nl_id) + $newsletters []= Class_Newsletter::getLoader()->find($nl_id); + + $this->_user + ->setNewsletters($newsletters) */ + + } + + + public function authenticateAction() { $this->getHelper('ViewRenderer')->setNoRender(); diff --git a/categories.org b/categories.org index 70db40af12b..91240ac33f0 100644 --- a/categories.org +++ b/categories.org @@ -220,3 +220,6 @@ var openDialogExemplaires = function() { ** Affichage "propriétés de la boite" [[file:application/modules/admin/controllers/AccueilController.php::public%20function%20reservationsAction()%20{][Action Mes reservations]] [[file:application/modules/admin/views/scripts/accueil/reservations.phtml][Html de la boite propriete]] +[[file:library/Class/Systeme/ModulesAccueil.php::'NEWSLETTERS'%20%3D>%20new%20Class_Systeme_ModulesAccueil_Newsletters,][Ajout de la boite dans le drag-drop]] + +** diff --git a/library/Class/Systeme/ModulesAccueil.php b/library/Class/Systeme/ModulesAccueil.php index e8a785eedfb..17bfedcb717 100644 --- a/library/Class/Systeme/ModulesAccueil.php +++ b/library/Class/Systeme/ModulesAccueil.php @@ -118,7 +118,12 @@ class Class_Systeme_ModulesAccueil extends Class_Systeme_ModulesAbstract { 'LANGUE' => new Class_Systeme_ModulesAccueil_Langue, 'BIB_NUMERIQUE' => new Class_Systeme_ModulesAccueil_BibliothequeNumerique, 'RESERVATIONS' => new Class_Systeme_ModulesAccueil_Reservations, - 'PRETS' => new Class_Systeme_ModulesAccueil_Prets + 'PRETS' => new Class_Systeme_ModulesAccueil_Prets, + 'NEWSLETTERS' => new Class_Systeme_ModulesAccueil_Newsletters + // 'FORMATIONS' => new Class_Systeme_ModulesAccueil_Formations, + // 'MULTIMEDIA' => new Class_Systeme_ModulesAccueil_Multimedia + + ]; } diff --git a/library/Class/Systeme/ModulesAccueil/Newsletters.php b/library/Class/Systeme/ModulesAccueil/Newsletters.php new file mode 100644 index 00000000000..f594fdcf8f9 --- /dev/null +++ b/library/Class/Systeme/ModulesAccueil/Newsletters.php @@ -0,0 +1,43 @@ +<?php +/** + * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved. + * + * AFI-OPAC 2.0 is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * AFI-OPAC 2.0 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with AFI-OPAC 2.0; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +class Class_Systeme_ModulesAccueil_Newsletters extends Class_Systeme_ModulesAccueil_Null{ + /** @var string */ + protected $_group = Class_Systeme_ModulesAccueil::GROUP_INFO; + + /** @var string */ + protected $_libelle = 'Lettres d\'informations'; + + /** @var string */ + protected $_action = 'newsletters'; + + /** @var int */ + protected $_popupWidth = 570; + + /** @var int */ + protected $_popupHeight = 400; + + /** @var array */ + protected $_defaultValues = array( + 'titre' => "Lettres d'informations", // Titre de la boite + ); + +} +?> \ No newline at end of file diff --git a/library/Class/Users.php b/library/Class/Users.php index 5ad13825187..4dc730fb567 100644 --- a/library/Class/Users.php +++ b/library/Class/Users.php @@ -434,6 +434,7 @@ class Class_Users extends Storm_Model_Abstract { } + /** * @return array */ diff --git a/library/ZendAfi/Controller/Action.php b/library/ZendAfi/Controller/Action.php index 55efdbeaafc..df41761e4c3 100644 --- a/library/ZendAfi/Controller/Action.php +++ b/library/ZendAfi/Controller/Action.php @@ -131,5 +131,9 @@ class ZendAfi_Controller_Action extends Zend_Controller_Action { * @param $model Storm_Model_Abstract */ protected function _postEditAction($model) {} + + protected function _stayOnPage() { + $this->_redirect($this->_request->getServer('HTTP_REFERER')); + } } ?> \ No newline at end of file diff --git a/library/ZendAfi/View/Helper/Accueil/Newsletters.php b/library/ZendAfi/View/Helper/Accueil/Newsletters.php new file mode 100644 index 00000000000..484d0b9e3b0 --- /dev/null +++ b/library/ZendAfi/View/Helper/Accueil/Newsletters.php @@ -0,0 +1,73 @@ +<?php +/** + * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved. + * + * AFI-OPAC 2.0 is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * AFI-OPAC 2.0 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with AFI-OPAC 2.0; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +class ZendAfi_View_Helper_Accueil_Newsletters extends ZendAfi_View_Helper_Accueil_Base { + + public function getHTML() { + $this->titre = $this->view->tagAnchor($this->view->url([ 'controller' => 'abonne', + 'action' => 'newsletters' + ]),$this->preferences['titre']); + $user = Class_Users::getIdentity(); + if (!isset($user)) + return $this->getHtmlArray() ; + $newsletters = sprintf('<ul>%s</ul>', + implode('', + array_map( + function($newsletter) { + $start_li='<li>'; + $titre = $newsletter->getTitre(); + + $button_subscribe = $this->view->tagAnchor($this->view->url(['controller' => 'abonne', + 'action' => 'subscribe-newsletter', + 'id' => $newsletter->getId()]), + $this->view->_("S'inscrire")); + + $button_unsubscribe = $this->view->tagAnchor($this->view->url(['controller' => 'abonne', + 'action' => 'unsubscribe-newsletter', + 'id' => $newsletter->getId()]), + $this->view->_('Se désinscrire')); + $user = Class_Users::getIdentity(); + foreach( $user->getNewsletters() as $user_newsletter ) { + if ($newsletter->getId() == $user_newsletter->getId()) + return $start_li.$titre.' '.$button_unsubscribe.'</li>'; + } + + return $start_li.$titre.' '.$button_subscribe.'</li>'; + }, + Class_Newsletter::getLoader()->findAll()))); + + $this->contenu = sprintf('<div class="boite_newsletters">%s</div>',$newsletters); + + return $this->getHtmlArray(); + } + + + public function isBoiteVisible() { + return null != Class_Users::getIdentity(); + } + + + public function shouldCacheContent() { + return false; + } + +} + +?> \ No newline at end of file diff --git a/public/opac/css/global.css b/public/opac/css/global.css index 2831e1962b0..4dccbd66fbc 100644 --- a/public/opac/css/global.css +++ b/public/opac/css/global.css @@ -274,13 +274,13 @@ table.calendar_main {margin-left: auto; margin-right: auto} } -.boite_prets ul, .boite_prets li, .boite_reservations ul, .boite_reservations li { +.boite_prets ul, .boite_prets li, .boite_reservations ul, .boite_reservations li, .boite_newsletters li , .boite_newsletters ul { list-style: none; padding: 0; margin:0; } -.boite_prets li, .boite_reservations li { +.boite_prets li, .boite_reservations li, .boite_newsletters li { margin-bottom: 5px; } diff --git a/tests/application/modules/admin/controllers/ProfilControllerPageAccueilTest.php b/tests/application/modules/admin/controllers/ProfilControllerPageAccueilTest.php index 6236aaf2fa0..630871502a8 100644 --- a/tests/application/modules/admin/controllers/ProfilControllerPageAccueilTest.php +++ b/tests/application/modules/admin/controllers/ProfilControllerPageAccueilTest.php @@ -47,6 +47,18 @@ abstract class Admin_ProfilControllerJeunessePageAccueilTestCase extends Admin_A 'type_module' => 'PRETS', 'preferences' => array()), + '10' => array('division' => 1, + 'type_module' => 'NEWSLETTERS', + 'preferences' => array()), + + '11' => array('division' => 1, + 'type_module' => 'FORMATIONS', + 'preferences' => array()), + + '12' => array('division' => 1, + 'type_module' => 'MULTIMEDIA', + 'preferences' => array()), + '666' => array('division' => 1, 'type_module' => 'WRONG', @@ -405,8 +417,59 @@ class Admin_ProfilControllerJeunessePageAccueilConfigEmptyReservationTest extend /** @test */ public function titreInputShouldHaveValueMesReservations() { - $this->assertXPath('//input[@name="titre"][@value="Mes réservations"]',$this->html); + $this->assertXPath('//input[@name="titre"][@value="Mes réservations"]'); } } + + +class Admin_ProfilControllerJeunessePageAccueilConfigNewslettersTest extends Admin_ProfilControllerJeunessePageAccueilTestCase { + public function setup() { + parent::setup(); + $this->dispatch('admin/accueil/newsletters?config=admin&id_profil=7&type_module=NEWSLETTERS&id_module=10&proprietes=boite=/titre=Mes newsletters/',true); + } + + /** @test */ + public function actionShouldBeNewsletters() { + $this->assertAction('newsletters'); + } + + /** @test */ + public function titleShouldBeProprieteDuModuleNewsletters() { + $this->assertXPathContentContains('//h1','Propriétés du module Lettres d\'informations',$this->_response->getBody()); + } + + + /** @test */ + public function comboBoiteShouldBePresent() { + $this->assertXPath('//select[@name="boite"]/option[@value="boite_de_la_division_droite"]'); + } + + + /** @test */ + public function titreInputShouldHaveValueMesNewsletters() { + $this->assertXPath('//input[@name="titre"][@value="Mes newsletters"]',$this->_response->getBody()); + } + +} + + + +class Admin_ProfilControllerJeunessePageAccueilConfigEmptyNewsletterTest extends Admin_ProfilControllerJeunessePageAccueilTestCase { + + public function setup() { + parent::setup(); + $this->dispatch('admin/accueil/newsletters?config=admin&id_profil=7&type_module=NEWSLETTERS&id_module=11',true); + + } + + /** @test */ + public function titreInputShouldHaveValueMesNewsletters() { + $this->assertXPath('//input[@name="titre"][@value="Lettres d\'informations"]',$this->_response->getBody()); + } +} + + + + ?> \ No newline at end of file diff --git a/tests/application/modules/opac/controllers/AbonneControllerNewslettersTest.php b/tests/application/modules/opac/controllers/AbonneControllerNewslettersTest.php index b67bd5b6036..6064ccf19ad 100644 --- a/tests/application/modules/opac/controllers/AbonneControllerNewslettersTest.php +++ b/tests/application/modules/opac/controllers/AbonneControllerNewslettersTest.php @@ -48,10 +48,8 @@ abstract class AbstractAbonneControllerNewslettersTestCase extends AbstractContr ->whenCalled('save') ->answers(true); - $this->newsletter_loader = $this->getMock('MockModelLoader', array('findAll', 'find')); - Storm_Model_Abstract::setLoaderFor('Class_Newsletter', $this->newsletter_loader); - - + $this->newsletter_loader = Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Newsletter'); + parent::setUp(); } } @@ -61,22 +59,14 @@ abstract class AbonneControllerWithTwoNewslettersTestCase extends AbstractAbonne public function setUp() { parent::setUp(); - $this->concerts = new Class_Newsletter(); - $this->concerts - ->setId(12) - ->setTitre('Concerts') - ->setContenu('Festival jazz'); + $this->concerts = Class_Newsletter::newInstanceWithId(12, ['titre' =>'Concerts', + 'contenu' => 'Festival jazz']); - $this->visites = new Class_Newsletter(); - $this->visites - ->setId(14) - ->setTitre('Visites') - ->setContenu('du patrimoine'); + $this->visites = Class_Newsletter::newInstanceWithId(14, [ 'titre' =>'Visites', + 'contenu' => 'du patrimoine']); - $this->newsletter_loader - ->expects($this->any()) - ->method('findAll') - ->will($this->returnValue(array($this->concerts, $this->visites))); + $this->newsletter_loader->whenCalled('findAll') + ->answers(array($this->concerts, $this->visites)); $this->marcus ->setNewsletters(array($this->concerts)); //Marcus is subscribed to concerts newsletter @@ -84,16 +74,13 @@ abstract class AbonneControllerWithTwoNewslettersTestCase extends AbstractAbonne } -class AbonneControllerFicheActionWithNoExistingNewsletterTest extends AbstractAbonneControllerNewslettersTestCase { +class AbonneControllerNewslettersFicheActionWithNoExistingNewslettersTest extends AbstractAbonneControllerNewslettersTestCase { public function setUp() { parent::setUp(); $this->marcus->setNewsletters(array()); - - $this->newsletter_loader - ->expects($this->any()) - ->method('findAll') - ->will($this->returnValue(array())); + $this->newsletter_loader->whenCalled('findAll') + ->answers(array()); $this->dispatch('/opac/abonne'); } @@ -118,7 +105,7 @@ class AbonneControllerFicheActionWithNoExistingNewsletterTest extends AbstractAb } -class AbonneControllerFicheActionWithOneSubscriptionTest extends AbonneControllerWithTwoNewslettersTestCase { +class AbonneControllerNewslettersFicheActionWithOneSubscriptionTest extends AbonneControllerWithTwoNewslettersTestCase { public function setUp() { parent::setUp(); $this->dispatch('/opac/abonne', true); @@ -154,7 +141,7 @@ class AbonneControllerFicheActionWithOneSubscriptionTest extends AbonneControlle } -class AbonneControllerFicheActionWithTwoSubscriptionsTest extends AbonneControllerWithTwoNewslettersTestCase { +class AbonneControllerNewslettersFicheActionWithTwoSubscriptionsTest extends AbonneControllerWithTwoNewslettersTestCase { public function setUp() { parent::setUp(); @@ -172,7 +159,7 @@ class AbonneControllerFicheActionWithTwoSubscriptionsTest extends AbonneControll } -class AbonneControllerFicheActionWithNoSubscriptionTest extends AbonneControllerWithTwoNewslettersTestCase { +class AbonneControllerNewslettersFicheActionWithNoSubscriptionTest extends AbonneControllerWithTwoNewslettersTestCase { public function setUp() { parent::setUp(); @@ -189,7 +176,7 @@ class AbonneControllerFicheActionWithNoSubscriptionTest extends AbonneController } -class AbonneControllerNewsletterEditActionTest extends AbonneControllerWithTwoNewslettersTestCase { +class AbonneControllerNewslettersEditActionTest extends AbonneControllerWithTwoNewslettersTestCase { public function setUp() { parent::setUp(); @@ -259,16 +246,10 @@ class AbonneControllerNewsletterEditActionTest extends AbonneControllerWithTwoNe -class AbonneControllerNewsletterSaveActionTest extends AbonneControllerWithTwoNewslettersTestCase { +class AbonneControllerNewslettersSaveActionTest extends AbonneControllerWithTwoNewslettersTestCase { public function setUp() { parent::setUp(); - $this->newsletter_loader - ->expects($this->once()) - ->method('find') - ->with(14) - ->will($this->returnValue($this->visites)); - $data = array('nom' => 'MILLER', 'prenom' => 'MARCUS', 'mail' => 'marcus@free.fr', @@ -319,7 +300,7 @@ class AbonneControllerNewsletterSaveActionTest extends AbonneControllerWithTwoNe } -class AbonneControllerNewsletterSaveWithEmptyDataTest extends AbonneControllerWithTwoNewslettersTestCase { +class AbonneControllerNewslettersSaveWithEmptyDataTest extends AbonneControllerWithTwoNewslettersTestCase { public function setUp() { parent::setUp(); @@ -345,7 +326,7 @@ class AbonneControllerNewsletterSaveWithEmptyDataTest extends AbonneControllerWi -class AbonneControllerNewsletterOpsysCommunicationTest extends AbonneControllerWithTwoNewslettersTestCase { +class AbonneControllerNewslettersOpsysCommunicationTest extends AbonneControllerWithTwoNewslettersTestCase { public function setUp() { parent::setUp(); @@ -402,8 +383,74 @@ class AbonneControllerNewsletterOpsysCommunicationTest extends AbonneControllerW +class AbonneControllerNewslettersSubscriptionTest extends AbonneControllerWithTwoNewslettersTestCase { + + public function setUp() { + parent::setUp(); + $_SERVER['HTTP_REFERER'] = '/opac/index'; + $this->dispatch('/opac/abonne/subscribe-newsletter/id/14',true); + + } + + + /** @test **/ + public function subscribeActionShouldCallSubscribenewsletterAction() { + $this->assertAction('subscribe-newsletter'); + } + + + /** @test **/ + public function subscribeActionShouldRedirectToCurrentPage() { + $this->assertRedirectTo('/opac/index'); + } + + + /** @test **/ + public function subscribeActionShouldAddNewsletterToUser() { + $this->assertContains( $this->visites,$this->marcus->getNewsletters()); + } + + + /** @test **/ + public function userShouldHaveBeenSaved() { + $this->assertTrue(Class_Users::methodHasBeenCalled('save')); + } + +} + + +class AbonneControllerNewslettersUnsubscriptionTest extends AbonneControllerWithTwoNewslettersTestCase { + + public function setUp() { + parent::setUp(); + $_SERVER['REQUEST_URI'] = '/'; + $this->dispatch('/opac/abonne/unsubscribe-newsletter/id/14',true); + + } + + /** @test **/ + public function unsubscribeActionShouldCallSubscribenewsletterAction() { + $this->assertAction('unsubscribe-newsletter'); + } + + + /** @test **/ + public function unsubscribeActionShouldAddNewsletterToUser() { + $this->assertNotContains( $this->visites,$this->marcus->getNewsletters()); + } + + + /** @test **/ + public function userShouldHaveBeenSaved() { + $this->assertTrue(Class_Users::methodHasBeenCalled('save')); + } + + + +} + -class AbonneControllerNewsletterValidationsTest extends AbonneControllerWithTwoNewslettersTestCase { +class AbonneControllerNewslettersValidationsTest extends AbonneControllerWithTwoNewslettersTestCase { protected function _postData($data) { $this->getRequest() ->setMethod('POST') diff --git a/tests/application/modules/opac/controllers/ProfilOptionsControllerTest.php b/tests/application/modules/opac/controllers/ProfilOptionsControllerTest.php index 551ddde4f81..2fcaa77e9c2 100644 --- a/tests/application/modules/opac/controllers/ProfilOptionsControllerTest.php +++ b/tests/application/modules/opac/controllers/ProfilOptionsControllerTest.php @@ -278,7 +278,13 @@ abstract class ProfilOptionsControllerProfilJeunesseWithPagesJeuxMusiqueTestCase '9' => ['division' => '2', 'type_module' => 'PRETS', - 'preferences' => ['titre' => 'Mes documents'] + 'preferences' => ['titre' => 'Mes documents'], + + '10' => ['division' => '2', + 'type_module' => 'NEWSLETTERS', + 'preferences' => ['titre' => 'Lettres d\'informations']], + + ] ], 'options' => []]; @@ -498,6 +504,12 @@ class ProfilOptionsControllerViewProfilJeunesseAccueilTest extends ProfilOptions } + /** @test */ + public function boiteNewslettersShouldBeVisibleInProfilJeunesse() { + $this->assertXPath("//div[@class='boite_newsletters']",$this->_response->getBody()); + } + + /** @test */ public function boiteNewsShouldBeVisibleInProfilJeunesse() { $this->assertXPathContentContains("//a[contains(@href, 'articleviewselection')]",'Articles'); diff --git a/tests/library/ZendAfi/View/Helper/Accueil/NewslettersTest.php b/tests/library/ZendAfi/View/Helper/Accueil/NewslettersTest.php new file mode 100644 index 00000000000..0c5e6c966ec --- /dev/null +++ b/tests/library/ZendAfi/View/Helper/Accueil/NewslettersTest.php @@ -0,0 +1,111 @@ +<?php +/** + * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved. + * + * AFI-OPAC 2.0 is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * AFI-OPAC 2.0 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with AFI-OPAC 2.0; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +require_once 'library/ZendAfi/View/Helper/ViewHelperTestCase.php'; + + +class NewslettersTestWithConnectedUser extends ViewHelperTestCase { + public function setUp() { + parent::setUp(); + + $helper = new ZendAfi_View_Helper_Accueil_Newsletters(2, [ + 'type_module'=>'NEWSLETTERS', + 'division' => '1', + 'preferences' => [ + 'titre' => 'Newsletters']]); + $account = new StdClass(); + $account->ID_USER = '123456'; + ZendAfi_Auth::getInstance()->getStorage()->write($account); + $user=Class_Users::newInstanceWithId('123456',['nom'=>'Estelle']); + $nouveautes_musique = Class_Newsletter::newInstanceWithId(2,['titre' =>'Nouveautes Musique']); + + $user->setNewsletters([$nouveautes_musique]); + + Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Newsletter') + ->whenCalled('findAll') + ->answers( [ $nouveautes_musique, + Class_Newsletter::newInstanceWithId(3,['titre' =>'Animations']) + ]); + + $this->html = $helper->getBoite(); + } + + + /** @test */ + public function h1ShouldContainsMesNewsletters () { + $this->assertXPathContentContains($this->html,'//h1','Newsletters'); + } + + + /** @test */ + public function listShouldDisplayNouveautesMusique() { + $this->assertXPathContentContains($this->html,'//ul//li','Nouveautes Musique'); + } + + /** @test */ + public function listShouldDisplayAnimations() { + $this->assertXPathContentContains($this->html,'//ul//li','Animations'); + } + + + /** @test */ + public function listShouldDisplayButtonSubscribe() { + $this->assertXPath($this->html,'//ul//li//a[contains(@href,"/subscribe-newsletter")]',$this->html); + + } + + + /** @test */ + public function listShouldDisplayButtonUnSubscribe() { + $this->assertXPath($this->html,'//ul//li//a[contains(@href,"/unsubscribe-newsletter")]',$this->html); + + } + + +} + + +class NewslettersTestWithNonConnectedUser extends ViewHelperTestCase { + public function setUp() { + parent::setUp(); + + $this->helper = new ZendAfi_View_Helper_Accueil_Newsletters(2, [ + 'type_module'=>'NEWSLETTERS', + 'division' => '1', + 'preferences' => ['titre' => 'Mes newsletters']] + ); + $this->html = $this->helper->getBoite(); + } + + + /** @test */ + public function boiteNewslettersShouldNotBeDisplayed () { + $this->assertEmpty($this->html); + } + + + /** @test */ + public function boiteNewslettersShouldNotCacheContents () { + $this->assertFalse($this->helper->shouldCacheContent()); + } + +} + +?> \ No newline at end of file -- GitLab