From: eileen Date: Mon, 1 Feb 2021 04:41:02 +0000 (+1300) Subject: [REF] Prelminary tidy up to support fix for dev/core#2344 X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=3017ca783340006c2aa455c12788e6ba1aa10f58;p=civicrm-core.git [REF] Prelminary tidy up to support fix for dev/core#2344 --- diff --git a/CRM/Contribute/Form/Task/PDFLetterCommon.php b/CRM/Contribute/Form/Task/PDFLetterCommon.php index be8422ac9a..ae64f85c56 100644 --- a/CRM/Contribute/Form/Task/PDFLetterCommon.php +++ b/CRM/Contribute/Form/Task/PDFLetterCommon.php @@ -30,7 +30,7 @@ class CRM_Contribute_Form_Task_PDFLetterCommon extends CRM_Contact_Form_Task_PDF if (empty($formValues)) { $formValues = $form->controller->exportValues($form->getName()); } - list($formValues, $categories, $html_message, $messageToken, $returnProperties) = self::processMessageTemplate($formValues); + [$formValues, $categories, $html_message, $messageToken, $returnProperties] = self::processMessageTemplate($formValues); $isPDF = FALSE; $emailParams = []; if (!empty($formValues['email_options'])) { @@ -82,7 +82,7 @@ class CRM_Contribute_Form_Task_PDFLetterCommon extends CRM_Contact_Form_Task_PDF //@todo - comment on what is stored there $contributionIDs = $form->getVar('_contributionContactIds'); } - list($contributions, $contacts) = self::buildContributionArray($groupBy, $contributionIDs, $returnProperties, $skipOnHold, $skipDeceased, $messageToken, $task, $separator, $form->_includesSoftCredits); + [$contributions, $contacts] = self::buildContributionArray($groupBy, $contributionIDs, $returnProperties, $skipOnHold, $skipDeceased, $messageToken, $task, $separator, $form->_includesSoftCredits); $html = []; $contactHtml = $emailedHtml = []; foreach ($contributions as $contributionId => $contribution) { @@ -135,7 +135,7 @@ class CRM_Contribute_Form_Task_PDFLetterCommon extends CRM_Contact_Form_Task_PDF if (!empty($html)) { $type = $formValues['document_type']; - if ($type == 'pdf') { + if ($type === 'pdf') { CRM_Utils_PDF_Utils::html2pdf($html, "CiviLetter.pdf", FALSE, $formValues); } else { @@ -265,7 +265,7 @@ class CRM_Contribute_Form_Task_PDFLetterCommon extends CRM_Contact_Form_Task_PDF if ($isIncludeSoftCredits) { //@todo find out why this happens & add comments - list($contactID) = explode('-', $item); + [$contactID] = explode('-', $item); $contactID = (int) $contactID; } else { diff --git a/CRM/Utils/Token.php b/CRM/Utils/Token.php index 923635f8ec..4e7633cb32 100644 --- a/CRM/Utils/Token.php +++ b/CRM/Utils/Token.php @@ -1106,7 +1106,7 @@ class CRM_Utils_Token { if ($matches[1]) { foreach ($matches[1] as $token) { - list($type, $name) = preg_split('/\./', $token, 2); + [$type, $name] = preg_split('/\./', $token, 2); if ($name && $type) { if (!isset($tokens[$type])) { $tokens[$type] = []; @@ -1135,7 +1135,7 @@ class CRM_Utils_Token { ); if ($matches[1]) { foreach ($matches[1] as $token) { - list($type, $name) = preg_split('/\./', $token, 2); + [$type, $name] = preg_split('/\./', $token, 2); if ($name) { $returnProperties["{$name}"] = 1; } @@ -1407,7 +1407,7 @@ class CRM_Utils_Token { ); // Prepare variables for calling replaceHookTokens $categories = array_keys($greetingTokens); - list($contact) = $greetingDetails; + [$contact] = $greetingDetails; // Replace tokens defined in Hooks. $tokenString = CRM_Utils_Token::replaceHookTokens($tokenString, $contact[$contactId], $categories); } @@ -1532,7 +1532,7 @@ class CRM_Utils_Token { public static function getUserTokenReplacement($token, $escapeSmarty = FALSE) { $value = ''; - list($objectName, $objectValue) = explode('-', $token, 2); + [$objectName, $objectValue] = explode('-', $token, 2); switch ($objectName) { case 'permission': @@ -1792,6 +1792,7 @@ class CRM_Utils_Token { * @param bool $escapeSmarty * * @return mixed|string + * @throws \CRM_Core_Exception */ public static function getContributionTokenReplacement($token, &$contribution, $html = FALSE, $escapeSmarty = FALSE) { self::_buildContributionTokens(); diff --git a/tests/phpunit/CRM/Contribute/Form/ContributionTest.php b/tests/phpunit/CRM/Contribute/Form/ContributionTest.php index 37ba950956..3bdf2aa968 100644 --- a/tests/phpunit/CRM/Contribute/Form/ContributionTest.php +++ b/tests/phpunit/CRM/Contribute/Form/ContributionTest.php @@ -1161,7 +1161,7 @@ Price Field - Price Field 1 1 $ 100.00 $ 100.00 * * @throws \Exception */ - public function testReSubmitSaleTax($thousandSeparator) { + public function testReSubmitSaleTax($thousandSeparator): void { $this->setCurrencySeparators($thousandSeparator); $this->enableTaxAndInvoicing(); $this->addTaxAccountToFinancialType($this->_financialTypeId); @@ -1205,7 +1205,7 @@ Price Field - Price Field 1 1 $ 100.00 $ 100.00 $mut->checkMailLog($strings); $this->callAPISuccessGetCount('FinancialTrxn', [], 3); $items = $this->callAPISuccess('FinancialItem', 'get', ['sequential' => 1])['values']; - $this->assertEquals(2, count($items)); + $this->assertCount(2, $items); $this->assertEquals('Contribution Amount', $items[0]['description']); $this->assertEquals('Sales Tax', $items[1]['description']); diff --git a/tests/phpunit/CRM/Contribute/Form/Task/PDFLetterCommonTest.php b/tests/phpunit/CRM/Contribute/Form/Task/PDFLetterCommonTest.php index 5d606d0810..e1f9e8e93a 100644 --- a/tests/phpunit/CRM/Contribute/Form/Task/PDFLetterCommonTest.php +++ b/tests/phpunit/CRM/Contribute/Form/Task/PDFLetterCommonTest.php @@ -22,7 +22,7 @@ class CRM_Contribute_Form_Task_PDFLetterCommonTest extends CiviUnitTestCase { protected $_docTypes = NULL; - protected $_contactIds = NULL; + protected $_contactIds; /** * Count how many times the hookTokens is called. @@ -41,6 +41,8 @@ class CRM_Contribute_Form_Task_PDFLetterCommonTest extends CiviUnitTestCase { /** * Clean up after each test. + * + * @throws \CRM_Core_Exception */ public function tearDown() { $this->quickCleanUpFinancialEntities(); @@ -50,8 +52,10 @@ class CRM_Contribute_Form_Task_PDFLetterCommonTest extends CiviUnitTestCase { /** * Test the buildContributionArray function. + * + * @throws \CRM_Core_Exception */ - public function testBuildContributionArray() { + public function testBuildContributionArray(): void { $this->_individualId = $this->individualCreate(); $customGroup = $this->callAPISuccess('CustomGroup', 'create', [ @@ -69,7 +73,7 @@ class CRM_Contribute_Form_Task_PDFLetterCommonTest extends CiviUnitTestCase { ]; $customField = $this->callAPISuccess('CustomField', 'create', $params); $customFieldKey = 'custom_' . $customField['id']; - $campaignTitle = 'Test Campaign ' . substr(sha1(rand()), 0, 7); + $campaignTitle = 'Test Campaign '; $params = [ 'contact_id' => $this->_individualId, @@ -94,7 +98,7 @@ class CRM_Contribute_Form_Task_PDFLetterCommonTest extends CiviUnitTestCase { ], ]; - list($contributions, $contacts) = CRM_Contribute_Form_Task_PDFLetterCommon::buildContributionArray('contact_id', $contributionIDs, $returnProperties, TRUE, TRUE, $messageToken, 'test', '**', FALSE); + [$contributions, $contacts] = CRM_Contribute_Form_Task_PDFLetterCommon::buildContributionArray('contact_id', $contributionIDs, $returnProperties, TRUE, TRUE, $messageToken, 'test', '**', FALSE); $this->assertEquals('Anthony', $contacts[$this->_individualId]['first_name']); $this->assertEquals('emo', $contacts[$this->_individualId]['favourite_emoticon']); @@ -126,8 +130,11 @@ class CRM_Contribute_Form_Task_PDFLetterCommonTest extends CiviUnitTestCase { /** * Test contribution token replacement in * html returned by postProcess function. + * + * @throws \CiviCRM_API3_Exception + * @throws \CRM_Core_Exception */ - public function testPostProcess() { + public function testPostProcess(): void { $this->createLoggedInUser(); $this->_individualId = $this->individualCreate(); foreach (['docx', 'odt'] as $docType) { @@ -171,10 +178,14 @@ class CRM_Contribute_Form_Task_PDFLetterCommonTest extends CiviUnitTestCase { /** * Test assignment of variables when using the group by function. * - * We are looking to see that the contribution aggregate and contributions arrays reflect the most - * recent contact rather than a total aggregate, since we are using group by. + * We are looking to see that the contribution aggregate and contributions + * arrays reflect the most recent contact rather than a total aggregate, + * since we are using group by. + * + * @throws \CiviCRM_API3_Exception + * @throws \CRM_Core_Exception */ - public function testPostProcessGroupByContact() { + public function testPostProcessGroupByContact(): void { $this->createLoggedInUser(); $this->hookClass->setHook('civicrm_tokenValues', [$this, 'hook_aggregateTokenValues']); $this->hookClass->setHook('civicrm_tokens', [$this, 'hook_tokens']);