DomainEntityAccessTest.php in Domain Access 8
File
domain/tests/src/Functional/DomainEntityAccessTest.php
View source
<?php
namespace Drupal\Tests\domain\Functional;
class DomainEntityAccessTest extends DomainTestBase {
public function testDomainCreate() {
$admin = $this
->drupalCreateUser([
'access administration pages',
'administer domains',
]);
$this
->drupalLogin($admin);
$storage = \Drupal::entityTypeManager()
->getStorage('domain');
$this
->domainTableIsEmpty();
$this
->drupalGet('admin/config/domain');
$this
->assertText('There are no domain record entities yet.', 'Text for no domains found.');
$this
->drupalGet('admin/config/domain/add');
$edit = $this
->domainPostValues();
$edit['hostname'] = 'example.com';
$this
->drupalGet('admin/config/domain/add');
$this
->submitForm($edit, 'Save');
$default_id = $storage
->loadDefaultId();
$this
->assertNotEmpty($default_id, 'Domain record saved via form.');
$storage
->resetCache([
$default_id,
]);
$new_domain = $storage
->load($default_id);
$this
->assertTrue($new_domain
->id() == $default_id, 'Domain loaded properly.');
$this
->drupalLogout();
$editor = $this
->drupalCreateUser([
'access administration pages',
'create domains',
'view domain list',
]);
$this
->drupalLogin($editor);
$this
->drupalGet('admin/config/domain/add');
$this
->assertResponse(200);
$edit = $this
->domainPostValues();
$edit['hostname'] = 'one.example.com';
$edit['id'] = \Drupal::entityTypeManager()
->getStorage('domain')
->createMachineName($edit['hostname']);
$this
->drupalGet('admin/config/domain/add');
$this
->submitForm($edit, 'Save');
$storage
->resetCache([
$edit['id'],
]);
$new_domain = $storage
->load($edit['id']);
$this
->assertTrue($new_domain
->id() == $edit['id'], 'Domain loaded properly.');
$this
->drupalLogout();
$noneditor = $this
->drupalCreateUser([
'access administration pages',
]);
$this
->drupalLogin($noneditor);
$this
->drupalGet('admin/config/domain/add');
$this
->assertResponse(403);
}
}