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

D10 - Fix intermittent test failure with billing blocks #964

Open
wants to merge 2 commits into
base: 6.x
Choose a base branch
from
Open
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
40 changes: 16 additions & 24 deletions tests/src/FunctionalJavascript/ContributionIatsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -364,27 +364,18 @@ public function testSubmitACHEFTContribution() {
$this->drupalGet(Url::fromRoute('entity.webform.civicrm', [
'webform' => $this->webform->id(),
]));
// The label has a <div> in it which can cause weird failures here.
$this->assertSession()->waitForText('Enable CiviCRM Processing');
$this->assertSession()->waitForField('nid');
$this->getSession()->getPage()->checkField('nid');
$this->getSession()->getPage()->clickLink('Contribution');
$this->getSession()->getPage()->selectFieldOption('civicrm_1_contribution_1_contribution_enable_contribution', 1);
$this->assertSession()->assertWaitOnAjaxRequest();
$this->assertSession()->pageTextContains('You must enable an email field for Contact 1 in order to process transactions.');
$this->getSession()->getPage()->pressButton('Enable It');
$this->assertSession()->assertWaitOnAjaxRequest();
$this->getSession()->getPage()->checkField('Contribution Amount');
$this->getSession()->getPage()->selectFieldOption('Currency', 'USD');
$this->getSession()->getPage()->selectFieldOption('Financial Type', 1);

$this->enableCivicrmOnWebform();
$params = [
'payment_processor_id' => $this->payment_processor_legacy_acheft['id'],
];
$this->configureContributionTab($params);
$this->getSession()->getPage()->checkField('Contribution Amount');
$this->assertCount(5, $this->getOptions('Payment Processor'));
$this->getSession()->getPage()->selectFieldOption('Payment Processor', $this->payment_processor_legacy_acheft['id']);

$this->enableBillingSection();

$this->getSession()->getPage()->pressButton('Save Settings');
$this->assertSession()->pageTextContains('Saved CiviCRM settings');
$this->saveCiviCRMSettings();

$this->drupalGet($this->webform->toUrl('canonical'));
$this->assertPageNoErrorMessages();
Expand All @@ -400,13 +391,6 @@ public function testSubmitACHEFTContribution() {
$this->htmlOutput();
$this->assertSession()->elementTextContains('css', '#wf-crm-billing-total', '99.00');

// Wait for the ACHEFT form to load in.
$this->assertSession()->waitForField('account_holder');
$this->getSession()->getPage()->fillField('Account Holder', 'CiviCRM user');
$this->getSession()->getPage()->fillField('Account No.', '12345678');
$this->getSession()->getPage()->fillField('Bank Identification Number', '111111111');
$this->getSession()->getPage()->fillField('Bank Name', 'Bank of CiviCRM');
$this->getSession()->getPage()->selectFieldOption('bank_account_type', 'Savings');
$billingValues = [
'first_name' => 'Frederick',
'last_name' => 'Pabst',
Expand All @@ -417,6 +401,15 @@ public function testSubmitACHEFTContribution() {
'postal_code' => '53177',
];
$this->fillBillingFields($billingValues);
// Wait for the ACHEFT form to load in.
$this->waitUntilStyleChange('#billing-payment-block', 'display', 'block');
$this->assertSession()->waitForElementVisible('css', '#account_holder');

$this->getSession()->getPage()->fillField('bank_account_number', '12345678');
$this->getSession()->getPage()->fillField('bank_identification_number', '111111111');
$this->getSession()->getPage()->fillField('bank_name', 'Bank of CiviCRM');
$this->getSession()->getPage()->fillField('account_holder', 'CiviCRM user');
$this->getSession()->getPage()->selectFieldOption('bank_account_type', 'Savings');
$this->getSession()->getPage()->pressButton('Submit');

$api_result = $this->utils->wf_civicrm_api('contribution', 'get', [
Expand All @@ -430,7 +423,6 @@ public function testSubmitACHEFTContribution() {
$this->assertEquals('99.00', $contribution['total_amount']);
$this->assertEquals('Pending', $contribution['contribution_status']);
$this->assertEquals('USD', $contribution['currency']);

}

public function testSubmitRecurringContribution() {
Expand Down
25 changes: 23 additions & 2 deletions tests/src/FunctionalJavascript/WebformCivicrmTestBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -681,12 +681,11 @@ protected function fillBillingFields($params) {
$this->getSession()->getPage()->fillField('Billing Last Name', $params['last_name']);
$this->getSession()->getPage()->fillField('Street Address', $params['street_address']);
$this->getSession()->getPage()->fillField('City', $params['city']);
$this->getSession()->getPage()->fillField('Postal Code', $params['postal_code']);

$this->getSession()->getPage()->selectFieldOption('Country', $params['country']);
$this->getSession()->wait(1000);
$this->getSession()->getPage()->selectFieldOption('State/Province', $params['state_province']);

$this->getSession()->getPage()->fillField('Postal Code', $params['postal_code']);
}

/**
Expand Down Expand Up @@ -719,7 +718,10 @@ protected function fillCardAndSubmit($billingValues = []) {
$this->fillBillingFields($billingValues);
}
// Wait for the credit card form to load in.
$this->waitUntilStyleChange('#billing-payment-block', 'display', 'block');

$this->assertSession()->waitForField('credit_card_number');
$this->createScreenshot($this->htmlOutputDirectory . '/credit_card.png');
$this->getSession()->getPage()->fillField('credit_card_number', '4222222222222220');
$this->getSession()->getPage()->fillField('cvv2', '123');
$this->getSession()->getPage()->selectFieldOption($this->getCreditCardMonthFieldName(), '11');
Expand Down Expand Up @@ -809,4 +811,23 @@ protected function getCreditCardMonthFieldName(): string {
return 'credit_card_exp_date[m]';
}

/**
* Wait until a specified style property of an element changes to a specified value.
*
* @param string $selector
* @param string $prop
* The style property
* @param string $value
* The style value.
*/
public function waitUntilStyleChange($selector, $prop, $value) {
$this->getSession()->wait(10000, sprintf(
'document.querySelector("%s").style.%s === "%s"',
$selector,
$prop,
$value
));
}


}