本文整理汇总了PHP中EmailMessage::getById方法的典型用法代码示例。如果您正苦于以下问题:PHP EmailMessage::getById方法的具体用法?PHP EmailMessage::getById怎么用?PHP EmailMessage::getById使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EmailMessage
的用法示例。
在下文中一共展示了EmailMessage::getById方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: resolveAndSaveEmailMessage
public static function resolveAndSaveEmailMessage($textContent, $htmlContent, Item $itemOwnerModel, Contact $contact, MarketingList $marketingList, $itemId, $folderId)
{
$recipient = static::resolveRecipient($contact);
if (empty($recipient)) {
throw new MissingRecipientsForEmailMessageException();
}
$userId = static::resolveCurrentUserId();
if (get_class($itemOwnerModel) == 'Campaign') {
$ownerId = $itemOwnerModel->owner->id;
} else {
$ownerId = $marketingList->owner->id;
}
$subject = $itemOwnerModel->subject;
$serializedData = serialize($subject);
$headers = static::resolveHeaders($itemId);
$nowTimestamp = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
$emailMessageData = compact('subject', 'serializedData', 'textContent', 'htmlContent', 'userId', 'ownerId', 'headers', 'attachments', 'folderId', 'nowTimestamp');
$attachments = array('relatedModelType' => strtolower(get_class($itemOwnerModel)), 'relatedModelId' => $itemOwnerModel->id);
$sender = static::resolveSender($marketingList, $itemOwnerModel);
$emailMessageData = CMap::mergeArray($emailMessageData, $sender, $recipient, $attachments);
$emailMessageId = static::saveEmailMessageWithRelated($emailMessageData);
if (empty($emailMessageId)) {
throw new FailedToSaveModelException();
}
$emailMessage = EmailMessage::getById($emailMessageId);
return $emailMessage;
}
示例2: testRun
public function testRun()
{
$super = User::getByUsername('super');
Yii::app()->user->userModel = $super;
$box = EmailBox::resolveAndGetByName(EmailBox::NOTIFICATIONS_NAME);
$outboxFolder = EmailFolder::getByBoxAndType($box, EmailFolder::TYPE_OUTBOX);
$sentFolder = EmailFolder::getByBoxAndType($box, EmailFolder::TYPE_SENT);
$emailMessage = EmailMessageTestHelper::createDraftSystemEmail('My Email Message', $super);
$emailMessage->folder = $outboxFolder;
$saved = $emailMessage->save();
$this->assertTrue($saved);
$emailMessageId = $emailMessage->id;
$emailMessage->forget();
unset($emailMessage);
$emailMessage2 = EmailMessageTestHelper::createDraftSystemEmail('My Email Message', $super);
$emailMessage2->folder = $outboxFolder;
$saved = $emailMessage2->save();
$this->assertTrue($saved);
$emailMessage2Id = $emailMessage2->id;
$emailMessage2->forget();
unset($emailMessage2);
$this->assertEquals(2, EmailMessage::getCount());
$job = new ProcessOutboundEmailJob();
$this->assertTrue($job->run());
$emailMessages = EmailMessage::getAll();
$this->assertEquals(2, count($emailMessages));
$emailMessage = EmailMessage::getById($emailMessageId);
$this->assertEquals($sentFolder, $emailMessage->folder);
$emailMessage2 = EmailMessage::getById($emailMessage2Id);
$this->assertEquals($sentFolder, $emailMessage2->folder);
}
示例3: updateFolderForEmailMessageWithSQL
/**
* Update an email message's folder and save it using SQL
* @param EmailMessage $emailMessage
* @param EmailFolder $folder
* @throws NotSupportedException
*/
protected static function updateFolderForEmailMessageWithSQL(EmailMessage &$emailMessage, EmailFolder $folder)
{
// TODO: @Shoaibi/@Jason: Critical0: This fails CampaignItemsUtilTest.php:243
$folderForeignKeyName = RedBeanModel::getForeignKeyName('EmailMessage', 'folder');
$tableName = EmailMessage::getTableName();
$sql = "UPDATE " . DatabaseCompatibilityUtil::quoteString($tableName);
$sql .= " SET " . DatabaseCompatibilityUtil::quoteString($folderForeignKeyName);
$sql .= " = " . $folder->id;
$sql .= " WHERE " . DatabaseCompatibilityUtil::quoteString('id') . " = " . $emailMessage->id;
$effectedRows = ZurmoRedBean::exec($sql);
if ($effectedRows == 1) {
$emailMessageId = $emailMessage->id;
$emailMessage->forgetAll();
$emailMessage = EmailMessage::getById($emailMessageId);
return true;
}
return false;
}
示例4: testUpdateLatestActivityDateTimeWhenAnEmailIsSentOrArchived
public function testUpdateLatestActivityDateTimeWhenAnEmailIsSentOrArchived()
{
$emailMessage = EmailMessageTestHelper::createDraftSystemEmail('subject 1', Yii::app()->user->userModel);
$account3 = AccountTestHelper::createAccountByNameForOwner('account3', Yii::app()->user->userModel);
$account4 = AccountTestHelper::createAccountByNameForOwner('account4', Yii::app()->user->userModel);
$account5 = AccountTestHelper::createAccountByNameForOwner('account4', Yii::app()->user->userModel);
$dateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
$account5->setLatestActivityDateTime($dateTime);
$this->assertTrue($account5->save());
$account3Id = $account3->id;
$account4Id = $account4->id;
$account5Id = $account5->id;
$this->assertNull($account3->latestActivityDateTime);
$this->assertNull($account4->latestActivityDateTime);
$this->assertEquals($dateTime, $account5->latestActivityDateTime);
$emailMessage->sender->personsOrAccounts->add($account3);
$emailMessage->recipients[0]->personsOrAccounts->add($account4);
$emailMessage->recipients[0]->personsOrAccounts->add($account5);
$this->assertTrue($emailMessage->save());
$this->assertNull($account3->latestActivityDateTime);
$this->assertNull($account4->latestActivityDateTime);
$this->assertEquals($dateTime, $account5->latestActivityDateTime);
$emailMessageId = $emailMessage->id;
$emailMessage->forget();
$account3->forget();
$account4->forget();
$account5->forget();
//Retrieve email message and set sentDateTime, at this point the accounts should update with this value
$sentDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time() - 86400);
$emailMessage = EmailMessage::getById($emailMessageId);
$emailMessage->sentDateTime = $sentDateTime;
$this->assertTrue($emailMessage->save());
$account3 = Account::getById($account3Id);
$account4 = Account::getById($account4Id);
$account5 = Account::getById($account5Id);
$this->assertEquals($sentDateTime, $account3->latestActivityDateTime);
$this->assertEquals($sentDateTime, $account4->latestActivityDateTime);
$this->assertEquals($dateTime, $account5->latestActivityDateTime);
}
开发者ID:RamaKavanan,项目名称:InitialVersion,代码行数:39,代码来源:AccountLatestActivityDateTimeDocumentationTest.php
示例5: testSuperUserCompleteMatchVariations
public function testSuperUserCompleteMatchVariations()
{
$super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
$this->runControllerWithNoExceptionsAndGetContent('emailMessages/default/matchingList');
$message1 = EmailMessageTestHelper::createArchivedUnmatchedReceivedMessage($super);
$message1Id = $message1->id;
$message2 = EmailMessageTestHelper::createArchivedUnmatchedReceivedMessage($super);
$message2Id = $message2->id;
$message3 = EmailMessageTestHelper::createArchivedUnmatchedReceivedMessage($super);
$contact = ContactTestHelper::createContactByNameForOwner('gail', $super);
$startingContactState = ContactsUtil::getStartingState();
$startingLeadState = LeadsUtil::getStartingState();
//test validating selecting an existing contact
$this->setGetArray(array('id' => $message1->id));
$this->setPostArray(array('ajax' => 'select-contact-form-' . $message1->id, 'AnyContactSelectForm' => array($message1->id => array('contactId' => $contact->id, 'contactName' => 'Some Name'))));
$this->runControllerWithExitExceptionAndGetContent('emailMessages/default/completeMatch');
//test validating creating a new contact
$this->setGetArray(array('id' => $message1->id));
$this->setPostArray(array('ajax' => 'contact-inline-create-form-' . $message1->id, 'Contact' => array($message1->id => array('firstName' => 'Gail', 'lastName' => 'Green', 'officePhone' => '456765421', 'state' => array('id' => $startingContactState->id)))));
$this->runControllerWithExitExceptionAndGetContent('emailMessages/default/completeMatch');
//test validating creating a new lead
$this->setGetArray(array('id' => $message1->id));
$this->setPostArray(array('ajax' => 'lead-inline-create-form-' . $message1->id, 'Lead' => array($message1->id => array('firstName' => 'Gail', 'lastName' => 'Green', 'officePhone' => '456765421', 'state' => array('id' => $startingLeadState->id)))));
$this->runControllerWithExitExceptionAndGetContent('emailMessages/default/completeMatch');
//test selecting existing contact and saving
$this->assertNull($contact->primaryEmail->emailAddress);
$this->setGetArray(array('id' => $message1->id));
$this->setPostArray(array('AnyContactSelectForm' => array($message1->id => array('contactId' => $contact->id, 'contactName' => 'Some Name'))));
$this->runControllerWithNoExceptionsAndGetContent('emailMessages/default/completeMatch', true);
$message1->forget();
$message1 = EmailMessage::getById($message1Id);
$this->assertNull($contact->primaryEmail->emailAddress);
$this->assertCount(1, $message1->sender->personsOrAccounts);
$this->assertTrue($message1->sender->personsOrAccounts[0]->isSame($contact));
$this->assertEquals('Archived', $message1->folder);
//assert subject of the email going to edit.
$this->setGetArray(array('id' => $contact->id));
$this->runControllerWithNoExceptionsAndGetContent('contacts/default/details');
$this->assertEquals('A test unmatched archived received email', $message1->subject);
//edit subject of email message.
$this->setGetArray(array('id' => $message1->id));
$createEmailMessageFormData = array('subject' => 'A test unmatched archived received email edited');
$this->setPostArray(array('ajax' => 'edit-form', 'EmailMessage' => $createEmailMessageFormData));
$this->runControllerWithRedirectExceptionAndGetUrl('emailMessages/default/edit');
//assert subject is edited or not.
$this->setGetArray(array('id' => $contact->id));
$this->runControllerWithNoExceptionsAndGetContent('contacts/default/details');
$this->assertEquals('A test unmatched archived received email edited', $message1->subject);
//delete email message.
$this->setGetArray(array('id' => $message1->id));
$this->runControllerWithRedirectExceptionAndGetUrl('emailMessages/default/delete', true);
//assert subject not present.
try {
EmailMessage::getById($message1->id);
$this->fail();
} catch (NotFoundException $e) {
//success
}
//Test the default permission was setted
$everyoneGroup = Group::getByName(Group::EVERYONE_GROUP_NAME);
$explicitReadWriteModelPermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem($message1);
$readWritePermitables = $explicitReadWriteModelPermissions->getReadWritePermitables();
$this->assertEquals($everyoneGroup, $readWritePermitables[$everyoneGroup->getClassId('Permitable')]);
//test creating new contact and saving
$this->assertEquals(1, Contact::getCount());
$this->setGetArray(array('id' => $message2->id));
$this->setPostArray(array('Contact' => array($message2->id => array('firstName' => 'George', 'lastName' => 'Patton', 'officePhone' => '456765421', 'state' => array('id' => $startingContactState->id)))));
$this->runControllerWithNoExceptionsAndGetContent('emailMessages/default/completeMatch', true);
$message2->forget();
$message2 = EmailMessage::getById($message2Id);
$this->assertEquals(2, Contact::getCount());
$contacts = Contact::getByName('George Patton');
$contact = $contacts[0];
$this->assertCount(1, $message2->sender->personsOrAccounts);
$this->assertTrue($message2->sender->personsOrAccounts[0]->isSame($contact));
$this->assertEquals('Archived', $message2->folder);
//Test the default permission was setted
$explicitReadWriteModelPermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem($message2);
$readWritePermitables = $explicitReadWriteModelPermissions->getReadWritePermitables();
$this->assertEquals($everyoneGroup, $readWritePermitables[$everyoneGroup->getClassId('Permitable')]);
//test creating new lead and saving
$this->assertEquals(2, Contact::getCount());
$this->setGetArray(array('id' => $message3->id));
$this->setPostArray(array('Lead' => array($message3->id => array('firstName' => 'Billy', 'lastName' => 'Kid', 'officePhone' => '456765421', 'state' => array('id' => $startingLeadState->id)))));
$this->runControllerWithNoExceptionsAndGetContent('emailMessages/default/completeMatch', true);
$this->assertEquals(3, Contact::getCount());
$contacts = Contact::getByName('Billy Kid');
$contact = $contacts[0];
$this->assertCount(1, $message3->sender->personsOrAccounts);
$this->assertTrue($message3->sender->personsOrAccounts[0]->isSame($contact));
$this->assertEquals('Archived', $message3->folder);
//Test the default permission was setted
$explicitReadWriteModelPermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem($message3);
$readWritePermitables = $explicitReadWriteModelPermissions->getReadWritePermitables();
$this->assertEquals($everyoneGroup, $readWritePermitables[$everyoneGroup->getClassId('Permitable')]);
}
示例6: testResolveContactToSenderOrRecipientForReceivedEmail
public function testResolveContactToSenderOrRecipientForReceivedEmail()
{
$super = User::getByUsername('super');
Yii::app()->user->userModel = $super;
$message1 = self::$message1;
$contact = new Contact();
$contact->firstName = 'Jason';
$contact->lastName = 'Green';
$contact->state = ContactsUtil::getStartingState();
$saved = $contact->save();
$this->assertTrue($saved);
$contactId = $contact->id;
$contact->forget();
$contact = Contact::getById($contactId);
$this->assertNull($contact->primaryEmail->emailAddress);
ArchivedEmailMatchingUtil::resolveContactToSenderOrRecipient($message1, $contact);
$saved = $message1->save();
$this->assertTrue($saved);
$messageId = $message1->id;
$message1->forget();
$contact->forget();
RedBeanModel::forgetAll();
//simulates crossing page requests
$message1 = EmailMessage::getById($messageId);
$contact = Contact::getById($contactId);
$this->assertEquals(1, $message1->sender->personsOrAccounts->count());
$castedDownModel = EmailMessageMashableActivityRules::castDownItem($message1->sender->personsOrAccounts[0]);
$this->assertEquals('Contact', get_class($castedDownModel));
$this->assertEquals($contact->id, $castedDownModel->id);
}
示例7: actionDelete
public function actionDelete($id, $redirectUrl = null, $redirect = true)
{
$emailMessage = EmailMessage::getById(intval($id));
if ($redirectUrl == null) {
$redirectUrl = array('/home/default');
}
ControllerSecurityUtil::resolveAccessCanCurrentUserDeleteModel($emailMessage);
$emailMessage->delete();
if ($redirect) {
$this->redirect($redirectUrl);
}
}
示例8: makeEmailMessage
protected function makeEmailMessage(Contact $contact, $subject = null)
{
$interval = mt_rand(4, 35) * 86400;
if (!isset($subject)) {
$subject = 'A test archived sent email';
}
//#1 Create Archived - Sent
$emailMessage = new EmailMessage();
$emailMessage->setScenario('importModel');
$emailMessage->owner = $contact->owner;
$emailMessage->subject = $subject;
$emailContent = new EmailMessageContent();
$emailContent->textContent = 'My First Message';
$emailContent->htmlContent = 'Some fake HTML content';
$emailMessage->content = $emailContent;
//Sending is current user (super)
$sender = new EmailMessageSender();
$sender->fromAddress = 'super@zurmotest.com';
$sender->fromName = 'Super User';
$sender->personsOrAccounts->add(Yii::app()->user->userModel);
$emailMessage->sender = $sender;
//Recipient is BobMessage
$recipient = new EmailMessageRecipient();
$recipient->toAddress = 'bob.message@zurmotest.com';
$recipient->toName = strval($contact);
$recipient->personsOrAccounts->add($contact);
$recipient->type = EmailMessageRecipient::TYPE_TO;
$emailMessage->recipients->add($recipient);
$emailMessage->folder = EmailFolder::getByBoxAndType($this->emailBox, EmailFolder::TYPE_SENT);
$emailMessage->createdDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time() - $interval);
$emailMessage->sentDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time() - $interval + mt_rand(0, 3) * 86400);
$emailMessage->addPermissions(Group::getByName(Group::EVERYONE_GROUP_NAME), Permission::READ_WRITE_CHANGE_PERMISSIONS_CHANGE_OWNER);
$saved = $emailMessage->save();
if (!$saved) {
throw new FailedToSaveModelException();
}
$emailMessage = EmailMessage::getById($emailMessage->id);
AllPermissionsOptimizationUtil::securableItemGivenPermissionsForGroup($emailMessage, Group::getByName(Group::EVERYONE_GROUP_NAME));
$emailMessage->save();
return $emailMessage;
}
示例9: testCreateEmailMessageWithBinaryAttachments
public function testCreateEmailMessageWithBinaryAttachments()
{
$super = User::getByUsername('super');
Yii::app()->user->userModel = $super;
$authenticationData = $this->login();
$headers = array('Accept: application/json', 'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'], 'ZURMO_TOKEN: ' . $authenticationData['token'], 'ZURMO_API_REQUEST_TYPE: REST');
$data['subject'] = 'Test 1 Subject';
$data['textContent'] = 'Test 1 Text Content';
$data['htmlContent'] = 'Test 1 Html Content';
$data['sentFrom']['email'] = 'senderTest@example.com';
$data['recipients'] = array('to' => array(array('name' => 'TO1', 'email' => 'to1@example.com'), array('name' => 'TO2', 'email' => 'to2@example.com')));
$pathToFiles = Yii::getPathOfAlias('application.modules.api.tests.unit.files');
$filePath_1 = $pathToFiles . DIRECTORY_SEPARATOR . 'table.csv';
$filePath_2 = $pathToFiles . DIRECTORY_SEPARATOR . 'image.png';
$filePath_3 = $pathToFiles . DIRECTORY_SEPARATOR . 'text.txt';
$filePath_4 = $pathToFiles . DIRECTORY_SEPARATOR . 'text.abc';
$data['attachments'] = array(array('filename' => 'table.csv', 'attachment' => base64_encode(file_get_contents($filePath_1))), array('filename' => 'image.png', 'attachment' => base64_encode(file_get_contents($filePath_2))), array('filename' => 'text.txt', 'attachment' => base64_encode(file_get_contents($filePath_3))), array('filename' => 'text.abc', 'attachment' => base64_encode(file_get_contents($filePath_4))), array('name' => 'text.abc', 'file' => base64_encode(file_get_contents($filePath_4))));
$response = $this->createApiCallWithRelativeUrl('create/', 'POST', $headers, array('data' => $data));
$response = json_decode($response, true);
$this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']);
$this->assertArrayHasKey('id', $response['data']);
$emailMessageId = $response['data']['id'];
$emailMessage = EmailMessage::getById($emailMessageId);
$this->assertEquals('Test 1 Subject', $emailMessage->subject);
$this->assertEquals('Test 1 Text Content', $emailMessage->content->textContent);
$this->assertEquals('Test 1 Html Content', $emailMessage->content->htmlContent);
$this->assertEquals('senderTest@example.com', $emailMessage->sender->fromAddress);
$this->assertEquals(3, count($emailMessage->files));
$this->assertEquals($data['attachments'][0]['filename'], $emailMessage->files[0]->name);
$this->assertEquals(filesize($filePath_1), $emailMessage->files[0]->size);
$this->assertEquals(md5_file($filePath_1), md5($emailMessage->files[0]->fileContent->content));
$this->assertEquals($data['attachments'][1]['filename'], $emailMessage->files[1]->name);
$this->assertEquals(filesize($filePath_2), $emailMessage->files[1]->size);
$this->assertEquals(md5_file($filePath_2), md5($emailMessage->files[1]->fileContent->content));
$this->assertEquals($data['attachments'][2]['filename'], $emailMessage->files[2]->name);
$this->assertEquals(filesize($filePath_3), $emailMessage->files[2]->size);
$this->assertEquals(md5_file($filePath_3), md5($emailMessage->files[2]->fileContent->content));
}
示例10: testCreateEmailMessageThatIsANotification
/**
* A notification email is different than a regular outbound email because it is owned by a super user
* that is different than the user logged in. So the sender does not have a 'person'
*/
public function testCreateEmailMessageThatIsANotification()
{
$super = User::getByUsername('super');
Yii::app()->user->userModel = $super;
$billy = User::getByUsername('billy');
$this->assertEquals(0, EmailMessage::getCount());
$emailMessage = new EmailMessage();
$emailMessage->owner = BaseControlUserConfigUtil::getUserToRunAs();
$emailMessage->subject = 'My First Email';
//Set sender, and recipient, and content
$emailContent = new EmailMessageContent();
$emailContent->textContent = 'My First Message';
$emailContent->htmlContent = 'Some fake HTML content';
$emailMessage->content = $emailContent;
//Sending from the system, does not have a 'person'.
$sender = new EmailMessageSender();
$sender->fromAddress = 'system@somewhere.com';
$sender->fromName = 'Zurmo System';
$emailMessage->sender = $sender;
//Recipient is billy.
$recipient = new EmailMessageRecipient();
$recipient->toAddress = 'billy@fakeemail.com';
$recipient->toName = 'Billy James';
$recipient->type = EmailMessageRecipient::TYPE_TO;
$recipient->personsOrAccounts->add($billy);
$emailMessage->recipients->add($recipient);
//At this point the message is in no folder
$this->assertTrue($emailMessage->folder->id < 0);
$box = EmailBox::resolveAndGetByName(EmailBox::NOTIFICATIONS_NAME);
$emailMessage->folder = EmailFolder::getByBoxAndType($box, EmailFolder::TYPE_DRAFT);
//Save, at this point the email should be in the draft folder
$saved = $emailMessage->save();
$this->assertTrue($saved);
$this->assertTrue($emailMessage->folder->id > 0);
$this->assertEquals(0, EmailMessageSendError::getCount());
$emailMessageSendError = new EmailMessageSendError();
$data = array();
$data['message'] = 'error message';
$emailMessageSendError->serializedData = serialize($data);
$emailMessage->folder = EmailFolder::getByBoxAndType($emailMessage->folder->emailBox, EmailFolder::TYPE_OUTBOX_ERROR);
$emailMessage->error = $emailMessageSendError;
$saved = $emailMessage->save();
$this->assertTrue($saved);
$this->assertEquals(1, EmailMessageSendError::getCount());
//Now swap the error with a new one
$emailMessageId = $emailMessage->id;
$emailMessage->forget();
$emailMessage = EmailMessage::getById($emailMessageId);
$emailMessageSendError = new EmailMessageSendError();
$data = array();
$data['message'] = 'error message 2';
$emailMessageSendError->serializedData = serialize($data);
$emailMessage->error = $emailMessageSendError;
$saved = $emailMessage->save();
$this->assertTrue($saved);
$this->assertEquals(1, EmailMessageSendError::getCount());
}
示例11: testEmailCopyActivity
public function testEmailCopyActivity()
{
$this->markTestSkipped();
Yii::app()->user->userModel = User::getByUsername('super');
$this->setFirstModel();
$this->setSecondModel();
$emailMessage = EmailMessageTestHelper::createDraftSystemEmail('Subject 1', Yii::app()->user->userModel);
$this->assertTrue($emailMessage->save());
$emailMessageId = $emailMessage->id;
$emailMessage->forgetAll();
$emailMessage = EmailMessage::getById($emailMessageId);
$newSender = new EmailMessageSender();
$newSender->fromAddress = $this->selectedModels[1]->primaryEmail->emailAddress;
$newSender->fromName = strval($this->selectedModels[1]);
$newSender->personsOrAccounts->add($this->selectedModels[1]);
$emailMessage->sender = $newSender;
$emailMessage->save();
ListViewMergeUtil::processCopyEmailActivity($this->selectedModels[0], $this->selectedModels[1]);
$emailMessage = EmailMessage::getById($emailMessageId);
$this->assertEquals(strval($this->selectedModels[0]), $emailMessage->sender->fromName);
$this->assertEquals('test@yahoo.com', $emailMessage->sender->fromAddress);
//For recipient
$emailMessage = EmailMessageTestHelper::createDraftSystemEmail('Subject 2', Yii::app()->user->userModel);
$this->assertTrue($emailMessage->save());
$emailMessageId = $emailMessage->id;
$emailMessage->forgetAll();
$emailMessage = EmailMessage::getById($emailMessageId);
$recipient = new EmailMessageRecipient();
$recipient->toAddress = $this->selectedModels[1]->primaryEmail->emailAddress;
$recipient->toName = strval($this->selectedModels[1]);
$recipient->type = EmailMessageRecipient::TYPE_TO;
$recipient->personsOrAccounts->add($this->selectedModels[1]);
$emailMessage->recipients->add($recipient);
$this->assertTrue($emailMessage->save());
ListViewMergeUtil::processCopyEmailActivity($this->selectedModels[0], $this->selectedModels[1]);
$emailMessage = EmailMessage::getById($emailMessageId);
$recipients = $emailMessage->recipients;
$this->assertCount(2, $recipients);
$this->assertEquals(strval($this->selectedModels[0]), $recipients[1]->toName);
$this->assertEquals('test@yahoo.com', $recipients[1]->toAddress);
$this->assertCount(1, $recipients[1]->personsOrAccounts);
}
示例12: generateAndProcessEmailMessages
public function generateAndProcessEmailMessages($count)
{
$box = EmailBox::resolveAndGetByName(EmailBox::NOTIFICATIONS_NAME);
$outboxFolder = EmailFolder::getByBoxAndType($box, EmailFolder::TYPE_OUTBOX);
$sentFolder = EmailFolder::getByBoxAndType($box, EmailFolder::TYPE_SENT);
$fileNames = array('testImage.png', 'testZip.zip', 'testPDF.pdf');
$emailMessageIds = array();
$files = array();
for ($i = 0; $i < $count; $i++) {
$emailMessage = EmailMessageTestHelper::createDraftSystemEmail('My Email Message ' . $i, $this->user);
foreach ($fileNames as $index => $fileName) {
$file = ZurmoTestHelper::createFileModel($fileName);
$files[$index]['name'] = $fileName;
$files[$index]['type'] = $file->type;
$files[$index]['size'] = $file->size;
$files[$index]['contents'] = $file->fileContent->content;
$emailMessage->files->add($file);
}
$emailMessage->folder = $outboxFolder;
$saved = $emailMessage->save(false);
$this->assertTrue($saved);
$emailMessageIds[] = $emailMessage->id;
$emailMessage->forget();
unset($emailMessage);
}
OutboundEmailBatchSizeConfigUtil::setBatchSize($count + 1);
Yii::app()->jobQueue->deleteAll();
ForgetAllCacheUtil::forgetAllCaches();
$job = new ProcessOutboundEmailJob();
$startedAt = microtime(true);
$this->assertTrue($job->run());
$timeTaken = microtime(true) - $startedAt;
ForgetAllCacheUtil::forgetAllCaches();
$emailMessages = EmailMessage::getAll();
$this->assertEquals($count, count($emailMessages));
foreach ($emailMessageIds as $i => $emailMessageId) {
$emailMessage = EmailMessage::getById($emailMessageId);
$this->assertEquals('My Email Message ' . $i, $emailMessage->subject);
$this->assertEquals(1, $emailMessage->sendAttempts);
$this->assertEquals($sentFolder->id, $emailMessage->folder->id);
$this->assertNotEmpty($emailMessage->files);
$this->assertCount(count($files), $emailMessage->files);
foreach ($emailMessage->files as $index => $file) {
$this->assertEquals($file->name, $emailMessage->files[$index]->name);
$this->assertEquals($file->type, $emailMessage->files[$index]->type);
$this->assertEquals($file->size, $emailMessage->files[$index]->size);
$this->assertEquals($file->fileContent->content, $emailMessage->files[$index]->fileContent->content);
$this->assertEquals($file->fileContent->id, $emailMessage->files[$index]->fileContent->id);
}
}
return $timeTaken;
}
示例13: testCrudForHasOneAndHasManyEmailMessageRelations
public function testCrudForHasOneAndHasManyEmailMessageRelations()
{
$emailMessage = EmailMessageTestHelper::createDraftSystemEmail('test crud relations', $this->user);
$this->assertTrue($emailMessage->save());
$emailMessageId = $emailMessage->id;
$emailMessage->forgetAll();
//Check read hasOne relation
$emailMessage = EmailMessage::getById($emailMessageId);
$emailMessageSender = $emailMessage->sender;
$this->assertEquals('system@somewhere.com', $emailMessageSender->fromAddress);
//Check update hasOne relation
$emailMessageSender->fromAddress = 'system@somewhere.org';
$this->assertTrue($emailMessage->save());
$emailMessage->forgetAll();
$emailMessage = EmailMessage::getById($emailMessageId);
$emailMessageSender = $emailMessage->sender;
$this->assertEquals('system@somewhere.org', $emailMessageSender->fromAddress);
//Check delete hasOne relation
$emailMessageSender2 = new EmailMessageSender();
$emailMessageSender2->fromAddress = 'system@somewhere.org';
$emailMessageSender2->fromName = 'system name';
$emailMessage->sender = $emailMessageSender2;
$this->assertTrue($emailMessage->save());
$emailMessage->forgetAll();
$found = true;
try {
EmailMessageSender::getById($emailMessageSender->id);
} catch (NotFoundException $exception) {
$found = false;
}
$this->assertFalse($found);
//Check read hasMany relation
$emailMessage = EmailMessage::getById($emailMessageId);
$recipients = $emailMessage->recipients;
$recipient = $recipients[0];
$this->assertCount(1, $recipients);
$this->assertEquals('billy@fakeemail.com', $recipient->toAddress);
//Check update hasMany relation
$recipient->toAddress = 'billy@fakeemail.org';
$this->assertTrue($emailMessage->save());
$emailMessage->forgetAll();
$emailMessage = EmailMessage::getById($emailMessageId);
$recipient = $emailMessage->recipients[0];
$this->assertEquals('billy@fakeemail.org', $recipient->toAddress);
//Check add hasMany relation
$recipient = new EmailMessageRecipient();
$recipient->toAddress = 'anne@fakeemail.com';
$recipient->toName = 'Anne Frank';
$recipient->type = EmailMessageRecipient::TYPE_BCC;
$emailMessage->recipients->add($recipient);
$this->assertTrue($emailMessage->save());
$emailMessage->forgetAll();
$emailMessage = EmailMessage::getById($emailMessageId);
$recipients = $emailMessage->recipients;
$recipient = $recipients[1];
$this->assertCount(2, $recipients);
//Check update hasMany relation with more than one model set
$recipient->toAddress = 'anne@fakeemail.org';
$this->assertTrue($emailMessage->save());
$emailMessage->forgetAll();
$emailMessage = EmailMessage::getById($emailMessageId);
$recipient = $emailMessage->recipients[1];
$this->assertEquals('anne@fakeemail.org', $recipient->toAddress);
//Check delete hasMany relation
$emailMessage->recipients->remove($recipient);
$this->assertTrue($emailMessage->save());
$emailMessage->forgetAll();
$found = true;
try {
EmailMessageRecipient::getById($recipient->id);
} catch (NotFoundException $exception) {
$found = false;
}
$this->assertFalse($found);
//Check delete last hasMany relation model
$emailMessage = EmailMessage::getById($emailMessageId);
$recipient = $emailMessage->recipients[0];
$emailMessage->recipients->remove($recipient);
$this->assertTrue($emailMessage->save());
$emailMessage->forgetAll();
$found = true;
try {
EmailMessageRecipient::getById($recipient->id);
} catch (NotFoundException $exception) {
$found = false;
}
$this->assertFalse($found);
$this->assertCount(0, $emailMessage->recipients);
}
示例14: actionDelete
public function actionDelete($id)
{
$emailMessage = EmailMessage::getById(intval($id));
ControllerSecurityUtil::resolveAccessCanCurrentUserDeleteModel($emailMessage);
$emailMessage->delete();
}