diff --git a/core/modules/update/tests/src/Functional/UpdateSettingsFormTest.php b/core/modules/update/tests/src/Functional/UpdateSettingsFormTest.php index f653d35dce..ba04807a0d 100644 --- a/core/modules/update/tests/src/Functional/UpdateSettingsFormTest.php +++ b/core/modules/update/tests/src/Functional/UpdateSettingsFormTest.php @@ -46,22 +46,43 @@ public function testUpdateSettingsForm() { $this->drupalGet($url); $this->assertSession()->fieldExists('update_notify_emails'); + $values_to_enter = [ + 'http://example.com', + 'sofie@example.com', + 'http://example.com/also-not-an-email-address', + 'dries@example.com', + ]; + // Fill in `http://example.com` as the email address to notify. We expect - // this to trigger a validation error, because it's not an email address. + // this to trigger a validation error, because it's not an email address, + // and for the corresponding form item to be highlighted. + $this->assertSession()->fieldExists('update_notify_emails')->setValue($values_to_enter[0]); $this->submitForm([], 'Save configuration'); $this->assertSession()->statusMessageNotExists(MessengerInterface::TYPE_STATUS); $this->assertSession()->statusMessageNotExists(MessengerInterface::TYPE_WARNING); $this->assertSession()->statusMessageContains('http://example.com is not a valid email address.', MessengerInterface::TYPE_ERROR); + $this->assertTrue($this->assertSession()->fieldExists('update_notify_emails')->hasClass('error')); + $this->assertSame([], $this->config('update.settings')->get('notification.emails')); + + // Next, set multiple invalid email addresses, and assert the same as above + // except the message should be adjusted now. + $this->assertSession()->fieldExists('update_notify_emails')->setValue(implode("\n", $values_to_enter)); + $this->submitForm([], 'Save configuration'); + $this->assertSession()->statusMessageNotExists(MessengerInterface::TYPE_STATUS); + $this->assertSession()->statusMessageNotExists(MessengerInterface::TYPE_WARNING); + $this->assertSession()->statusMessageContains('http://example.com, http://example.com/also-not-an-email-address are not valid email addresses.', MessengerInterface::TYPE_ERROR); + $this->assertTrue($this->assertSession()->fieldExists('update_notify_emails')->hasClass('error')); $this->assertSame([], $this->config('update.settings')->get('notification.emails')); - // Now fill in a valid email address, now the form should be saved + // Now fill in valid email addresses, now the form should be saved // successfully. - $this->assertSession()->fieldExists('update_notify_emails')->setValue('sofie@example.com'); + $this->assertSession()->fieldExists('update_notify_emails')->setValue("$values_to_enter[1]\r\n$values_to_enter[3]"); $this->submitForm([], 'Save configuration'); $this->assertSession()->statusMessageContains('The configuration options have been saved.', MessengerInterface::TYPE_STATUS); $this->assertSession()->statusMessageNotExists(MessengerInterface::TYPE_WARNING); $this->assertSession()->statusMessageNotExists(MessengerInterface::TYPE_ERROR); - $this->assertSame(['sofie@example.com'], $this->config('update.settings')->get('notification.emails')); + $this->assertFalse($this->assertSession()->fieldExists('update_notify_emails')->hasClass('error')); + $this->assertSame(['sofie@example.com', 'dries@example.com'], $this->config('update.settings')->get('notification.emails')); } }