public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     SecurityTestHelper::createSuperAdmin();
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     NotificationTestHelper::createNotificationByContentAndTypeForOwner('message1', $super);
 }
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     Yii::app()->user->userModel = SecurityTestHelper::createSuperAdmin();
     self::$super = Yii::app()->user->userModel;
     self::$steve = UserTestHelper::createBasicUserWithEmailAddress('steve');
     NotificationTestHelper::setNotificationSettingsForUser(self::$steve, 'NewTaskNotificationRules');
     self::$sally = UserTestHelper::createBasicUserWithEmailAddress('sally');
     self::$katie = UserTestHelper::createBasicUserWithEmailAddress('katie');
 }
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     SecurityTestHelper::createSuperAdmin();
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     AllPermissionsOptimizationUtil::rebuild();
     //create everyone group
     $everyoneGroup = Group::getByName(Group::EVERYONE_GROUP_NAME);
     $everyoneGroup->save();
     //Create test users
     $steven = UserTestHelper::createBasicUser('steven');
     $steven->primaryEmail->emailAddress = '*****@*****.**';
     //Steven has turned off notifications
     NotificationTestHelper::setNotificationSettingsForUser($steven, 'NewMission', false, false);
     NotificationTestHelper::setNotificationSettingsForUser($steven, 'MissionStatusChange', false, false);
     NotificationTestHelper::setNotificationSettingsForUser($steven, 'MissionNewComment', false, false);
     $sally = UserTestHelper::createBasicUser('sally');
     $sally->primaryEmail->emailAddress = '*****@*****.**';
     $mary = UserTestHelper::createBasicUser('mary');
     $mary->primaryEmail->emailAddress = '*****@*****.**';
     //give 3 users access, create, delete for mission rights.
     $steven->setRight('MissionsModule', MissionsModule::RIGHT_ACCESS_MISSIONS);
     $steven->setRight('MissionsModule', MissionsModule::RIGHT_CREATE_MISSIONS);
     $steven->setRight('MissionsModule', MissionsModule::RIGHT_DELETE_MISSIONS);
     $saved = $steven->save();
     if (!$saved) {
         throw new NotSupportedException();
     }
     $sally->setRight('MissionsModule', MissionsModule::RIGHT_ACCESS_MISSIONS);
     $sally->setRight('MissionsModule', MissionsModule::RIGHT_CREATE_MISSIONS);
     $sally->setRight('MissionsModule', MissionsModule::RIGHT_DELETE_MISSIONS);
     $saved = $sally->save();
     if (!$saved) {
         throw new NotSupportedException();
     }
     $mary->setRight('MissionsModule', MissionsModule::RIGHT_ACCESS_MISSIONS);
     $mary->setRight('MissionsModule', MissionsModule::RIGHT_CREATE_MISSIONS);
     $mary->setRight('MissionsModule', MissionsModule::RIGHT_DELETE_MISSIONS);
     $saved = $mary->save();
     if (!$saved) {
         throw new NotSupportedException();
     }
 }
 /**
  * @depends testExportByModelIds
  */
 public function testExportRedBeanDataProviderWithMultiplePagesOfData()
 {
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     //Disabling email notification
     NotificationTestHelper::setNotificationSettingsForUser($super, 'ExportProcessCompleted', true, false);
     $numberOfUserNotifications = Notification::getCountByTypeAndUser('ExportProcessCompleted', Yii::app()->user->userModel);
     $numberOfEmailMessages = EmailMessage::getCount();
     $account = new Account(false);
     $searchForm = new AccountsSearchForm($account);
     $dataProvider = ExportTestHelper::makeRedBeanDataProvider($searchForm, 'Account', 0, Yii::app()->user->userModel->id);
     $totalItems = $dataProvider->getTotalItemCount();
     $this->assertEquals(4, $totalItems);
     $exportItem = new ExportItem();
     $exportItem->isCompleted = 0;
     $exportItem->exportFileType = 'csv';
     $exportItem->exportFileName = 'test3';
     $exportItem->modelClassName = 'Account';
     $exportItem->serializedData = serialize($dataProvider);
     $this->assertTrue($exportItem->save());
     $id = $exportItem->id;
     $exportItem->forget();
     unset($exportItem);
     ExportModule::$asynchronousPageSize = 2;
     //Delete queued jobs from test exportItems created above
     Yii::app()->jobQueue->deleteAll();
     $job = new ExportJob();
     $this->assertEquals(0, count(Yii::app()->jobQueue->getAll()));
     $this->assertTrue($job->run());
     $this->assertEquals(0, count(Yii::app()->jobQueue->getAll()));
     $exportItem = ExportItem::getById($id);
     $fileModel = $exportItem->exportFileModel;
     $this->assertEquals(1, $exportItem->isCompleted);
     $this->assertEquals('csv', $exportItem->exportFileType);
     $this->assertEquals('test3', $exportItem->exportFileName);
     $this->assertTrue($fileModel instanceof ExportFileModel);
     // Get csv string via regular csv export process(directly, not in background)
     // We suppose that csv generated thisway is corrected, this function itself
     // is tested in another test.
     $data = array();
     $rows = $dataProvider->getData();
     $modelToExportAdapter = new ModelToExportAdapter($rows[0]);
     $headerData = $modelToExportAdapter->getHeaderData();
     foreach ($rows as $model) {
         $modelToExportAdapter = new ModelToExportAdapter($model);
         $data[] = $modelToExportAdapter->getData();
     }
     $output = ExportItemToCsvFileUtil::export($data, $headerData, 'test3.csv', false);
     $this->assertEquals($output, $fileModel->fileContent->content);
     // Check if user got notification message, and if its type is ExportProcessCompleted
     $this->assertEquals($numberOfUserNotifications + 1, Notification::getCountByTypeAndUser('ExportProcessCompleted', Yii::app()->user->userModel));
     //Check no email notification was sent to super because he has disabled it
     $this->assertEquals($numberOfEmailMessages, EmailMessage::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 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));
 }