You are here

public function MaxlengthCustomWidgetTest::testMaxlengthCustomWidgetSupported in Maxlength 8

Tests that a custom textarea widget gets picked up and is supported.

File

tests/src/FunctionalJavascript/MaxlengthCustomWidgetTest.php, line 52

Class

MaxlengthCustomWidgetTest
Tests the custom widget support.

Namespace

Drupal\Tests\maxlength\FunctionalJavascript

Code

public function testMaxlengthCustomWidgetSupported() {
  $admin_user = $this
    ->drupalCreateUser([
    'bypass node access',
    'administer nodes',
    'administer node form display',
  ]);
  $this
    ->drupalLogin($admin_user);
  $this
    ->drupalGet('admin/structure/types/manage/article/form-display');
  $page = $this
    ->getSession()
    ->getPage();
  $page
    ->pressButton('edit-fields-body-settings-edit');
  $this
    ->getSession()
    ->wait(1000);
  $this
    ->assertSession()
    ->elementsCount('css', '[data-drupal-selector="edit-fields-body-settings-edit-form-third-party-settings-maxlength-maxlength-js-summary"]', 1);
  $page
    ->findField('Summary max length')
    ->setValue("123");
  $page
    ->pressButton('Save');
  $this
    ->assertSession()
    ->responseContains('Max summary length: 123');
  $this
    ->drupalGet('node/add/article');

  // Give maxlength.js some time to manipulate the DOM.
  $this
    ->getSession()
    ->wait(1000, 'jQuery("div.counter").is(":visible")');

  // Check each counter for summary and body.
  $this
    ->assertSession()
    ->elementsCount('css', 'div.counter', 2);

  // Check that the counter div follows the description of the field.
  $found = $this
    ->xpath('//textarea[@data-drupal-selector="edit-body-0-value"]/following-sibling::div[@id="edit-body-0-value-counter"]');
  $this
    ->assertCount(1, $found);
}