public function testRun()
 {
     //Create workflow
     $workflow = new Workflow();
     $workflow->setDescription('aDescription');
     $workflow->setIsActive(true);
     $workflow->setOrder(5);
     $workflow->setModuleClassName('WorkflowsTest2Module');
     $workflow->setName('myFirstWorkflow');
     $workflow->setTriggerOn(Workflow::TRIGGER_ON_NEW_AND_EXISTING);
     $workflow->setType(Workflow::TYPE_ON_SAVE);
     $workflow->setTriggersStructure('1');
     //Add action that is missing required owner
     $action = new ActionForWorkflowForm('WorkflowModelTestItem2', Workflow::TYPE_ON_SAVE);
     $action->type = ActionForWorkflowForm::TYPE_CREATE;
     $action->relation = 'hasMany2';
     $attributes = array('string' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => 'jason'), 'lastName' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => 'jason'));
     $action->setAttributes(array(ActionForWorkflowForm::ACTION_ATTRIBUTES => $attributes));
     $workflow->addAction($action);
     //Create the saved Workflow
     $savedWorkflow = new SavedWorkflow();
     SavedWorkflowToWorkflowAdapter::resolveWorkflowToSavedWorkflow($workflow, $savedWorkflow);
     $saved = $savedWorkflow->save();
     $this->assertTrue($saved);
     $this->assertEquals(0, Notification::getCount());
     $job = new WorkflowValidityCheckJob();
     $this->assertTrue($job->run());
     $notifications = Notification::getAll();
     $this->assertEquals(1, count($notifications));
 }
 public function getUnreadCountForCurrentUser()
 {
     $searchAttributeData = $this->getMetadataFilteredByFilteredBy(MashableInboxForm::FILTERED_BY_UNREAD);
     $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('Notification');
     $where = RedBeanModelDataProvider::makeWhere('Notification', $searchAttributeData, $joinTablesAdapter);
     return Notification::getCount($joinTablesAdapter, $where, null, true);
 }
 public function testProcessWorkflowAfterSave()
 {
     $model = new WorkflowModelTestItem();
     $event = new CEvent($model);
     $observer = new WorkflowsObserver();
     $observer->setDepth(25);
     $this->assertEquals(0, Notification::getCount());
     $observer->processWorkflowAfterSave($event);
     $this->assertEquals(1, Notification::getCount());
 }
 /**
  * The best we can cover for is making sure the notification is created and it is not marked as critical.
  */
 public function testLogAndNotifyOnDuplicateGameModel()
 {
     $this->assertEquals(0, Yii::app()->emailHelper->getQueuedCount());
     $this->assertEquals(0, Yii::app()->emailHelper->getSentCount());
     $this->assertEquals(0, Notification::getCount());
     GamificationUtil::logAndNotifyOnDuplicateGameModel('some content');
     //It should not send an email because it is non-allowed to send email notification
     $this->assertEquals(0, Yii::app()->emailHelper->getQueuedCount());
     $this->assertEquals(0, Yii::app()->emailHelper->getSentCount());
     $this->assertEquals(1, Notification::getCount());
 }
 /**
  * @depends testCreateActionForRowsAndColumns
  */
 public function testExportAction()
 {
     $notificationsBeforeCount = Notification::getCount();
     $notificationMessagesBeforeCount = NotificationMessage::getCount();
     $savedReports = SavedReport::getAll();
     $this->assertEquals(2, count($savedReports));
     $this->setGetArray(array('id' => $savedReports[0]->id));
     //Test where there is no data to export
     $this->runControllerWithRedirectExceptionAndGetContent('reports/default/export');
     $this->assertContains('There is no data to export.', Yii::app()->user->getFlash('notification'));
     $reportModelTestItem = new ReportModelTestItem();
     $reportModelTestItem->string = 'string1';
     $reportModelTestItem->lastName = 'xLast1';
     $this->assertTrue($reportModelTestItem->save());
     $reportModelTestItem = new ReportModelTestItem();
     $reportModelTestItem->string = 'string2';
     $reportModelTestItem->lastName = 'xLast2';
     $this->assertTrue($reportModelTestItem->save());
     $content = $this->runControllerWithExitExceptionAndGetContent('reports/default/export');
     $this->assertEquals('Testing download.', $content);
     ExportModule::$asynchronousThreshold = 1;
     $this->runControllerWithRedirectExceptionAndGetUrl('reports/default/export');
     // Start background job
     $job = new ExportJob();
     $this->assertTrue($job->run());
     $exportItems = ExportItem::getAll();
     $this->assertEquals(1, count($exportItems));
     $fileModel = $exportItems[0]->exportFileModel;
     $this->assertEquals(1, $exportItems[0]->isCompleted);
     $this->assertEquals('csv', $exportItems[0]->exportFileType);
     $this->assertEquals('reports', $exportItems[0]->exportFileName);
     $this->assertTrue($fileModel instanceof ExportFileModel);
     $this->assertEquals($notificationsBeforeCount + 1, Notification::getCount());
     $this->assertEquals($notificationMessagesBeforeCount + 1, NotificationMessage::getCount());
 }
 public function testRunWithMissingTriggerMultiselectPicklistValue()
 {
     $this->clearNotificationsWorkflowsAndEmailMessages();
     $this->createStageValues();
     //Create workflow
     $workflow = new Workflow();
     $workflow->setDescription('bDescription');
     $workflow->setIsActive(true);
     $workflow->setOrder(5);
     $workflow->setModuleClassName('OpportunitiesModule');
     $workflow->setName('mySecondWorkflow');
     $workflow->setTriggerOn(Workflow::TRIGGER_ON_NEW_AND_EXISTING);
     $workflow->setType(Workflow::TYPE_ON_SAVE);
     $workflow->setTriggersStructure('1');
     $trigger = new TriggerForWorkflowForm('OpportunitiesModule', 'Opportunity', Workflow::TYPE_ON_SAVE);
     $trigger->attributeIndexOrDerivedType = 'stage';
     $trigger->value = 'Closed Won,Negotiating';
     $trigger->operator = OperatorRules::TYPE_ONE_OF;
     $trigger->relationFilter = TriggerForWorkflowForm::RELATION_FILTER_ANY;
     $workflow->addTrigger($trigger);
     //Create the saved Workflow
     $savedWorkflow = new SavedWorkflow();
     SavedWorkflowToWorkflowAdapter::resolveWorkflowToSavedWorkflow($workflow, $savedWorkflow);
     $saved = $savedWorkflow->save();
     $this->assertTrue($saved);
     $this->assertEquals(0, Notification::getCount());
     $this->assertEquals(0, EmailMessage::getCount());
     $job = new WorkflowValidityCheckJob();
     $this->assertTrue($job->run());
     $this->assertEquals(0, Notification::getCount());
     $this->assertEquals(0, EmailMessage::getCount());
     $this->clearNotificationsWorkflowsAndEmailMessages();
     $workflow = new Workflow();
     $workflow->setDescription('cDescription');
     $workflow->setIsActive(true);
     $workflow->setOrder(5);
     $workflow->setModuleClassName('OpportunitiesModule');
     $workflow->setName('mySecondWorkflow');
     $workflow->setTriggerOn(Workflow::TRIGGER_ON_NEW_AND_EXISTING);
     $workflow->setType(Workflow::TYPE_ON_SAVE);
     $workflow->setTriggersStructure('1');
     $trigger = new TriggerForWorkflowForm('OpportunitiesModule', 'Opportunity', Workflow::TYPE_ON_SAVE);
     $trigger->attributeIndexOrDerivedType = 'stage';
     $trigger->value = 'Closed Won,Unexisting state';
     $trigger->operator = OperatorRules::TYPE_BECOMES;
     $trigger->relationFilter = TriggerForWorkflowForm::RELATION_FILTER_ANY;
     $workflow->addTrigger($trigger);
     //Create the saved Workflow
     $savedWorkflow = new SavedWorkflow();
     SavedWorkflowToWorkflowAdapter::resolveWorkflowToSavedWorkflow($workflow, $savedWorkflow);
     $saved = $savedWorkflow->save();
     $this->assertTrue($saved);
     $this->assertEquals(0, Notification::getCount());
     $this->assertEquals(0, EmailMessage::getCount());
     $job = new WorkflowValidityCheckJob();
     $this->assertTrue($job->run());
     $this->assertEquals(1, Notification::getCount());
     $this->assertEquals(1, EmailMessage::getCount());
 }
 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());
 }
 /**
  * Walkthrough test for synchronous download
  */
 public function testAsynchronousDownloadDefaultControllerActions()
 {
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $notificationsBeforeCount = Notification::getCount();
     $notificationMessagesBeforeCount = NotificationMessage::getCount();
     $products = Product::getAll();
     if (count($products)) {
         foreach ($products as $product) {
             $product->delete();
         }
     }
     $products = array();
     for ($i = 0; $i <= ExportModule::$asynchronousThreshold + 1; $i++) {
         $products[] = ProductTestHelper::createProductByNameForOwner('superProduct' . $i, $super);
     }
     $this->setGetArray(array('Product_page' => '1', 'export' => '', 'ajax' => '', 'selectAll' => '1', 'selectedIds' => ''));
     $this->runControllerWithRedirectExceptionAndGetUrl('products/default/export');
     // Start background job
     $job = new ExportJob();
     $this->assertTrue($job->run());
     $exportItems = ExportItem::getAll();
     $this->assertEquals(1, count($exportItems));
     $fileModel = $exportItems[0]->exportFileModel;
     $this->assertEquals(1, $exportItems[0]->isCompleted);
     $this->assertEquals('csv', $exportItems[0]->exportFileType);
     $this->assertEquals('products', $exportItems[0]->exportFileName);
     $this->assertTrue($fileModel instanceof ExportFileModel);
     $this->assertEquals($notificationsBeforeCount + 1, Notification::getCount());
     $this->assertEquals($notificationMessagesBeforeCount + 1, NotificationMessage::getCount());
     // Check export job, when many ids are selected.
     // This will probably never happen, but we need test for this case too.
     $notificationsBeforeCount = Notification::getCount();
     $notificationMessagesBeforeCount = NotificationMessage::getCount();
     // Now test case when multiple ids are selected
     $exportItems = ExportItem::getAll();
     if (count($exportItems)) {
         foreach ($exportItems as $exportItem) {
             $exportItem->delete();
         }
     }
     $selectedIds = "";
     foreach ($products as $product) {
         $selectedIds .= $product->id . ",";
         // Not Coding Standard
     }
     $this->setGetArray(array('ProductsSearchForm' => array('anyMixedAttributesScope' => array(0 => 'All'), 'anyMixedAttributes' => '', 'quantity' => ''), 'multiselect_ProductsSearchForm_anyMixedAttributesScope' => 'All', 'Product_page' => '1', 'export' => '', 'ajax' => '', 'selectAll' => '', 'selectedIds' => "{$selectedIds}"));
     $this->runControllerWithRedirectExceptionAndGetUrl('products/default/export');
     // Start background job
     $job = new ExportJob();
     $this->assertTrue($job->run());
     $exportItems = ExportItem::getAll();
     $this->assertEquals(1, count($exportItems));
     $fileModel = $exportItems[0]->exportFileModel;
     $this->assertEquals(1, $exportItems[0]->isCompleted);
     $this->assertEquals('csv', $exportItems[0]->exportFileType);
     $this->assertEquals('products', $exportItems[0]->exportFileName);
     $this->assertTrue($fileModel instanceof ExportFileModel);
     $this->assertEquals($notificationsBeforeCount + 1, Notification::getCount());
     $this->assertEquals($notificationMessagesBeforeCount + 1, NotificationMessage::getCount());
 }
 /**
  * @depends testResolveConversationParticipants
  */
 public function testResolveEmailInvitesByPeople()
 {
     $this->assertEquals(0, Notification::getCount());
     $this->assertEquals(0, EmailMessage::getCount());
     $super = Yii::app()->user->userModel;
     $super->primaryEmail->emailAddress = '*****@*****.**';
     NotificationTestHelper::setNotificationSettingsForUser($super, 'ConversationInvites');
     $jack = User::getByUsername('jack');
     $jack->primaryEmail->emailAddress = '*****@*****.**';
     NotificationTestHelper::setNotificationSettingsForUser($jack, 'ConversationInvites', true, false);
     $steven = User::getByUsername('steven');
     $steven->primaryEmail->emailAddress = '*****@*****.**';
     NotificationTestHelper::setNotificationSettingsForUser($steven, 'ConversationInvites', false, true);
     $mary = User::getByUsername('mary');
     $mary->primaryEmail->emailAddress = '*****@*****.**';
     NotificationTestHelper::setNotificationSettingsForUser($mary, 'ConversationInvites', false, false);
     $conversation = new Conversation();
     $conversation->owner = $super;
     $conversation->subject = 'Test Resolve Conversation Participants';
     $conversation->description = 'This is for testing conversation participants.';
     $this->assertTrue($conversation->save());
     ConversationParticipantsUtil::resolveEmailInvitesByPeople($conversation, array($super, $jack, $steven, $mary));
     $this->assertEquals(2, Notification::getCount());
     $notifications = Notification::getAll();
     $this->assertContains('<h2 class="h2">Join the Conversation</h2>Clark Kent would like you to join a conversation <strong>"Test Resolve Conversation Participants"</strong><br/>', $notifications[0]->notificationMessage->htmlContent);
     $this->assertContains('Clark Kent would like you to join a conversation "Test Resolve Conversation Participants"', $notifications[0]->notificationMessage->textContent);
     $this->assertEquals(2, EmailMessage::getCount());
     $emailMessages = EmailMessage::getAll();
     $this->assertContains('<h2 class="h2">Join the Conversation</h2>Clark Kent would like you to join a conversation <strong>"Test Resolve Conversation Participants"</strong><br/>', $emailMessages[0]->content->htmlContent);
     $this->assertContains('Powered By <a href="http://www.zurmo.com">Zurmo</a>', $emailMessages[0]->content->htmlContent);
     $this->assertContains('Clark Kent would like you to join a conversation "Test Resolve Conversation Participants"', $emailMessages[0]->content->textContent);
     $this->assertContains('Manage your email preferences', $emailMessages[0]->content->textContent);
     $this->assertEquals('You have been invited to participate in a conversation', $emailMessages[0]->subject);
 }
 public function testTaskStatusBecomesRejectedNotificationWhenOwnerIsCurrentUser()
 {
     $task = new Task();
     $task->name = 'Reject Task';
     $task->requestedByUser = self::$sally;
     $task->owner = Yii::app()->user->userModel;
     $this->assertEquals(0, Yii::app()->emailHelper->getQueuedCount());
     $this->assertEquals(0, Notification::getCount());
     $this->assertTrue($task->save());
     //Now change status
     $task->status = Task::STATUS_REJECTED;
     $this->assertTrue($task->save());
     //No emails should be queued up
     $this->assertEquals(0, Yii::app()->emailHelper->getQueuedCount());
     $this->assertEquals(0, Notification::getCount());
 }
 /**
  * @depends testSuperUserCreateMission
  */
 public function testAddingCommentsAndUpdatingActivityStampsOnMission()
 {
     if (!SECURITY_OPTIMIZED) {
         return;
     }
     $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $missions = Mission::getAll();
     $this->assertEquals(1, count($missions));
     $this->assertEquals(0, $missions[0]->comments->count());
     $this->assertEquals(2, Yii::app()->emailHelper->getQueuedCount());
     $this->assertEquals(0, Yii::app()->emailHelper->getSentCount());
     $this->assertEquals(2, Notification::getCount());
     $oldStamp = $missions[0]->latestDateTime;
     //Validate comment
     $this->setGetArray(array('relatedModelId' => $missions[0]->id, 'relatedModelClassName' => 'Mission', 'relatedModelRelationName' => 'comments', 'redirectUrl' => 'someRedirect'));
     $this->setPostArray(array('ajax' => 'comment-inline-edit-form', 'Comment' => array('description' => 'a ValidComment Name')));
     $content = $this->runControllerWithExitExceptionAndGetContent('comments/default/inlineCreateSave');
     $this->assertEquals('[]', $content);
     //Now save that comment.
     sleep(2);
     //to force some time to pass.
     $this->setGetArray(array('relatedModelId' => $missions[0]->id, 'relatedModelClassName' => 'Mission', 'relatedModelRelationName' => 'comments', 'redirectUrl' => 'someRedirect'));
     $this->setPostArray(array('Comment' => array('description' => 'a ValidComment Name')));
     $content = $this->runControllerWithRedirectExceptionAndGetContent('comments/default/inlineCreateSave');
     $id = $missions[0]->id;
     $missions[0]->forget();
     $mission = Mission::getById($id);
     $this->assertEquals(1, $mission->comments->count());
     //should update latest activity stamp
     $this->assertNotEquals($oldStamp, $missions[0]->latestDateTime);
     $newStamp = $missions[0]->latestDateTime;
     sleep(2);
     // Sleeps are bad in tests, but I need some time to pass
     //Mary should be able to add a comment because everyone can do this on a mission
     $mary = $this->logoutCurrentUserLoginNewUserAndGetByUsername('mary');
     $this->setGetArray(array('relatedModelId' => $missions[0]->id, 'relatedModelClassName' => 'Mission', 'relatedModelRelationName' => 'comments', 'redirectUrl' => 'someRedirect'));
     $this->setPostArray(array('Comment' => array('description' => 'a ValidComment Name 2')));
     $content = $this->runControllerWithRedirectExceptionAndGetContent('comments/default/inlineCreateSave');
     $id = $missions[0]->id;
     $missions[0]->forget();
     $mission = Mission::getById($id);
     $this->assertEquals(2, $mission->comments->count());
     $this->assertNotEquals($newStamp, $mission->latestDateTime);
 }
 public function testRunAndProcessStuckJobs()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $emailAddress = new Email();
     $emailAddress->emailAddress = '*****@*****.**';
     Yii::app()->user->userModel->primaryEmail = $emailAddress;
     $saved = Yii::app()->user->userModel->save();
     $this->assertTrue($saved);
     $this->assertEquals(0, Yii::app()->emailHelper->getQueuedCount());
     $this->assertEquals(0, Yii::app()->emailHelper->getSentCount());
     $monitorJob = new MonitorJob();
     $this->assertEquals(0, JobInProcess::getCount());
     $this->assertEquals(0, StuckJob::getCount());
     $this->assertEquals(0, Notification::getCount());
     $this->assertEquals(0, EmailMessage::getCount());
     $jobInProcess = new JobInProcess();
     $jobInProcess->type = 'Test';
     $this->assertTrue($jobInProcess->save());
     //Should make createdDateTime long enough in past to trigger as stuck.
     $createdDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time() - 10000);
     $sql = "Update item set createddatetime = '" . $createdDateTime . "' where id = " . $jobInProcess->getClassId('Item');
     ZurmoRedBean::exec($sql);
     $jobInProcess->forget();
     $monitorJob->run();
     $this->assertEquals(0, JobInProcess::getCount());
     //should still be 0 but the quantity should increase
     $this->assertEquals(0, Notification::getCount());
     //There should now be one stuck job with quantity 1
     $stuckJobs = StuckJob::getAll();
     $this->assertEquals(1, count($stuckJobs));
     $this->assertEquals('Test', $stuckJobs[0]->type);
     $this->assertEquals(1, $stuckJobs[0]->quantity);
     //Now it should increase to 2
     $jobInProcess = new JobInProcess();
     $jobInProcess->type = 'Test';
     $this->assertTrue($jobInProcess->save());
     //Should make createdDateTime long enough in past to trigger as stuck.
     $createdDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time() - 10000);
     $sql = "Update item set createddatetime = '" . $createdDateTime . "' where id = " . $jobInProcess->getClassId('Item');
     ZurmoRedBean::exec($sql);
     $jobInProcess->forget();
     $monitorJob->run();
     $this->assertEquals(0, JobInProcess::getCount());
     //should still be 0 but the quantity should increase
     $this->assertEquals(0, Notification::getCount());
     //There should now be one stuck job with quantity 1
     $stuckJobs = StuckJob::getAll();
     $this->assertEquals(1, count($stuckJobs));
     $this->assertEquals('Test', $stuckJobs[0]->type);
     $this->assertEquals(2, $stuckJobs[0]->quantity);
     //Set quantity to 3, then run monitor again and notification should go out.
     $stuckJobs[0]->quantity = 3;
     $this->assertTrue($stuckJobs[0]->save());
     $jobInProcess = new JobInProcess();
     $jobInProcess->type = 'Test';
     $this->assertTrue($jobInProcess->save());
     //Should make createdDateTime long enough in past to trigger as stuck.
     $createdDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time() - 10000);
     $sql = "Update item set createddatetime = '" . $createdDateTime . "' where id = " . $jobInProcess->getClassId('Item');
     ZurmoRedBean::exec($sql);
     $jobInProcess->forget();
     //Now the threshold of 4 should be reached and we should send a notification
     $monitorJob->run();
     ForgetAllCacheUtil::forgetAllCaches();
     $stuckJobs = StuckJob::getAll();
     $this->assertEquals(1, count($stuckJobs));
     $this->assertEquals('Test', $stuckJobs[0]->type);
     $this->assertEquals(4, $stuckJobs[0]->quantity);
     $this->assertEquals(1, Notification::getCount());
     //Confirm an email was sent
     $this->assertEquals(0, Yii::app()->emailHelper->getQueuedCount());
     $this->assertEquals(1, EmailMessage::getCount());
     $this->assertEquals(1, Yii::app()->emailHelper->getSentCount());
 }
 public function testNewNotificationWhenProjectIsArchived()
 {
     $project = new Project();
     $project->name = 'project-' . __FUNCTION__;
     $project->owner = self::$steve;
     $project->status = Project::STATUS_ARCHIVED;
     $this->assertEquals(0, EmailMessage::getCount());
     $this->assertEquals(0, Notification::getCount());
     ProjectsNotificationUtil::submitProjectNotificationMessage($project, ProjectAuditEvent::PROJECT_ARCHIVED);
     $emailMessages = EmailMessage::getAll();
     $notifications = Notification::getAll();
     $this->assertCount(1, $emailMessages);
     $this->assertCount(1, $notifications);
     $this->assertEquals('PROJECT: project-' . __FUNCTION__, $emailMessages[0]->subject);
     $this->assertContains("The project, 'project-" . __FUNCTION__ . "', is now archived.", $emailMessages[0]->content->textContent);
     $this->assertContains("The project, 'project-" . __FUNCTION__ . "', is now archived.", $emailMessages[0]->content->htmlContent);
     $this->assertContains("The project, 'project-" . __FUNCTION__ . "', is now archived.", $notifications[0]->notificationMessage->textContent);
     $this->assertContains("The project, 'project-" . __FUNCTION__ . "', is now archived.", $notifications[0]->notificationMessage->htmlContent);
 }
 /**
  * @depends testNotificationMessage
  */
 public function testGetCountByTypeAndUser()
 {
     $super = User::getByUsername('super');
     $billy = User::getByUsername('billy');
     Yii::app()->user->userModel = $super;
     $this->assertEquals(0, Notification::getCount());
     $notification = new Notification();
     $notification->type = 'Simple';
     $notification->owner = $super;
     $this->assertTrue($notification->save());
     $notification = new Notification();
     $notification->type = 'Simple';
     $notification->owner = $super;
     $this->assertTrue($notification->save());
     //There are 2 notifications
     $this->assertEquals(2, Notification::getCount());
     //And 0 notifications unread for billy
     $this->assertEquals(0, Notification::getCountByTypeAndUser('Simple', $billy));
     //Now add another super notification, but not simple.
     $notification = new Notification();
     $notification->type = 'Simple2Test';
     $notification->owner = $super;
     $this->assertTrue($notification->save());
     //And there are still 2 notifications for super
     $this->assertEquals(2, Notification::getCountByTypeAndUser('Simple', $super));
     //Add a notification for billy.
     $notification = new Notification();
     $notification->type = 'Simple';
     $notification->owner = $billy;
     $this->assertTrue($notification->save());
     //And there is still 1 unread notification for billy
     $this->assertEquals(1, Notification::getCountByTypeAndUser('Simple', $billy));
 }
