diff --git a/.gitattributes b/.gitattributes index 73e700cae309980fe51c48b659f7df9e5929a75a..790a7d31b7e11f8e216dffe9d747fc076b5a3c10 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 47741981c9eb633b626fb8b3813d733f4363e20d..811e67ca7f822728bfd10336a3c5c45adfc15c32 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 323996fd6a37c98dc3c603d87e7e32d9e785cab2..a424fc516cad3ff6672af037e3055c3ed7535656 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 0000000000000000000000000000000000000000..1ee72338282ab71020370b93d04bc6825f5ba26b --- /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 94eafb06b386218f95865072cc56e6e1777ef91a..3ac88c9304a4fe0ec0ed0c5e63713de08b5bf860 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 0e27b3d8345c4bb86653b49e297d87b2b3be44d2..495b13b9eda8519ef5f48e58e5cd64f5544c91da 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 e56bd710f61c29694b5188acd385dfa5e9d8ea23..a65955dc1c80a3bea5547c45a193fc89234db974 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));