diff --git a/core/modules/system/src/Tests/Validation/WidgetBaseErrorElementTest.php b/core/modules/system/src/Tests/Validation/WidgetBaseErrorElementTest.php index 85e0466..7417f87 100644 --- a/core/modules/system/src/Tests/Validation/WidgetBaseErrorElementTest.php +++ b/core/modules/system/src/Tests/Validation/WidgetBaseErrorElementTest.php @@ -37,21 +37,21 @@ class WidgetBaseErrorElementTest extends WebTestBase { * * @var \Drupal\user\UserInterface */ - protected $adminUser; + protected $admin_user; /** * Entity form display. * * @var \Drupal\Core\Entity\Display\EntityFormDisplayInterface */ - protected $formDisplay; + protected $form_display; /** * URL to add new content. * * @var string */ - protected $formContentAddUrl; + protected $form_content_add_url; /** * {@inheritdoc} @@ -60,17 +60,17 @@ protected function setUp() { parent::setUp(); $this->drupalCreateContentType(['type' => 'article']); - $this->adminUser = $this->drupalCreateUser([ + $this->admin_user = $this->drupalCreateUser([ 'create article content', 'edit own article content', 'administer content types', ]); - $this->drupalLogin($this->adminUser); + $this->drupalLogin($this->admin_user); // Set article's form display. - $this->formDisplay = EntityFormDisplay::load('node.article.default'); - if (!$this->formDisplay) { - $this->formDisplay = EntityFormDisplay::create([ + $this->form_display = EntityFormDisplay::load('node.article.default'); + if (!$this->form_display) { + $this->form_display = EntityFormDisplay::create([ 'targetEntityType' => 'node', 'bundle' => 'article', 'mode' => 'default', @@ -78,10 +78,7 @@ protected function setUp() { ])->save(); } - $this->formContentAddUrl = 'node/add/article'; - - $this->drupalGet($this->formContentAddUrl); - $this->assertResponse(200, 'Article add form can be accessed at ' . $this->formContentAddUrl); + $this->form_content_add_url = 'node/add/article'; } /** @@ -90,25 +87,25 @@ protected function setUp() { public function testMultipleFormElementsWidget() { $edit = []; // Add an text area with summary and email field to the article content type. - $fieldStorage = FieldStorageConfig::create([ + $field_storage = FieldStorageConfig::create([ 'field_name' => 'field_test_multiple', 'entity_type' => 'node', 'type' => 'text_with_summary_and_email', ]); - $fieldStorage->save(); + $field_storage->save(); - $fieldInstance = FieldConfig::create([ - 'field_storage' => $fieldStorage, + $field_instance = FieldConfig::create([ + 'field_storage' => $field_storage, 'bundle' => 'article', 'label' => 'Text with summary', 'settings' => [ 'display_summary' => TRUE, ], ]); - $fieldInstance->save(); + $field_instance->save(); - $this->formDisplay - ->setComponent($fieldInstance->getName(), [ + $this->form_display + ->setComponent($field_instance->getName(), [ 'type' => 'text_textarea_with_summary_and_email', ])->save(); @@ -117,12 +114,12 @@ public function testMultipleFormElementsWidget() { $edit['field_test_multiple[0][summary]'] = 'Some summary'; $edit['field_test_multiple[0][value]'] = 'Some text'; $edit['field_test_multiple[0][email]'] = $email; - $this->drupalPostForm($this->formContentAddUrl, $edit, t('Save')); + $this->drupalPostForm($this->form_content_add_url, $edit, t('Save')); $this->assertResponse(200); - $this->assertPattern('/(?ms)
.*1 error has been found.*
.*Email<\/a>.*<\/div>.*<\/div>/', 'Error message for the invalid email "'. $email .'" found on '. $this->formContentAddUrl .' form.'); - $this->assertTrue((bool) $this->xpath('//input[@name="field_test_multiple[0][email]" and boolean(@aria-invalid)]'), 'Email test field is marked invalid on form '. $this->formContentAddUrl); - $this->assertTrue((bool) $this->xpath('//textarea[@name="field_test_multiple[0][summary]" and not(boolean(@aria-invalid))]'), 'Summary test field is not marked invalid on form '. $this->formContentAddUrl); - $this->assertTrue((bool) $this->xpath('//textarea[@name="field_test_multiple[0][value]" and not(boolean(@aria-invalid))]'), 'Value test field is not marked invalid on form '. $this->formContentAddUrl); + $this->assertPattern('/(?ms)
.*1 error has been found.*
.*Email<\/a>.*<\/div>.*<\/div>/', 'Error message for the invalid email "'. $email .'" found on '. $this->form_content_add_url .' form.'); + $this->assertTrue((bool) $this->xpath('//input[@name="field_test_multiple[0][email]" and boolean(@aria-invalid)]'), 'Email test field is marked invalid on form '. $this->form_content_add_url); + $this->assertTrue((bool) $this->xpath('//textarea[@name="field_test_multiple[0][summary]" and not(boolean(@aria-invalid))]'), 'Summary test field is not marked invalid on form '. $this->form_content_add_url); + $this->assertTrue((bool) $this->xpath('//textarea[@name="field_test_multiple[0][value]" and not(boolean(@aria-invalid))]'), 'Value test field is not marked invalid on form '. $this->form_content_add_url); } /** @@ -131,22 +128,22 @@ public function testMultipleFormElementsWidget() { public function testSingleCardinalityWidget() { $edit = []; // Add an email field to the article content type. - $fieldStorage = FieldStorageConfig::create([ + $field_storage = FieldStorageConfig::create([ 'field_name' => 'field_email', 'entity_type' => 'node', 'type' => 'email', ]); - $fieldStorage->save(); + $field_storage->save(); - $fieldInstance = FieldConfig::create([ - 'field_storage' => $fieldStorage, + $field_instance = FieldConfig::create([ + 'field_storage' => $field_storage, 'bundle' => 'article', 'label' => 'Email', ]); - $fieldInstance->save(); + $field_instance->save(); - $this->formDisplay - ->setComponent($fieldInstance->getName(), [ + $this->form_display + ->setComponent($field_instance->getName(), [ 'type' => 'email_default', 'settings' => [ 'placeholder' => 'example@example.com', @@ -154,43 +151,43 @@ public function testSingleCardinalityWidget() { ])->save(); // Post errorneous email address and check form errors. - $fieldName = 'field_email[0][value]'; + $field_name = 'field_email[0][value]'; $email = 'invalid#invalid.com'; $edit['title[0][value]'] = $this->randomMachineName(8);; - $edit[$fieldName] = $email; - $this->drupalPostForm($this->formContentAddUrl, $edit, t('Save')); + $edit[$field_name] = $email; + $this->drupalPostForm($this->form_content_add_url, $edit, t('Save')); $this->assertResponse(200); - $this->assertPattern('/(?ms)
.*1 error has been found.*
.*Email<\/a>.*<\/div>.*<\/div>/', 'Error message for the invalid email "'. $email .'" found on '. $this->formContentAddUrl .' form.'); - $this->assertTrue((bool) $this->xpath('//input[@name="'. $fieldName .'" and boolean(@aria-invalid)]'), 'Email field is marked invalid on form '. $this->formContentAddUrl); + $this->assertPattern('/(?ms)
.*1 error has been found.*
.*Email<\/a>.*<\/div>.*<\/div>/', 'Error message for the invalid email "'. $email .'" found on '. $this->form_content_add_url .' form.'); + $this->assertTrue((bool) $this->xpath('//input[@name="'. $field_name .'" and boolean(@aria-invalid)]'), 'Email field is marked invalid on form '. $this->form_content_add_url); } /** * Test validation violation of email multiple cardinality widget. */ public function testMultipleCardinalityWidget() { - $validEmail1 = 'test1@example.com'; - $validEmail2 = 'test1@example.com'; - $invalidEmail1 = 'invalid1#invalid.com'; - $invalidEmail2 = 'invalid1#invalid.com'; + $valid_email_1 = 'test1@example.com'; + $valid_email_2 = 'test1@example.com'; + $invalid_email_1 = 'invalid1#invalid.com'; + $invalid_email_2 = 'invalid1#invalid.com'; $edit = []; // Add an email field to the article content type. - $fieldStorage = FieldStorageConfig::create([ + $field_storage = FieldStorageConfig::create([ 'field_name' => 'field_email', 'entity_type' => 'node', 'type' => 'email', 'cardinality' => 3, ]); - $fieldStorage->save(); + $field_storage->save(); - $fieldInstance = FieldConfig::create([ - 'field_storage' => $fieldStorage, + $field_instance = FieldConfig::create([ + 'field_storage' => $field_storage, 'bundle' => 'article', 'label' => 'Email', ]); - $fieldInstance->save(); + $field_instance->save(); - $this->formDisplay - ->setComponent($fieldInstance->getName(), [ + $this->form_display + ->setComponent($field_instance->getName(), [ 'type' => 'email_default', 'settings' => [ 'placeholder' => 'example@example.com', @@ -200,27 +197,27 @@ public function testMultipleCardinalityWidget() { // Post 3 email addresses, set errorneous email address in second field // and check form errors. $edit['title[0][value]'] = $this->randomMachineName(8); - $edit['field_email[0][value]'] = $validEmail1; - $edit['field_email[1][value]'] = $invalidEmail1; - $edit['field_email[2][value]'] = $validEmail2; - $this->drupalPostForm($this->formContentAddUrl, $edit, t('Save')); + $edit['field_email[0][value]'] = $valid_email_1; + $edit['field_email[1][value]'] = $invalid_email_1; + $edit['field_email[2][value]'] = $valid_email_2; + $this->drupalPostForm($this->form_content_add_url, $edit, t('Save')); $this->assertResponse(200); - $this->assertPattern('/(?ms)
.*1 error has been found.*
.*Email \(value 2\)<\/a>.*<\/div>.*<\/div>/', 'Error message for the invalid email "'. $invalidEmail1 .'" found on '. $this->formContentAddUrl .' form.'); - $this->assertTrue((bool) $this->xpath('//input[@name="field_email[0][value]" and not(boolean(@aria-invalid))]'), 'First email field is not marked invalid on form '. $this->formContentAddUrl); - $this->assertTrue((bool) $this->xpath('//input[@name="field_email[1][value]" and boolean(@aria-invalid)]'), 'Second email field is marked invalid on form '. $this->formContentAddUrl); - $this->assertTrue((bool) $this->xpath('//input[@name="field_email[2][value]" and not(boolean(@aria-invalid))]'), 'Third email field is not marked invalid on form '. $this->formContentAddUrl); + $this->assertPattern('/(?ms)
.*1 error has been found.*
.*Email \(value 2\)<\/a>.*<\/div>.*<\/div>/', 'Error message for the invalid email "'. $invalid_email_1 .'" found on '. $this->form_content_add_url .' form.'); + $this->assertTrue((bool) $this->xpath('//input[@name="field_email[0][value]" and not(boolean(@aria-invalid))]'), 'First email field is not marked invalid on form '. $this->form_content_add_url); + $this->assertTrue((bool) $this->xpath('//input[@name="field_email[1][value]" and boolean(@aria-invalid)]'), 'Second email field is marked invalid on form '. $this->form_content_add_url); + $this->assertTrue((bool) $this->xpath('//input[@name="field_email[2][value]" and not(boolean(@aria-invalid))]'), 'Third email field is not marked invalid on form '. $this->form_content_add_url); // Now set errorneous email address in first and third fields // and check form errors. $edit['title[0][value]'] = $this->randomMachineName(8); - $edit['field_email[0][value]'] = $invalidEmail1; - $edit['field_email[1][value]'] = $validEmail1; - $edit['field_email[2][value]'] = $invalidEmail2; - $this->drupalPostForm($this->formContentAddUrl, $edit, t('Save')); + $edit['field_email[0][value]'] = $invalid_email_1; + $edit['field_email[1][value]'] = $valid_email_1; + $edit['field_email[2][value]'] = $invalid_email_2; + $this->drupalPostForm($this->form_content_add_url, $edit, t('Save')); $this->assertResponse(200); - $this->assertPattern('/(?ms)
.*2 errors have been found.*
.*Email \(value 1\)<\/a>.*Email \(value 3\)<\/a>.*<\/div>.*<\/div>/', 'Error message for the invalid email "'. $invalidEmail1 .', '. $invalidEmail2 .'" found on '. $this->formContentAddUrl .' form.'); - $this->assertTrue((bool) $this->xpath('//input[@name="field_email[0][value]" and boolean(@aria-invalid)]'), 'First email field is marked invalid on form '. $this->formContentAddUrl); - $this->assertTrue((bool) $this->xpath('//input[@name="field_email[1][value]" and not(boolean(@aria-invalid))]'), 'Second email field is not marked invalid on form '. $this->formContentAddUrl); - $this->assertTrue((bool) $this->xpath('//input[@name="field_email[2][value]" and boolean(@aria-invalid)]'), 'Third email field is marked invalid on form '. $this->formContentAddUrl); + $this->assertPattern('/(?ms)
.*2 errors have been found.*
.*Email \(value 1\)<\/a>.*Email \(value 3\)<\/a>.*<\/div>.*<\/div>/', 'Error message for the invalid email "'. $invalid_email_1 .', '. $invalid_email_2 .'" found on '. $this->form_content_add_url .' form.'); + $this->assertTrue((bool) $this->xpath('//input[@name="field_email[0][value]" and boolean(@aria-invalid)]'), 'First email field is marked invalid on form '. $this->form_content_add_url); + $this->assertTrue((bool) $this->xpath('//input[@name="field_email[1][value]" and not(boolean(@aria-invalid))]'), 'Second email field is not marked invalid on form '. $this->form_content_add_url); + $this->assertTrue((bool) $this->xpath('//input[@name="field_email[2][value]" and boolean(@aria-invalid)]'), 'Third email field is marked invalid on form '. $this->form_content_add_url); } } diff --git a/core/modules/system/tests/modules/widgetbase_error_element_test/src/Plugin/Field/FieldFormatter/TextWithSummaryAndEmailDefaultFormatter.php b/core/modules/system/tests/modules/widgetbase_error_element_test/src/Plugin/Field/FieldFormatter/TextWithSummaryAndEmailDefaultFormatter.php index 7aef2d8..c7bdffe 100644 --- a/core/modules/system/tests/modules/widgetbase_error_element_test/src/Plugin/Field/FieldFormatter/TextWithSummaryAndEmailDefaultFormatter.php +++ b/core/modules/system/tests/modules/widgetbase_error_element_test/src/Plugin/Field/FieldFormatter/TextWithSummaryAndEmailDefaultFormatter.php @@ -11,7 +11,7 @@ use Drupal\Core\Field\FieldItemListInterface; /** - * Plugin implementation of the 'test_text_default' formatter. + * Plugin implementation of the 'text_with_summary_and_email_default' formatter. * * @FieldFormatter( * id = "text_with_summary_and_email_default", diff --git a/core/modules/system/tests/modules/widgetbase_error_element_test/src/Plugin/Field/FieldType/TextWithSummaryAndEmailItem.php b/core/modules/system/tests/modules/widgetbase_error_element_test/src/Plugin/Field/FieldType/TextWithSummaryAndEmailItem.php index beafeec..f5cda8d 100644 --- a/core/modules/system/tests/modules/widgetbase_error_element_test/src/Plugin/Field/FieldType/TextWithSummaryAndEmailItem.php +++ b/core/modules/system/tests/modules/widgetbase_error_element_test/src/Plugin/Field/FieldType/TextWithSummaryAndEmailItem.php @@ -13,7 +13,7 @@ use Drupal\text\Plugin\Field\FieldType\TextWithSummaryItem; /** - * Plugin implementation of the 'test_text_with_summary' field type. + * Plugin implementation of the 'text_with_summary_and_email' field type. * * @FieldType( * id = "text_with_summary_and_email",