You are here

public function ContributionIatsTest::testSubmit1stPayContribution in Webform CiviCRM Integration 8.5

File

tests/src/FunctionalJavascript/ContributionIatsTest.php, line 106

Class

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

Namespace

Drupal\Tests\webform_civicrm\FunctionalJavascript

Code

public function testSubmit1stPayContribution() {
  $this
    ->drupalLogin($this->adminUser);
  $this
    ->drupalGet(Url::fromRoute('entity.webform.civicrm', [
    'webform' => $this->webform
      ->id(),
  ]));
  $this
    ->enableCivicrmOnWebform();
  $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', 'Donation');

  // throw new \Exception(var_export($this->getOptions('Payment Processor'), TRUE));
  $this
    ->assertCount(4, $this
    ->getOptions('Payment Processor'));
  $this
    ->getSession()
    ->getPage()
    ->selectFieldOption('Payment Processor', $this->payment_processor_faps['id']);
  $this
    ->enableBillingSection();
  $this
    ->saveCiviCRMSettings();
  $this
    ->drupalGet($this->webform
    ->toUrl('canonical'));
  $this
    ->assertPageNoErrorMessages();
  $edit = [
    'First Name' => 'Frederick',
    'Last Name' => 'Pabst',
    'Email' => 'fred@example.com',
  ];
  $this
    ->postSubmission($this->webform, $edit, 'Next >');
  $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
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  $this
    ->filliATSCryptogram();
  $billingValues = [
    'first_name' => 'Frederick',
    'last_name' => 'Pabst',
    'street_address' => '123 Milwaukee Ave',
    'city' => 'Milwaukee',
    'country' => '1228',
    'state_province' => '1048',
    'postal_code' => '53177',
  ];
  $this
    ->fillBillingFields($billingValues);
  $this
    ->getSession()
    ->getPage()
    ->pressButton('Submit');
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  $this
    ->assertPageNoErrorMessages();
  $this
    ->createScreenshot($this->htmlOutputDirectory . 'faps169.png');
  $this
    ->htmlOutput();
  $this
    ->assertSession()
    ->waitForElementVisible('css', '.webform-confirmation');
  $this
    ->assertSession()
    ->pageTextContains('New submission added to CiviCRM Webform Test.');
  $this
    ->assertPageNoErrorMessages();

  // ToDo: load the Contribution and check the values
  $utils = \Drupal::service('webform_civicrm.utils');
  $api_result = $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']);
  $contribution_total_amount = $contribution['total_amount'];
  $this
    ->assertEquals('Completed', $contribution['contribution_status']);
  $this
    ->assertEquals('USD', $contribution['currency']);
}