Merge pull request #10946 from mattwire/CRM-21037_activity_sendsms_unittests
[civicrm-core.git] / tests / phpunit / api / v3 / EmailTest.php
index da77eea2773fe863c07d1fa0f736e180260d84c9..a9165a437ac71b57edb29302c487b43f3b28547c 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
-| CiviCRM version 4.7                                                |
+| CiviCRM version 5                                                  |
 +--------------------------------------------------------------------+
 | Copyright CiviCRM LLC (c) 2004-2018                                |
 +--------------------------------------------------------------------+
@@ -376,4 +376,38 @@ class api_v3_EmailTest extends CiviUnitTestCase {
     $this->assertEquals('1-2@example.com', $get['values'][$emailID]['email']);
   }
 
+  public function testEmailOnHold() {
+    $params = array();
+    $params_change = array();
+    $params = array(
+      'contact_id' => $this->_contactID,
+      'email' => 'api@a-team.com',
+      'on_hold' => '2',
+    );
+    $result = $this->callAPIAndDocument('email', 'create', $params, __FUNCTION__, __FILE__);
+    $this->assertEquals(1, $result['count']);
+    $this->assertNotNull($result['id']);
+    $this->assertNotNull($result['values'][$result['id']]['id']);
+    $this->assertEquals(2, $result['values'][$result['id']]['on_hold']);
+    $this->assertEquals(date('Y-m-d H:i'), date('Y-m-d H:i', strtotime($result['values'][$result['id']]['hold_date'])));
+
+    // set on_hold is '0'
+    // if isMultipleBulkMail is active, the value in On-hold select is string
+    $params_change = array(
+      'id' => $result['id'],
+      'contact_id' => $this->_contactID,
+      'email' => 'api@a-team.com',
+      'is_primary' => 1,
+      'on_hold' => '0',
+    );
+    $result_change = $this->callAPISuccess('email', 'create', $params_change + array('action' => 'get'));
+    $this->assertEquals(1, $result_change['count']);
+    $this->assertEquals($result['id'], $result_change['id']);
+    $this->assertEmpty($result_change['values'][$result_change['id']]['on_hold']);
+    $this->assertEquals(date('Y-m-d H:i'), date('Y-m-d H:i', strtotime($result_change['values'][$result_change['id']]['reset_date'])));
+    $this->assertEmpty($result_change['values'][$result_change['id']]['hold_date']);
+
+    $delresult = $this->callAPISuccess('email', 'delete', array('id' => $result['id']));
+  }
+
 }