X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fapi%2Fv3%2FEmailTest.php;h=85c24952c4cfa5757a7e338808f9d6feada78abe;hb=7d61e75fdbf9dc67efb0d87f8fd273083eb2d487;hp=3f7719172cd0474c0f5be5d3889535935920df1d;hpb=3f9fd3b1ae2edb719ebb485133f25ce7470d4d34;p=civicrm-core.git diff --git a/tests/phpunit/api/v3/EmailTest.php b/tests/phpunit/api/v3/EmailTest.php index 3f7719172c..85c24952c4 100644 --- a/tests/phpunit/api/v3/EmailTest.php +++ b/tests/phpunit/api/v3/EmailTest.php @@ -1,28 +1,12 @@ _contactID = $this->organizationCreate(NULL); $this->_locationType = $this->locationTypeCreate(NULL); - $this->_locationType2 = $this->locationTypeCreate(array( + $this->_locationType2 = $this->locationTypeCreate([ 'name' => 'New Location Type 2', 'vcard_name' => 'New Location Type 2', 'description' => 'Another Location Type', 'is_active' => 1, - )); - $this->_params = array( + ]); + $this->_params = [ 'contact_id' => $this->_contactID, 'location_type_id' => $this->_locationType->id, 'email' => 'api@a-team.com', 'is_primary' => 1, //TODO email_type_id - ); + ]; } /** @@ -66,16 +50,16 @@ class api_v3_EmailTest extends CiviUnitTestCase { $this->_apiversion = $version; $params = $this->_params; //check there are no emails to start with - $get = $this->callAPISuccess('email', 'get', array( + $get = $this->callAPISuccess('email', 'get', [ 'location_type_id' => $this->_locationType->id, - )); + ]); $this->assertEquals(0, $get['count'], 'Contact not successfully deleted In line ' . __LINE__); $result = $this->callAPIAndDocument('email', 'create', $params, __FUNCTION__, __FILE__); $this->assertEquals(1, $result['count']); $this->assertNotNull($result['id']); $this->assertNotNull($result['values'][$result['id']]['id']); - $delresult = $this->callAPISuccess('email', 'delete', array('id' => $result['id'])); + $delresult = $this->callAPISuccess('email', 'delete', ['id' => $result['id']]); } /** @@ -89,9 +73,9 @@ class api_v3_EmailTest extends CiviUnitTestCase { $this->_apiversion = $version; $params = $this->_params; unset($params['location_type_id']); - $result = $this->callAPIAndDocument('email', 'create', $params, __FUNCTION__, __FILE__); + $result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__); $this->assertEquals(CRM_Core_BAO_LocationType::getDefault()->id, $result['values'][$result['id']]['location_type_id']); - $delresult = $this->callAPISuccess('email', 'delete', array('id' => $result['id'])); + $this->callAPISuccess($this->_entity, 'delete', ['id' => $result['id']]); } /** @@ -108,10 +92,10 @@ class api_v3_EmailTest extends CiviUnitTestCase { $email1 = $this->callAPISuccess('email', 'create', $params); //now we check & make sure it has been set to primary $expected = 1; - $check = $this->callAPISuccess('email', 'getcount', array( + $check = $this->callAPISuccess('email', 'getcount', [ 'is_primary' => 1, 'id' => $email1['id'], - ), + ], $expected ); } @@ -124,10 +108,10 @@ class api_v3_EmailTest extends CiviUnitTestCase { $this->_apiversion = $version; $email1 = $this->callAPISuccess('email', 'create', $this->_params); $email2 = $this->callAPISuccess('email', 'create', $this->_params); - $check = $this->callAPISuccess('email', 'getcount', array( + $check = $this->callAPISuccess('email', 'getcount', [ 'is_primary' => 1, 'contact_id' => $this->_contactID, - )); + ]); $this->assertEquals(1, $check); } @@ -137,7 +121,7 @@ class api_v3_EmailTest extends CiviUnitTestCase { */ public function testCreateEmailWithoutEmail($version) { $this->_apiversion = $version; - $result = $this->callAPIFailure('Email', 'Create', array('contact_id' => 4)); + $result = $this->callAPIFailure('Email', 'Create', ['contact_id' => 4]); $this->assertContains('missing', $result['error_message']); $this->assertContains('email', $result['error_message']); } @@ -151,11 +135,11 @@ class api_v3_EmailTest extends CiviUnitTestCase { $result = $this->callAPISuccess('email', 'create', $this->_params); $get = $this->callAPISuccess('email', 'create', $this->_params); $this->assertEquals($get['count'], 1); - $get = $this->callAPISuccess('email', 'create', $this->_params + array('debug' => 1)); + $get = $this->callAPISuccess('email', 'create', $this->_params + ['debug' => 1]); $this->assertEquals($get['count'], 1); - $get = $this->callAPISuccess('email', 'create', $this->_params + array('debug' => 1, 'action' => 'get')); + $get = $this->callAPISuccess('email', 'create', $this->_params + ['debug' => 1, 'action' => 'get']); $this->assertEquals($get['count'], 1); - $delresult = $this->callAPISuccess('email', 'delete', array('id' => $result['id'])); + $delresult = $this->callAPISuccess('email', 'delete', ['id' => $result['id']]); } /** @@ -164,28 +148,28 @@ class api_v3_EmailTest extends CiviUnitTestCase { */ public function testDeleteEmail($version) { $this->_apiversion = $version; - $params = array( + $params = [ 'contact_id' => $this->_contactID, 'location_type_id' => $this->_locationType->id, 'email' => 'api@a-team.com', 'is_primary' => 1, //TODO email_type_id - ); + ]; //check there are no emails to start with - $get = $this->callAPISuccess('email', 'get', array( + $get = $this->callAPISuccess('email', 'get', [ 'location_type_id' => $this->_locationType->id, - )); + ]); $this->assertEquals(0, $get['count'], 'email already exists ' . __LINE__); //create one $create = $this->callAPISuccess('email', 'create', $params); - $result = $this->callAPIAndDocument('email', 'delete', array('id' => $create['id']), __FUNCTION__, __FILE__); + $result = $this->callAPIAndDocument('email', 'delete', ['id' => $create['id']], __FUNCTION__, __FILE__); $this->assertEquals(1, $result['count']); - $get = $this->callAPISuccess('email', 'get', array( + $get = $this->callAPISuccess('email', 'get', [ 'location_type_id' => $this->_locationType->id, - )); + ]); $this->assertEquals(0, $get['count'], 'Contact not successfully deleted In line ' . __LINE__); } @@ -196,93 +180,93 @@ class api_v3_EmailTest extends CiviUnitTestCase { public function testReplaceEmail($version) { $this->_apiversion = $version; // check there are no emails to start with - $get = $this->callAPISuccess('email', 'get', array( + $get = $this->callAPISuccess('email', 'get', [ 'contact_id' => $this->_contactID, - )); + ]); $this->assertEquals(0, $get['count'], 'email already exists ' . __LINE__); // initialize email list with three emails at loc #1 and two emails at loc #2 - $replace1Params = array( + $replace1Params = [ 'contact_id' => $this->_contactID, - 'values' => array( - array( + 'values' => [ + [ 'location_type_id' => $this->_locationType->id, 'email' => '1-1@example.com', 'is_primary' => 1, - ), - array( + ], + [ 'location_type_id' => $this->_locationType->id, 'email' => '1-2@example.com', 'is_primary' => 0, - ), - array( + ], + [ 'location_type_id' => $this->_locationType->id, 'email' => '1-3@example.com', 'is_primary' => 0, - ), - array( + ], + [ 'location_type_id' => $this->_locationType2->id, 'email' => '2-1@example.com', 'is_primary' => 0, - ), - array( + ], + [ 'location_type_id' => $this->_locationType2->id, 'email' => '2-2@example.com', 'is_primary' => 0, - ), - ), - ); + ], + ], + ]; $replace1 = $this->callAPIAndDocument('email', 'replace', $replace1Params, __FUNCTION__, __FILE__); $this->assertEquals(5, $replace1['count']); // check emails at location #1 or #2 - $get = $this->callAPISuccess('email', 'get', array( + $get = $this->callAPISuccess('email', 'get', [ 'contact_id' => $this->_contactID, - )); + ]); $this->assertEquals(5, $get['count'], 'Incorrect email count at ' . __LINE__); // replace the subset of emails in location #1, but preserve location #2 - $replace2Params = array( + $replace2Params = [ 'contact_id' => $this->_contactID, 'location_type_id' => $this->_locationType->id, - 'values' => array( - array( + 'values' => [ + [ 'email' => '1-4@example.com', 'is_primary' => 1, - ), - ), - ); + ], + ], + ]; $replace2 = $this->callAPISuccess('email', 'replace', $replace2Params); $this->assertEquals(1, $replace2['count']); // check emails at location #1 -- all three replaced by one - $get = $this->callAPISuccess('email', 'get', array( + $get = $this->callAPISuccess('email', 'get', [ 'contact_id' => $this->_contactID, 'location_type_id' => $this->_locationType->id, - )); + ]); $this->assertEquals(1, $get['count'], 'Incorrect email count at ' . __LINE__); // check emails at location #2 -- preserve the original two - $get = $this->callAPISuccess('email', 'get', array( + $get = $this->callAPISuccess('email', 'get', [ 'contact_id' => $this->_contactID, 'location_type_id' => $this->_locationType2->id, - )); + ]); $this->assertEquals(2, $get['count'], 'Incorrect email count at ' . __LINE__); // replace the set of emails with an empty set - $replace3Params = array( + $replace3Params = [ 'contact_id' => $this->_contactID, - 'values' => array(), - ); + 'values' => [], + ]; $replace3 = $this->callAPISuccess('email', 'replace', $replace3Params); $this->assertEquals(0, $replace3['count']); // check emails - $get = $this->callAPISuccess('email', 'get', array( + $get = $this->callAPISuccess('email', 'get', [ 'contact_id' => $this->_contactID, - )); + ]); $this->assertAPISuccess($get); $this->assertEquals(0, $get['count'], 'Incorrect email count at ' . __LINE__); } @@ -294,87 +278,87 @@ class api_v3_EmailTest extends CiviUnitTestCase { public function testReplaceEmailsInChain($version) { $this->_apiversion = $version; // check there are no emails to start with - $get = $this->callAPISuccess('email', 'get', array( + $get = $this->callAPISuccess('email', 'get', [ 'contact_id' => $this->_contactID, - )); + ]); $this->assertAPISuccess($get); $this->assertEquals(0, $get['count'], 'email already exists ' . __LINE__); $description = "Demonstrates use of Replace in a nested API call."; $subfile = "NestedReplaceEmail"; // initialize email list with three emails at loc #1 and two emails at loc #2 - $getReplace1Params = array( + $getReplace1Params = [ 'id' => $this->_contactID, - 'api.email.replace' => array( - 'values' => array( - array( + 'api.email.replace' => [ + 'values' => [ + [ 'location_type_id' => $this->_locationType->id, 'email' => '1-1@example.com', 'is_primary' => 1, - ), - array( + ], + [ 'location_type_id' => $this->_locationType->id, 'email' => '1-2@example.com', 'is_primary' => 0, - ), - array( + ], + [ 'location_type_id' => $this->_locationType->id, 'email' => '1-3@example.com', 'is_primary' => 0, - ), - array( + ], + [ 'location_type_id' => $this->_locationType2->id, 'email' => '2-1@example.com', 'is_primary' => 0, - ), - array( + ], + [ 'location_type_id' => $this->_locationType2->id, 'email' => '2-2@example.com', 'is_primary' => 0, - ), - ), - ), - ); + ], + ], + ], + ]; $getReplace1 = $this->callAPIAndDocument('contact', 'get', $getReplace1Params, __FUNCTION__, __FILE__, $description, $subfile); $this->assertEquals(5, $getReplace1['values'][$this->_contactID]['api.email.replace']['count']); // check emails at location #1 or #2 - $get = $this->callAPISuccess('email', 'get', array( + $get = $this->callAPISuccess('email', 'get', [ 'contact_id' => $this->_contactID, - )); + ]); $this->assertEquals(5, $get['count'], 'Incorrect email count at ' . __LINE__); // replace the subset of emails in location #1, but preserve location #2 - $getReplace2Params = array( + $getReplace2Params = [ 'id' => $this->_contactID, - 'api.email.replace' => array( + 'api.email.replace' => [ 'location_type_id' => $this->_locationType->id, - 'values' => array( - array( + 'values' => [ + [ 'email' => '1-4@example.com', 'is_primary' => 1, - ), - ), - ), - ); + ], + ], + ], + ]; $getReplace2 = $this->callAPISuccess('contact', 'get', $getReplace2Params); $this->assertEquals(0, $getReplace2['values'][$this->_contactID]['api.email.replace']['is_error']); $this->assertEquals(1, $getReplace2['values'][$this->_contactID]['api.email.replace']['count']); // check emails at location #1 -- all three replaced by one - $get = $this->callAPISuccess('email', 'get', array( + $get = $this->callAPISuccess('email', 'get', [ 'contact_id' => $this->_contactID, 'location_type_id' => $this->_locationType->id, - )); + ]); $this->assertEquals(1, $get['count'], 'Incorrect email count at ' . __LINE__); // check emails at location #2 -- preserve the original two - $get = $this->callAPISuccess('email', 'get', array( + $get = $this->callAPISuccess('email', 'get', [ 'contact_id' => $this->_contactID, 'location_type_id' => $this->_locationType2->id, - )); + ]); $this->assertEquals(2, $get['count'], 'Incorrect email count at ' . __LINE__); } @@ -385,23 +369,23 @@ class api_v3_EmailTest extends CiviUnitTestCase { public function testReplaceEmailWithId($version) { $this->_apiversion = $version; // check there are no emails to start with - $get = $this->callAPISuccess('email', 'get', array( + $get = $this->callAPISuccess('email', 'get', [ 'contact_id' => $this->_contactID, - )); + ]); $this->assertEquals(0, $get['count'], 'email already exists ' . __LINE__); // initialize email address - $replace1Params = array( + $replace1Params = [ 'contact_id' => $this->_contactID, - 'values' => array( - array( + 'values' => [ + [ 'location_type_id' => $this->_locationType->id, 'email' => '1-1@example.com', 'is_primary' => 1, 'on_hold' => 1, - ), - ), - ); + ], + ], + ]; $replace1 = $this->callAPISuccess('email', 'replace', $replace1Params); $this->assertEquals(1, $replace1['count']); @@ -409,23 +393,23 @@ class api_v3_EmailTest extends CiviUnitTestCase { $emailID = array_shift($keys); // update the email address, but preserve any other fields - $replace2Params = array( + $replace2Params = [ 'contact_id' => $this->_contactID, - 'values' => array( - array( + 'values' => [ + [ 'id' => $emailID, 'email' => '1-2@example.com', - ), - ), - ); + ], + ], + ]; $replace2 = $this->callAPISuccess('email', 'replace', $replace2Params); $this->assertEquals(1, $replace2['count']); // ensure the 'email' was updated while other fields were preserved - $get = $this->callAPISuccess('email', 'get', array( + $get = $this->callAPISuccess('email', 'get', [ 'contact_id' => $this->_contactID, 'location_type_id' => $this->_locationType->id, - )); + ]); $this->assertEquals(1, $get['count'], 'Incorrect email count at ' . __LINE__); $this->assertEquals(1, $get['values'][$emailID]['is_primary']); @@ -434,13 +418,13 @@ class api_v3_EmailTest extends CiviUnitTestCase { } public function testEmailOnHold() { - $params = array(); - $params_change = array(); - $params = array( + $params = []; + $params_change = []; + $params = [ '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']); @@ -450,21 +434,21 @@ class api_v3_EmailTest extends CiviUnitTestCase { // set on_hold is '0' // if isMultipleBulkMail is active, the value in On-hold select is string - $params_change = array( + $params_change = [ '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')); + ]; + $result_change = $this->callAPISuccess('email', 'create', $params_change + ['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'])); + $delresult = $this->callAPISuccess('email', 'delete', ['id' => $result['id']]); } }