From: eileen Date: Fri, 26 Jul 2013 03:04:19 +0000 (+1200) Subject: CRM-13072 upgrade emailTest X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=e5eb3437d12be1119e5a75a2dfcb96b0574474b2;p=civicrm-core.git CRM-13072 upgrade emailTest --- diff --git a/tests/phpunit/api/v3/EmailTest.php b/tests/phpunit/api/v3/EmailTest.php index c6042bc4d6..4c92d71267 100644 --- a/tests/phpunit/api/v3/EmailTest.php +++ b/tests/phpunit/api/v3/EmailTest.php @@ -1,5 +1,4 @@ $this->_locationType->id, 'email' => 'api@a-team.com', 'is_primary' => 1, - 'version' => $this->_apiversion, + //TODO email_type_id ); } @@ -64,21 +63,16 @@ class api_v3_EmailTest extends CiviUnitTestCase { public function testCreateEmail() { $params = $this->_params; //check there are no emails to start with - $get = civicrm_api('email', 'get', array( - 'version' => 3, - 'location_type_id' => $this->_locationType->id, - )); - $this->assertEquals(0, $get['is_error'], 'In line ' . __LINE__); + $get = $this->callAPISuccess('email', 'get', array( + 'location_type_id' => $this->_locationType->id, + )); $this->assertEquals(0, $get['count'], 'Contact not successfully deleted In line ' . __LINE__); - $result = civicrm_api('email', 'create', $params); - $this->documentMe($params, $result, __FUNCTION__, __FILE__); - $this->assertApiSuccess($result, 'In line ' . __LINE__); + $result = $this->callAPIAndDocument('email', 'create', $params, __FUNCTION__, __FILE__); $this->assertEquals(1, $result['count'], 'In line ' . __LINE__); $this->assertNotNull($result['id'], 'In line ' . __LINE__); $this->assertNotNull($result['values'][$result['id']]['id'], 'In line ' . __LINE__); - $delresult = civicrm_api('email', 'delete', array('id' => $result['id'], 'version' => 3)); - $this->assertEquals(0, $delresult['is_error'], 'In line ' . __LINE__); + $delresult = $this->callAPISuccess('email', 'delete', array('id' => $result['id'])); } /* * If a new email is set to is_primary the prev should no longer be @@ -91,23 +85,21 @@ class api_v3_EmailTest extends CiviUnitTestCase { public function testCreateEmailPrimaryHandlingChangeToPrimary() { $params = $this->_params; unset($params['is_primary']); - $email1 = civicrm_api('email', 'create', $params); - $this->assertApiSuccess($email1, 'In line ' . __LINE__); + $email1 = $this->callAPISuccess('email', 'create', $params); //now we check & make sure it has been set to primary - $check = civicrm_api('email', 'getcount', array( - 'version' => 3, - 'is_primary' => 1, - 'id' => $email1['id'], - )); - $this->assertEquals(1, $check); + $expected = 1; + $check = $this->callAPISuccess('email', 'getcount', array( + 'is_primary' => 1, + 'id' => $email1['id'], + ), + $expected + ); } + public function testCreateEmailPrimaryHandlingChangeExisting() { - $email1 = civicrm_api('email', 'create', $this->_params); - $this->assertApiSuccess($email1, 'In line ' . __LINE__); - $email2 = civicrm_api('email', 'create', $this->_params); - $this->assertApiSuccess($email2, 'In line ' . __LINE__); - $check = civicrm_api('email', 'getcount', array( - 'version' => 3, + $email1 = $this->callAPISuccess('email', 'create', $this->_params); + $email2 = $this->callAPISuccess('email', 'create', $this->_params); + $check = $this->callAPISuccess('email', 'getcount', array( 'is_primary' => 1, 'contact_id' => $this->_contactID, )); @@ -115,26 +107,20 @@ class api_v3_EmailTest extends CiviUnitTestCase { } public function testCreateEmailWithoutEmail() { - $result = civicrm_api('Email', 'Create', array('contact_id' => 4, 'version' => 3)); - $this->assertEquals(1, $result['is_error'], 'In line ' . __LINE__); + $result = $this->callAPIFailure('Email', 'Create', array('contact_id' => 4)); $this->assertContains('missing', $result['error_message'], 'In line ' . __LINE__); $this->assertContains('email', $result['error_message'], 'In line ' . __LINE__); } public function testGetEmail() { - $result = civicrm_api('email', 'create', $this->_params); - $this->assertAPISuccess($result, 'create email in line ' . __LINE__); - $get = civicrm_api('email', 'create', $this->_params); - $this->assertAPISuccess($get, 'In line ' . __LINE__); + $result = $this->callAPISuccess('email', 'create', $this->_params); + $get = $this->callAPISuccess('email', 'create', $this->_params); $this->assertEquals($get['count'], 1); - $get = civicrm_api('email', 'create', $this->_params + array('debug' => 1)); - $this->assertAPISuccess($get, 'In line ' . __LINE__); + $get = $this->callAPISuccess('email', 'create', $this->_params + array('debug' => 1)); $this->assertEquals($get['count'], 1); - $get = civicrm_api('email', 'create', $this->_params + array('debug' => 1, 'action' => 'get')); - $this->assertAPISuccess($get, 'In line ' . __LINE__); + $get = $this->callAPISuccess('email', 'create', $this->_params + array('debug' => 1, 'action' => 'get')); $this->assertEquals($get['count'], 1); - $delresult = civicrm_api('email', 'delete', array('id' => $result['id'], 'version' => 3)); - $this->assertAPISuccess($delresult, 'In line ' . __LINE__); + $delresult = $this->callAPISuccess('email', 'delete', array('id' => $result['id'])); } public function testDeleteEmail() { $params = array( @@ -142,46 +128,35 @@ class api_v3_EmailTest extends CiviUnitTestCase { 'location_type_id' => $this->_locationType->id, 'email' => 'api@a-team.com', 'is_primary' => 1, - 'version' => $this->_apiversion, + //TODO email_type_id ); //check there are no emails to start with - $get = civicrm_api('email', 'get', array( - 'version' => 3, - 'location_type_id' => $this->_locationType->id, - )); - $this->assertEquals(0, $get['is_error'], 'In line ' . __LINE__); + $get = $this->callAPISuccess('email', 'get', array( + 'location_type_id' => $this->_locationType->id, + )); $this->assertEquals(0, $get['count'], 'email already exists ' . __LINE__); //create one - $create = civicrm_api('email', 'create', $params); + $create = $this->callAPISuccess('email', 'create', $params); - $this->assertEquals(0, $create['is_error'], 'In line ' . __LINE__); - - $result = civicrm_api('email', 'delete', array('id' => $create['id'], 'version' => 3)); - $this->documentMe($params, $result, __FUNCTION__, __FILE__); - $this->assertAPISuccess($result, 'In line ' . __LINE__); + $result = $this->callAPIAndDocument('email', 'delete', array('id' => $create['id'],), __FUNCTION__, __FILE__); $this->assertEquals(1, $result['count'], 'In line ' . __LINE__); - $get = civicrm_api('email', 'get', array( - 'version' => 3, - 'location_type_id' => $this->_locationType->id, - )); - $this->assertEquals(0, $get['is_error'], 'In line ' . __LINE__); + $get = $this->callAPISuccess('email', 'get', array( + 'location_type_id' => $this->_locationType->id, + )); $this->assertEquals(0, $get['count'], 'Contact not successfully deleted In line ' . __LINE__); } public function testReplaceEmail() { // check there are no emails to start with - $get = civicrm_api('email', 'get', array( - 'version' => $this->_apiversion, + $get = $this->callAPISuccess('email', 'get', array( 'contact_id' => $this->_contactID, )); - $this->assertAPISuccess($get, 'In line ' . __LINE__); $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( - 'version' => $this->_apiversion, 'contact_id' => $this->_contactID, 'values' => array( array( @@ -211,22 +186,17 @@ class api_v3_EmailTest extends CiviUnitTestCase { ), ), ); - $replace1 = civicrm_api('email', 'replace', $replace1Params); - $this->documentMe($replace1Params, $replace1, __FUNCTION__, __FILE__); - $this->assertAPISuccess($replace1, 'In line ' . __LINE__); + $replace1 = $this->callAPIAndDocument('email', 'replace', $replace1Params, __FUNCTION__, __FILE__); $this->assertEquals(5, $replace1['count'], 'In line ' . __LINE__); // check emails at location #1 or #2 - $get = civicrm_api('email', 'get', array( - 'version' => $this->_apiversion, + $get = $this->callAPISuccess('email', 'get', array( 'contact_id' => $this->_contactID, )); - $this->assertAPISuccess($get, 'In line ' . __LINE__); $this->assertEquals(5, $get['count'], 'Incorrect email count at ' . __LINE__); // replace the subset of emails in location #1, but preserve location #2 $replace2Params = array( - 'version' => $this->_apiversion, 'contact_id' => $this->_contactID, 'location_type_id' => $this->_locationType->id, 'values' => array( @@ -236,43 +206,35 @@ class api_v3_EmailTest extends CiviUnitTestCase { ), ), ); - $replace2 = civicrm_api('email', 'replace', $replace2Params); - // $this->documentMe($replace2Params, $replace2, __FUNCTION__, __FILE__); - $this->assertAPISuccess($replace2, 'In line ' . __LINE__); + $replace2 = $this->callAPISuccess('email', 'replace', $replace2Params); $this->assertEquals(1, $replace2['count'], 'In line ' . __LINE__); // check emails at location #1 -- all three replaced by one - $get = civicrm_api('email', 'get', array( - 'version' => $this->_apiversion, - 'contact_id' => $this->_contactID, - 'location_type_id' => $this->_locationType->id, - )); - $this->assertAPISuccess($get, 'In line ' . __LINE__); + $get = $this->callAPISuccess('email', 'get', array( + '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 = civicrm_api('email', 'get', array( - 'version' => $this->_apiversion, - 'contact_id' => $this->_contactID, - 'location_type_id' => $this->_locationType2->id, - )); - $this->assertAPISuccess($get, 'In line ' . __LINE__); + $get = $this->callAPISuccess('email', 'get', array( + '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( - 'version' => $this->_apiversion, 'contact_id' => $this->_contactID, 'values' => array(), ); - $replace3 = civicrm_api('email', 'replace', $replace3Params); - // $this->documentMe($replace3Params, $replace3, __FUNCTION__, __FILE__); - $this->assertEquals(0, $replace3['is_error'], 'In line ' . __LINE__); + $replace3 = $this->callAPISuccess('email', 'replace', $replace3Params); $this->assertEquals(0, $replace3['count'], 'In line ' . __LINE__); // check emails - $get = civicrm_api('email', 'get', array( - 'version' => $this->_apiversion, + $get = $this->callAPISuccess('email', 'get', array( + 'contact_id' => $this->_contactID, )); $this->assertAPISuccess($get, 'In line ' . __LINE__); @@ -281,8 +243,8 @@ class api_v3_EmailTest extends CiviUnitTestCase { public function testReplaceEmailsInChain() { // check there are no emails to start with - $get = civicrm_api('email', 'get', array( - 'version' => $this->_apiversion, + $get = $this->callAPISuccess('email', 'get', array( + 'contact_id' => $this->_contactID, )); $this->assertAPISuccess($get, 'In line ' . __LINE__); @@ -291,7 +253,7 @@ class api_v3_EmailTest extends CiviUnitTestCase { $subfile = "NestedReplaceEmail"; // initialize email list with three emails at loc #1 and two emails at loc #2 $getReplace1Params = array( - 'version' => $this->_apiversion, + 'id' => $this->_contactID, 'api.email.replace' => array( 'values' => array( @@ -323,23 +285,17 @@ class api_v3_EmailTest extends CiviUnitTestCase { ), ), ); - $getReplace1 = civicrm_api('contact', 'get', $getReplace1Params); - - $this->documentMe($getReplace1Params, $getReplace1, __FUNCTION__, __FILE__, $description, $subfile); - $this->assertAPISuccess($getReplace1['values'][$this->_contactID]['api.email.replace'], 'In line ' . __LINE__); + $getReplace1 = $this->callAPIAndDocument('contact', 'get', $getReplace1Params, __FUNCTION__, __FILE__, $description, $subfile); $this->assertEquals(5, $getReplace1['values'][$this->_contactID]['api.email.replace']['count'], 'In line ' . __LINE__); // check emails at location #1 or #2 - $get = civicrm_api('email', 'get', array( - 'version' => $this->_apiversion, + $get = $this->callAPISuccess('email', 'get', array( 'contact_id' => $this->_contactID, )); - $this->assertAPISuccess($get, 'In line ' . __LINE__); $this->assertEquals(5, $get['count'], 'Incorrect email count at ' . __LINE__); // replace the subset of emails in location #1, but preserve location #2 $getReplace2Params = array( - 'version' => $this->_apiversion, 'id' => $this->_contactID, 'api.email.replace' => array( 'location_type_id' => $this->_locationType->id, @@ -351,43 +307,35 @@ class api_v3_EmailTest extends CiviUnitTestCase { ), ), ); - $getReplace2 = civicrm_api('contact', 'get', $getReplace2Params); - // $this->documentMe($getReplace2Params, $getReplace2, __FUNCTION__, __FILE__); + $getReplace2 = $this->callAPISuccess('contact', 'get', $getReplace2Params); $this->assertEquals(0, $getReplace2['values'][$this->_contactID]['api.email.replace']['is_error'], 'In line ' . __LINE__); $this->assertEquals(1, $getReplace2['values'][$this->_contactID]['api.email.replace']['count'], 'In line ' . __LINE__); // check emails at location #1 -- all three replaced by one - $get = civicrm_api('email', 'get', array( - 'version' => $this->_apiversion, - 'contact_id' => $this->_contactID, - 'location_type_id' => $this->_locationType->id, - )); + $get = $this->callAPISuccess('email', 'get', array( + 'contact_id' => $this->_contactID, + 'location_type_id' => $this->_locationType->id, + )); - $this->assertAPISuccess($get, 'In line ' . __LINE__); $this->assertEquals(1, $get['count'], 'Incorrect email count at ' . __LINE__); // check emails at location #2 -- preserve the original two - $get = civicrm_api('email', 'get', array( - 'version' => $this->_apiversion, - 'contact_id' => $this->_contactID, - 'location_type_id' => $this->_locationType2->id, - )); - $this->assertAPISuccess($get, 'In line ' . __LINE__); + $get = $this->callAPISuccess('email', 'get', array( + 'contact_id' => $this->_contactID, + 'location_type_id' => $this->_locationType2->id, + )); $this->assertEquals(2, $get['count'], 'Incorrect email count at ' . __LINE__); } public function testReplaceEmailWithId() { // check there are no emails to start with - $get = civicrm_api('email', 'get', array( - 'version' => $this->_apiversion, + $get = $this->callAPISuccess('email', 'get', array( 'contact_id' => $this->_contactID, )); - $this->assertAPISuccess($get, 'In line ' . __LINE__); $this->assertEquals(0, $get['count'], 'email already exists ' . __LINE__); // initialize email address $replace1Params = array( - 'version' => $this->_apiversion, 'contact_id' => $this->_contactID, 'values' => array( array( @@ -398,9 +346,7 @@ class api_v3_EmailTest extends CiviUnitTestCase { ), ), ); - $replace1 = civicrm_api('email', 'replace', $replace1Params); - // $this->documentMe($replace1Params, $replace1, __FUNCTION__, __FILE__); - $this->assertAPISuccess($replace1, 'In line ' . __LINE__); + $replace1 = $this->callAPISuccess('email', 'replace', $replace1Params); $this->assertEquals(1, $replace1['count'], 'In line ' . __LINE__); $keys = array_keys($replace1['values']); @@ -408,7 +354,6 @@ class api_v3_EmailTest extends CiviUnitTestCase { // update the email address, but preserve any other fields $replace2Params = array( - 'version' => $this->_apiversion, 'contact_id' => $this->_contactID, 'values' => array( array( @@ -417,18 +362,15 @@ class api_v3_EmailTest extends CiviUnitTestCase { ), ), ); - $replace2 = civicrm_api('email', 'replace', $replace2Params); - // $this->documentMe($replace2Params, $replace2, __FUNCTION__, __FILE__); - $this->assertAPISuccess($replace2, 'In line ' . __LINE__); + $replace2 = $this->callAPISuccess('email', 'replace', $replace2Params); $this->assertEquals(1, $replace2['count'], 'In line ' . __LINE__); // ensure the 'email' was updated while other fields were preserved - $get = civicrm_api('email', 'get', array( - 'version' => $this->_apiversion, - 'contact_id' => $this->_contactID, - 'location_type_id' => $this->_locationType->id, - )); - $this->assertAPISuccess($get, 'In line ' . __LINE__); + $get = $this->callAPISuccess('email', 'get', array( + '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'], 'In line ' . __LINE__); $this->assertEquals(1, $get['values'][$emailID]['on_hold'], 'In line ' . __LINE__);