ConfigPermsTest.php in Custom Permissions 8.2
File
tests/src/Functional/ConfigPermsTest.php
View source
<?php
namespace Drupal\Tests\config_perms\Functional;
use Drupal\Tests\BrowserTestBase;
class ConfigPermsTest extends BrowserTestBase {
protected $defaultTheme = 'stark';
protected static $modules = [
'config_perms',
];
public function testAdministerConfigPermsPermission() {
$user_with_permission = $this
->drupalCreateUser([
'administer config permissions',
]);
$user_without_permission = $this
->drupalCreateUser();
$this
->drupalLogin($user_with_permission);
$this
->drupalGet('/admin/people/custom-permissions/list');
$this
->assertSession()
->statusCodeEquals(200);
$this
->drupalLogout();
$this
->drupalLogin($user_without_permission);
$this
->drupalGet('/admin/people/custom-permissions/list');
$this
->assertSession()
->statusCodeEquals(403);
$this
->drupalLogout();
}
public function testPermissions() {
$user_with_permission = $this
->drupalCreateUser([
'Administer account settings',
]);
$user_without_permission = $this
->drupalCreateUser();
$this
->drupalLogin($user_with_permission);
$this
->drupalGet('admin/config/people/accounts');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextContains('Account settings');
$this
->drupalLogout();
$this
->drupalLogin($user_without_permission);
$this
->drupalGet('admin/config/people/accounts');
$this
->assertSession()
->statusCodeEquals(403);
$this
->drupalLogout();
}
public function testOverridePermissions() {
$user_custom_permission = $this
->drupalCreateUser([
'Administer account settings',
]);
$user_core_permission = $this
->drupalCreateUser([
'administer account settings',
]);
$this
->drupalLogin($user_custom_permission);
$this
->drupalGet('admin/config/people/accounts');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextContains('Account settings');
$this
->drupalLogout();
$this
->drupalLogin($user_core_permission);
$this
->drupalGet('admin/config/people/accounts');
$this
->assertSession()
->statusCodeEquals(403);
$this
->drupalLogout();
}
}