diff --git a/tests/phpunit/CRMTraits/Profile/ProfileTrait.php b/tests/phpunit/CRMTraits/Profile/ProfileTrait.php index b41dbf4a7eb..d6c4d397436 100644 --- a/tests/phpunit/CRMTraits/Profile/ProfileTrait.php +++ b/tests/phpunit/CRMTraits/Profile/ProfileTrait.php @@ -40,9 +40,9 @@ trait CRMTraits_Profile_ProfileTrait { * @param array $ufGroupParams */ protected function createJoinedProfile($joinParams, $ufGroupParams = []) { - $this->createProfile($ufGroupParams); + $profileID = $this->createProfile($ufGroupParams); $joinParams = array_merge([ - 'uf_group_id' => 'our profile', + 'uf_group_id' => $profileID, 'entity_table' => 'civicrm_contribution_page', 'weight' => 1, ], $joinParams); @@ -59,6 +59,8 @@ protected function createJoinedProfile($joinParams, $ufGroupParams = []) { * Create a profile. * * @param $ufGroupParams + * + * @return int */ protected function createProfile($ufGroupParams) { $profile = $this->callAPISuccess('UFGroup', 'create', array_merge([ @@ -74,6 +76,28 @@ protected function createProfile($ufGroupParams) { 'uf_group_id' => $profile['id'], 'field_name' => 'first_name', ]); + return $profile['id']; + } + + /** + * Ensure we don't have a profile with the id or one to ensure that we are not casting an array to it. + */ + protected function eliminateUFGroupOne() { + $profileID = $this->createProfile(['name' => 'dummy_for_removing']); + CRM_Core_DAO::executeQuery("UPDATE civicrm_uf_join SET uf_group_id = $profileID WHERE uf_group_id = 1"); + CRM_Core_DAO::executeQuery("UPDATE civicrm_uf_field SET uf_group_id = $profileID WHERE uf_group_id = 1"); + CRM_Core_DAO::executeQuery('UPDATE civicrm_uf_group SET id = 900 WHERE id = 1'); + $this->ids['UFGroup']['dummy'] = $profileID; + } + + /** + * Bring back UF group one. + */ + protected function restoreUFGroupOne() { + $profileID = $this->ids['UFGroup']['dummy']; + CRM_Core_DAO::executeQuery('UPDATE civicrm_uf_group SET id = 1 WHERE id = 900'); + CRM_Core_DAO::executeQuery("UPDATE civicrm_uf_join SET uf_group_id = 1 WHERE uf_group_id = $profileID"); + CRM_Core_DAO::executeQuery("UPDATE civicrm_uf_field SET uf_group_id = 1 WHERE uf_group_id = $profileID"); } } diff --git a/tests/phpunit/api/v3/ContributionTest.php b/tests/phpunit/api/v3/ContributionTest.php index be3c2059ecd..a63b33bb9a4 100644 --- a/tests/phpunit/api/v3/ContributionTest.php +++ b/tests/phpunit/api/v3/ContributionTest.php @@ -117,13 +117,15 @@ public function setUp() { /** * Clean up after each test. + * + * @throws \CRM_Core_Exception */ public function tearDown() { $this->quickCleanUpFinancialEntities(); $this->quickCleanup(['civicrm_uf_match']); $financialAccounts = $this->callAPISuccess('FinancialAccount', 'get', []); foreach ($financialAccounts['values'] as $financialAccount) { - if ($financialAccount['name'] == 'Test Tax financial account ' || $financialAccount['name'] == 'Test taxable financial Type') { + if ($financialAccount['name'] === 'Test Tax financial account ' || $financialAccount['name'] === 'Test taxable financial Type') { $entityFinancialTypes = $this->callAPISuccess('EntityFinancialAccount', 'get', [ 'financial_account_id' => $financialAccount['id'], ]); @@ -133,6 +135,7 @@ public function tearDown() { $this->callAPISuccess('FinancialAccount', 'delete', ['id' => $financialAccount['id']]); } } + $this->restoreUFGroupOne(); } /** @@ -3058,6 +3061,9 @@ public function testCompleteTransactionWithParticipantRecord() { $this->_individualId = $this->createLoggedInUser(); $contributionID = $this->createPendingParticipantContribution(); $this->createJoinedProfile(['entity_id' => $this->_ids['event']['test'], 'entity_table' => 'civicrm_event']); + $this->createJoinedProfile(['entity_id' => $this->_ids['event']['test'], 'entity_table' => 'civicrm_event', 'weight' => 2], ['name' => 'post_1', 'title' => 'title_post_2', 'frontend_title' => 'public 2']); + $this->createJoinedProfile(['entity_id' => $this->_ids['event']['test'], 'entity_table' => 'civicrm_event', 'weight' => 3], ['name' => 'post_2', 'title' => 'title_post_3', 'frontend_title' => 'public 3']); + $this->eliminateUFGroupOne(); $this->callAPISuccess('contribution', 'completetransaction', [ 'id' => $contributionID, @@ -3074,7 +3080,7 @@ public function testCompleteTransactionWithParticipantRecord() { 'contact_id' => $this->_individualId, ])['values']; - $this->assertEquals(3, count($activities)); + $this->assertCount(3, $activities); $activityNames = array_count_values(CRM_Utils_Array::collect('activity_name', $activities)); // record two activities before and after completing payment for Event registration $this->assertEquals(2, $activityNames['Event Registration']); @@ -3087,7 +3093,9 @@ public function testCompleteTransactionWithParticipantRecord() { 'This letter is a confirmation that your registration has been received and your status has been updated to Registered.', 'First Name: Logged In', 'Public title', - ], ['Back end title']); + 'public 2', + 'public 3', + ], ['Back end title', 'title_post_2', 'title_post_3']); $mut->stop(); }