MaxlengthCustomWidgetTest.php in Maxlength 8
File
tests/src/FunctionalJavascript/MaxlengthCustomWidgetTest.php
View source
<?php
namespace Drupal\Tests\maxlength\FunctionalJavascript;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
class MaxlengthCustomWidgetTest extends WebDriverTestBase {
protected static $modules = [
'node',
'field',
'field_ui',
'maxlength',
'maxlength_custom_widget_test',
];
protected $defaultTheme = 'classy';
protected function setUp() {
parent::setUp();
$this
->drupalCreateContentType([
'type' => 'article',
'name' => 'Article',
]);
EntityFormDisplay::load('node.article.default')
->setComponent('body', [
'type' => 'text_textarea_custom_widget',
'third_party_settings' => [
'maxlength' => [
'maxlength_js' => 200,
],
],
])
->save();
}
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');
$this
->getSession()
->wait(1000, 'jQuery("div.counter").is(":visible")');
$this
->assertSession()
->elementsCount('css', 'div.counter', 2);
$found = $this
->xpath('//textarea[@data-drupal-selector="edit-body-0-value"]/following-sibling::div[@id="edit-body-0-value-counter"]');
$this
->assertCount(1, $found);
}
}