* @group headless
*/
class CRM_Core_BAO_EmailTest extends CiviUnitTestCase {
+
public function setUp() {
parent::setUp();
- $this->quickCleanup(array('civicrm_contact', 'civicrm_email'));
+ $this->quickCleanup(['civicrm_contact', 'civicrm_email']);
}
/**
public function testAdd() {
$contactId = $this->individualCreate();
- $params = array();
- $params = array(
+ $params = [];
+ $params = [
'email' => 'jane.doe@example.com',
'is_primary' => 1,
'location_type_id' => 1,
'contact_id' => $contactId,
- );
+ ];
CRM_Core_BAO_Email::add($params);
// Now call add() to modify an existing email address
- $params = array();
- $params = array(
+ $params = [];
+ $params = [
'id' => $emailId,
'contact_id' => $contactId,
'is_bulkmail' => 1,
'on_hold' => 1,
- );
+ ];
CRM_Core_BAO_Email::add($params);
public function testHoldEmail() {
$contactId = $this->individualCreate();
- $params = array(
+ $params = [
'email' => 'jane.doe@example.com',
'is_primary' => 1,
'location_type_id' => 1,
'contact_id' => $contactId,
- );
+ ];
CRM_Core_BAO_Email::add($params);
'Database check for created email address.'
);
- // Now call add() to update on_hold=true and check record state
- $params = array();
- $params = array(
+ // Now call add() to update on_hold=1 ("On Hold Bounce") and check record state
+ $params = [];
+ $params = [
'id' => $emailId,
'contact_id' => $contactId,
'on_hold' => 1,
- );
+ ];
CRM_Core_BAO_Email::add($params);
'Check if on_hold=1 in updated email record.'
);
- // Now call add() with on_hold=false and verify that reset_date is set.
- $params = array();
- $params = array(
+ // Now call add() to update on_hold=2 ("On Hold Opt-out") and check record state
+ $params = [];
+ $params = [
'id' => $emailId,
'contact_id' => $contactId,
- 'on_hold' => 'null',
+ 'on_hold' => 2,
+ ];
+
+ CRM_Core_BAO_Email::add($params);
+
+ // Use assertDBNotNull to get back value of hold_date and check that it's in the current year.
+ // NOTE: The assertEquals will fail IF this test is run just as the year is changing (low likelihood).
+ $holdDate = $this->assertDBNotNull('CRM_Core_DAO_Email', $emailId, 'hold_date', 'id',
+ 'Retrieve hold_date from the updated email record.'
);
+ $this->assertEquals(substr($holdDate, 0, 4), substr(date('YmdHis'), 0, 4),
+ 'Compare hold_date (' . $holdDate . ') in DB to current year.'
+ );
+
+ $this->assertDBCompareValue('CRM_Core_DAO_Email', $emailId, 'on_hold', 'id', 2,
+ 'Check if on_hold=2 in updated email record.'
+ );
+
+ // Now call add() with on_hold=null (not on hold) and verify that reset_date is set.
+ $params = [];
+ $params = [
+ 'id' => $emailId,
+ 'contact_id' => $contactId,
+ 'on_hold' => 'null',
+ ];
+
CRM_Core_BAO_Email::add($params);
$this->assertDBCompareValue('CRM_Core_DAO_Email', $emailId, 'on_hold', 'id', 0,
'Check if on_hold=0 in updated email record.'
* AllEmails() method - get all emails for our contact, with primary email first
*/
public function testAllEmails() {
- $contactParams = array(
+ $contactParams = [
'first_name' => 'Alan',
'last_name' => 'Smith',
'email' => 'alan.smith1@example.com',
- 'api.email.create.0' => array('email' => 'alan.smith2@example.com', 'location_type_id' => 'Home'),
- 'api.email.create.1' => array('email' => 'alan.smith3@example.com', 'location_type_id' => 'Main'),
- );
+ 'api.email.create.0' => ['email' => 'alan.smith2@example.com', 'location_type_id' => 'Home'],
+ 'api.email.create.1' => ['email' => 'alan.smith3@example.com', 'location_type_id' => 'Main'],
+ ];
$contactId = $this->individualCreate($contactParams);