From b56a449b90807b497e85d7c7eebf917fe4160c8e Mon Sep 17 00:00:00 2001 From: gloas <gloas@git-test.afi-sa.fr> Date: Tue, 20 Aug 2013 15:53:05 +0000 Subject: [PATCH] rel #9357 ajout du checkbox auto_subscribe + tests + patch cosmo --- .gitattributes | 1 + .../controllers/NewsletterController.php | 3 ++ cosmogramme/php/_init.php | 2 +- cosmogramme/sql/patch/patch_170.sql | 1 + library/Class/Users.php | 12 ++++++ .../controllers/NewsletterControllerTest.php | 7 ++++ .../Class/NewsletterSubscriptionTest.php | 37 ++++++++++++++++++- 7 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 cosmogramme/sql/patch/patch_170.sql diff --git a/.gitattributes b/.gitattributes index 73e700cae30..790a7d31b7e 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2168,6 +2168,7 @@ cosmogramme/sql/patch/patch_166.sql -text cosmogramme/sql/patch/patch_167.sql -text cosmogramme/sql/patch/patch_168.sql -text cosmogramme/sql/patch/patch_169.sql -text +cosmogramme/sql/patch/patch_170.sql -text cosmogramme/storm_init.php -text cosmogramme/tests/bootstrap.php -text cosmogramme/tests/php/classes/AbonneIntegrationTest.php -text diff --git a/application/modules/admin/controllers/NewsletterController.php b/application/modules/admin/controllers/NewsletterController.php index 47741981c9e..811e67ca7f8 100644 --- a/application/modules/admin/controllers/NewsletterController.php +++ b/application/modules/admin/controllers/NewsletterController.php @@ -83,10 +83,13 @@ class Admin_NewsletterController extends Zend_Controller_Action { $form ->addElement($titre) ->addElement($expediteur) + ->addElement('checkbox', 'auto_subscribe', ['label' => "Inscrire automatiquement les nouveaux lecteurs à la lettre d'information"]) ->addElement($contenu) ->addDisplayGroup(array('titre', 'expediteur'), 'letter', array("legend" => "Lettre")) + ->addDisplayGroup(['auto_subscribe'], + 'add_reader',['legend' => 'Inscription automatique']) ->addDisplayGroup(array('contenu'), 'contenu_html', array("legend" => "Contenu HTML")) diff --git a/cosmogramme/php/_init.php b/cosmogramme/php/_init.php index 323996fd6a3..a424fc516ca 100644 --- a/cosmogramme/php/_init.php +++ b/cosmogramme/php/_init.php @@ -1,7 +1,7 @@ <?PHP // Constantes define("VERSION_COSMOGRAMME","6.36"); -define("PATCH_LEVEL","169"); +define("PATCH_LEVEL","170"); define("APPLI","cosmogramme"); define("COSMOPATH", "/var/www/html/vhosts/opac2/www/htdocs"); define("CRLF", chr(13) . chr(10)); diff --git a/cosmogramme/sql/patch/patch_170.sql b/cosmogramme/sql/patch/patch_170.sql new file mode 100644 index 00000000000..1ee72338282 --- /dev/null +++ b/cosmogramme/sql/patch/patch_170.sql @@ -0,0 +1 @@ +alter table newsletters add column auto_subscribe boolean not null; diff --git a/library/Class/Users.php b/library/Class/Users.php index 94eafb06b38..3ac88c9304a 100644 --- a/library/Class/Users.php +++ b/library/Class/Users.php @@ -989,6 +989,18 @@ class Class_Users extends Storm_Model_Abstract { } + + + public function beforeSave() { + if(!$this->isNew()) + return $this; + + $newletters = Class_Newsletter::findAllBy(['auto_subscribe'=>true]); + $this->setNewsletters($newletters); + + } + + /** * @param $day string YYYY-MM-DD formatted * @return string const error type @see Class_Multimedia_DeviceHold diff --git a/tests/application/modules/admin/controllers/NewsletterControllerTest.php b/tests/application/modules/admin/controllers/NewsletterControllerTest.php index 0e27b3d8345..495b13b9eda 100644 --- a/tests/application/modules/admin/controllers/NewsletterControllerTest.php +++ b/tests/application/modules/admin/controllers/NewsletterControllerTest.php @@ -173,6 +173,12 @@ class Admin_NewsletterControllerAddActionTest extends Admin_NewsletterController public function testSubmitButton() { $this->assertXPath("//div[contains(@onclick,\"submit()\")]",$this->_response->getBody()); } + + + /** @test **/ + public function autoAddNewUsersCheckboxShouldBeDisplay() { + $this->assertXPath("//input[@type='checkbox'][@name='auto_subscribe']",$this->_response->getBody()); + } } @@ -766,4 +772,5 @@ class Admin_NewsletterControllerEditSubcsribersDeleteTest extends Admin_Newslett } } + ?> \ No newline at end of file diff --git a/tests/library/Class/NewsletterSubscriptionTest.php b/tests/library/Class/NewsletterSubscriptionTest.php index e56bd710f61..a65955dc1c8 100644 --- a/tests/library/Class/NewsletterSubscriptionTest.php +++ b/tests/library/Class/NewsletterSubscriptionTest.php @@ -218,7 +218,6 @@ class UserWithOneSubscriptionTest extends Storm_Test_ModelTestCase { Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Users') ->whenCalled('delete') ->answers(true) - ->getWrapper() ->whenCalled('save') ->answers(true); } @@ -320,6 +319,42 @@ class UserWithOneSubscriptionTest extends Storm_Test_ModelTestCase { } + /** @test **/ + public function createUserMarcusWithAutoSubscribeCheckedOnConcertShouldAddMarcusToSubscriber() { + + $this->concerts->setAutoSubscribe(true); + + Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Newsletter'); + Class_Newsletter::whenCalled('findAllBy') + ->with(['auto_subscribe'=>true]) + ->answers([$this->concerts]); + + $marcus = Class_Users::newInstance(['login'=>'Marcus', + 'password'=>'vue']); + $marcus->save(); + $this->assertContains($this->concerts, $marcus->getNewsletters()); + + } + + + /** @test **/ + public function createUserMarcusWithAutoSubscribeNotCheckedOnConcertShouldNotAddMarcusToSubscriber() { + + $this->concerts->setAutoSubscribe(false); + + Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Newsletter'); + Class_Newsletter::whenCalled('findAllBy') + ->with(['auto_subscribe'=>true]) + ->answers([]); + + $marcus = Class_Users::newInstance(['login'=>'Marcus', + 'password'=>'vue']); + $marcus->save(); + $this->assertNotContains($this->concerts, $marcus->getNewsletters()); + + } + + public function testSavingMarcusWithNewSubscriptionsAddThem() { $this->_setLoaderFindAllReturnsSubscriptionFor(array('role' => 'user', 'model' => $this->marcus)); -- GitLab