Namespace
Drupal\Tests\update\Functional
File
core/modules/update/tests/src/Functional/UpdateSettingsFormTest.php
View source
<?php
declare (strict_types=1);
namespace Drupal\Tests\update\Functional;
use Drupal\Core\Messenger\MessengerInterface;
use Drupal\Core\Url;
use Drupal\Tests\BrowserTestBase;
class UpdateSettingsFormTest extends BrowserTestBase {
protected static $modules = [
'update',
];
protected $defaultTheme = 'stark';
public function testUpdateSettingsForm() {
$url = Url::fromRoute('update.settings');
$this
->drupalGet($url);
$this
->assertSession()
->pageTextContains('Access denied');
$permissions = [
'administer site configuration',
];
$account = $this
->setUpCurrentUser([
'name' => 'system_admin',
'pass' => 'adminPass',
], $permissions);
$this
->drupalLogin($account);
$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',
];
$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'));
$this
->assertSession()
->fieldExists('update_notify_emails')
->setValue(implode("\n", array_slice($values_to_enter, 1, 2)));
$this
->submitForm([], 'Save configuration');
$this
->assertSession()
->statusMessageNotExists(MessengerInterface::TYPE_STATUS);
$this
->assertSession()
->statusMessageNotExists(MessengerInterface::TYPE_WARNING);
$this
->assertSession()
->statusMessageContains('"http://example.com/also-not-an-email-address" 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'));
$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'));
$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
->assertFalse($this
->assertSession()
->fieldExists('update_notify_emails')
->hasClass('error'));
$this
->assertSame([
'sofie@example.com',
'dries@example.com',
], $this
->config('update.settings')
->get('notification.emails'));
}
}
Classes