コード例 #1
0
 /**
  * Override to handle sending email messages on new comment
  */
 protected function afterSuccessfulSave($model)
 {
     assert('$model instanceof Item');
     parent::afterSuccessfulSave($model);
     $user = Yii::app()->user->userModel;
     if ($this->relatedModel instanceof Conversation) {
         $participants = ConversationsUtil::resolvePeopleToSendNotificationToOnNewComment($this->relatedModel, $user);
         CommentsUtil::sendNotificationOnNewComment($this->relatedModel, $model, $user, $participants);
     } elseif ($this->relatedModel instanceof Mission) {
         $participants = MissionsUtil::resolvePeopleToSendNotificationToOnNewComment($this->relatedModel, $user);
         CommentsUtil::sendNotificationOnNewComment($this->relatedModel, $model, $user, $participants);
     }
 }
コード例 #2
0
 public function testsSendNotificationOnNewComment()
 {
     $super = User::getByUsername('super');
     $steven = User::getByUsername('steven');
     $jack = User::getByUsername('jack');
     $conversation = new Conversation();
     $conversation->owner = Yii::app()->user->userModel;
     $conversation->subject = 'My test subject2';
     $conversation->description = 'My test description2';
     $this->assertTrue($conversation->save());
     $comment = new Comment();
     $comment->description = 'This is the 1st test comment';
     //Confirm no email notifications are sitting in the queue
     $this->assertEquals(0, Yii::app()->emailHelper->getQueuedCount());
     $this->assertEquals(0, Yii::app()->emailHelper->getSentCount());
     //Confirm there is no inbox notification
     $this->assertEquals(0, Notification::getCount());
     //No message was sent because Steven and Jack don't have primary email address
     CommentsUtil::sendNotificationOnNewComment($conversation, $comment, array($steven, $jack));
     $this->assertEquals(0, Yii::app()->emailHelper->getQueuedCount());
     $this->assertEquals(0, Yii::app()->emailHelper->getSentCount());
     //Two inbox notifications sent
     $this->assertEquals(2, Notification::getCount());
     $super->primaryEmail->emailAddress = '*****@*****.**';
     $steven->primaryEmail->emailAddress = '*****@*****.**';
     $jack->primaryEmail->emailAddress = '*****@*****.**';
     $this->assertTrue($super->save());
     $this->assertTrue($steven->save());
     $this->assertTrue($jack->save());
     //Two email message were sent one to Steven and one to Jack
     CommentsUtil::sendNotificationOnNewComment($conversation, $comment, array($steven, $jack));
     $this->assertEquals(2, Yii::app()->emailHelper->getQueuedCount());
     $this->assertEquals(0, Yii::app()->emailHelper->getSentCount());
     $emailMessages = EmailMessage::getAll();
     $emailMessage1 = $emailMessages[0];
     $emailMessage2 = $emailMessages[1];
     $this->assertCount(1, $emailMessage1->recipients);
     $this->assertCount(1, $emailMessage2->recipients);
     //Two inbox notifications created
     $this->assertEquals(4, Notification::getCount());
     //One email message was sent to Super but not to Steven
     //One inbox notification to Steven but not to Super
     NotificationTestHelper::setNotificationSettingsForUser($steven, 'ConversationNewComment', true, false);
     NotificationTestHelper::setNotificationSettingsForUser($super, 'ConversationNewComment', false, true);
     CommentsUtil::sendNotificationOnNewComment($conversation, $comment, array($steven, $super));
     $this->assertEquals(3, Yii::app()->emailHelper->getQueuedCount());
     $this->assertEquals(0, Yii::app()->emailHelper->getSentCount());
     $emailMessages = EmailMessage::getAll();
     $emailMessage = $emailMessages[2];
     $this->assertEquals(1, count($emailMessage->recipients));
     $this->assertEquals(5, Notification::getCount());
     $notifications = Notification::getAll();
     $notification = $notifications[4];
     $this->assertEquals(strval($steven), strval($notification->owner));
 }
コード例 #3
0
ファイル: CommentsUtilTest.php プロジェクト: youprofit/Zurmo
 public function testsSendNotificationOnNewComment()
 {
     $super = User::getByUsername('super');
     $steven = User::getByUsername('steven');
     $jack = User::getByUsername('jack');
     $conversation = new Conversation();
     $conversation->owner = Yii::app()->user->userModel;
     $conversation->subject = 'My test subject2';
     $conversation->description = 'My test description2';
     $this->assertTrue($conversation->save());
     $comment = new Comment();
     $comment->description = 'This is the 1st test comment';
     //Confirm no email notifications are sitting in the queue
     $this->assertEquals(0, Yii::app()->emailHelper->getQueuedCount());
     $this->assertEquals(0, Yii::app()->emailHelper->getSentCount());
     //No message was sent because Steven and Jack don't have primary email address
     CommentsUtil::sendNotificationOnNewComment($conversation, $comment, $super, array($steven, $jack));
     $this->assertEquals(0, Yii::app()->emailHelper->getQueuedCount());
     $this->assertEquals(0, Yii::app()->emailHelper->getSentCount());
     $super->primaryEmail->emailAddress = '*****@*****.**';
     $steven->primaryEmail->emailAddress = '*****@*****.**';
     $jack->primaryEmail->emailAddress = '*****@*****.**';
     $this->assertTrue($super->save());
     $this->assertTrue($steven->save());
     $this->assertTrue($jack->save());
     //One email message was sent because to Steven and Jack
     CommentsUtil::sendNotificationOnNewComment($conversation, $comment, $super, array($steven, $jack));
     $this->assertEquals(1, Yii::app()->emailHelper->getQueuedCount());
     $this->assertEquals(0, Yii::app()->emailHelper->getSentCount());
     $emailMessages = EmailMessage::getAll();
     $emailMessage = $emailMessages[0];
     $this->assertEquals(2, count($emailMessage->recipients));
     //One email message was sent to Super but not to Steven
     UserConfigurationFormAdapter::setValue($steven, true, 'turnOffEmailNotifications');
     CommentsUtil::sendNotificationOnNewComment($conversation, $comment, $jack, array($steven, $super));
     $this->assertEquals(2, Yii::app()->emailHelper->getQueuedCount());
     $this->assertEquals(0, Yii::app()->emailHelper->getSentCount());
     $emailMessages = EmailMessage::getAll();
     $emailMessage = $emailMessages[1];
     $this->assertEquals(1, count($emailMessage->recipients));
 }
 /**
  * Override to handle sending email messages on new comment
  */
 protected function afterSuccessfulSave($model)
 {
     assert('$model instanceof Item');
     parent::afterSuccessfulSave($model);
     $user = Yii::app()->user->userModel;
     if ($this->relatedModel instanceof Conversation) {
         $participants = ConversationsUtil::resolvePeopleToSendNotificationToOnNewComment($this->relatedModel, $user);
         CommentsUtil::sendNotificationOnNewComment($this->relatedModel, $model, $participants);
     } elseif ($this->relatedModel instanceof Mission) {
         $participants = MissionsUtil::resolvePeopleToSendNotificationToOnNewComment($this->relatedModel, $user);
         CommentsUtil::sendNotificationOnNewComment($this->relatedModel, $model, $participants);
     } elseif ($this->relatedModel instanceof Task) {
         TasksNotificationUtil::submitTaskNotificationMessage($this->relatedModel, TasksNotificationUtil::TASK_NEW_COMMENT, $model->createdByUser, $model);
         //Log the event
         if ($this->relatedModel->project->id > 0) {
             ProjectsUtil::logAddCommentEvent($this->relatedModel, $model->description);
         }
     }
 }