MaxlengthJavascriptTest.php in Maxlength 8
File
tests/src/FunctionalJavascript/MaxlengthJavascriptTest.php
View source
<?php
namespace Drupal\Tests\maxlength\FunctionalJavascript;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
class MaxlengthJavascriptTest extends WebDriverTestBase {
public static $modules = [
'entity_test',
'maxlength',
];
protected $defaultTheme = 'classy';
public function testMaxlengthIsUnique() {
FieldStorageConfig::create([
'type' => 'text_long',
'entity_type' => 'entity_test',
'field_name' => 'foo',
])
->save();
FieldConfig::create([
'entity_type' => 'entity_test',
'bundle' => 'entity_test',
'field_name' => 'foo',
'label' => 'Foo',
'description' => 'Description of a text field',
])
->save();
$widget = [
'type' => 'text_textarea',
'third_party_settings' => [
'maxlength' => [
'maxlength_js' => 200,
],
],
];
EntityFormDisplay::load('entity_test.entity_test.default')
->setComponent('foo', $widget)
->save();
$entity = EntityTest::create([
'type' => 'entity_test',
'name' => 'Test',
]);
$entity
->save();
$this
->drupalLogin($this
->drupalCreateUser([
'administer entity_test content',
]));
$this
->drupalGet($entity
->toUrl('edit-form'));
$this
->getSession()
->wait(1000, 'jQuery("div.counter").is(":visible")');
$this
->assertSession()
->elementsCount('css', 'div.counter', 1);
$found = $this
->xpath('//div[@data-drupal-selector="edit-foo-0"]/following-sibling::div[@id="edit-foo-0-value-counter"]');
$this
->assertCount(1, $found);
}
}