Skip to content

Commit

Permalink
CATL-1613: Add unit test to test is_non_case_email_skipped option dur…
Browse files Browse the repository at this point in the history
…ing Inbound Email Processing
  • Loading branch information
i-grou committed Aug 20, 2020
1 parent ed3e70a commit 0e17410
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 2 deletions.
64 changes: 62 additions & 2 deletions tests/phpunit/CRM/Utils/Mail/EmailProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,19 @@ public function setUp() {
public function tearDown() {
CRM_Utils_File::cleanDir(__DIR__ . '/data/mail');
parent::tearDown();
$this->quickCleanup(['civicrm_group', 'civicrm_group_contact', 'civicrm_mailing', 'civicrm_mailing_job', 'civicrm_mailing_event_bounce', 'civicrm_mailing_event_queue', 'civicrm_mailing_group', 'civicrm_mailing_recipients', 'civicrm_contact', 'civicrm_email']);
$this->quickCleanup([
'civicrm_group',
'civicrm_group_contact',
'civicrm_mailing',
'civicrm_mailing_job',
'civicrm_mailing_event_bounce',
'civicrm_mailing_event_queue',
'civicrm_mailing_group',
'civicrm_mailing_recipients',
'civicrm_contact',
'civicrm_email',
'civicrm_activity',
]);
}

/**
Expand Down Expand Up @@ -139,7 +151,6 @@ public function testBounceProcessingDeletedEmail() {
}

/**
*
* Wrapper to check for mailing bounces.
*
* Normally we would call $this->callAPISuccessGetCount but there is not one & there is resistance to
Expand Down Expand Up @@ -169,4 +180,53 @@ public function setUpMailing() {
$this->eventQueue = $this->callAPISuccess('MailingEventQueue', 'get', ['api.MailingEventQueue.create' => ['hash' => 'aaaaaaaaaaaaaaaa']]);
}

/**
* Set up mail account with 'Skip emails which do not have a Case ID or
* Case token' option enabled.
*/
public function setUpSkipNonCasesEmail() {
$this->callAPISuccess('MailSettings', 'get', [
'api.MailSettings.create' => [
'name' => 'mailbox',
'protocol' => 'Localdir',
'source' => __DIR__ . '/data/mail',
'domain' => 'example.com',
'is_default' => '0',
'is_non_case_email_skipped' => TRUE,
],
]);
}

/**
* Test case email processing when is_non_case_email_skipped is enabled.
*/
public function testInboundProcessingCaseEmail() {
$this->setUpSkipNonCasesEmail();
$mail = 'test_cases_email.eml';

copy(__DIR__ . '/data/inbound/' . $mail, __DIR__ . '/data/mail/' . $mail);
$this->callAPISuccess('job', 'fetch_activities', []);
$result = civicrm_api3('Activity', 'get', [
'sequential' => 1,
'subject' => ['LIKE' => "%[case #214bf6d]%"],
]);
$this->assertTrue(!empty($result['values'][0]['id']));
}

/**
* Test non case email processing when is_non_case_email_skipped is enabled.
*/
public function testInboundProcessingNonCaseEmail() {
$this->setUpSkipNonCasesEmail();
$mail = 'test_non_cases_email.eml';

copy(__DIR__ . '/data/inbound/' . $mail, __DIR__ . '/data/mail/' . $mail);
$this->callAPISuccess('job', 'fetch_activities', []);
$result = civicrm_api3('Activity', 'get', [
'sequential' => 1,
'subject' => ['LIKE' => "%Love letter%"],
]);
$this->assertTrue(empty($result['values']));
}

}
15 changes: 15 additions & 0 deletions tests/phpunit/CRM/Utils/Mail/data/inbound/test_cases_email.eml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Delivered-To: [email protected]
Received: by 10.2.13.84 with SMTP id 1234567890;
Wed, 19 Dec 2018 10:01:11 +0100 (CET)
Return-Path: <>
Message-ID: <[email protected]>
Date: Wed, 19 Dec 2018 10:01:07 +0100
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Content-Disposition: inline
From: [email protected]
To: [email protected]
Subject: [case #214bf6d] Magic is here

This test case is full of fun.
15 changes: 15 additions & 0 deletions tests/phpunit/CRM/Utils/Mail/data/inbound/test_non_cases_email.eml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Delivered-To: [email protected]
Received: by 10.2.13.84 with SMTP id 1234567890;
Wed, 19 Dec 2018 10:01:11 +0100 (CET)
Return-Path: <>
Message-ID: <[email protected]>
Date: Wed, 19 Dec 2018 10:01:07 +0100
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Content-Disposition: inline
From: [email protected]
To: [email protected]
Subject: Love letter

I love you unit test, because you are not related to cases.

0 comments on commit 0e17410

Please sign in to comment.