Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

COMCL-589: Merge Dev Branch #95

Merged
merged 4 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 21 additions & 15 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
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
Expand All @@ -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" = "<?php" ]; then
echo "$INSERT_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 }}
Expand All @@ -85,4 +91,4 @@ jobs:
- name: Run phpunit tests
if: ${{ always() }}
working-directory: ${{ env.CIVICRM_EXTENSIONS_DIR }}/uk.co.compucorp.certificate
run: phpunit5
run: phpunit8
14 changes: 11 additions & 3 deletions CRM/Certificate/Token/Membership.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down Expand Up @@ -115,8 +123,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;
Expand Down
37 changes: 0 additions & 37 deletions tests/phpunit/BaseHeadlessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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() {
Expand All @@ -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 = "") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down Expand Up @@ -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();
}
Expand Down
5 changes: 4 additions & 1 deletion tests/phpunit/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading