Skip to content

Commit

Permalink
Add test for uF group one bug
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Oct 4, 2019
1 parent 9b970fb commit a04af76
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
28 changes: 26 additions & 2 deletions tests/phpunit/CRMTraits/Profile/ProfileTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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([
Expand All @@ -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");
}

}
14 changes: 11 additions & 3 deletions tests/phpunit/api/v3/ContributionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
]);
Expand All @@ -133,6 +135,7 @@ public function tearDown() {
$this->callAPISuccess('FinancialAccount', 'delete', ['id' => $financialAccount['id']]);
}
}
$this->restoreUFGroupOne();
}

/**
Expand Down Expand Up @@ -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,
Expand All @@ -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']);
Expand All @@ -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();
}

Expand Down

0 comments on commit a04af76

Please sign in to comment.