You are here

public function ContributionDummyTest::testOnePageDonation in Webform CiviCRM Integration 8.5

Test One-page donation

File

tests/src/FunctionalJavascript/ContributionDummyTest.php, line 46

Class

ContributionDummyTest
Tests submitting a Webform with CiviCRM: Contribution with Line Items and Sales Tax

Namespace

Drupal\Tests\webform_civicrm\FunctionalJavascript

Code

public function testOnePageDonation() {
  $payment_processor = $this
    ->createPaymentProcessor();
  $this
    ->drupalLogin($this->adminUser);
  $this
    ->drupalGet(Url::fromRoute('entity.webform.civicrm', [
    'webform' => $this->webform
      ->id(),
  ]));
  $this
    ->enableCivicrmOnWebform();
  $this
    ->configureContributionTab(FALSE, $payment_processor['id']);
  $this
    ->getSession()
    ->getPage()
    ->checkField("Contribution Amount");
  $this
    ->assertSession()
    ->checkboxChecked("Contribution Amount");
  $this
    ->getSession()
    ->getPage()
    ->clickLink('Additional Settings');
  $this
    ->getSession()
    ->getPage()
    ->checkField("Disable Contact Paging");
  $this
    ->assertSession()
    ->checkboxChecked("Disable Contact Paging");
  $this
    ->saveCiviCRMSettings();
  $this
    ->drupalGet($this->webform
    ->toUrl('edit-form'));
  $this
    ->assertSession()
    ->pageTextNotContains('contact_pagebreak');
  $this
    ->drupalGet($this->webform
    ->toUrl('canonical'));
  $this
    ->assertPageNoErrorMessages();
  $this
    ->getSession()
    ->getPage()
    ->fillField('First Name', 'Frederick');
  $this
    ->getSession()
    ->getPage()
    ->fillField('Last Name', 'Pabst');
  $this
    ->getSession()
    ->getPage()
    ->fillField('Email', 'fred@example.com');
  $this
    ->getSession()
    ->getPage()
    ->fillField('Contribution Amount', '10.00');
  $this
    ->assertSession()
    ->elementExists('css', '#wf-crm-billing-items');
  $this
    ->htmlOutput();
  $this
    ->assertSession()
    ->elementTextContains('css', '#wf-crm-billing-total', '10.00');
  $this
    ->fillCardAndSubmit();
  $api_result = $this->utils
    ->wf_civicrm_api('contribution', 'get', [
    'sequential' => 1,
  ]);
  $this
    ->assertEquals(1, $api_result['count']);
  $contribution = reset($api_result['values']);
  $this
    ->assertNotEmpty($contribution['trxn_id']);
  $this
    ->assertEquals($this->webform
    ->label(), $contribution['contribution_source']);
  $this
    ->assertEquals('Donation', $contribution['financial_type']);
  $this
    ->assertEquals('10.00', $contribution['total_amount']);
  $this
    ->assertEquals('Completed', $contribution['contribution_status']);
  $this
    ->assertEquals('USD', $contribution['currency']);
}