public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     SecurityTestHelper::createSuperAdmin();
     SecurityTestHelper::createUsers();
     $super = User::getByUsername('super');
     $super->primaryEmail->emailAddress = '*****@*****.**';
     $saved = $super->save();
     if (!$saved) {
         throw new FailedToSaveModelException();
     }
     MarketingListTestHelper::createMarketingListByName('testMarketingList');
     $campaign = CampaignTestHelper::createCampaign('testCampaign', 'testSubject', 'testContent', 'testHtmlContent');
     $contact = ContactTestHelper::createContactByNameForOwner('test', $super);
     $emailMessage = EmailMessageTestHelper::createArchivedUnmatchedSentMessage($super);
     $campaignItem = new CampaignItem();
     $campaignItem->contact = $contact;
     $campaignItem->processed = true;
     $campaignItem->campaign = $campaign;
     $campaignItem->emailMessage = $emailMessage;
     $campaignItem->unrestrictedSave();
     if (!$saved) {
         throw new FailedToSaveModelException();
     }
     AllPermissionsOptimizationUtil::rebuild();
 }
 /**
  * @depends testResolveEmailAddressToContactIfEmailRelationAvailableForSentMessage
  */
 public function testResolveContactToSenderOrRecipient()
 {
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $message1 = EmailMessageTestHelper::createArchivedUnmatchedReceivedMessage($super);
     $contact = new Contact();
     $this->assertCount(0, $message1->sender->personsOrAccounts);
     ArchivedEmailMatchingUtil::resolveContactToSenderOrRecipient($message1, $contact);
     $this->assertTrue($message1->recipients->count() == 1);
     $this->assertTrue($message1->recipients->offsetGet(0)->personsOrAccounts[0]->isSame($super));
     $this->assertTrue($message1->sender->personsOrAccounts[0]->isSame($contact));
     $message1 = EmailMessageTestHelper::createArchivedUnmatchedSentMessage($super);
     $contact = new Contact();
     $this->assertTrue($message1->recipients->count() == 1);
     $this->assertCount(0, $message1->recipients->offsetGet(0)->personsOrAccounts);
     ArchivedEmailMatchingUtil::resolveContactToSenderOrRecipient($message1, $contact);
     $this->assertTrue($message1->sender->personsOrAccounts[0]->isSame($super));
     $this->assertTrue($message1->recipients->count() == 1);
     $this->assertTrue($message1->recipients->offsetGet(0)->personsOrAccounts[0]->isSame($contact));
 }