You are here

public function ContributionDummyTest::testOverThousand in Webform CiviCRM Integration 8.5

File

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

Class

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

Namespace

Drupal\Tests\webform_civicrm\FunctionalJavascript

Code

public function testOverThousand() {
  $payment_processor = $this
    ->createPaymentProcessor();
  $this
    ->drupalLogin($this->adminUser);
  $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
    ->configureContributionTab(FALSE, $payment_processor['id']);
  $this
    ->getSession()
    ->getPage()
    ->checkField('Contribution Amount');
  $el = $this
    ->getSession()
    ->getPage()
    ->findField('Payment Processor');
  $opts = $el
    ->findAll('css', 'option');
  $this
    ->assertCount(3, $opts, 'Payment processor values: ' . implode(', ', array_map(static function (NodeElement $el) {
    return $el
      ->getValue();
  }, $opts)));
  $this
    ->enableBillingSection();
  $this
    ->saveCiviCRMSettings();
  $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()
    ->pressButton('Next >');
  $this
    ->getSession()
    ->getPage()
    ->fillField('Contribution Amount', '1200.00');
  $this
    ->assertSession()
    ->elementExists('css', '#wf-crm-billing-items');
  $this
    ->htmlOutput();
  $this
    ->assertSession()
    ->elementTextContains('css', '#wf-crm-billing-total', '1,200');
  $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('1200.00', $contribution['total_amount']);
  $this
    ->assertEquals('Completed', $contribution['contribution_status']);
  $this
    ->assertEquals('USD', $contribution['currency']);
  $api_result = $this->utils
    ->wf_civicrm_api('line_item', 'get', [
    'sequential' => 1,
  ]);
  $this
    ->assertEquals('1.00', $api_result['values'][0]['qty']);
  $this
    ->assertEquals('1200.00', $api_result['values'][0]['unit_price']);
  $this
    ->assertEquals('1200.00', $api_result['values'][0]['line_total']);
  $this
    ->assertEquals('1', $api_result['values'][0]['financial_type_id']);
}