class ParagraphsContactTest

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

Tests paragraphs with contact forms.

@group paragraphs

Hierarchy

  • class \Drupal\Tests\paragraphs\Functional\WidgetLegacy\ParagraphsTestBase extends \Drupal\Tests\BrowserTestBase uses \Drupal\Tests\field_ui\Traits\FieldUiTestTrait

Expanded class hierarchy of ParagraphsContactTest

File

paragraphs/tests/src/Functional/WidgetLegacy/ParagraphsContactTest.php, line 12

Namespace

Drupal\Tests\paragraphs\Functional\WidgetLegacy
View source
class ParagraphsContactTest extends ParagraphsTestBase {

  /**
   * Modules to enable.
   *
   * @var array
   */
  protected static $modules = array(
    'contact',
  );

  /**
   * Tests adding paragraphs in contact forms.
   */
  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', 'entity_reference_paragraphs');

    // 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');
    $this
      ->assertSession()
      ->pageTextContains('Deleted Paragraph: paragraphs_contact');
  }

}

Members

Namesort ascending Modifiers Type Description Overrides
ParagraphsTestBase::setUp protected function 19
ParagraphsTestBase::setParagraphsWidgetMode protected function Sets the Paragraphs widget display mode.
ParagraphsTestBase::setParagraphsTypeWeight protected function Sets the weight of a given Paragraphs type.
ParagraphsTestBase::setDefaultParagraphType protected function Sets the default paragraph type.
ParagraphsTestBase::setAllowedParagraphsTypes protected function Sets the allowed Paragraphs types that can be added.
ParagraphsTestBase::setAddMode protected function Sets the Paragraphs widget add mode. 1
ParagraphsTestBase::removeDefaultParagraphType protected function Removes the default paragraph type. 1
ParagraphsTestBase::loginAsAdmin function Creates an user with admin permissions and log in.
ParagraphsTestBase::$defaultTheme protected property 2
ParagraphsTestBase::$admin_user protected property Drupal user object created by loginAsAdmin(). 1
ParagraphsTestBase::$admin_permissions protected property List of permissions used by loginAsAdmin().
ParagraphsContactTest::testContactForm public function Tests adding paragraphs in contact forms.
ParagraphsContactTest::$modules protected static property Modules to enable. Overrides ParagraphsTestBase::$modules