You are here

function EventTest::testParticipantContactReference in Webform CiviCRM Integration 8.5

Test contact reference field for participants.

File

tests/src/FunctionalJavascript/EventTest.php, line 69

Class

EventTest
Tests submitting a Webform with CiviCRM: Contact with Event.

Namespace

Drupal\Tests\webform_civicrm\FunctionalJavascript

Code

function testParticipantContactReference() {
  $this
    ->createCustomFields();
  $this
    ->drupalLogin($this->rootUser);
  $this
    ->drupalGet(Url::fromRoute('entity.webform.civicrm', [
    'webform' => $this->webform
      ->id(),
  ]));
  $this
    ->enableCivicrmOnWebform();
  $this
    ->getSession()
    ->getPage()
    ->selectFieldOption('Number of Contacts', 2);
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();

  //Configure Event tab.
  $this
    ->getSession()
    ->getPage()
    ->clickLink('Event Registration');
  $this
    ->getSession()
    ->getPage()
    ->selectFieldOption('participant_reg_type', 'all');
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  $this
    ->htmlOutput();
  $this
    ->getSession()
    ->getPage()
    ->selectFieldOption('participant_1_number_of_participant', 1);
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  $this
    ->htmlOutput();
  $this
    ->getSession()
    ->getPage()
    ->selectFieldOption('civicrm_1_participant_1_participant_event_id[]', 'Test Event');
  $this
    ->getSession()
    ->getPage()
    ->checkField('Participant Fee');
  $this
    ->getSession()
    ->getPage()
    ->checkField('Text');
  $this
    ->getSession()
    ->getPage()
    ->selectFieldOption('Participant Contact Ref', '- User Select -');
  $this
    ->configureContributionTab();
  $this
    ->getSession()
    ->getPage()
    ->selectFieldOption('Payment Processor', 'Pay Later');
  $this
    ->saveCiviCRMSettings();
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  $this
    ->drupalGet($this->webform
    ->toUrl('canonical'));
  $this
    ->htmlOutput();
  $this
    ->assertPageNoErrorMessages();
  $params = [
    'civicrm_1_contact_1_contact_first_name' => 'Frederick',
    'civicrm_1_contact_1_contact_last_name' => 'Pabst',
    'civicrm_1_contact_1_email_email' => 'fred@example.com',
    'civicrm_2_contact_1_contact_first_name' => 'Mark',
    'civicrm_2_contact_1_contact_last_name' => 'Smith',
    'Participant Fee' => 20,
    'Text' => 'Foo',
  ];
  foreach ($params as $key => $val) {
    $this
      ->getSession()
      ->getPage()
      ->fillField($key, $val);
  }
  $refName = 'civicrm_1_participant_1_cg' . $this->cg['id'] . '_custom_' . $this->_customFields['participant_contact_ref']['id'];
  $this
    ->getSession()
    ->getPage()
    ->selectFieldOption($refName, 2);
  $this
    ->getSession()
    ->getPage()
    ->pressButton('Next >');
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  $this
    ->assertPageNoErrorMessages();
  $this
    ->htmlOutput();
  $this
    ->assertSession()
    ->elementExists('css', '#wf-crm-billing-items');
  $this
    ->htmlOutput();
  $this
    ->assertSession()
    ->elementTextContains('css', '#wf-crm-billing-total', '40.00');
  $this
    ->getSession()
    ->getPage()
    ->pressButton('Submit');
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  $this
    ->assertPageNoErrorMessages();
  $this
    ->htmlOutput();
  $contactRef = $this->utils
    ->wf_civicrm_api('Contact', 'get', [
    'first_name' => 'Mark',
    'last_name' => 'Smith',
  ]);
  $participant = current($this->utils
    ->wf_civicrm_api('Participant', 'get', [
    'contact_id' => $this->rootUserCid,
  ])['values']);
  $customKey = 'custom_' . $this->_customFields['participant_contact_ref']['id'];
  $this
    ->assertEquals('Smith, Mark', $participant[$customKey]);
  $this
    ->assertEquals($contactRef['id'], $participant["{$customKey}_id"]);
}