* Test CRM_Member_Form_Membership::formRule() with a parameter
* that has an start date before the join date and a rolling
* membership type.
+ *
+ * @throws \CRM_Core_Exception
*/
public function testFormRuleRollingEarlyStart(): void {
$unixNow = time();
$files = [];
$obj = new CRM_Member_Form_Membership();
$rc = CRM_Member_Form_Membership::formRule($params, $files, $obj);
- $this->assertisArray($rc);
+ $this->assertIsArray($rc);
$this->assertArrayHasKey('start_date', $rc);
}
* that has an end date before the start date and a rolling
* membership type
*/
- public function testFormRuleRollingEarlyEnd() {
- $unixNow = time();
- $unixYesterday = $unixNow - (24 * 60 * 60);
+ public function testFormRuleRollingEarlyEnd(): void {
+ $unixYesterday = time() - (24 * 60 * 60);
$ymdYesterday = date('Y-m-d', $unixYesterday);
$params = [
'join_date' => date('Y-m-d'),
$obj = new CRM_Member_Form_Membership();
$rc = CRM_Member_Form_Membership::formRule($params, $files, $obj);
$this->assertIsArray($rc);
- $this->assertTrue(array_key_exists('end_date', $rc));
+ $this->assertArrayHasKey('end_date', $rc);
}
/**
- * Test CRM_Member_Form_Membership::formRule() with end date but no start date and a rolling membership type.
+ * Test CRM_Member_Form_Membership::formRule() with end date but no start
+ * date and a rolling membership type.
+ *
+ * @throws \CRM_Core_Exception
*/
- public function testFormRuleRollingEndNoStart() {
+ public function testFormRuleRollingEndNoStart(): void {
$unixNow = time();
$unixYearFromNow = $unixNow + (365 * 24 * 60 * 60);
$ymdYearFromNow = date('Y-m-d', $unixYearFromNow);
];
$files = [];
$obj = new CRM_Member_Form_Membership();
- $rc = $obj::formRule($params, $files, $obj);
- $this->assertIsArray($rc);
- $this->assertTrue(array_key_exists('start_date', $rc));
+ $ruleResult = $obj::formRule($params, $files, $obj);
+ $this->assertIsArray($ruleResult);
+ $this->assertArrayHasKey('start_date', $ruleResult);
}
/**
* Test CRM_Member_Form_Membership::formRule() with a parameter
* that has an end date and a lifetime membership type
+ *
+ * @throws \CRM_Core_Exception
*/
- public function testFormRuleRollingLifetimeEnd() {
+ public function testFormRuleRollingLifetimeEnd(): void {
$unixNow = time();
$unixYearFromNow = $unixNow + (365 * 24 * 60 * 60);
$params = [
$obj = new CRM_Member_Form_Membership();
$rc = $obj::formRule($params, $files, $obj);
$this->assertIsArray($rc);
- $this->assertTrue(array_key_exists('status_id', $rc));
+ $this->assertArrayHasKey('status_id', $rc);
}
/**
$this->assertTrue($validationResponse);
}
- public function testFormRuleUntilDateOverrideWithNoOverrideEndDate() {
+ /**
+ * @throws \CRM_Core_Exception
+ */
+ public function testFormRuleUntilDateOverrideWithNoOverrideEndDate(): void {
$params = [
'join_date' => date('Y-m-d'),
'membership_type_id' => [$this->ids['contact']['organization'], $this->ids['membership_type']['AnnualFixed']],
* Test CRM_Member_Form_Membership::formRule() with a join date
* of one month from now and a rolling membership type
*/
- public function testFormRuleRollingJoin1MonthFromNow() {
+ public function testFormRuleRollingJoin1MonthFromNow(): void {
$unixNow = time();
$unix1MFmNow = $unixNow + (31 * 24 * 60 * 60);
$params = [
* @dataProvider getThousandSeparators
*/
public function testSubmit(string $thousandSeparator): void {
- CRM_Core_Session::singleton()->getStatus(TRUE);
+ $_REQUEST['mode'] = 'test';
$this->setCurrencySeparators($thousandSeparator);
- $form = $this->getForm();
- $this->mut = new CiviMailUtils($this, TRUE);
- $form->_mode = 'test';
$this->createLoggedInUser();
$params = [
'cid' => $this->_individualId,
'send_receipt' => TRUE,
'receipt_text' => 'Receipt text',
];
- $form->_contactID = $this->_individualId;
- $form->testSubmit($params);
+ $form = $this->getForm($params);
+ $mailUtil = new CiviMailUtils($this, TRUE);
+ $form->buildForm();
+ $form->postProcess();
$membership = $this->callAPISuccessGetSingle('Membership', ['contact_id' => $this->_individualId]);
$membershipEndYear = date('Y') + 1;
- if (date('m-d') == '12-31') {
+ if (date('m-d') === '12-31') {
// If you join on Dec 31, then the first term would end right away, so
// add a year.
$membershipEndYear++;
'return' => 'payment_instrument_id',
]),
], 'online');
- $this->mut->checkMailLog([
+ $mailUtil->checkMailLog([
Civi::format()->money('1234.56'),
'Receipt text',
]);
- $this->mut->stop();
$this->assertEquals([
[
'text' => 'AnnualFixed membership for Mr. Anthony Anderson II has been added. The new Membership Expiration Date is December 31st, ' . $membershipEndYear . '. A membership confirmation and receipt has been sent to anthony_anderson@civicrm.org.',
}
/**
- * CRM-20946: Test the financial entires especially the reversed amount,
+ * CRM-20946: Test the financial entries especially the reversed amount,
* after related Contribution is cancelled
*
* @throws \CRM_Core_Exception
/**
* Test membership with soft credits.
+ *
+ * @throws \CRM_Core_Exception
*/
- public function testMembershipSoftCredit() {
- $softIndividualId = $this->individualCreate();
-
- $form = $this->getForm();
- $form->preProcess();
+ public function testMembershipSoftCredit(): void {
$this->createLoggedInUser();
+ $softIndividualID = $this->individualCreate();
$params = $this->getBaseSubmitParams();
unset($params['auto_renew'], $params['is_recur']);
$params['record_contribution'] = TRUE;
'name' => "Gift",
'option_group_id' => "soft_credit_type",
]);
- $params['soft_credit_contact_id'] = $softIndividualId;
- $form->_contactID = $this->_individualId;
- // $form->_mode = 'test';
- $form->testSubmit($params);
+ $params['soft_credit_contact_id'] = $softIndividualID;
+ $form = $this->getForm($params);
+ $form->postProcess();
// Membership is created on main contact.
$this->callAPISuccessGetSingle('Membership', ['contact_id' => $this->_individualId]);
// Verify is main contribution is created on soft contact.
$contribution = $this->callAPISuccessGetSingle('Contribution', [
- 'contact_id' => $softIndividualId,
+ 'contact_id' => $softIndividualID,
]);
$this->assertEquals($contribution['soft_credit'][1]['contact_id'], $this->_individualId);
* @throws \CRM_Core_Exception
*/
public function testSubmitPayLaterWithBilling(): void {
- $form = $this->getForm();
- $this->createLoggedInUser();
$params = [
'contact_id' => $this->_individualId,
'join_date' => date('Y-m-d'),
'billing_postal_code-5' => '90210',
'billing_country_id-5' => '1228',
];
+ $form = $this->getForm($params);
+ $this->createLoggedInUser();
+
$form->_contactID = $this->_individualId;
$form->testSubmit($params);
* @param array $formValues
*
* @return \CRM_Member_Form_Membership
- * @throws \CRM_Core_Exception
*/
protected function getForm(array $formValues = []): CRM_Member_Form_Membership {
if (isset($_REQUEST['cid'])) {
/** @var CRM_Member_Form_Membership $form*/
$form = $this->getFormObject('CRM_Member_Form_Membership', $formValues);
$form->preProcess();
+ $form->buildForm();
return $form;
}
*
* @throws \CRM_Core_Exception
*/
- protected function createTwoMembershipsViaPriceSetInBackEnd(int $contactId, $isTaxEnabled = TRUE): void {
- $form = $this->getForm();
- $form->preProcess();
+ protected function createTwoMembershipsViaPriceSetInBackEnd(int $contactId, bool $isTaxEnabled = TRUE): void {
+ // register for both of these memberships via backoffice membership form submission
$this->createLoggedInUser();
$this->createMembershipPriceSet();
-
- // register for both of these memberships via backoffice membership form submission
$params = [
'cid' => $contactId,
'contact_id' => $contactId,
'billing_postal_code-5' => '90210',
'billing_country_id-5' => '1228',
];
- $form->testSubmit($params);
+ $form = $this->getForm($params);
+ $form->postProcess();
}
/**
* @throws \CRM_Core_Exception
* @throws \Exception
*/
- public function testCreatePendingWithMultipleTerms() {
+ public function testCreatePendingWithMultipleTerms(): void {
CRM_Core_Session::singleton()->getStatus(TRUE);
$this->mut = new CiviMailUtils($this, TRUE);
$this->createLoggedInUser();
}
/**
- * Test Membership Payment owned by other contact, membership view should show all contribution records in listing.
- * is other contact.
+ * Test Membership Payment owned by other contact, membership view should
+ * show all contribution records in listing. is other contact.
+ *
+ * @throws \CRM_Core_Exception
*/
public function testMembershipViewContributionOwnerDifferent(): void {
// Membership Owner