From 934388bddc2b814681b5cf9ed85413a5e51972e3 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Wed, 22 Sep 2021 07:31:29 +1200 Subject: [PATCH] Test cleanup Fixes passing null to event create. Remove some tests duplicated by syntaxconformance --- .../phpunit/api/v3/ParticipantPaymentTest.php | 69 ++----------------- tests/phpunit/api/v3/ParticipantTest.php | 48 ++++++------- 2 files changed, 28 insertions(+), 89 deletions(-) diff --git a/tests/phpunit/api/v3/ParticipantPaymentTest.php b/tests/phpunit/api/v3/ParticipantPaymentTest.php index 2841eeb44a..56c09e4f55 100644 --- a/tests/phpunit/api/v3/ParticipantPaymentTest.php +++ b/tests/phpunit/api/v3/ParticipantPaymentTest.php @@ -32,7 +32,7 @@ class api_v3_ParticipantPaymentTest extends CiviUnitTestCase { public function setUp(): void { parent::setUp(); $this->useTransaction(TRUE); - $event = $this->eventCreate(NULL); + $event = $this->eventCreate(); $this->_eventID = $event['id']; $this->_contactID = $this->individualCreate(); $this->_createdParticipants = []; @@ -60,29 +60,10 @@ class api_v3_ParticipantPaymentTest extends CiviUnitTestCase { ]); } - /** - * Test civicrm_participant_payment_create with empty params. - */ - public function testPaymentCreateEmptyParams() { - $params = []; - $this->callAPIFailure('participant_payment', 'create', $params); - } - - /** - * Check without contribution_id. - */ - public function testPaymentCreateMissingContributionId() { - //Without Payment EntityID - $params = [ - 'participant_id' => $this->_participantID, - ]; - $this->callAPIFailure('participant_payment', 'create', $params); - } - /** * Check with valid array. */ - public function testPaymentCreate() { + public function testPaymentCreate(): void { //Create Contribution & get contribution ID $contributionID = $this->contributionCreate(['contact_id' => $this->_contactID]); @@ -92,18 +73,14 @@ class api_v3_ParticipantPaymentTest extends CiviUnitTestCase { 'contribution_id' => $contributionID, ]; - $result = $this->callAPIAndDocument('participant_payment', 'create', $params, __FUNCTION__, __FILE__); - $this->assertTrue(array_key_exists('id', $result)); - - //delete created contribution - $this->contributionDelete($contributionID); + $this->callAPIAndDocument('participant_payment', 'create', $params, __FUNCTION__, __FILE__); } /** * Test getPaymentInfo() returns correct * information of the participant payment */ - public function testPaymentInfoForEvent() { + public function testPaymentInfoForEvent(): void { //Create Contribution & get contribution ID $contributionID = $this->contributionCreate(['contact_id' => $this->_contactID]); @@ -120,35 +97,6 @@ class api_v3_ParticipantPaymentTest extends CiviUnitTestCase { $this->assertEquals('100.00', $paymentInfo['total']); } - ///////////////// civicrm_participant_payment_create methods - - /** - * Check with empty array. - */ - public function testPaymentUpdateEmpty() { - $this->callAPIFailure('participant_payment', 'create', []); - } - - /** - * Check with missing participant_id. - */ - public function testPaymentUpdateMissingParticipantId() { - $params = [ - 'contribution_id' => '3', - ]; - $this->callAPIFailure('participant_payment', 'create', $params); - } - - /** - * Check with missing contribution_id. - */ - public function testPaymentUpdateMissingContributionId() { - $params = [ - 'participant_id' => $this->_participantID, - ]; - $participantPayment = $this->callAPIFailure('participant_payment', 'create', $params); - } - /** * Check financial records for offline Participants. */ @@ -251,15 +199,6 @@ class api_v3_ParticipantPaymentTest extends CiviUnitTestCase { $this->callAPISuccess('participant_payment', 'delete', $params); } - /** - * Check with empty array. - */ - public function testPaymentDeleteWithEmptyParams() { - $params = []; - $deletePayment = $this->callAPIFailure('participant_payment', 'delete', $params); - $this->assertEquals('Mandatory key(s) missing from params array: id', $deletePayment['error_message']); - } - /** * Check with wrong id. */ diff --git a/tests/phpunit/api/v3/ParticipantTest.php b/tests/phpunit/api/v3/ParticipantTest.php index f9d20b6c0f..a868a32fa2 100644 --- a/tests/phpunit/api/v3/ParticipantTest.php +++ b/tests/phpunit/api/v3/ParticipantTest.php @@ -34,10 +34,9 @@ class api_v3_ParticipantTest extends CiviUnitTestCase { protected $_params; public function setUp(): void { - $this->_apiversion = 3; parent::setUp(); $this->_entity = 'participant'; - $event = $this->eventCreate(NULL); + $event = $this->eventCreate(); $this->_eventID = $event['id']; $this->_contactID = $this->individualCreate(); @@ -80,12 +79,13 @@ class api_v3_ParticipantTest extends CiviUnitTestCase { ]; // true tells quickCleanup to drop any tables that might have been created in the test $this->quickCleanup($tablesToTruncate, TRUE); + parent::tearDown(); } /** * Check that getCount can count past 25. */ - public function testGetCountLimit() { + public function testGetCountLimit(): void { $contactIDs = []; for ($count = $this->callAPISuccessGetCount('Participant', []); $count < 27; $count++) { @@ -102,7 +102,7 @@ class api_v3_ParticipantTest extends CiviUnitTestCase { /** * Test get participants with role_id. */ - public function testGetParticipantWithRole() { + public function testGetParticipantWithRole(): void { $roleId = [1, 2, 3]; foreach ($roleId as $role) { $this->participantCreate([ @@ -118,7 +118,7 @@ class api_v3_ParticipantTest extends CiviUnitTestCase { $result = $this->callAPISuccess('participant', 'get', $params); //Assert all the returned participants has a role_id of 2 foreach ($result['values'] as $pid => $values) { - $this->assertEquals($values['participant_role_id'], 2); + $this->assertEquals(2, $values['participant_role_id']); } $this->participantCreate([ @@ -131,8 +131,8 @@ class api_v3_ParticipantTest extends CiviUnitTestCase { 'IS NULL' => 1, ]; $result = $this->callAPISuccess('participant', 'get', $params); - foreach ($result['values'] as $pid => $values) { - $this->assertEquals($values['participant_role_id'], NULL); + foreach ($result['values'] as $values) { + $this->assertEquals(NULL, $values['participant_role_id']); } } @@ -143,18 +143,18 @@ class api_v3_ParticipantTest extends CiviUnitTestCase { * variables specific to participant so it can be replicated into other entities * and / or moved to the automated test suite */ - public function testCreateWithCustom() { + public function testCreateWithCustom(): void { $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__); $params = $this->_params; - $params['custom_' . $ids['custom_field_id']] = "custom string"; + $params['custom_' . $ids['custom_field_id']] = 'custom string'; $result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__); $this->assertEquals($result['id'], $result['values'][$result['id']]['id']); $check = $this->callAPISuccess($this->_entity, 'get', ['id' => $result['id']]); - $this->assertEquals("custom string", $check['values'][$check['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__); + $this->assertEquals('custom string', $check['values'][$check['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__); $this->customFieldDelete($ids['custom_field_id']); $this->customGroupDelete($ids['custom_group_id']); @@ -176,8 +176,8 @@ class api_v3_ParticipantTest extends CiviUnitTestCase { $result = $this->callAPISuccess('participant', 'get', $params); $this->assertAPISuccess($result, " in line " . __LINE__); $this->assertEquals($result['values'][$this->_participantID]['event_id'], $this->_eventID); - $this->assertEquals($result['values'][$this->_participantID]['participant_register_date'], '2007-02-19 00:00:00'); - $this->assertEquals($result['values'][$this->_participantID]['participant_source'], 'Wimbeldon'); + $this->assertEquals('2007-02-19 00:00:00', $result['values'][$this->_participantID]['participant_register_date']); + $this->assertEquals('Wimbeldon', $result['values'][$this->_participantID]['participant_source']); $params = [ 'id' => $this->_participantID, 'return' => 'id,participant_register_date,event_id', @@ -229,38 +229,38 @@ class api_v3_ParticipantTest extends CiviUnitTestCase { /** * Check with params id. */ - public function testGetNestedEventGet() { + public function testGetNestedEventGet(): void { //create a second event & add participant to it. - $event = $this->eventCreate(NULL); - $this->callAPISuccess('participant', 'create', [ + $event = $this->eventCreate(); + $this->callAPISuccess('Participant', 'create', [ 'event_id' => $event['id'], 'contact_id' => $this->_contactID, ]); - $description = "Demonstrates use of nested get to fetch event data with participant records."; - $subfile = "NestedEventGet"; + $description = 'Demonstrates use of nested get to fetch event data with participant records.'; + $subfile = 'NestedEventGet'; $params = [ 'id' => $this->_participantID, 'api.event.get' => 1, ]; - $result = $this->callAPIAndDocument('participant', 'get', $params, __FUNCTION__, __FILE__, $description, $subfile); - $this->assertEquals($result['values'][$this->_participantID]['event_id'], $this->_eventID); - $this->assertEquals($result['values'][$this->_participantID]['participant_register_date'], '2007-02-19 00:00:00'); - $this->assertEquals($result['values'][$this->_participantID]['participant_source'], 'Wimbeldon'); - $this->assertEquals($this->_eventID, $result['values'][$this->_participantID]['api.event.get']['id']); + $result = $this->callAPIAndDocument('participant', 'get', $params, __FUNCTION__, __FILE__, $description, $subfile)['values']; + $this->assertEquals($this->_eventID, $result[$this->_participantID]['event_id']); + $this->assertEquals('2007-02-19 00:00:00', $result[$this->_participantID]['participant_register_date']); + $this->assertEquals('Wimbeldon', $result[$this->_participantID]['participant_source']); + $this->assertEquals($this->_eventID, $result[$this->_participantID]['api.event.get']['id']); } /** * Check Participant Get respects return properties. */ - public function testGetWithReturnProperties() { + public function testGetWithReturnProperties(): void { $params = [ 'contact_id' => $this->_contactID, 'return.status_id' => 1, 'return.participant_status_id' => 1, 'options' => ['limit' => 1], ]; - $result = $this->callAPISuccess('participant', 'get', $params); + $result = $this->callAPISuccess('Participant', 'get', $params); $this->assertArrayHasKey('participant_status_id', $result['values'][$result['id']]); } -- 2.25.1