public function ParagraphsContactTest::testContactForm

Same name in this branch
  1. 8.x-1.x paragraphs/tests/src/Functional/WidgetStable/ParagraphsContactTest.php \Drupal\Tests\paragraphs\Functional\WidgetStable\ParagraphsContactTest::testContactForm()
  2. 8.x-1.x paragraphs/tests/src/Functional/WidgetLegacy/ParagraphsContactTest.php \Drupal\Tests\paragraphs\Functional\WidgetLegacy\ParagraphsContactTest::testContactForm()

Tests adding paragraphs in contact forms.

File

paragraphs/tests/src/Functional/WidgetStable/ParagraphsContactTest.php, line 26

Class

ParagraphsContactTest
Tests paragraphs with contact forms.

Namespace

Drupal\Tests\paragraphs\Functional\WidgetStable

Code

public function testContactForm() {
  $this
    ->loginAsAdmin([
    'administer contact forms',
    'access site-wide contact form',
  ]);

  // Add a paragraph type.
  $this
    ->addParagraphsType('paragraphs_contact');
  $this
    ->addParagraphsType('text');

  // Create a contact form.
  $contact_form = ContactForm::create([
    'id' => 'test_contact_form',
    'label' => 'Test form',
  ]);
  $contact_form
    ->save();

  // Add a paragraphs field to the contact form.
  $this
    ->addParagraphsField($contact_form
    ->id(), 'paragraphs', 'contact_message');

  // Add a paragraph to the contact form.
  $this
    ->drupalGet('contact/test_contact_form');
  $this
    ->submitForm([], 'paragraphs_paragraphs_contact_add_more');

  // Check that the paragraph is displayed.
  $this
    ->assertSession()
    ->pageTextContains('paragraphs_contact');
  $this
    ->submitForm([], 'paragraphs_0_remove');
  $elements = $this
    ->xpath('//table[starts-with(@id, :id)]/tbody', [
    ':id' => 'paragraphs-values',
  ]);
  $header = $this
    ->xpath('//table[starts-with(@id, :id)]/thead', [
    ':id' => 'paragraphs-values',
  ]);
  $this
    ->assertEquals($elements, []);
  $this
    ->assertNotEquals($header, []);
}