You are here

public function ContactSubmissionTest::testStaticCurrentUser in Webform CiviCRM Integration 8.5

Test Existing Contact Element configured as Current (logged-in) User

File

tests/src/FunctionalJavascript/ContactSubmissionTest.php, line 265

Class

ContactSubmissionTest
Tests submitting a Webform with CiviCRM and a single contact.

Namespace

Drupal\Tests\webform_civicrm\FunctionalJavascript

Code

public function testStaticCurrentUser() {
  $this
    ->drupalLogin($this->rootUser);
  $this
    ->drupalGet(Url::fromRoute('entity.webform.civicrm', [
    'webform' => $this->webform
      ->id(),
  ]));
  $this
    ->enableCivicrmOnWebform();

  // Scenario: root user is configuring the form - so that the logged in Contact details appear
  $this
    ->assertSession()
    ->checkboxChecked('Existing Contact');
  $this
    ->assertSession()
    ->checkboxChecked('First Name');
  $this
    ->assertSession()
    ->checkboxChecked('Last Name');
  $this
    ->getSession()
    ->getPage()
    ->checkField('Preferred Communication Method(s)');
  $this
    ->assertSession()
    ->checkboxChecked('Preferred Communication Method(s)');
  $this
    ->saveCiviCRMSettings();
  $this
    ->drupalGet($this->webform
    ->toUrl('edit-form'));
  $editContact = [
    'selector' => 'edit-webform-ui-elements-civicrm-1-contact-1-contact-existing-operations',
    'widget' => 'Static',
    'default' => 'Current User',
  ];
  $this
    ->editContactElement($editContact);
  $this
    ->assertSession()
    ->pageTextContains('Existing Contact has been updated');
  $this
    ->editCivicrmOptionElement('edit-webform-ui-elements-civicrm-1-contact-1-contact-preferred-communication-method-operations', FALSE);
  $this
    ->drupalLogout();
  $this
    ->drupalLogin($this->adminUser);
  $currentUserUF = $this
    ->getUFMatchRecord($this->adminUser
    ->id());
  $this->utils
    ->wf_civicrm_api('contact', 'create', [
    'id' => $currentUserUF['contact_id'],
    'first_name' => "Admin",
    'last_name' => "User",
  ]);
  $this
    ->drupalGet($this->webform
    ->toUrl('canonical'));
  $this
    ->assertPageNoErrorMessages();
  $this
    ->assertSession()
    ->waitForField('First Name');
  $this
    ->assertSession()
    ->fieldValueEquals('First Name', 'Admin');
  $this
    ->assertSession()
    ->fieldValueEquals('Last Name', 'User');
  $this
    ->getSession()
    ->getPage()
    ->pressButton('Submit');
  $this
    ->assertSession()
    ->pageTextContains('New submission added to CiviCRM Webform Test.');
  $this
    ->assertPageNoErrorMessages();
}