From b6afc8a1911b86f59548bf61fdf28789f0afc5c3 Mon Sep 17 00:00:00 2001 From: Muhammad Shahrukh <> Date: Thu, 8 Aug 2024 16:49:24 +0500 Subject: [PATCH 1/3] COMCL-670: Fix membership token usage --- CRM/Certificate/Token/Membership.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CRM/Certificate/Token/Membership.php b/CRM/Certificate/Token/Membership.php index affa687..4b43334 100644 --- a/CRM/Certificate/Token/Membership.php +++ b/CRM/Certificate/Token/Membership.php @@ -115,8 +115,8 @@ private function getMembership($membershipId, $contactId) { $status = CRM_Member_BAO_MembershipStatus::getMembershipStatus($result['status_id']); $type = CRM_Member_BAO_MembershipType::getMembershipType($result['membership_type_id']); - $result['status'] = $status['membership_status'] ?? ''; - $result['type'] = $type['name'] ?? ''; + $result['status_idlabel'] = $status['membership_status'] ?? ''; + $result['membership_type_idlabel'] = $type['name'] ?? ''; $result['fee'] = CRM_Utils_Money::format($type['minimum_fee'] ?? ''); return $result; From 958779815b3dc5b6de0981158695401ed88d216c Mon Sep 17 00:00:00 2001 From: Muhammad Shahrukh <> Date: Thu, 8 Aug 2024 16:55:29 +0500 Subject: [PATCH 2/3] COMCL-670: Update CivICRM test version to 5.75.0 --- .github/workflows/unit-test.yml | 34 +++++++++++++++++++-------------- tests/phpunit/bootstrap.php | 5 ++++- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index 6b63a07..11f3fa7 100755 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -34,14 +34,14 @@ jobs: run : amp config:set --mysql_dsn=mysql://root:root@mysql:3306 - name: Build Drupal site - run: civibuild create drupal-clean --civi-ver 5.51.3 --cms-ver 7.79 --web-root $GITHUB_WORKSPACE/site + run: civibuild create drupal-clean --civi-ver 5.75.0 --cms-ver 7.79 --web-root $GITHUB_WORKSPACE/site - uses: compucorp/apply-patch@1.0.0 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: repo: compucorp/civicrm-core - version: 5.51.3 + version: 5.75.0 path: site/web/sites/all/modules/civicrm - uses: actions/checkout@v2 @@ -52,20 +52,26 @@ jobs: working-directory: ${{ env.CIVICRM_EXTENSIONS_DIR }} run: | git clone --depth 1 https://github.com/civicrm/org.civicrm.shoreditch.git - git clone --depth 1 --no-single-branch https://github.com/compucorp/uk.co.compucorp.civicase.git - git clone --depth 1 https://github.com/compucorp/uk.co.compucorp.usermenu.git + git clone --depth 1 -b 4.2.0-dev --no-single-branch https://github.com/compucorp/uk.co.compucorp.civicase.git + git clone --depth 1 -b 2.1.0-dev https://github.com/compucorp/uk.co.compucorp.usermenu.git - - name: Switch Civicase Branch - working-directory: ${{ env.CIVICRM_EXTENSIONS_DIR }}/uk.co.compucorp.civicase + - name: Setup Test DB + run: echo "CREATE DATABASE civicrm_test;" | mysql -u root --password=root --host=mysql + + - name: Update civicrm.settings.php run: | - if [[ $(git ls-remote --heads origin ${GITHUB_HEAD_REF}) ]] - then - git checkout ${GITHUB_HEAD_REF} - elif [[ $(git ls-remote --heads origin ${GITHUB_BASE_REF}) ]] - then - git checkout ${GITHUB_BASE_REF} - fi - shell: bash + FILE_PATH="$GITHUB_WORKSPACE/site/web/sites/default/civicrm.settings.php" + INSERT_LINE="\$GLOBALS['_CV']['TEST_DB_DSN'] = 'mysql://root:root@mysql:3306/civicrm_test?new_link=true';" + TMP_FILE=$(mktemp) + while IFS= read -r line + do + echo "$line" >> "$TMP_FILE" + if [ "$line" = "> "$TMP_FILE" + fi + done < "$FILE_PATH" + mv "$TMP_FILE" "$FILE_PATH" + echo "File modified successfully." - name: Install Certificate and its dependencies working-directory: ${{ env.CIVICRM_EXTENSIONS_DIR }} diff --git a/tests/phpunit/bootstrap.php b/tests/phpunit/bootstrap.php index 5f2c4ec..1f0a1a7 100644 --- a/tests/phpunit/bootstrap.php +++ b/tests/phpunit/bootstrap.php @@ -2,7 +2,10 @@ ini_set('memory_limit', '2G'); -eval(cv('php:boot --level=classloader', 'phpcode')); +define('CIVICRM_CONTAINER_CACHE', 'never'); +define('CIVICRM_TEST', 1); +putenv('CIVICRM_UF=' . ($_ENV['CIVICRM_UF'] = 'UnitTests')); +eval(cv('php:boot --level=settings', 'phpcode')); // phpcs:ignore // Allow autoloading of PHPUnit helper classes in this extension. $loader = new \Composer\Autoload\ClassLoader(); From f108e7e9199c575f856a04fd1874aa4fb247bce9 Mon Sep 17 00:00:00 2001 From: Muhammad Shahrukh <> Date: Fri, 9 Aug 2024 00:38:26 +0500 Subject: [PATCH 3/3] COMCL-670: Fix failing tests --- .github/workflows/unit-test.yml | 2 +- CRM/Certificate/Token/Membership.php | 10 ++++- tests/phpunit/BaseHeadlessTest.php | 37 ------------------- .../Service/CertificateCaseGeneratorTest.php | 6 +-- .../Service/CertificateEventGeneratorTest.php | 14 +++---- .../CertificateMembershipGeneratorTest.php | 4 +- .../GetcontactcertificatesTest.php | 4 +- .../GetrelationshipcertificatesTest.php | 4 +- 8 files changed, 26 insertions(+), 55 deletions(-) diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index 11f3fa7..4177ff9 100755 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -91,4 +91,4 @@ jobs: - name: Run phpunit tests if: ${{ always() }} working-directory: ${{ env.CIVICRM_EXTENSIONS_DIR }}/uk.co.compucorp.certificate - run: phpunit5 + run: phpunit8 diff --git a/CRM/Certificate/Token/Membership.php b/CRM/Certificate/Token/Membership.php index 4b43334..1b4fd56 100644 --- a/CRM/Certificate/Token/Membership.php +++ b/CRM/Certificate/Token/Membership.php @@ -23,7 +23,15 @@ public function __construct($tokenNames = []) { */ public static function entityTokens() { $membershipCustomFields = CRM_Utils_Token::getCustomFieldTokens('Membership'); - $membershipTokens = CRM_Core_SelectValues::membershipTokens(); + $membershipTokens = [ + '{membership.id}' => ts('Membership ID'), + '{membership.status_id:label}' => ts('Status'), + '{membership.membership_type_id:label}' => ts('Membership Type'), + '{membership.start_date}' => ts('Membership Start Date'), + '{membership.join_date}' => ts('Member Since'), + '{membership.end_date}' => ts('Membership Expiration Date'), + '{membership.fee}' => ts('Membership Fee'), + ]; $extraTokens = [ 'source' => ts('Membership Source'), 'membership_name' => ts('Membership Name'), diff --git a/tests/phpunit/BaseHeadlessTest.php b/tests/phpunit/BaseHeadlessTest.php index fe823cb..02c5e35 100644 --- a/tests/phpunit/BaseHeadlessTest.php +++ b/tests/phpunit/BaseHeadlessTest.php @@ -21,41 +21,4 @@ public function setUpHeadless() { ->apply(); } - /** - * {@inheritDoc} - */ - public function getMockBuilder($className) { - $mockBuilder = (new class($this, $className) extends PHPUnit_Framework_MockObject_MockBuilder { - - /** - * {@inheritDoc} - */ - public function getMock() { - static::setSupressedErrorHandler(); - - try { - return parent::getMock(); - } finally { - restore_error_handler(); - } - } - - /** - * Supress depreciation warnings. - */ - public static function setSupressedErrorHandler() { - $previousHandler = set_error_handler(function ($code, $description, $file = NULL, $line = NULL, $context = NULL) use (&$previousHandler) { - if ($code & E_DEPRECATED) { - return TRUE; - } - - return $previousHandler($code, $description, $file, $line, $context); - }); - } - - }); - - return $mockBuilder; - } - } diff --git a/tests/phpunit/CRM/Certificate/Service/CertificateCaseGeneratorTest.php b/tests/phpunit/CRM/Certificate/Service/CertificateCaseGeneratorTest.php index 78f76b6..94b0775 100644 --- a/tests/phpunit/CRM/Certificate/Service/CertificateCaseGeneratorTest.php +++ b/tests/phpunit/CRM/Certificate/Service/CertificateCaseGeneratorTest.php @@ -38,8 +38,8 @@ public function testGenerateCertificateWillResolveTokens() { $generatorService = new CRM_Certificate_Service_CertificateGenerator(); $result = $generatorService->generate($template['id'], $contactId, $caseId); - $this->assertContains($contact['display_name'], $result['html']); - $this->assertContains($case['subject'], $result['html']); + $this->assertStringContainsString($contact['display_name'], $result['html']); + $this->assertStringContainsString($case['subject'], $result['html']); } public function testGenerateCertificateWillResolveCaseCustomFieldTokens() { @@ -58,7 +58,7 @@ public function testGenerateCertificateWillResolveCaseCustomFieldTokens() { $generatorService = new CRM_Certificate_Service_CertificateGenerator(); $result = $generatorService->generate($template['id'], $contactId, $caseId); - $this->assertContains($customTokenValue, $result['html']); + $this->assertStringContainsString($customTokenValue, $result['html']); } private function getMsgContent() { diff --git a/tests/phpunit/CRM/Certificate/Service/CertificateEventGeneratorTest.php b/tests/phpunit/CRM/Certificate/Service/CertificateEventGeneratorTest.php index cff536b..9fa4dcf 100644 --- a/tests/phpunit/CRM/Certificate/Service/CertificateEventGeneratorTest.php +++ b/tests/phpunit/CRM/Certificate/Service/CertificateEventGeneratorTest.php @@ -20,8 +20,8 @@ public function testGenerateCertificateWillResolveEventTokens() { $generatorService = new CRM_Certificate_Service_CertificateGenerator(); $result = $generatorService->generate($template['id'], $contact['id'], $participant['id']); - $this->assertContains($contact['display_name'], $result['html']); - $this->assertContains($event['title'], $result['html']); + $this->assertStringContainsString($contact['display_name'], $result['html']); + $this->assertStringContainsString($event['title'], $result['html']); } public function testGenerateCertificateWillResolveParticipantTokens() { @@ -37,8 +37,8 @@ public function testGenerateCertificateWillResolveParticipantTokens() { $generatorService = new CRM_Certificate_Service_CertificateGenerator(); $result = $generatorService->generate($template['id'], $contact['id'], $participant['id']); - $this->assertContains($participant['participant_role'], $result['html']); - $this->assertContains($participant['participant_source'], $result['html']); + $this->assertStringContainsString($participant['participant_role'], $result['html']); + $this->assertStringContainsString($participant['participant_source'], $result['html']); } public function testGenerateCertificateWillResolveEventTokenWithEmptySummaryField() { @@ -64,9 +64,9 @@ public function testGenerateCertificateWillResolveEventTokenWithEmptySummaryFiel $generatorService = new CRM_Certificate_Service_CertificateGenerator(); $result = $generatorService->generate($template["id"], $contact["id"], $participant["id"]); - $this->assertContains($contact["display_name"], $result["html"]); - $this->assertContains($event["title"], $result["html"]); - $this->assertContains(CRM_Utils_Date::customFormat($event["start_date"]), $result["html"]); + $this->assertStringContainsString($contact["display_name"], $result["html"]); + $this->assertStringContainsString($event["title"], $result["html"]); + $this->assertStringContainsString(CRM_Utils_Date::customFormat($event["start_date"]), $result["html"]); } private function getMsgContent($extra = "") { diff --git a/tests/phpunit/CRM/Certificate/Service/CertificateMembershipGeneratorTest.php b/tests/phpunit/CRM/Certificate/Service/CertificateMembershipGeneratorTest.php index d89eb77..e98dc61 100644 --- a/tests/phpunit/CRM/Certificate/Service/CertificateMembershipGeneratorTest.php +++ b/tests/phpunit/CRM/Certificate/Service/CertificateMembershipGeneratorTest.php @@ -19,8 +19,8 @@ public function testGenerateCertificateWillResolveMembershipTokens() { $generatorService = new CRM_Certificate_Service_CertificateGenerator(); $result = $generatorService->generate($template['id'], $contact['id'], $membership['id']); - $this->assertContains($contact['display_name'], $result['html']); - $this->assertContains($membership['membership_name'], $result['html']); + $this->assertStringContainsString($contact['display_name'], $result['html']); + $this->assertStringContainsString($membership['membership_name'], $result['html']); } private function getMsgContent($extra = "") { diff --git a/tests/phpunit/api/v3/CompuCertificate/GetcontactcertificatesTest.php b/tests/phpunit/api/v3/CompuCertificate/GetcontactcertificatesTest.php index 81bbff2..22889ef 100644 --- a/tests/phpunit/api/v3/CompuCertificate/GetcontactcertificatesTest.php +++ b/tests/phpunit/api/v3/CompuCertificate/GetcontactcertificatesTest.php @@ -23,7 +23,7 @@ class api_v3_CompuCertificate_GetcontactcertificatesTest extends BaseHeadlessTes */ private $client_id; - public function setUp() { + public function setUp(): void { parent::setUp(); $contact = ContactFabricator::fabricate(); $this->registerCurrentLoggedInContactInSession($contact['id']); @@ -240,7 +240,7 @@ public function testExpiredCaseCertficateIsNotReturnedForAPI($startDate, $endDat $this->assertEquals($results['count'] > 0, $valid); } - public function tearDown() { + public function tearDown(): void { $this->unregisterCurrentLoggedInContactFromSession(); parent::tearDown(); } diff --git a/tests/phpunit/api/v3/CompuCertificate/GetrelationshipcertificatesTest.php b/tests/phpunit/api/v3/CompuCertificate/GetrelationshipcertificatesTest.php index b8696eb..fefa519 100644 --- a/tests/phpunit/api/v3/CompuCertificate/GetrelationshipcertificatesTest.php +++ b/tests/phpunit/api/v3/CompuCertificate/GetrelationshipcertificatesTest.php @@ -25,7 +25,7 @@ class api_v3_CompuCertificate_GetrelatedcontactcertificatesTest extends BaseHead */ private $client_id; - public function setUp() { + public function setUp(): void { parent::setUp(); $contact = ContactFabricator::fabricate(); $this->registerCurrentLoggedInContactInSession($contact['id']); @@ -134,7 +134,7 @@ public function testRelatedMembershipCertficateIsReturnedForContact() { $this->assertEquals($membership['id'], $results['values'][0]['membership_id']); } - public function tearDown() { + public function tearDown(): void { $this->unregisterCurrentLoggedInContactFromSession(); parent::tearDown(); }