From 91786f443a2a7bf636d83723404e6cf925b8064d Mon Sep 17 00:00:00 2001 From: eileen Date: Sat, 5 Oct 2019 13:10:20 +0200 Subject: [PATCH] Rename (some) labels to differ from names to simulate the fact they are different in internationalised extensions Adjust tests for renamed labels --- tests/phpunit/CRM/Case/BAO/CaseTest.php | 4 +++- .../Contribute/Form/AdditionalPaymentTest.php | 3 ++- .../Import/Parser/ContributionTest.php | 2 +- .../CRM/Event/BAO/AdditionalPaymentTest.php | 9 +++++--- tests/phpunit/CRM/Export/BAO/ExportTest.php | 2 +- .../CRM/Member/Form/MembershipRenewalTest.php | 6 +++++ .../CRM/Member/Form/MembershipTest.php | 9 ++++++-- tests/phpunit/CRM/Pledge/Form/SearchTest.php | 4 ++-- tests/phpunit/CiviTest/CiviUnitTestCase.php | 22 +++++++++++++++++++ tests/phpunit/api/v3/ContributionPageTest.php | 2 +- tests/phpunit/api/v3/ContributionTest.php | 3 +-- tests/phpunit/api/v3/PledgePaymentTest.php | 15 +++++++++---- tests/phpunit/api/v3/PledgeTest.php | 11 +++++----- 13 files changed, 69 insertions(+), 23 deletions(-) diff --git a/tests/phpunit/CRM/Case/BAO/CaseTest.php b/tests/phpunit/CRM/Case/BAO/CaseTest.php index 2c346a4dc8..5f86d42af3 100644 --- a/tests/phpunit/CRM/Case/BAO/CaseTest.php +++ b/tests/phpunit/CRM/Case/BAO/CaseTest.php @@ -138,6 +138,8 @@ class CRM_Case_BAO_CaseTest extends CiviUnitTestCase { /** * Test that Case count is exactly one for logged in user for user's active role. + * + * @throws \CRM_Core_Exception */ public function testActiveCaseRole() { $individual = $this->individualCreate(); @@ -241,7 +243,7 @@ class CRM_Case_BAO_CaseTest extends CiviUnitTestCase { * } */ public function testGetCasesSummary() { - $cases = CRM_Case_BAO_Case::getCasesSummary(TRUE, 3); + $cases = CRM_Case_BAO_Case::getCasesSummary(); $this->assertEquals(1, $cases['rows']['Housing Support']['Ongoing']['count']); } diff --git a/tests/phpunit/CRM/Contribute/Form/AdditionalPaymentTest.php b/tests/phpunit/CRM/Contribute/Form/AdditionalPaymentTest.php index 48973291f8..3dc683081b 100644 --- a/tests/phpunit/CRM/Contribute/Form/AdditionalPaymentTest.php +++ b/tests/phpunit/CRM/Contribute/Form/AdditionalPaymentTest.php @@ -359,6 +359,7 @@ class CRM_Contribute_Form_AdditionalPaymentTest extends CiviUnitTestCase { * * @param string $typeofContribution * + * @throws \CRM_Core_Exception */ public function createContribution($typeofContribution = 'Pending') { if ($typeofContribution == 'Partially paid') { @@ -377,7 +378,7 @@ class CRM_Contribute_Form_AdditionalPaymentTest extends CiviUnitTestCase { $contribution = $this->callAPISuccess('Contribution', 'create', $contributionParams); $contribution = $this->callAPISuccessGetSingle('Contribution', ['id' => $contribution['id']]); $this->assertNotEmpty($contribution); - $this->assertEquals($typeofContribution, $contribution['contribution_status']); + $this->assertEquals($typeofContribution, CRM_Core_PseudoConstant::getName('CRM_Contribute_BAO_Contribution', 'contribution_status_id', $contribution['contribution_status_id'])); $this->_contributionId = $contribution['id']; } diff --git a/tests/phpunit/CRM/Contribute/Import/Parser/ContributionTest.php b/tests/phpunit/CRM/Contribute/Import/Parser/ContributionTest.php index 7213e1100d..02e42c062b 100644 --- a/tests/phpunit/CRM/Contribute/Import/Parser/ContributionTest.php +++ b/tests/phpunit/CRM/Contribute/Import/Parser/ContributionTest.php @@ -132,7 +132,7 @@ class CRM_Contribute_Import_Parser_ContributionTest extends CiviUnitTestCase { // Note that the expected result should logically be CRM_Import_Parser::valid but writing test to reflect not fix here $this->runImport($values, CRM_Import_Parser::DUPLICATE_UPDATE, NULL); $contribution = $this->callAPISuccessGetSingle('Contribution', ['contact_id' => $contactID]); - $this->assertEquals('Pending', $contribution['contribution_status']); + $this->assertEquals('Pending Label**', $contribution['contribution_status']); $this->callAPISuccess('OptionValue', 'create', [ 'option_group_id' => 'contribution_status', diff --git a/tests/phpunit/CRM/Event/BAO/AdditionalPaymentTest.php b/tests/phpunit/CRM/Event/BAO/AdditionalPaymentTest.php index 4471184896..fd0ec22ae2 100644 --- a/tests/phpunit/CRM/Event/BAO/AdditionalPaymentTest.php +++ b/tests/phpunit/CRM/Event/BAO/AdditionalPaymentTest.php @@ -53,7 +53,7 @@ class CRM_Event_BAO_AdditionalPaymentTest extends CiviUnitTestCase { * @param array $contributionParams * * @return array - * @throws Exception + * @throws \CRM_Core_Exception */ protected function addParticipantWithPayment($feeTotal, $actualPaidAmt, $participantParams = [], $contributionParams = []) { $priceSetId = $this->eventPriceSetCreate($feeTotal); @@ -134,6 +134,9 @@ class CRM_Event_BAO_AdditionalPaymentTest extends CiviUnitTestCase { /** * See https://lab.civicrm.org/dev/core/issues/153 + * + * @throws \CiviCRM_API3_Exception + * @throws \CRM_Core_Exception */ public function testPaymentWithCustomPaymentInstrument() { $feeAmt = 100; @@ -159,7 +162,7 @@ class CRM_Event_BAO_AdditionalPaymentTest extends CiviUnitTestCase { $this->assertEquals(round($paymentInfo['total']), $feeAmt, 'Total amount recorded is not proper'); $this->assertEquals(round($paymentInfo['paid']), $amtPaid, 'Amount paid is not proper'); $this->assertEquals(round($paymentInfo['balance']), $feeAmt, 'Balance amount is not proper'); - $this->assertEquals($paymentInfo['contribution_status'], 'Pending', 'Contribution status is not proper'); + $this->assertEquals($paymentInfo['contribution_status'], 'Pending Label**', 'Contribution status is not correct'); // make additional payment via 'Record Payment' form $form = new CRM_Contribute_Form_AdditionalPayment(); @@ -244,7 +247,7 @@ class CRM_Event_BAO_AdditionalPaymentTest extends CiviUnitTestCase { $this->assertEquals($transaction[1]['status'], 'Completed'); $this->assertEquals($transaction[2]['total_amount'], -50.00); - $this->assertEquals($transaction[2]['status'], 'Refunded'); + $this->assertEquals($transaction[2]['status'], 'Refunded Label**'); } } diff --git a/tests/phpunit/CRM/Export/BAO/ExportTest.php b/tests/phpunit/CRM/Export/BAO/ExportTest.php index 3f2ffdb4a0..86df6ae15a 100644 --- a/tests/phpunit/CRM/Export/BAO/ExportTest.php +++ b/tests/phpunit/CRM/Export/BAO/ExportTest.php @@ -303,7 +303,7 @@ class CRM_Export_BAO_ExportTest extends CiviUnitTestCase { 'Campaign ID' => '', 'Status Override' => '', 'Total Amount' => '200.00', - 'Contribution Status' => 'Pending', + 'Contribution Status' => 'Pending Label**', 'Date Received' => '2019-07-25 07:34:23', 'Payment Method' => 'Check', 'Transaction ID' => '', diff --git a/tests/phpunit/CRM/Member/Form/MembershipRenewalTest.php b/tests/phpunit/CRM/Member/Form/MembershipRenewalTest.php index 94405ce678..a4a41da33a 100644 --- a/tests/phpunit/CRM/Member/Form/MembershipRenewalTest.php +++ b/tests/phpunit/CRM/Member/Form/MembershipRenewalTest.php @@ -208,6 +208,8 @@ class CRM_Member_Form_MembershipRenewalTest extends CiviUnitTestCase { /** * Test the submit function of the membership form. + * + * @throws \CRM_Core_Exception */ public function testSubmitRecur() { $form = $this->getForm(); @@ -408,6 +410,8 @@ class CRM_Member_Form_MembershipRenewalTest extends CiviUnitTestCase { /** * Test the submit function of the membership form. + * + * @throws \CRM_Core_Exception */ public function testSubmitPayLater() { $form = $this->getForm(NULL); @@ -459,6 +463,8 @@ class CRM_Member_Form_MembershipRenewalTest extends CiviUnitTestCase { /** * Test the submit function of the membership form. + * + * @throws \CRM_Core_Exception */ public function testSubmitPayLaterWithBilling() { $form = $this->getForm(NULL); diff --git a/tests/phpunit/CRM/Member/Form/MembershipTest.php b/tests/phpunit/CRM/Member/Form/MembershipTest.php index d70cee2413..a11ccbba8b 100644 --- a/tests/phpunit/CRM/Member/Form/MembershipTest.php +++ b/tests/phpunit/CRM/Member/Form/MembershipTest.php @@ -44,7 +44,6 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { protected $_individualId; protected $_contribution; protected $_financialTypeId = 1; - protected $_apiversion; protected $_entity = 'Membership'; protected $_params; protected $_ids = []; @@ -88,6 +87,8 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { * * Connect to the database, truncate the tables that will be used * and redirect stdin to a temporary file. + * + * @throws \CRM_Core_Exception */ public function setUp() { $this->_apiversion = 3; @@ -140,6 +141,8 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { /** * Test CRM_Member_Form_Membership::formRule() with a parameter * that has an empty contact_select_id value + * + * @throws \CiviCRM_API3_Exception */ public function testFormRuleEmptyContact() { $params = [ @@ -712,13 +715,15 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { /** * Test the submit function of the membership form. + * + * @throws \CRM_Core_Exception */ public function testSubmitRecur() { CRM_Core_Session::singleton()->getStatus(TRUE); $pendingVal = $this->callAPISuccessGetValue('OptionValue', [ 'return' => "id", 'option_group_id' => "contribution_status", - 'label' => "Pending", + 'label' => "Pending Label**", ]); //Update label for Pending contribution status. $this->callAPISuccess('OptionValue', 'create', [ diff --git a/tests/phpunit/CRM/Pledge/Form/SearchTest.php b/tests/phpunit/CRM/Pledge/Form/SearchTest.php index 46eb73ebb3..9e34d8099b 100644 --- a/tests/phpunit/CRM/Pledge/Form/SearchTest.php +++ b/tests/phpunit/CRM/Pledge/Form/SearchTest.php @@ -44,13 +44,13 @@ class CRM_Pledge_Form_SearchTest extends CiviUnitTestCase { 'pledge_next_pay_date' => $date, 'pledge_next_pay_amount' => '20.00', 'pledge_status_id' => '2', - 'pledge_status' => 'Pending', + 'pledge_status' => 'Pending Label**', 'pledge_is_test' => '0', 'pledge_financial_type' => 'Donation', 'pledge_currency' => 'USD', 'campaign' => NULL, 'campaign_id' => NULL, - 'pledge_status_name' => 'Pending', + 'pledge_status_name' => 'Pending Label**', 'checkbox' => 'mark_x_1', 'action' => 'ViewEditmore', 'contact_type' => '
', diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index 8cc6355d74..8e0109380a 100644 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -359,6 +359,7 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase { $_REQUEST = $_GET = $_POST = []; error_reporting(E_ALL); + $this->renameLabels(); $this->_sethtmlGlobals(); } @@ -451,6 +452,7 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase { */ protected function tearDown() { $this->_apiversion = 3; + $this->resetLabels(); error_reporting(E_ALL & ~E_NOTICE); CRM_Utils_Hook::singleton()->reset(); @@ -3320,4 +3322,24 @@ AND ( TABLE_NAME LIKE 'civicrm_value_%' ) return $csv; } + /** + * Rename various labels to not match the names. + * + * Doing these mimics the fact the name != the label in international installs & triggers failures in + * code that expects it to. + */ + protected function renameLabels() { + $replacements = ['Pending', 'Refunded']; + foreach ($replacements as $name) { + CRM_Core_DAO::executeQuery("UPDATE civicrm_option_value SET label = '{$name} Label**' where label = '{$name}' AND name = '{$name}'"); + } + } + + /** + * Undo any label renaming. + */ + protected function resetLabels() { + CRM_Core_DAO::executeQuery("UPDATE civicrm_option_value SET label = REPLACE(name, ' Label**', '') WHERE label LIKE '% Label**'"); + } + } diff --git a/tests/phpunit/api/v3/ContributionPageTest.php b/tests/phpunit/api/v3/ContributionPageTest.php index 631dc3a922..9afeef81a1 100644 --- a/tests/phpunit/api/v3/ContributionPageTest.php +++ b/tests/phpunit/api/v3/ContributionPageTest.php @@ -541,7 +541,7 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { $contributions = $this->callAPISuccess('contribution', 'get', ['contribution_page_id' => $this->_ids['contribution_page']]); $this->assertCount(2, $contributions['values']); foreach ($contributions['values'] as $val) { - $this->assertEquals('Pending', $val['contribution_status']); + $this->assertEquals(CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Pending'), $val['contribution_status_id']); } //Membership should be in Pending state. diff --git a/tests/phpunit/api/v3/ContributionTest.php b/tests/phpunit/api/v3/ContributionTest.php index a63b33bb9a..c7f938fb88 100644 --- a/tests/phpunit/api/v3/ContributionTest.php +++ b/tests/phpunit/api/v3/ContributionTest.php @@ -1861,8 +1861,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { $this->assertEquals($p2['fee_amount'], $res['fee_amount']); $this->assertEquals($p2['trxn_id'], $res['trxn_id']); $this->assertEquals($p2['invoice_id'], $res['invoice_id']); - // contribution_status_id = 2 => Pending - $this->assertEquals('Pending', $res['contribution_status']); + $this->assertEquals(CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Pending'), $res['contribution_status_id']); $this->contributionDelete($contribution1['id']); $this->contributionDelete($contribution2['id']); diff --git a/tests/phpunit/api/v3/PledgePaymentTest.php b/tests/phpunit/api/v3/PledgePaymentTest.php index 5de1670e48..17a2c98d85 100644 --- a/tests/phpunit/api/v3/PledgePaymentTest.php +++ b/tests/phpunit/api/v3/PledgePaymentTest.php @@ -35,12 +35,15 @@ class api_v3_PledgePaymentTest extends CiviUnitTestCase { protected $_individualId; protected $_pledgeID; - protected $_apiversion = 3; protected $_contributionID; protected $_financialTypeId = 1; protected $_entity = 'PledgePayment'; - public $DBResetRequired = TRUE; + /** + * Setup for tests. + * + * @throws \CRM_Core_Exception + */ public function setUp() { parent::setUp(); $this->_individualId = $this->individualCreate(); @@ -48,6 +51,10 @@ class api_v3_PledgePaymentTest extends CiviUnitTestCase { $this->_contributionID = $this->contributionCreate(['contact_id' => $this->_individualId]); } + /** + * Clean up after function. + * @throws \CRM_Core_Exception + */ public function tearDown() { $tablesToTruncate = [ 'civicrm_contribution', @@ -106,7 +113,7 @@ class api_v3_PledgePaymentTest extends CiviUnitTestCase { 'id' => $this->_pledgeID, 'return' => 'pledge_status', ]); - $this->assertEquals('Pending', $checkStatus['pledge_status']); + $this->assertEquals('Pending Label**', $checkStatus['pledge_status']); //Execute process_pledge job log. $result = $this->callAPISuccess('Job', 'process_pledge', []); @@ -129,7 +136,7 @@ class api_v3_PledgePaymentTest extends CiviUnitTestCase { 'id' => $this->_pledgeID, 'return' => 'pledge_status', ]); - $this->assertEquals('Pending', $checkStatus['pledge_status']); + $this->assertEquals('Pending Label**', $checkStatus['pledge_status']); //Make first payment. $paymentParams = [ diff --git a/tests/phpunit/api/v3/PledgeTest.php b/tests/phpunit/api/v3/PledgeTest.php index 36eb602b23..6c09644595 100644 --- a/tests/phpunit/api/v3/PledgeTest.php +++ b/tests/phpunit/api/v3/PledgeTest.php @@ -35,12 +35,13 @@ class api_v3_PledgeTest extends CiviUnitTestCase { protected $_individualId; protected $_pledge; - protected $_apiversion; protected $_params; protected $_entity; protected $scheduled_date; - public $DBResetRequired = TRUE; + /** + * @throws \CRM_Core_Exception + */ public function setUp() { $this->_apiversion = 3; parent::setUp(); @@ -119,7 +120,7 @@ class api_v3_PledgeTest extends CiviUnitTestCase { $this->assertEquals($this->_pledge['id'], $pledge['pledge_id']); $this->assertEquals(date('Y-m-d') . ' 00:00:00', $pledge['pledge_create_date']); $this->assertEquals(100.00, $pledge['pledge_amount']); - $this->assertEquals('Pending', $pledge['pledge_status']); + $this->assertEquals('Pending Label**', $pledge['pledge_status']); $this->assertEquals(5, $pledge['pledge_frequency_interval']); $this->assertEquals('year', $pledge['pledge_frequency_unit']); $this->assertEquals(date('Y-m-d', strtotime($this->scheduled_date)) . ' 00:00:00', $pledge['pledge_next_pay_date']); @@ -426,7 +427,7 @@ class api_v3_PledgeTest extends CiviUnitTestCase { $this->assertEquals($old_contact_id, $this->_individualId); $this->assertEquals($old_frequency_unit, 'year'); $this->assertEquals($old_frequency_interval, 5); - $this->assertEquals($old_status_id, 'Pending'); + $this->assertEquals($old_status_id, 'Pending Label**'); $params = [ 'id' => $pledgeID, 'contact_id' => $this->_individualId, @@ -473,7 +474,7 @@ class api_v3_PledgeTest extends CiviUnitTestCase { $this->assertEquals($old_contact_id, $this->_individualId); $this->assertEquals($old_frequency_unit, 'year'); $this->assertEquals($old_frequency_interval, 5); - $this->assertEquals($old_status_id, 'Pending'); + $this->assertEquals($old_status_id, 'Pending Label**'); $params = [ 'id' => $pledgeID, 'contact_id' => $this->_individualId, -- 2.25.1