public function testSubmitNonCritical() { $super = User::getByUsername('super'); $emailAddress = new Email(); $emailAddress->emailAddress = '*****@*****.**'; $super->primaryEmail = $emailAddress; $saved = $super->save(); $this->assertTrue($saved); $billy = User::getByUsername('billy'); $emailAddress = new Email(); $emailAddress->emailAddress = '*****@*****.**'; $billy->primaryEmail = $emailAddress; $saved = $billy->save(); $this->assertTrue($saved); $notifications = Notification::getAll(); $this->assertEquals(0, count($notifications)); $message = new NotificationMessage(); $message->textContent = 'text content'; $message->htmlContent = 'html content'; $rules = new SimpleNotificationRules(); $rules->addUser($super); $rules->addUser($billy); NotificationsUtil::submit($message, $rules); //It should not send an email because it is non-critical $this->assertEquals(0, Yii::app()->emailHelper->getQueuedCount()); $this->assertEquals(0, Yii::app()->emailHelper->getSentCount()); $notifications = Notification::getAll(); $this->assertEquals(0, Yii::app()->emailHelper->getQueuedCount()); $this->assertEquals(0, Yii::app()->emailHelper->getSentCount()); }
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, count(JobInProcess::getAll())); $this->assertEquals(0, count(Notification::getAll())); $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() - 1000); $sql = "Update item set createddatetime = '" . $createdDateTime . "' where id = " . $jobInProcess->getClassId('Item'); R::exec($sql); $jobInProcess->forget(); $monitorJob->run(); $this->assertEquals(1, count(Notification::getAll())); //Confirm an email was sent $this->assertEquals(0, Yii::app()->emailHelper->getQueuedCount()); $this->assertEquals(1, Yii::app()->emailHelper->getSentCount()); }
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, count(Notification::getAll())); $job = new WorkflowValidityCheckJob(); $this->assertTrue($job->run()); $notifications = Notification::getAll(); $this->assertEquals(1, count($notifications)); }
public function testProcessWorkflowAfterSave() { $model = new WorkflowModelTestItem(); $event = new CEvent($model); $observer = new WorkflowsObserver(); $observer->setDepth(25); $this->assertEquals(0, count(Notification::getAll())); $observer->processWorkflowAfterSave($event); $this->assertEquals(1, count(Notification::getAll())); }
/** * 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, count(Notification::getAll())); GamificationUtil::logAndNotifyOnDuplicateGameModel('some content'); //It should not send an email because it is non-critical $this->assertEquals(0, Yii::app()->emailHelper->getQueuedCount()); $this->assertEquals(0, Yii::app()->emailHelper->getSentCount()); $this->assertEquals(1, count(Notification::getAll())); }
public function testSuperUserAllDefaultControllerActions() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); $notifications = Notification::getAll(); $this->assertEquals(1, count($notifications)); //Test all default controller actions that do not require any POST/GET variables to be passed. //This actions are being redirected to the mashableInbox module. //This does not include portlet controller actions. $this->runControllerWithRedirectExceptionAndGetContent('notifications/default'); $this->runControllerWithRedirectExceptionAndGetContent('notifications/default/index'); $this->runControllerWithRedirectExceptionAndGetContent('notifications/default/userList'); }
public function testSubscribeContactToList() { $marketingList = MarketingList::getById(self::$marketingListId); $this->assertEquals(0, $marketingList->marketingListMembers->count()); $action = new ActionForWorkflowForm('Contact', Workflow::TYPE_ON_SAVE); $action->type = ActionForWorkflowForm::TYPE_SUBSCRIBE_TO_LIST; $attributes = array('marketingList' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => self::$marketingListId)); $action->setAttributes(array(ActionForWorkflowForm::ACTION_ATTRIBUTES => $attributes)); $contact = ContactTestHelper::createContactByNameForOwner('jason', Yii::app()->user->userModel); $helper = new WorkflowActionProcessingHelper(88, 'some name', $action, $contact, Yii::app()->user->userModel); $helper->processNonUpdateSelfAction(); $marketingList->forget(); $marketingList = MarketingList::getById(self::$marketingListId); $this->assertEquals(1, $marketingList->marketingListMembers->count()); $this->assertEquals(0, $marketingList->marketingListMembers[0]->unsubscribed); //Try adding the same contact again to the list, it should not add the contact again. $helper = new WorkflowActionProcessingHelper(88, 'some name', $action, $contact, Yii::app()->user->userModel); $helper->processNonUpdateSelfAction(); $marketingList->forget(); $marketingList = MarketingList::getById(self::$marketingListId); $this->assertEquals(1, $marketingList->marketingListMembers->count()); $this->assertEquals(0, $marketingList->marketingListMembers[0]->unsubscribed); //Unsubscribe contact from list, then resubscribe $marketingListMembers = MarketingListMember::getAll(); $this->assertEquals(1, count($marketingListMembers)); $marketingListMembers[0]->unsubscribed = true; $marketingListMembers[0]->unrestrictedSave(); $marketingList->forget(); $marketingList = MarketingList::getById(self::$marketingListId); $this->assertEquals(1, $marketingList->marketingListMembers->count()); $this->assertEquals(1, $marketingList->marketingListMembers[0]->unsubscribed); //Try to resubscribe the contact, it should not resubscribe them $helper = new WorkflowActionProcessingHelper(88, 'some name', $action, $contact, Yii::app()->user->userModel); $helper->processNonUpdateSelfAction(); $marketingList->forget(); $marketingList = MarketingList::getById(self::$marketingListId); $this->assertEquals(1, $marketingList->marketingListMembers->count()); $this->assertEquals(1, $marketingList->marketingListMembers[0]->unsubscribed); //Test gracefully handling trying to subscribe to a marketing list that does not exist $this->assertEquals(0, count(Notification::getAll())); $action = new ActionForWorkflowForm('Contact', Workflow::TYPE_ON_SAVE); $action->type = ActionForWorkflowForm::TYPE_SUBSCRIBE_TO_LIST; $attributes = array('marketingList' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => 123456789)); $action->setAttributes(array(ActionForWorkflowForm::ACTION_ATTRIBUTES => $attributes)); $helper = new WorkflowActionProcessingHelper(88, 'some name', $action, $contact, Yii::app()->user->userModel); $helper->processNonUpdateSelfAction(); $notifications = Notification::getAll(); $this->assertEquals(1, count($notifications)); //Test gracefully handling trying to unsubscribe to a marketing list that does not exist $this->assertTrue($notifications[0]->delete()); $this->assertEquals(0, count(Notification::getAll())); $action = new ActionForWorkflowForm('Contact', Workflow::TYPE_ON_SAVE); $action->type = ActionForWorkflowForm::TYPE_UNSUBSCRIBE_FROM_LIST; $attributes = array('marketingList' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => 123456789)); $action->setAttributes(array(ActionForWorkflowForm::ACTION_ATTRIBUTES => $attributes)); $helper = new WorkflowActionProcessingHelper(88, 'some name', $action, $contact, Yii::app()->user->userModel); $helper->processNonUpdateSelfAction(); $this->assertEquals(1, count(Notification::getAll())); }
public function testProjectNotifications() { $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; $super->primaryEmail->emailAddress = '*****@*****.**'; $super->save(); Yii::app()->user->userModel = $super; $user = UserTestHelper::createBasicUser('ProjectUser'); Notification::deleteAll(); EmailMessage::deleteAll(); $project = new Project(); $project->name = 'Project For Notifications Test'; $project->owner = $super; $project->description = 'Description'; $this->assertTrue($project->save()); //New project notification $notifications = Notification::getAll(); $emailMessages = EmailMessage::getAll(); $this->assertCount(1, $notifications); $this->assertCount(1, $emailMessages); $this->assertContains("The project, 'Project For Notifications Test', is now owned by you.", $notifications[0]->notificationMessage->textContent); $this->assertContains("The project, 'Project For Notifications Test', is now owned by you.", $emailMessages[0]->content->textContent); //Project archived notification $project->status = Project::STATUS_ARCHIVED; $this->assertTrue($project->save()); $notifications = Notification::getAll(); $emailMessages = EmailMessage::getAll(); $this->assertCount(2, $notifications); $this->assertCount(2, $emailMessages); $this->assertContains("The project, 'Project For Notifications Test', is now archived.", $notifications[1]->notificationMessage->textContent); $this->assertContains("The project, 'Project For Notifications Test', is now archived.", $emailMessages[1]->content->textContent); }
/** * @depends testCreateActionForRowsAndColumns */ public function testExportAction() { if (RedBeanDatabase::isFrozen()) { return; } $notificationsBeforeCount = count(Notification::getAll()); $notificationMessagesBeforeCount = count(NotificationMessage::getAll()); $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, count(Notification::getAll())); $this->assertEquals($notificationMessagesBeforeCount + 1, count(NotificationMessage::getAll())); }
/** * @depends testNotificationMessage */ public function testGetCountByTypeAndUser() { $super = User::getByUsername('super'); $billy = User::getByUsername('billy'); Yii::app()->user->userModel = $super; $this->assertEquals(0, count(Notification::getAll())); $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, count(Notification::getAll())); //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)); }
/** * @depends testAjaxChangeStatus */ public function testSendNotificationInNewComment() { $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); $missions = Mission::getAll(); $this->assertEquals(1, count($missions)); $mission = $missions[0]; $this->assertEquals(0, $mission->comments->count()); EmailMessage::deleteAll(); Notification::deleteAll(); $messageCount = 0; $this->assertEquals(0, Yii::app()->emailHelper->getSentCount()); //Save new comment. $this->setGetArray(array('relatedModelId' => $mission->id, 'relatedModelClassName' => 'Mission', 'relatedModelRelationName' => 'comments', 'redirectUrl' => 'someRedirect')); $this->setPostArray(array('Comment' => array('description' => 'a ValidComment Name'))); $this->runControllerWithRedirectExceptionAndGetContent('comments/default/inlineCreateSave'); $this->assertEquals(1, $mission->comments->count()); $this->assertEquals($messageCount + 1, Yii::app()->emailHelper->getQueuedCount()); $this->assertEquals(0, Yii::app()->emailHelper->getSentCount()); $emailMessages = EmailMessage::getAll(); $emailMessage = $emailMessages[$messageCount]; $this->assertEquals(1, count($emailMessage->recipients)); $this->assertContains('mission', $emailMessage->subject); $this->assertContains(strval($mission), $emailMessage->subject); $this->assertContains(strval($mission->comments[0]), $emailMessage->content->htmlContent); $this->assertContains(strval($mission->comments[0]), $emailMessage->content->textContent); $notifications = Notification::getAll(); $notification = $notifications[$messageCount]; $this->assertCount(1, $notifications); $this->assertEquals('Mission new comment', strval($notification)); $this->assertContains(strval($mission->comments[0]), $notification->notificationMessage->htmlContent); $this->assertContains(strval($mission->comments[0]), $notification->notificationMessage->textContent); }
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, count(JobInProcess::getAll())); $this->assertEquals(0, count(StuckJob::getAll())); $this->assertEquals(0, count(Notification::getAll())); $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, count(JobInProcess::getAll())); //should still be 0 but the quantity should increase $this->assertEquals(0, count(Notification::getAll())); //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, count(JobInProcess::getAll())); //should still be 0 but the quantity should increase $this->assertEquals(0, count(Notification::getAll())); //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, count(Notification::getAll())); //Confirm an email was sent $this->assertEquals(0, Yii::app()->emailHelper->getQueuedCount()); $this->assertEquals(1, EmailMessage::getCount()); $this->assertEquals(1, Yii::app()->emailHelper->getSentCount()); }
protected function clearNotificationsWorkflowsAndEmailMessages() { $notifications = Notification::getAll(); foreach ($notifications as $notification) { $notification->delete(); } $emailMessages = EmailMessage::getAll(); foreach ($emailMessages as $emailMessage) { $emailMessage->delete(); } $workflows = SavedWorkflow::getAll(); foreach ($workflows as $workflow) { $workflow->delete(); } }
public function testSubmittingDuplicateNotifications() { $user = $this->user; Notification::deleteAll(); EmailMessage::deleteAll(); $message = new NotificationMessage(); $message->textContent = 'text content'; $message->htmlContent = 'html content'; $rules = new SimpleNotificationRules(); $rules->setCritical(true); $rules->setAllowDuplicates(false); $rules->addUser($user); NotificationsUtil::submit($message, $rules); $this->assertEquals(1, Yii::app()->emailHelper->getSentCount()); $this->assertCount(1, Notification::getAll()); NotificationsUtil::submit($message, $rules); $this->assertEquals(1, Yii::app()->emailHelper->getSentCount()); $this->assertCount(1, Notification::getAll()); $rules->setAllowDuplicates(true); NotificationsUtil::submit($message, $rules); $this->assertEquals(2, Yii::app()->emailHelper->getSentCount()); $this->assertCount(2, Notification::getAll()); }
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); }
protected function deleteAllNotifications() { foreach (Notification::getAll() as $notification) { $notification->delete(); } }
protected function runInstallation($memcacheOn = true) { $instanceRoot = INSTANCE_ROOT; $form = new InstallSettingsForm(); $form->databaseType = 'mysql'; $form->databaseHostname = $this->temporaryDatabaseHostname; $form->databaseName = $this->temporaryDatabaseName; $form->databaseUsername = $this->temporaryDatabaseUsername; $form->databasePassword = $this->temporaryDatabasePassword; $form->databasePort = $this->temporaryDatabasePort; $form->superUserPassword = $this->superUserPassword; if (!$memcacheOn) { $form->setMemcacheIsNotAvailable(); } $messageStreamer = new MessageStreamer(); $messageStreamer->setExtraRenderBytes(0); $messageStreamer->setEmptyTemplate(); $perInstanceConfigFile = "{$instanceRoot}/protected/config/perInstanceTest.php"; $debugConfigFile = "{$instanceRoot}/protected/config/debugTest.php"; if (is_file($perInstanceConfigFile)) { $originalPerInstanceConfiguration = file_get_contents($perInstanceConfigFile); unlink($perInstanceConfigFile); } if (is_file($debugConfigFile)) { $originalDebugConfiguration = file_get_contents($debugConfigFile); unlink($debugConfigFile); } $this->assertTrue(!is_file($perInstanceConfigFile)); $this->assertTrue(!is_file($debugConfigFile)); InstallUtil::runInstallation($form, $messageStreamer); $notifications = Notification::getAll(); $this->assertCount(1, $notifications); $this->assertEquals('If this website is in production mode, please remove the app/test.php file.', $notifications[0]->notificationMessage->textContent); $perInstanceConfiguration = file_get_contents($perInstanceConfigFile); $debugConfiguration = file_get_contents($debugConfigFile); //Check if super user is created. $user = User::getByUsername('super'); $this->assertEquals('super', $user->username); //Check if config files is updated. $this->assertRegExp('/\\$connectionString = \'mysql:host=' . $this->temporaryDatabaseHostname . ';port=' . $this->temporaryDatabasePort . ';dbname=' . $this->temporaryDatabaseName . '\';/', $perInstanceConfiguration); $this->assertRegExp('/\\$username = \'' . $this->temporaryDatabaseUsername . '\';/', $perInstanceConfiguration); $this->assertRegExp('/\\$password = \'' . $this->temporaryDatabasePassword . '\';/', $perInstanceConfiguration); if ($memcacheOn) { $this->assertRegExp('/\\$memcacheLevelCaching\\s*=\\s*true;/', $debugConfiguration); } else { $this->assertRegExp('/\\$memcacheLevelCaching\\s*=\\s*false;/', $debugConfiguration); } //Restore original config files. unlink($debugConfigFile); unlink($perInstanceConfigFile); file_put_contents($perInstanceConfigFile, $originalPerInstanceConfiguration); file_put_contents($debugConfigFile, $originalDebugConfiguration); }
/** * @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 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)); }
/** * Walkthrough test for asynchronous download */ public function testAsynchronousDownloadDefaultControllerActions() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); $notificationsBeforeCount = count(Notification::getAll()); $notificationMessagesBeforeCount = count(NotificationMessage::getAll()); $accounts = Account::getAll(); if (count($accounts)) { foreach ($accounts as $account) { $account->delete(); } } $accounts = array(); for ($i = 0; $i <= ExportModule::$asynchronusThreshold + 1; $i++) { $accounts[] = AccountTestHelper::createAccountByNameForOwner('superAccount' . $i, $super); } $this->setGetArray(array('Account_page' => '1', 'export' => '', 'selectAll' => '1', 'selectedIds' => '', 'ajax' => '')); $this->runControllerWithRedirectExceptionAndGetUrl('accounts/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('accounts', $exportItems[0]->exportFileName); $this->assertTrue($fileModel instanceof ExportFileModel); $this->assertEquals($notificationsBeforeCount + 1, count(Notification::getAll())); $this->assertEquals($notificationMessagesBeforeCount + 1, count(NotificationMessage::getAll())); // Check export job, when many ids are selected. // This will probably never happen, but we need test for this case too. $notificationsBeforeCount = count(Notification::getAll()); $notificationMessagesBeforeCount = count(NotificationMessage::getAll()); // Now test case when multiple ids are selected $exportItems = ExportItem::getAll(); if (count($exportItems)) { foreach ($exportItems as $exportItem) { $exportItem->delete(); } } $selectedIds = ""; foreach ($accounts as $account) { $selectedIds .= $account->id . ","; // Not Coding Standard } $this->setGetArray(array('AccountsSearchForm' => array('anyMixedAttributesScope' => array(0 => 'All'), 'anyMixedAttributes' => '', 'name' => '', 'officePhone' => ''), 'multiselect_AccountsSearchForm_anyMixedAttributesScope' => 'All', 'selectAll' => '', 'selectedIds' => "{$selectedIds}", 'Account_page' => '1', 'export' => '', 'ajax' => '')); $this->runControllerWithRedirectExceptionAndGetUrl('accounts/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('accounts', $exportItems[0]->exportFileName); $this->assertTrue($fileModel instanceof ExportFileModel); $this->assertEquals($notificationsBeforeCount + 1, count(Notification::getAll())); $this->assertEquals($notificationMessagesBeforeCount + 1, count(NotificationMessage::getAll())); }
public function testTaskNotifications() { $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; $userOwner = UserTestHelper::createBasicUserWithEmailAddress('TaskUserOwner'); $userRequester = UserTestHelper::createBasicUserWithEmailAddress('TaskUserRequester'); Notification::deleteAll(); EmailMessage::deleteAll(); $dueStamp = DateTimeUtil::convertTimestampToDbFormatDateTime(time() + 10000); $completedStamp = DateTimeUtil::convertTimestampToDbFormatDateTime(time() + 9000); $task = new Task(); $task->name = 'Task for Notifications Test'; $task->owner = $userOwner; $task->requestedByUser = $userRequester; $task->dueDateTime = $dueStamp; $task->completedDateTime = $completedStamp; $task->description = 'my test description'; $task->status = Task::STATUS_NEW; $this->assertTrue($task->save()); //New task notification owned by other $notifications = Notification::getAll(); $emailMessages = EmailMessage::getAll(); $this->assertCount(1, $notifications); $this->assertCount(1, $emailMessages); $this->assertContains("The task, 'Task for Notifications Test', is now owned by you.", $notifications[0]->notificationMessage->textContent); $this->assertContains("The task, 'Task for Notifications Test', is now owned by you.", $emailMessages[0]->content->textContent); //Deliver task notification $task->status = TASK::STATUS_AWAITING_ACCEPTANCE; $task->save(); $notifications = Notification::getAll(); $emailMessages = EmailMessage::getAll(); $this->assertCount(2, $notifications); $this->assertCount(2, $emailMessages); $this->assertContains("The task you requested, 'Task for Notifications Test', has been finished. You can now choose to accept or reject the task.", $notifications[1]->notificationMessage->textContent); $this->assertContains("The task you requested, 'Task for Notifications Test', has been finished. You can now choose to accept or reject the task.", $emailMessages[1]->content->textContent); //Reject task notification $task->status = TASK::STATUS_REJECTED; $task->save(); $notifications = Notification::getAll(); $emailMessages = EmailMessage::getAll(); $this->assertCount(3, $notifications); $this->assertCount(3, $emailMessages); $this->assertContains("The task, 'Task for Notifications Test', has been rejected by Clark Kent.", $notifications[2]->notificationMessage->textContent); $this->assertContains("The task, 'Task for Notifications Test', has been rejected by Clark Kent.", $emailMessages[2]->content->textContent); //Accept task notification $task->status = TASK::STATUS_COMPLETED; $task->save(); $notifications = Notification::getAll(); $emailMessages = EmailMessage::getAll(); $this->assertCount(4, $notifications); $this->assertCount(4, $emailMessages); $this->assertContains("The task, 'Task for Notifications Test', was accepted by Clark Kent.", $notifications[3]->notificationMessage->textContent); $this->assertContains("The task, 'Task for Notifications Test', was accepted by Clark Kent.", $emailMessages[3]->content->textContent); }
public function testRedeemReward() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); $super->primaryEmail->emailAddress = '*****@*****.**'; $super->save(); Yii::app()->user->userModel = $super; $gameRewards = GameReward::getByName('myNewGameReward'); //not enough coins $this->setGetArray(array('id' => $gameRewards[0]->id)); $content = $this->runControllerWithExitExceptionAndGetContent('gameRewards/default/redeemReward'); $this->assertContains('You do not have enough coins to redeem this reward', $content); //enough coins $gameCoin = new GameCoin(); $gameCoin->person = $super; $gameCoin->value = 100; $this->assertTrue($gameCoin->save()); $notifications = Notification::getAll(); //check for no notification $this->assertEquals(0, EmailMessage::getCount()); $this->assertEquals(0, count($notifications)); $this->setGetArray(array('id' => $gameRewards[0]->id)); $content = $this->runControllerWithExitExceptionAndGetContent('gameRewards/default/redeemReward'); $this->assertContains('myNewGameReward has been redeemed.', $content); //check for notification $notifications = Notification::getAll(); $this->assertEquals(1, count($notifications)); //email content $this->assertContains('myNewGameReward was redeemed by Clark Kent.', $notifications[0]->notificationMessage->htmlContent); //check url $this->assertContains('/gameRewards/default/details?id=13', $notifications[0]->notificationMessage->htmlContent); // Not Coding Standard //check for email notification $emailMessages = EmailMessage::getAll(); $this->assertCount(1, $emailMessages); $this->assertContains('myNewGameReward was redeemed by Clark Kent.', $emailMessages[0]->content->htmlContent); $this->assertContains('myNewGameReward was redeemed by Clark Kent.', $emailMessages[0]->content->textContent); }
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); }