You are here

public function ContactAjaxTest::sendContactAjax in Contact ajax 8

Send each contact form testing respect and the confirmation_type.

1 call to ContactAjaxTest::sendContactAjax()
ContactAjaxTest::testContactAjax in tests/src/FunctionalJavascript/ContactAjaxTest.php
Tests contact messages submitted through contact form.

File

tests/src/FunctionalJavascript/ContactAjaxTest.php, line 157

Class

ContactAjaxTest
Tests contact form ajax submission.

Namespace

Drupal\Tests\contact_ajax\FunctionalJavascript

Code

public function sendContactAjax() {
  $assert = $this
    ->assertSession();

  // Build common data for tests.
  $edit = [];
  $edit['name'] = 'Test name';
  $edit['mail'] = 'simpletest@example.com';
  $edit['subject[0][value]'] = 'test subject';
  $edit['message[0][value]'] = 'test message';

  // Send form reload the same form.
  $form_id = 'test_id';
  $this
    ->drupalGet('contact/' . $form_id);
  $this
    ->drupalPostForm(NULL, $edit, t('Send message'));
  $assert
    ->assertWaitOnAjaxRequest();
  $assert
    ->pageTextContains('Your message has been sent.', '[OK] Your message has been sent.');

  // Submit form reload custom message.
  $form_id = 'test_custom_message_id';
  $this
    ->drupalGet('contact/' . $form_id);
  $this
    ->drupalPostForm(NULL, $edit, t('Send message'));
  $assert
    ->assertWaitOnAjaxRequest();
  $assert
    ->pageTextContains('test ajax message', '[OK] test ajax message.');

  // Send form reload another node.
  $form_id = 'test_node_content';
  $this
    ->drupalGet('contact/' . $form_id);
  $this
    ->drupalPostForm(NULL, $edit, t('Send message'));
  $assert
    ->assertWaitOnAjaxRequest();
  $assert
    ->pageTextContains('test ajax title', '[OK] test ajax title');

  // Send form reload another element.
  $form_id = 'test_load_other_element';
  $this
    ->drupalGet('contact/' . $form_id);
  $assert
    ->responseContains('id="ajax-contact-prefix"', '[OK] ajax prefix wrapper added');
  $this
    ->drupalPostForm(NULL, $edit, t('Send message'));
  $assert
    ->assertWaitOnAjaxRequest();
  $assert
    ->pageTextContains('Your message has been sent.', '[OK] Your message has been sent.');
  $assert
    ->responseNotContains('<form', '[OK] Form has been removed.');

  // Send uncomplete form shows validation errors.
  unset($edit['name']);
  $form_id = 'test_load_with_validation_errors';
  $this
    ->drupalGet('contact/' . $form_id);
  $this
    ->drupalPostForm(NULL, $edit, t('Send message'));
  $assert
    ->assertWaitOnAjaxRequest();
  $assert
    ->pageTextContains('Your name field is required.', '[OK] test render with form errors.');
}