KeyAdminTest.php in Key 8
File
tests/src/Functional/KeyAdminTest.php
View source
<?php
namespace Drupal\Tests\key\Functional;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Tests\BrowserTestBase;
use Drupal\Core\Url;
class KeyAdminTest extends BrowserTestBase {
use KeyTestTrait;
protected static $modules = [
'key',
];
protected $adminUser;
protected $defaultTheme = 'stark';
protected function setUp() {
parent::setUp();
$this->adminUser = $this
->drupalCreateUser([
'administer keys',
]);
}
public function testKeyListBuilder() {
$this
->drupalLogin($this->adminUser);
$assert_session = $this
->assertSession();
$this
->drupalGet('admin/config/system/keys');
$assert_session
->statusCodeEquals(200);
$assert_session
->responseContains(new FormattableMarkup('No keys are available. <a href=":link">Add a key</a>.', [
':link' => Url::fromRoute('entity.key.add_form')
->toString(),
]));
$this
->drupalGet('admin/config/system/keys/add');
$edit = [
'id' => 'testing_key',
'label' => 'Testing Key',
];
$this
->drupalPostForm(NULL, $edit, 'Save');
$this
->drupalGet('admin/config/system/keys');
$assert_session
->statusCodeEquals(200);
$assert_session
->pageTextNotContains('No keys are available.');
}
public function testAdminUserRoutes() {
$this
->createTestKey('key_foo');
$this
->createTestKeyConfigOverride('test_override', 'key_foo');
$this
->drupalLogin($this->adminUser);
$basicKeyRoutes = [
'entity.key.collection' => [],
'entity.key.add_form' => [],
'entity.key.edit_form' => [
'key' => 'key_foo',
],
'entity.key.delete_form' => [
'key' => 'key_foo',
],
];
$overrideKeyRoutes = [
'entity.key_config_override.collection' => [],
'entity.key_config_override.add_form' => [],
'entity.key_config_override.delete_form' => [
'key_config_override' => 'test_override',
],
];
$this
->routeAccessTest($basicKeyRoutes, 200);
$this
->routeAccessTest($overrideKeyRoutes, 403);
}
}