}
}
+ /**
+ * Assert that the sent mail included the supplied strings.
+ *
+ * @param array $strings
+ * @param int $mailIndex
+ */
+ protected function assertMailSentNotContainStrings(array $strings, int $mailIndex = 0): void {
+ foreach ($strings as $string) {
+ $this->assertMailSentNotContainingString($string, $mailIndex);
+ }
+ }
+
/**
* Assert that the sent mail included the supplied string.
*
$this->assertStringContainsString(preg_replace('/\s+/', '', $string), preg_replace('/\s+/', '', $mail['body']));
}
+ /**
+ * Assert that the sent mail included the supplied string.
+ *
+ * @param string $string
+ * @param int $mailIndex
+ */
+ protected function assertMailSentNotContainingString(string $string, int $mailIndex = 0): void {
+ $mail = $this->form->getMail()[$mailIndex];
+ $this->assertStringNotContainsString(preg_replace('/\s+/', '', $string), preg_replace('/\s+/', '', $mail['body']));
+ }
+
/**
* Assert that the sent mail included the supplied string.
*
$this->assertStringContainsString($string, $mail['headers']);
}
+ /**
+ * Assert the right number of mails were sent.
+ *
+ * @param int $count
+ */
+ protected function assertMailSentCount(int $count): void {
+ $this->assertCount($count, $this->form->getMail());
+ }
+
/**
* Assert that the sent mail included the supplied strings.
*
$this->assertMailSentContainingHeaderString('Test Frontend title');
}
+ /**
+ * Test a zero dollar membership (quick config, not separate payment).
+ *
+ * @throws \CRM_Core_Exception
+ */
+ public function testSubmitMembershipBlockNotSeparatePaymentZeroDollarsWithEmail(): void {
+ $this->createTestEntity('MembershipType', [
+ 'min_amount' => 0,
+ 'name' => 'Free',
+ 'duration_unit' => 'year',
+ 'duration_interval' => 1,
+ 'period_type' => 'rolling',
+ 'member_of_contact_id' => CRM_Core_BAO_Domain::getDomain()->contact_id,
+ 'financial_type_id:name' => 'Member Dues',
+ 'is_active' => 1,
+ 'sequential' => 1,
+ 'visibility' => 'Public',
+ ], 'free');
+ $this->contributionPageQuickConfigCreate([], [], FALSE, TRUE, TRUE, TRUE);
+ $this->submitOnlineContributionForm([
+ 'payment_processor_id' => $this->ids['PaymentProcessor']['dummy'],
+ 'price_' . $this->ids['PriceField']['contribution_amount'] => -1,
+ 'price_' . $this->ids['PriceField']['membership_amount'] => $this->ids['PriceFieldValue']['membership_free'],
+ 'id' => $this->getContributionPageID(),
+ ] + $this->getBillingSubmitValues(),
+ $this->getContributionPageID());
+
+ $contribution = $this->callAPISuccessGetSingle('Contribution', ['contribution_page_id' => $this->getContributionPageID()]);
+ $this->callAPISuccessGetSingle('MembershipPayment', ['contribution_id' => $contribution['id']]);
+ //Assert only one mail is being sent.
+ $this->assertMailSentCount(1);
+ $this->assertMailSentContainingStrings([
+ 'Free',
+ ]);
+ $this->assertMailSentNotContainingString('Amount');
+ }
+
}
$this->assertEquals(date('Y-m-d', strtotime('+ 2 year - 1 day')), $membership['end_date']);
}
- /**
- * Test submit with a membership block in place.
- */
- public function testSubmitMembershipBlockNotSeparatePaymentZeroDollarsWithEmail(): void {
- $mut = new CiviMailUtils($this, TRUE);
- $this->setUpMembershipContributionPage(FALSE, FALSE, ['minimum_fee' => 0]);
- $this->addProfile('supporter_profile', $this->getContributionPageID());
-
- $submitParams = [
- $this->getPriceFieldLabel('membership') => $this->getPriceFieldValue('general'),
- 'id' => $this->getContributionPageID(),
- 'billing_first_name' => 'Billy',
- 'billing_middle_name' => 'Goat',
- 'billing_last_name' => 'Gruffier',
- 'email-Primary' => 'billy-goat@the-new-bridge.net',
- 'payment_processor_id' => $this->params['payment_processor_id'],
- ];
-
- $this->callAPISuccess('ContributionPage', 'submit', $submitParams);
- $contribution = $this->callAPISuccess('contribution', 'getsingle', ['contribution_page_id' => $this->getContributionPageID()]);
- $this->callAPISuccess('membership_payment', 'getsingle', ['contribution_id' => $contribution['id']]);
- //Assert only one mail is being sent.
- $msgs = $mut->getAllMessages();
- $this->assertCount(1, $msgs);
-
- $mut->checkMailLog([
- 'Membership Type',
- 'General',
- 'Gruffier',
- ], [
- 'Amount',
- ]);
- $mut->stop();
- $mut->clearMessages();
- }
-
/**
* Test submit with a pay later and check line item in mails.
*/