Skip to content

Commit

Permalink
Minor test cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Jul 28, 2022
1 parent cabac33 commit 2eb1dc0
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 139 deletions.
2 changes: 1 addition & 1 deletion CRM/Event/Form/Registration/Register.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ public function setDefaultValues() {
$unsetSubmittedOptions[$val['id']] = $optionFullIds;
}
//reset values for all options those are full.
CRM_Event_Form_Registration::resetElementValue($unsetSubmittedOptions, $this);
CRM_Event_Form_Registration::resetElementValue($unsetSubmittedOptions ?? [], $this);
}

//set default participant fields, CRM-4320.
Expand Down
8 changes: 4 additions & 4 deletions tests/phpunit/CRM/Contact/Page/View/UserDashBoardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,16 +162,16 @@ public function testDashboardContentContributions(): void {
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
public function testDashboardPartialPayments() {
public function testDashboardPartialPayments(): void {
$contributionId = $this->contributionCreate([
'contact_id' => $this->contactID,
'contribution_status_id' => 'Pending',
'total_amount' => 25,
]);
$result = civicrm_api3('Payment', 'create', [
$this->callAPISuccess('Payment', 'create', [
'contribution_id' => $contributionId,
'total_amount' => 11,
'trxn_date' => "2021-05-11",
'trxn_date' => '2021-05-11',
]);
$this->contributions[] = civicrm_api3('Contribution', 'get', [
'contact_id' => $this->contactID,
Expand Down Expand Up @@ -205,7 +205,7 @@ protected function runUserDashboard(): void {
/**
* Tests the event dashboard as a minimally permissioned user.
*/
public function testEventDashboard() {
public function testEventDashboard(): void {
CRM_Core_Config::singleton()->userPermissionClass->permissions = [
'register for events',
'access Contact Dashboard',
Expand Down
257 changes: 127 additions & 130 deletions tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,9 @@ class CRM_Event_Form_Registration_ConfirmTest extends CiviUnitTestCase {

use CRMTraits_Profile_ProfileTrait;


/**
* Should financials be checked after the test but before tear down.
*
* Ideally all tests (or at least all that call any financial api calls ) should do this but there
* are some test data issues and some real bugs currently blocking.
*
* @var bool
*/
protected $isValidateFinancialsOnPostAssert = TRUE;

public function setUp(): void {
$this->useTransaction(TRUE);
parent::setUp();
public function tearDown(): void {
$this->quickCleanUpFinancialEntities();
parent::tearDown();
}

/**
Expand Down Expand Up @@ -376,7 +365,7 @@ public function testWaitlistRegistrationContactIdParam() {
* @throws \CRM_Core_Exception
* @throws \Exception
*/
public function testTaxMultipleParticipant() {
public function testTaxMultipleParticipant(): void {
// @todo - figure out why this doesn't pass validate financials
$this->isValidateFinancialsOnPostAssert = FALSE;
$mut = new CiviMailUtils($this);
Expand Down Expand Up @@ -452,8 +441,8 @@ public function testTaxMultipleParticipant() {
]
);
$this->assertContains(' (multiple participants)', $contribution['amount_level']);
$this->assertEquals($contribution['tax_amount'], 40, 'Invalid Tax amount.');
$this->assertEquals($contribution['total_amount'], 440, 'Invalid Tax amount.');
$this->assertEquals(40, $contribution['tax_amount'], 'Invalid Tax amount.');
$this->assertEquals(440, $contribution['total_amount'], 'Invalid Tax amount.');
$mailSent = $mut->getAllMessages();
$this->assertCount(3, $mailSent, 'Three mails should have been sent to the 3 participants.');
$this->assertStringContainsString('contactID:::' . $contribution['contact_id'], $mailSent[0]);
Expand Down Expand Up @@ -503,30 +492,31 @@ public function testOnlineRegNoPrice(): void {
);
// Create online event registration.
$this->submitForm(
$event['id'],
[
'first_name' => 'Bruce',
'last_name' => 'Wayne',
'email-Primary' => 'bruce@gotham.com',
'price_' . $priceField['id'] => '',
'priceSetId' => $priceField['values'][$priceField['id']]['price_set_id'],
'payment_processor_id' => $paymentProcessorID,
'amount' => 0,
'amount_level' => '',
'bypass_payment' => '',
'is_primary' => 1,
'is_pay_later' => 0,
'campaign_id' => NULL,
'defaultRole' => 1,
'participant_role_id' => '1',
'tax_amount' => NULL,
'ip_address' => '127.0.0.1',
'invoiceID' => '57adc34957a29171948e8643ce906332',
'button' => '_qf_Register_upload',
$event['id'], [
[
'first_name' => 'Bruce',
'last_name' => 'Wayne',
'email-Primary' => 'bruce@gotham.com',
'price_' . $priceField['id'] => '',
'priceSetId' => $priceField['values'][$priceField['id']]['price_set_id'],
'payment_processor_id' => $paymentProcessorID,
'amount' => 0,
'amount_level' => '',
'bypass_payment' => '',
'is_primary' => 1,
'is_pay_later' => 0,
'campaign_id' => NULL,
'defaultRole' => 1,
'participant_role_id' => '1',
'tax_amount' => NULL,
'ip_address' => '127.0.0.1',
'invoiceID' => '57adc34957a29171948e8643ce906332',
'button' => '_qf_Register_upload',
],
]
);
$contribution = $this->callAPISuccess('Contribution', 'get', ['invoice_id' => '57adc34957a29171948e8643ce906332']);
$this->assertEquals($contribution['count'], '0', "Contribution should not be created for zero fee event registration when no price field selected.");
$this->assertEquals('0', $contribution['count'], 'Contribution should not be created for zero fee event registration when no price field selected.');
}

/**
Expand Down Expand Up @@ -564,59 +554,61 @@ public function testAssignProfiles() {
* Submit event registration with a note field
*
* @param array $event
* @param int $contact_id
* @param int|null $contact_id
*
* @return array
* @throws \Exception
*/
private function submitWithNote($event, $contact_id) {
if (empty($contact_id)) {
private function submitWithNote(array $event, ?int $contact_id): array {
if ($contact_id === NULL) {
$contact_id = $this->createLoggedInUser();
}
$mut = new CiviMailUtils($this, TRUE);
$this->submitForm($event['id'], [
'first_name' => 'k',
'last_name' => 'p',
'email-Primary' => 'demo@example.com',
'hidden_processor' => '1',
'credit_card_number' => '4111111111111111',
'cvv2' => '123',
'credit_card_exp_date' => [
'M' => '1',
'Y' => '2019',
],
'credit_card_type' => 'Visa',
'billing_first_name' => 'p',
'billing_middle_name' => '',
'billing_last_name' => 'p',
'billing_street_address-5' => 'p',
'billing_city-5' => 'p',
'billing_state_province_id-5' => '1061',
'billing_postal_code-5' => '7',
'billing_country_id-5' => '1228',
'priceSetId' => '6',
'price_7' => [
13 => 1,
[
'first_name' => 'k',
'last_name' => 'p',
'email-Primary' => 'demo@example.com',
'hidden_processor' => '1',
'credit_card_number' => '4111111111111111',
'cvv2' => '123',
'credit_card_exp_date' => [
'M' => '1',
'Y' => '2019',
],
'credit_card_type' => 'Visa',
'billing_first_name' => 'p',
'billing_middle_name' => '',
'billing_last_name' => 'p',
'billing_street_address-5' => 'p',
'billing_city-5' => 'p',
'billing_state_province_id-5' => '1061',
'billing_postal_code-5' => '7',
'billing_country_id-5' => '1228',
'priceSetId' => '6',
'price_7' => [
13 => 1,
],
'payment_processor_id' => '1',
'bypass_payment' => '',
'is_primary' => 1,
'is_pay_later' => 0,
'campaign_id' => NULL,
'defaultRole' => 1,
'participant_role_id' => '1',
'currencyID' => 'USD',
'amount_level' => 'Tiny-tots (ages 5-8) - 1',
'amount' => '800.00',
'tax_amount' => NULL,
'year' => '2019',
'month' => '1',
'ip_address' => '127.0.0.1',
'invoiceID' => '57adc34957a29171948e8643ce906332',
'button' => '_qf_Register_upload',
'billing_state_province-5' => 'AP',
'billing_country-5' => 'US',
'note' => $event['note'],
],
'payment_processor_id' => '1',
'bypass_payment' => '',
'is_primary' => 1,
'is_pay_later' => 0,
'campaign_id' => NULL,
'defaultRole' => 1,
'participant_role_id' => '1',
'currencyID' => 'USD',
'amount_level' => 'Tiny-tots (ages 5-8) - 1',
'amount' => '800.00',
'tax_amount' => NULL,
'year' => '2019',
'month' => '1',
'ip_address' => '127.0.0.1',
'invoiceID' => '57adc34957a29171948e8643ce906332',
'button' => '_qf_Register_upload',
'billing_state_province-5' => 'AP',
'billing_country-5' => 'US',
'note' => $event['note'],
]);
$participant = $this->callAPISuccessGetSingle('Participant', []);
$mut->checkMailLog(['Comment: ' . $event['note'] . chr(0x0A)]);
Expand All @@ -630,21 +622,20 @@ private function submitWithNote($event, $contact_id) {
* Create an event with a "pre" profile
*
* @throws \CRM_Core_Exception
* @throws \Exception
*/
private function creatEventWithProfile($event) {
private function creatEventWithProfile($event): array {
if (empty($event)) {
$event = $this->eventCreate();
$this->createJoinedProfile(['entity_table' => 'civicrm_event', 'entity_id' => $event['id']]);
$this->uf_field_add($this->ids["UFGroup"]["our profile"], 'note', 'Contact', 'Comment');
$this->uf_field_add($this->ids['UFGroup']['our profile'], 'note', 'Contact', 'Comment');
}

$_REQUEST['id'] = $event['id'];
/* @var \CRM_Event_Form_Registration_Confirm $form */
$form = $this->getFormObject('CRM_Event_Form_Registration_Confirm');
$form->set('params', [[]]);
$form->set('values', [
'event' => $event['values'][$event['id']],
'event' => $event,
'location' => [],
'custom_pre_id' => $this->ids['UFGroup']['our profile'],
]);
Expand Down Expand Up @@ -707,14 +698,14 @@ public function testNoteSubmission(): void {
//now that the contact has one note, register this contact again with a different note
//and confirm that the note shown in the email is the current one
$event = $this->creatEventWithProfile($event);
$event['custom_pre_id'] = $this->ids["UFGroup"]["our profile"];
$event['custom_pre_id'] = $this->ids['UFGroup']['our profile'];
$event['note'] = 'This is note 2';
[$contact_id, $participant_id] = $this->submitWithNote($event, $contact_id);
civicrm_api3('Participant', 'delete', ['id' => $participant_id]);

//finally, submit a blank note and confirm that the note shown in the email is blank
$event = $this->creatEventWithProfile($event);
$event['custom_pre_id'] = $this->ids["UFGroup"]["our profile"];
$event['custom_pre_id'] = $this->ids['UFGroup']['our profile'];
$event['note'] = '';
$this->submitWithNote($event, $contact_id);
}
Expand All @@ -728,48 +719,48 @@ public function testSubmitNonPrimaryEmail(): void {
$event = $this->eventCreate();
$mut = new CiviMailUtils($this, TRUE);
$this->submitForm($event['id'], [
'first_name' => 'k',
'last_name' => 'p',
'email-Other' => 'nonprimaryemail@example.com',
'hidden_processor' => '1',
'credit_card_number' => '4111111111111111',
'cvv2' => '123',
'credit_card_exp_date' => [
'M' => '1',
'Y' => '2019',
],
'credit_card_type' => 'Visa',
'billing_first_name' => 'p',
'billing_middle_name' => '',
'billing_last_name' => 'p',
'billing_street_address-5' => 'p',
'billing_city-5' => 'p',
'billing_state_province_id-5' => '1061',
'billing_postal_code-5' => '7',
'billing_country_id-5' => '1228',
'priceSetId' => '6',
'price_7' => [
13 => 1,
[
'first_name' => 'k',
'last_name' => 'p',
'email-Other' => 'nonprimaryemail@example.com',
'hidden_processor' => '1',
'credit_card_number' => '4111111111111111',
'cvv2' => '123',
'credit_card_exp_date' => [
'M' => '1',
'Y' => '2019',
],
'credit_card_type' => 'Visa',
'billing_first_name' => 'p',
'billing_middle_name' => '',
'billing_last_name' => 'p',
'billing_street_address-5' => 'p',
'billing_city-5' => 'p',
'billing_state_province_id-5' => '1061',
'billing_postal_code-5' => '7',
'billing_country_id-5' => '1228',
'priceSetId' => '6',
'price_7' => [
13 => 1,
],
'payment_processor_id' => '1',
'bypass_payment' => '',
'is_primary' => 1,
'is_pay_later' => 0,
'campaign_id' => NULL,
'defaultRole' => 1,
'participant_role_id' => '1',
'currencyID' => 'USD',
'amount_level' => 'Tiny-tots (ages 5-8) - 1',
'amount' => '800.00',
'tax_amount' => NULL,
'year' => '2019',
'month' => '1',
'invoiceID' => '57adc34957a29171948e8643ce906332',
'button' => '_qf_Register_upload',
'billing_state_province-5' => 'AP',
'billing_country-5' => 'US',
],
'payment_processor_id' => '1',
'bypass_payment' => '',
'MAX_FILE_SIZE' => '33554432',
'is_primary' => 1,
'is_pay_later' => 0,
'campaign_id' => NULL,
'defaultRole' => 1,
'participant_role_id' => '1',
'currencyID' => 'USD',
'amount_level' => 'Tiny-tots (ages 5-8) - 1',
'amount' => '800.00',
'tax_amount' => NULL,
'year' => '2019',
'month' => '1',
'ip_address' => '127.0.0.1',
'invoiceID' => '57adc34957a29171948e8643ce906332',
'button' => '_qf_Register_upload',
'billing_state_province-5' => 'AP',
'billing_country-5' => 'US',
]);
$mut->checkMailLog(['nonprimaryemail@example.com']);
$mut->stop();
Expand All @@ -787,8 +778,14 @@ public function testSubmitNonPrimaryEmail(): void {
*/
protected function submitForm(int $eventID, array $params): void {
$_REQUEST['id'] = $eventID;
$form = $this->getFormObject('CRM_Event_Form_Registration_Register', $params);
$form->buildForm();
$form->postProcess();
$form = $this->getFormObject('CRM_Event_Form_Registration_Confirm', []);
$form->set('params', [$params]);
if (!isset($params[0])) {
$params = [$params];
}
$form->set('params', $params);
$form->set('registerByID', $this->createLoggedInUser());
$form->buildForm();
$form->postProcess();
Expand Down
Loading

0 comments on commit 2eb1dc0

Please sign in to comment.