Commit 76b2c612 authored by Liam Morland's avatar Liam Morland
Browse files

ISTWCMS-3968: Create basic test for access to Drupal paths

parent ecdb9516
......@@ -47,6 +47,39 @@ class UwWcmsBasicTest extends BrowserTestBase {
$big_pipe_enabled = \Drupal::moduleHandler()->moduleExists('big_pipe');
$this->assertFalse($big_pipe_enabled, 'BigPipe module is not enabled.');
$this->createUsers();
// The variable $test_paths stores Drupal paths and permission information.
// In this array, the keys are paths. If the value is TRUE, everyone has
// access. Otherwise, the value must be an array of roles that have access.
// Other roles do not have access.
$test_paths = [
'' => TRUE,
'admin' => [
'uw_role_site_manager',
'uw_role_content_editor',
'uw_role_content_author',
],
];
// Test these paths with each user.
foreach ($this->drupalUsers as $role => $user) {
if ($user) {
$this->drupalLogin($user);
}
elseif ($this->loggedInUser) {
$this->drupalLogout();
}
foreach ($test_paths as $path => $permissions) {
// Get the expected HTTP response code.
$expected_code = ($permissions === TRUE || in_array($role, $permissions, TRUE)) ? 200 : 403;
// Test this path for the HTTP response code.
$this->drupalGet($path);
$this_code = $this->getSession()->getStatusCode();
$message = sprintf('Response status code for %s on path %s is %d; %d expected.', $role, $path, $this_code, $expected_code);
$this->assert(intval($this_code) === $expected_code, $message);
}
}
}
/**
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment