You are here

public function MultiCustomFieldsSubmissionTest::testContactRefSubmission in Webform CiviCRM Integration 8.5

Submit webform with 3 contact reference fields.

File

tests/src/FunctionalJavascript/MultiCustomFieldsSubmissionTest.php, line 187

Class

MultiCustomFieldsSubmissionTest
Tests submitting a Webform with CiviCRM: single contact + custom fields.

Namespace

Drupal\Tests\webform_civicrm\FunctionalJavascript

Code

public function testContactRefSubmission() {
  $this->_totalMV = 5;
  $this
    ->createMultiValueCustomFields();
  $this
    ->drupalLogin($this->rootUser);
  $this
    ->drupalGet(Url::fromRoute('entity.webform.civicrm', [
    'webform' => $this->webform
      ->id(),
  ]));
  $this
    ->enableCivicrmOnWebform();
  $this
    ->getSession()
    ->getPage()
    ->selectFieldOption("number_of_contacts", $this->_totalMV);
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  $this
    ->htmlOutput();
  $this
    ->enableCustomFields(1);
  $this
    ->htmlOutput();
  foreach ([
    2,
    3,
    4,
    5,
  ] as $c) {
    $this
      ->getSession()
      ->getPage()
      ->clickLink("Contact {$c}");
    $this
      ->assertSession()
      ->assertWaitOnAjaxRequest();
    $this
      ->getSession()
      ->getPage()
      ->selectFieldOption("{$c}_contact_type", 'Household');
    $this
      ->assertSession()
      ->assertWaitOnAjaxRequest();
    $this
      ->getSession()
      ->getPage()
      ->checkField("civicrm_{$c}_contact_1_contact_existing");
    $this
      ->assertSession()
      ->checkboxChecked("civicrm_{$c}_contact_1_contact_existing");
  }
  $this
    ->saveCiviCRMSettings();
  $this->_hh = [];
  foreach ([
    2,
    3,
    4,
    5,
  ] as $c) {

    // Create 4 households to select on the ref fields while submitting the webform.
    $params = [
      'household_name' => "HH{$c}",
    ];
    $this->_hh[$c] = $this
      ->createHousehold($params);
    $this
      ->drupalGet($this->webform
      ->toUrl('edit-form'));
    $editContact = [
      'selector' => "edit-webform-ui-elements-civicrm-{$c}-contact-1-contact-existing-operations",
      'widget' => 'Select',
      'default' => '- None -',
    ];
    $this
      ->editContactElement($editContact);
  }
  $this
    ->htmlOutput();
  $this
    ->drupalGet($this->webform
    ->toUrl('canonical'));
  $this
    ->htmlOutput();
  $this
    ->assertPageNoErrorMessages();

  //Submit only 3 multi-value fields. Contact 1 is default to current user.
  $this
    ->getSession()
    ->getPage()
    ->selectFieldOption('civicrm_2_contact_1_contact_existing', $this->_hh[2]['id']);
  $this
    ->getSession()
    ->getPage()
    ->selectFieldOption('civicrm_3_contact_1_contact_existing', $this->_hh[3]['id']);
  $params = [];
  $params['civicrm_1_contact_1_cg1_custom_1'] = 'Jan';
  $params['civicrm_1_contact_1_cg1_custom_2'] = 100;
  $params['civicrm_1_contact_2_cg1_custom_1'] = 'Feb';
  $params['civicrm_1_contact_2_cg1_custom_2'] = 200;
  $params['civicrm_1_contact_3_cg1_custom_1'] = 'March';
  $params['civicrm_1_contact_3_cg1_custom_2'] = 200;
  $this
    ->submitWebform($params);
  $this
    ->verifyCustomValues($params);
}