/** * Test case when sender email is not user primary email. * In this case system should send notification to superadmin. * * @depends testRunCaseThree */ public function testRunCaseFour() { $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; $user = User::getByUsername('steve'); Yii::app()->imap->connect(); EmailMessage::deleteAll(); Yii::app()->imap->deleteMessages(true); // Check if there are no emails in dropbox $job = new EmailArchivingJob(); $this->assertTrue($job->run()); $this->assertEquals(0, EmailMessage::getCount()); $imapStats = Yii::app()->imap->getMessageBoxStatsDetailed(); $this->assertEquals(0, $imapStats->Nmsgs); Yii::app()->emailHelper->sendRawEmail("Email from invalid user", $user->primaryEmail->emailAddress, array(Yii::app()->imap->imapUsername), 'Some content here', '<strong>Some</strong> content here', null, null, null, self::$userMailer); // Change user email address. $originalUserAddress = $user->primaryEmail->emailAddress; $user = User::getByUsername('steve'); $user->primaryEmail->emailAddress = Yii::app()->params['emailTestAccounts']['testEmailAddress']; $this->assertTrue($user->save()); sleep(30); $job = new EmailArchivingJob(); $this->assertFalse($job->run()); $this->assertContains('Failed to process Message id', $job->getErrorMessage()); $this->assertEquals(1, EmailMessage::getCount()); $this->assertEquals(1, Notification::getCountByTypeAndUser('EmailMessageOwnerNotExist', $super)); $notifications = Notification::getByTypeAndUser('EmailMessageOwnerNotExist', $super); $this->assertContains('Email address does not exist in system', $notifications[0]->notificationMessage->textContent); $this->assertContains('Email address does not exist in system', $notifications[0]->notificationMessage->htmlContent); $this->assertEquals(1, Notification::getCountByTypeAndUser('EmailMessageArchivingEmailAddressNotMatching', $user)); }
/** * Test case when sender email is not user primary email. * In this case system should send email to user. * * @depends testRunCaseThree */ public function testRunCaseFour() { if (!EmailMessageTestHelper::isSetEmailAccountsTestConfiguration()) { $this->markTestSkipped(Zurmo::t('EmailMessagesModule', 'Test email settings are not configured in perInstanceTest.php file.')); } $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; $user = User::getByUsername('steve'); Yii::app()->imap->connect(); $messages = EmailMessage::getAll(); foreach ($messages as $message) { $message->delete(); } Yii::app()->imap->deleteMessages(true); // Check if there are no emails in dropbox $job = new EmailArchivingJob(); $this->assertTrue($job->run()); $this->assertEquals(0, count(EmailMessage::getAll())); $imapStats = Yii::app()->imap->getMessageBoxStatsDetailed(); $this->assertEquals(0, $imapStats->Nmsgs); Yii::app()->emailHelper->sendRawEmail("Email from invalid user", $user->primaryEmail->emailAddress, array(Yii::app()->imap->imapUsername), 'Some content here', '<strong>Some</strong> content here', null, null, null, self::$userMailer); // Change user email address. $originalUserAddress = $user->primaryEmail->emailAddress; $user = User::getByUsername('steve'); $user->primaryEmail->emailAddress = Yii::app()->params['emailTestAccounts']['testEmailAddress']; $this->assertTrue($user->save()); sleep(30); $job = new EmailArchivingJob(); $this->assertFalse($job->run()); $this->assertTrue(strpos($job->getErrorMessage(), 'Failed to process Message id') !== false); $this->assertEquals(1, count(EmailMessage::getAll())); $emailMessages = EmailMessage::getAll(); $this->assertEquals("Invalid email address", $emailMessages[0]->subject); $this->assertTrue(strpos($emailMessages[0]->content->textContent, 'Email address does not exist in system') !== false); $this->assertTrue(strpos($emailMessages[0]->content->htmlContent, 'Email address does not exist in system') !== false); $this->assertEquals($originalUserAddress, $emailMessages[0]->recipients[0]->toAddress); $this->assertEquals(1, Notification::getCountByTypeAndUser('EmailMessageArchivingEmailAddressNotMatching', $user)); }