示例#15
0
 public function count()
 {
     $this->set('content', Notification::getCount());
 }
 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));
 }
 public function testMakeMonitorStuckJobNotification()
 {
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $super->primaryEmail->emailAddress = '*****@*****.**';
     $this->assertTrue($super->save());
     $notificationInitalCount = Notification::getCount();
     $emailMessageInitialCount = EmailMessage::getCount();
     JobsManagerUtil::makeMonitorStuckJobNotification();
     $notifications = Notification::getAll();
     $emailMessages = EmailMessage::getAll();
     $this->assertCount($emailMessageInitialCount + 1, $notifications);
     $this->assertCount($notificationInitalCount + 1, $emailMessages);
     $this->assertEquals('The monitor job is stuck.', $notifications[0]->notificationMessage->htmlContent);
     $this->assertEquals('The monitor job is stuck.', $notifications[0]->notificationMessage->textContent);
     $this->assertContains('The monitor job is stuck.', $emailMessages[0]->content->htmlContent);
     $this->assertContains('The monitor job is stuck.', $emailMessages[0]->content->textContent);
 }
示例#18
0
 public function menubar()
 {
     $this->set('notifications', Notification::getCount());
     $this->setArg('area');
 }
 /**
  * @depends testRunInstallation
  */
 public function testRunAutoBuildFromUpdateSchemaCommand()
 {
     $this->runInstallation(true);
     $super = User::getByUsername('super');
     $super->primaryEmail->emailAddress = '*****@*****.**';
     $this->assertTrue($super->save());
     $this->assertEquals(0, EmailMessage::getCount());
     $this->assertEquals(1, Notification::getCount());
     $messageLogger = new MessageLogger();
     $messageLogger->addInfoMessage(Zurmo::t('InstallModule', 'Starting schema update process.'));
     $result = InstallUtil::runAutoBuildFromUpdateSchemaCommand($messageLogger);
     $messageLogger->addInfoMessage(Zurmo::t('InstallModule', 'Schema update complete.'));
     $this->assertTrue($result);
     //No email notification is sent since allowSendingEmail is false
     $this->assertEquals(0, EmailMessage::getCount());
     $this->assertEquals(2, Notification::getCount());
 }