From 3c27d4678c370b3a01d950b3fc08ac7a366aa28e Mon Sep 17 00:00:00 2001 From: eileen Date: Tue, 7 Feb 2017 15:09:36 +1300 Subject: [PATCH] Test classes tidy up. Mostly replacing instances of callAPIAndDocument with callAPISuccess where they are overwriting other test generated examples. I put this down to copy and paste --- tests/phpunit/api/v3/ContactTest.php | 8 +++---- tests/phpunit/api/v3/EventTest.php | 21 ++++++++----------- tests/phpunit/api/v3/MailingTest.php | 8 +++---- tests/phpunit/api/v3/PaymentProcessorTest.php | 16 ++++---------- tests/phpunit/api/v3/PcpTest.php | 6 +++--- tests/phpunit/api/v3/ProfileTest.php | 2 +- .../api/v3/TaxContributionPageTest.php | 10 ++++----- 7 files changed, 29 insertions(+), 42 deletions(-) diff --git a/tests/phpunit/api/v3/ContactTest.php b/tests/phpunit/api/v3/ContactTest.php index cfe690a31c..6bbcacc7e6 100644 --- a/tests/phpunit/api/v3/ContactTest.php +++ b/tests/phpunit/api/v3/ContactTest.php @@ -572,7 +572,7 @@ class api_v3_ContactTest extends CiviUnitTestCase { ), ); - $result = $this->callAPIAndDocument('Contact', 'create', $params, __FUNCTION__, __FILE__); + $result = $this->callAPISuccess('Contact', 'create', $params); $customFldId = $result['values'][$result['id']]['api.CustomField.create']['id']; $this->assertNotNull($result['id']); $this->assertNotNull($customFldId); @@ -583,7 +583,7 @@ class api_v3_ContactTest extends CiviUnitTestCase { 'api.CustomValue.get' => 1, ); - $result = $this->callAPIAndDocument('Contact', 'create', $params, __FUNCTION__, __FILE__); + $result = $this->callAPISuccess('Contact', 'create', $params); $this->assertNotNull($result['id']); $customFldDate = date("YmdHis", strtotime($result['values'][$result['id']]['api.CustomValue.get']['values'][0]['latest'])); $this->assertNotNull($customFldDate); @@ -606,14 +606,14 @@ class api_v3_ContactTest extends CiviUnitTestCase { ), 'api.CustomValue.get' => 1, ); - $result = $this->callAPIAndDocument('Contact', 'create', $params, __FUNCTION__, __FILE__); + $result = $this->callAPISuccess('Contact', 'create', $params); $this->assertNotNull($result['id']); $customFldDate = date("Ymd", strtotime($result['values'][$result['id']]['api.CustomValue.get']['values'][0]['latest'])); $customFldTime = date("His", strtotime($result['values'][$result['id']]['api.CustomValue.get']['values'][0]['latest'])); $this->assertNotNull($customFldDate); $this->assertEquals($dateTime, $customFldDate); $this->assertEquals(000000, $customFldTime); - $this->callAPIAndDocument('Contact', 'create', $params, __FUNCTION__, __FILE__); + $this->callAPISuccess('Contact', 'create', $params); } diff --git a/tests/phpunit/api/v3/EventTest.php b/tests/phpunit/api/v3/EventTest.php index 63b79a3179..ac5f7f2bbd 100644 --- a/tests/phpunit/api/v3/EventTest.php +++ b/tests/phpunit/api/v3/EventTest.php @@ -296,9 +296,8 @@ class api_v3_EventTest extends CiviUnitTestCase { 'api.Event.create' => $eventParams, 'sequential' => 1, ); - $createResult = $this->callAPIAndDocument('LocBlock', 'create', $locBlockParams, __FUNCTION__, __FILE__); + $createResult = $this->callAPISuccess('LocBlock', 'create', $locBlockParams); $locBlockId = $createResult['id']; - $addressId = $createResult['values'][0]['address_id']; $eventId = $createResult['values'][0]['api.Event.create']['id']; // request the event with its loc block: @@ -426,7 +425,7 @@ class api_v3_EventTest extends CiviUnitTestCase { $params['event_type_id'] = 1; $params['custom_' . $customField['id']] = "$contact_id"; - $result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__, $description, $subfile); + $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__, $description, $subfile); // Retrieve the activity, search for the contact. $result = $this->callAPIAndDocument($this->_entity, 'get', array( @@ -562,10 +561,10 @@ class api_v3_EventTest extends CiviUnitTestCase { $this->assertArrayHasKey('id', $result['values'][$result['id']]); $result = $this->callAPISuccess($this->_entity, 'Get', array('id' => $result['id'])); $this->callAPISuccess($this->_entity, 'Delete', array('id' => $result['id'])); - $this->assertEquals('2008-10-21 00:00:00', $result['values'][$result['id']]['start_date'], 'start date is not set in line ' . __LINE__); - $this->assertEquals('2008-10-23 00:00:00', $result['values'][$result['id']]['end_date'], 'end date is not set in line ' . __LINE__); - $this->assertEquals('2008-06-01 00:00:00', $result['values'][$result['id']]['registration_start_date'], 'start date is not set in line ' . __LINE__); - $this->assertEquals('2008-10-15 00:00:00', $result['values'][$result['id']]['registration_end_date'], 'end date is not set in line ' . __LINE__); + $this->assertEquals('2008-10-21 00:00:00', $result['values'][$result['id']]['start_date'], 'start date is not set'); + $this->assertEquals('2008-10-23 00:00:00', $result['values'][$result['id']]['end_date'], 'end date is not set'); + $this->assertEquals('2008-06-01 00:00:00', $result['values'][$result['id']]['registration_start_date'], 'start date is not set'); + $this->assertEquals('2008-10-15 00:00:00', $result['values'][$result['id']]['registration_end_date'], 'end date is not set'); } /** @@ -612,7 +611,7 @@ class api_v3_EventTest extends CiviUnitTestCase { $params = array( 'id' => $this->_eventIds[0], ); - $result = $this->callAPIAndDocument('Event', 'Delete', $params, __FUNCTION__, __FILE__); + $this->callAPIAndDocument('Event', 'Delete', $params, __FUNCTION__, __FILE__); } /** @@ -631,13 +630,13 @@ class api_v3_EventTest extends CiviUnitTestCase { */ public function testDeleteWithExistingParticipant() { $contactID = $this->individualCreate(); - $participantID = $this->participantCreate( + $this->participantCreate( array( 'contactID' => $contactID, 'eventID' => $this->_eventIds[0], ) ); - $result = $this->callAPISuccess('Event', 'Delete', array('id' => $this->_eventIds[0])); + $this->callAPISuccess('Event', 'Delete', array('id' => $this->_eventIds[0])); } public function testDeleteWithWrongEventId() { @@ -648,8 +647,6 @@ class api_v3_EventTest extends CiviUnitTestCase { $result = $this->callAPIFailure('Event', 'Delete', $params); } - ///////////////// civicrm_event_search methods - /** * Test civicrm_event_search with wrong params type. */ diff --git a/tests/phpunit/api/v3/MailingTest.php b/tests/phpunit/api/v3/MailingTest.php index eb60ca1085..04a1b73c6c 100644 --- a/tests/phpunit/api/v3/MailingTest.php +++ b/tests/phpunit/api/v3/MailingTest.php @@ -335,7 +335,7 @@ class api_v3_MailingTest extends CiviUnitTestCase { ); // END SAMPLE DATA - $create = $this->callAPIAndDocument('Mailing', 'create', $params, __FUNCTION__, __FILE__); + $create = $this->callAPISuccess('Mailing', 'create', $params); $preview = $create['values'][$create['id']]['api.MailingRecipients.get']; $this->assertEquals(1, $preview['count']); @@ -758,7 +758,7 @@ SELECT event_queue_id, time_stamp FROM mail_{$type}_temp"; * we can still have working click-trough URLs working (CRM-17959). */ public function testUrlWithMissingTrackingHash() { - $mail = $this->callAPIAndDocument('mailing', 'create', $this->_params + array('scheduled_date' => 'now'), __FUNCTION__, __FILE__); + $mail = $this->callAPISuccess('mailing', 'create', $this->_params + array('scheduled_date' => 'now'), __FUNCTION__, __FILE__); $jobs = $this->callAPISuccess('mailing_job', 'get', array('mailing_id' => $mail['id'])); $this->assertEquals(1, $jobs['count']); @@ -792,10 +792,10 @@ SELECT event_queue_id, time_stamp FROM mail_{$type}_temp"; $this->_params['body_text'] = str_replace("https://civicrm.org", $unicodeURL, $this->_params['body_text']); $this->_params['body_html'] = str_replace("https://civicrm.org", $unicodeURL, $this->_params['body_html']); - $mail = $this->callAPIAndDocument('mailing', 'create', $this->_params + array('scheduled_date' => 'now'), __FUNCTION__, __FILE__); + $mail = $this->callAPISuccess('mailing', 'create', $this->_params + array('scheduled_date' => 'now')); $params = array('mailing_id' => $mail['id'], 'test_email' => 'alice@example.org', 'test_group' => NULL); - $deliveredInfo = $this->callAPISuccess($this->_entity, 'send_test', $params); + $this->callAPISuccess($this->_entity, 'send_test', $params); $sql = "SELECT turl.id as url_id, turl.url, q.id as queue_id FROM civicrm_mailing_trackable_url as turl diff --git a/tests/phpunit/api/v3/PaymentProcessorTest.php b/tests/phpunit/api/v3/PaymentProcessorTest.php index cafbfffd88..b920675e38 100644 --- a/tests/phpunit/api/v3/PaymentProcessorTest.php +++ b/tests/phpunit/api/v3/PaymentProcessorTest.php @@ -57,8 +57,6 @@ class api_v3_PaymentProcessorTest extends CiviUnitTestCase { ); } - ///////////////// civicrm_payment_processor_add methods - /** * Check with no name. */ @@ -66,7 +64,7 @@ class api_v3_PaymentProcessorTest extends CiviUnitTestCase { $payProcParams = array( 'is_active' => 1, ); - $result = $this->callAPIFailure('payment_processor', 'create', $payProcParams); + $this->callAPIFailure('payment_processor', 'create', $payProcParams); } /** @@ -76,8 +74,6 @@ class api_v3_PaymentProcessorTest extends CiviUnitTestCase { $params = $this->_params; $result = $this->callAPIAndDocument('payment_processor', 'create', $params, __FUNCTION__, __FILE__); $this->assertNotNull($result['id']); - - //assertDBState compares expected values in $result to actual values in the DB $this->assertDBState('CRM_Financial_DAO_PaymentProcessor', $result['id'], $params); return $result['id']; } @@ -92,8 +88,6 @@ class api_v3_PaymentProcessorTest extends CiviUnitTestCase { $this->assertAPISuccess($result); } - ///////////////// civicrm_payment_processor_delete methods - /** * Check payment processor delete. */ @@ -103,11 +97,9 @@ class api_v3_PaymentProcessorTest extends CiviUnitTestCase { 'id' => $id, ); - $result = $this->callAPIAndDocument('payment_processor', 'delete', $params, __FUNCTION__, __FILE__); + $this->callAPIAndDocument('payment_processor', 'delete', $params, __FUNCTION__, __FILE__); } - ///////////////// civicrm_payment_processors_get methods - /** * Check with valid params array. */ @@ -121,8 +113,8 @@ class api_v3_PaymentProcessorTest extends CiviUnitTestCase { ); $results = $this->callAPISuccess('payment_processor', 'get', $params); - $this->assertEquals(1, $results['count'], ' in line ' . __LINE__); - $this->assertEquals('test@test.com', $results['values'][$results['id']]['user_name'], ' in line ' . __LINE__); + $this->assertEquals(1, $results['count']); + $this->assertEquals('test@test.com', $results['values'][$results['id']]['user_name']); } } diff --git a/tests/phpunit/api/v3/PcpTest.php b/tests/phpunit/api/v3/PcpTest.php index e366f1d4b0..73d0da3d51 100644 --- a/tests/phpunit/api/v3/PcpTest.php +++ b/tests/phpunit/api/v3/PcpTest.php @@ -91,7 +91,7 @@ class api_v3_PcpTest extends CiviUnitTestCase { $checkCreated = $this->callAPISuccess($this->entity, 'get', array('id' => $entity['id'])); $this->assertEquals(1, $checkCreated['count']); - $result = $this->callAPIAndDocument('Pcp', 'delete', + $this->callAPIAndDocument('Pcp', 'delete', array('id' => $entity['id']), __FUNCTION__, __FILE__); $checkDeleted = $this->callAPISuccess($this->entity, 'get', array('id' => $entity['id'])); @@ -109,8 +109,8 @@ class api_v3_PcpTest extends CiviUnitTestCase { $description = "Demonstrates get + delete in the same call."; $subfile = 'ChainedGetDelete'; $params = array('title' => "Pcp title", 'api.Pcp.delete' => 1); - $result = $this->callAPISuccess('Pcp', 'create', $this->params); - $result = $this->callAPIAndDocument('Pcp', 'get', $params, __FUNCTION__, + $this->callAPISuccess('Pcp', 'create', $this->params); + $this->callAPIAndDocument('Pcp', 'get', $params, __FUNCTION__, __FILE__, $description, $subfile); $this->assertEquals(0, $this->callAPISuccess('Pcp', 'getcount', array())); } diff --git a/tests/phpunit/api/v3/ProfileTest.php b/tests/phpunit/api/v3/ProfileTest.php index 4a56f5355e..622491574a 100644 --- a/tests/phpunit/api/v3/ProfileTest.php +++ b/tests/phpunit/api/v3/ProfileTest.php @@ -73,7 +73,7 @@ class api_v3_ProfileTest extends CiviUnitTestCase { $params = array( 'contact_id' => 1, ); - $result = $this->callAPIFailure('profile', 'get', $params, + $this->callAPIFailure('profile', 'get', $params, 'Mandatory key(s) missing from params array: profile_id' ); } diff --git a/tests/phpunit/api/v3/TaxContributionPageTest.php b/tests/phpunit/api/v3/TaxContributionPageTest.php index 96aee8d35f..91b784f527 100644 --- a/tests/phpunit/api/v3/TaxContributionPageTest.php +++ b/tests/phpunit/api/v3/TaxContributionPageTest.php @@ -241,7 +241,7 @@ class api_v3_TaxContributionPageTest extends CiviUnitTestCase { 'contribution_status_id' => 1, ); - $contribution = $this->callAPIAndDocument('contribution', 'create', $params, __FUNCTION__, __FILE__); + $contribution = $this->callAPISuccess('contribution', 'create', $params); $this->_ids['contributionId'] = $contribution['id']; $this->assertEquals($contribution['values'][$contribution['id']]['contact_id'], $this->_individualId); $this->assertEquals($contribution['values'][$contribution['id']]['total_amount'], 120.00); @@ -284,9 +284,7 @@ class api_v3_TaxContributionPageTest extends CiviUnitTestCase { ), ); - $description = "Create Contribution with Nested Line Items."; - $subfile = "CreateWithNestedLineItems"; - $contribution = $this->callAPIAndDocument('contribution', 'create', $params, __FUNCTION__, __FILE__, $description, $subfile); + $contribution = $this->callAPISuccess('contribution', 'create', $params); $lineItems = $this->callAPISuccess('line_item', 'get', array( 'entity_id' => $contribution['id'], @@ -311,7 +309,7 @@ class api_v3_TaxContributionPageTest extends CiviUnitTestCase { 'source' => 'SSF', 'contribution_status_id' => 2, ); - $contribution = $this->callAPIAndDocument('contribution', 'create', $params, __FUNCTION__, __FILE__); + $contribution = $this->callAPISuccess('contribution', 'create', $params, __FUNCTION__, __FILE__); $this->assertEquals($contribution['values'][$contribution['id']]['contact_id'], $this->_individualId); $this->assertEquals($contribution['values'][$contribution['id']]['total_amount'], 120.00); $this->assertEquals($contribution['values'][$contribution['id']]['financial_type_id'], $this->financialtypeID); @@ -337,7 +335,7 @@ class api_v3_TaxContributionPageTest extends CiviUnitTestCase { 'contribution_status_id' => 2, ); - $contribution = $this->callAPIAndDocument('contribution', 'create', $params, __FUNCTION__, __FILE__); + $contribution = $this->callAPISuccess('contribution', 'create', $params, __FUNCTION__, __FILE__); $this->assertEquals($contribution['values'][$contribution['id']]['contact_id'], $this->_individualId); $this->assertEquals($contribution['values'][$contribution['id']]['total_amount'], 120.00); $this->assertEquals($contribution['values'][$contribution['id']]['financial_type_id'], $this->financialtypeID); -- 2.25.1