SiteAlertUiTest.php in Site Alert 8
File
tests/src/Functional/SiteAlertUiTest.php
View source
<?php
namespace Drupal\Tests\site_alert\Functional;
class SiteAlertUiTest extends SiteAlertTestBase {
protected $defaultTheme = 'stark';
protected static $modules = [
'site_alert',
'block',
];
protected $adminUser;
protected function setUp() {
parent::setUp();
$this->adminUser = $this
->drupalCreateUser([
'administer site alert',
'add site alerts',
'update site alerts',
'delete site alerts',
'access administration pages',
]);
$this
->drupalLogin($this->adminUser);
}
public function testUi() {
$assert = $this
->assertSession();
$this
->drupalGet('admin/config/system/site-alerts');
$assert
->statusCodeEquals(200);
$assert
->pageTextContains('There are no site alerts yet.');
$this
->drupalGet('admin/config/system/site-alerts/add');
$this
->fillField('Label', 'Test alert');
$this
->fillField('Active', '1');
$this
->fillField('Severity', 'high');
$this
->fillField('Message', 'Test alert.');
$this
->pressButton('Save');
$assert
->statusCodeEquals(200);
$block_id = strtolower($this
->randomMachineName(8));
$this
->drupalPlaceBlock('site_alert_block', [
'id' => $block_id,
'timeout' => 0,
]);
$this
->drupalGet('<front>');
$assert
->pageTextContains('Test alert.');
$assert
->elementExists('css', '#block-' . $block_id);
$this
->drupalGet('admin/config/system/site-alerts');
$assert
->pageTextNotContains('There are no site alert entities yet.');
$this
->clickLink('Delete');
$assert
->pageTextContains('This action cannot be undone.');
$this
->pressButton('Delete');
$assert
->statusCodeEquals(200);
$assert
->pageTextContains('The Site Alert Test alert has been deleted.');
$this
->drupalGet('<front>');
$assert
->pageTextNotContains('Test alert.');
$assert
->elementNotExists('css', '#block-' . $block_id);
}
}