Skip to content

Commit

Permalink
COMCL-670: Fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Muhammad Shahrukh committed Aug 9, 2024
1 parent 9587798 commit 0a738bd
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 9 additions & 1 deletion 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
5 changes: 3 additions & 2 deletions tests/phpunit/BaseHeadlessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use Civi\Test;
use Civi\Test\HeadlessInterface;
use Civi\Test\TransactionalInterface;
use PHPUnit\Framework\MockObject\MockBuilder;

/**
* Base test class.
Expand All @@ -24,8 +25,8 @@ public function setUpHeadless() {
/**
* {@inheritDoc}
*/
public function getMockBuilder($className) {
$mockBuilder = (new class($this, $className) extends PHPUnit_Framework_MockObject_MockBuilder {
public function getMockBuilder($className): MockBuilder {
$mockBuilder = (new class($this, $className) extends MockBuilder {

/**
* {@inheritDoc}
Expand Down
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

0 comments on commit 0a738bd

Please sign in to comment.