/** * Given a UserConfigurationForm and user, save the configuration values for the specified user. */ public static function setConfigurationFromForm(UserNotificationConfigurationForm $form, User $user) { assert('$user instanceOf User && $user->id > 0'); $notificationSettingsNames = UserNotificationUtil::getAllNotificationSettingAttributes(); foreach ($notificationSettingsNames as $setting) { $form->{$setting} = (bool) $form->{$setting}; $form->{$setting} = (bool) $form->{$setting}; } UserNotificationUtil::setValue($user, $form->inboxAndEmailNotificationSettings, 'inboxAndEmailNotificationSettings', false); }
public static function setNotificationSettingsForUser(User $user, $notificationType, $inbox = true, $email = true) { assert('is_string($notificationType)'); assert('is_bool($inbox)'); assert('is_bool($email)'); $inboxAndEmailNotificationSettings = UserNotificationUtil::getNotificationSettingsByUser($user); $settingName = NotificationsUtil::resolveNotificationSettingNameFromType($notificationType); $inboxAndEmailNotificationSettings[$settingName]['inbox'] = $inbox; $inboxAndEmailNotificationSettings[$settingName]['email'] = $email; UserNotificationUtil::setValue($user, $inboxAndEmailNotificationSettings, 'inboxAndEmailNotificationSettings', false); }
public function testSubmitWithInboxNotificationSettingDisabledAndEmailNotificationSettingDisabled() { $initialNotificationCount = Notification::getCount(); $initialEmailMessageCount = EmailMessage::getCount(); $rules = new SimpleNotificationRules(); $rules->setAllowDuplicates(true); $rules->addUser($this->user); $inboxAndEmailNotificationSettings = UserTestHelper::getDefaultNotificationSettingsValuesForTestUser(); $inboxAndEmailNotificationSettings['enableSimpleNotification']['email'] = false; $inboxAndEmailNotificationSettings['enableSimpleNotification']['inbox'] = false; UserNotificationUtil::setValue($this->user, $inboxAndEmailNotificationSettings, 'inboxAndEmailNotificationSettings', false); $this->assertFalse(UserNotificationUtil::isEnabledByUserAndNotificationNameAndType($this->user, 'enableSimpleNotification', 'email')); $this->assertFalse(UserNotificationUtil::isEnabledByUserAndNotificationNameAndType($this->user, 'enableSimpleNotification', 'inbox')); $message = new NotificationMessage(); $message->textContent = 'text content for' . __FUNCTION__; $message->htmlContent = 'html content for' . __FUNCTION__; NotificationsUtil::submit($message, $rules); $this->assertEquals($initialNotificationCount, Notification::getCount()); $this->assertEquals($initialEmailMessageCount, EmailMessage::getCount()); }
/** * @depends testClosingConversations */ public function testSendEmailInNewComment() { if (!SECURITY_OPTIMIZED) { return; } $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); $steven = User::getByUsername('steven'); $sally = User::getByUsername('sally'); $mary = User::getByUsername('mary'); $conversations = Conversation::getAll(); $this->assertEquals(2, count($conversations)); $this->assertEquals(0, $conversations[0]->comments->count()); foreach (EmailMessage::getAll() as $emailMessage) { $emailMessage->delete(); } $initialQueued = 0; $conversation = $conversations[0]; $conversationParticipant = new ConversationParticipant(); $conversationParticipant->person = $steven; $conversation->conversationParticipants->add($conversationParticipant); $conversationParticipant = new ConversationParticipant(); $conversationParticipant->person = $sally; $conversation->conversationParticipants->add($conversationParticipant); $conversationParticipant = new ConversationParticipant(); $conversationParticipant->person = $mary; $conversation->conversationParticipants->add($conversationParticipant); $inboxAndEmailNotificationSettings = UserTestHelper::getDefaultNotificationSettingsValuesForTestUser(); $inboxAndEmailNotificationSettings['enableConversationNewCommentNotification'] = array('inbox' => false, 'email' => false); UserNotificationUtil::setValue($mary, $inboxAndEmailNotificationSettings, 'inboxAndEmailNotificationSettings', false); //Save a new comment $this->setGetArray(array('relatedModelId' => $conversation->id, 'relatedModelClassName' => 'Conversation', 'relatedModelRelationName' => 'comments', 'redirectUrl' => 'someRedirect')); $this->setPostArray(array('Comment' => array('description' => 'a ValidComment Name'))); $this->runControllerWithRedirectExceptionAndGetContent('comments/default/inlineCreateSave'); $this->assertEquals(1, $conversation->comments->count()); $this->assertEquals($initialQueued + 2, Yii::app()->emailHelper->getQueuedCount()); $this->assertEquals(0, Yii::app()->emailHelper->getSentCount()); $emailMessages = EmailMessage::getAll(); $emailMessage = $emailMessages[$initialQueued]; $this->assertEquals(1, count($emailMessage->recipients)); $emailMessage = $emailMessages[$initialQueued + 1]; $this->assertEquals(1, count($emailMessage->recipients)); $this->assertContains('conversation', $emailMessage->subject); $this->assertContains(strval($conversation), $emailMessage->subject); $this->assertContains(strval($conversation->comments[0]), $emailMessage->content->htmlContent); $this->assertContains(strval($conversation->comments[0]), $emailMessage->content->textContent); }
/** * Set default notifications settings to be all enabled * * @param User $user */ public static function setDefaultNotificationSettingsForUser($user) { $defaultNotificationSettings = static::getDefaultNotificationSettingsValuesForTestUser(); UserNotificationUtil::setValue($user, $defaultNotificationSettings, 'inboxAndEmailNotificationSettings', false); }