DeploymentAccessTest.php in Deploy - Content Staging 8
File
tests/src/Functional/DeploymentAccessTest.php
View source
<?php
namespace Drupal\Tests\deploy\Functional;
use Drupal\Tests\BrowserTestBase;
use Drupal\user\Entity\Role;
class DeploymentAccessTest extends BrowserTestBase {
public static $modules = [
'user',
'deploy',
'toolbar',
];
public function testDeploymentAccess() {
$web_assert = $this
->assertSession();
$permissions = [
'access administration pages',
'administer workspaces',
'access toolbar',
];
$test_user = $this
->drupalCreateUser($permissions);
$this
->drupalLogin($test_user);
$this
->drupalGet('<front>');
$web_assert
->linkExists('Live');
$web_assert
->linkByHrefNotExists('/admin/structure/deployment/add');
$this
->drupalGet('/admin/structure/deployment/add');
$web_assert
->statusCodeEquals('403');
$this
->drupalPostForm('/admin/structure/workspace/2/activate', [], 'Activate');
$this
->drupalGet('<front>');
$web_assert
->linkExists('Stage');
$web_assert
->linkByHrefNotExists('/admin/structure/deployment/add');
$this
->drupalGet('/admin/structure/deployment/add');
$web_assert
->statusCodeEquals('403');
$test_user_roles = $test_user
->getRoles();
$this
->grantPermissions(Role::load(reset($test_user_roles)), [
'Deploy to Live',
]);
$this
->drupalGet('<front>');
$web_assert
->linkExists('Stage');
$web_assert
->linkByHrefExists('/admin/structure/deployment/add');
$this
->drupalGet('/admin/structure/deployment/add');
$web_assert
->pageTextContains('Deploy changes from local Stage workspace to Live workspace');
$this
->drupalPostForm('/admin/structure/workspace/add', [
'machine_name' => 'my_workspace',
'label' => 'My Workspace',
'upstream' => 2,
], 'Save');
$this
->drupalPostForm('/admin/structure/workspace/2/edit', [
'upstream' => 3,
], 'Save');
$this
->drupalGet('/admin/structure/deployment/add');
$web_assert
->statusCodeEquals('403');
$test_user_roles = $test_user
->getRoles();
$this
->grantPermissions(Role::load(reset($test_user_roles)), [
'deploy to own workspace',
]);
$this
->drupalGet('/admin/structure/deployment/add');
$web_assert
->pageTextContains('Deploy changes from local Stage workspace to My Workspace workspace');
$this
->drupalPostForm('/admin/structure/workspace/3/activate', [], 'Activate');
$this
->drupalGet('/admin/structure/deployment/add');
$web_assert
->statusCodeEquals('403');
$test_user_roles = $test_user
->getRoles();
$this
->grantPermissions(Role::load(reset($test_user_roles)), [
'deploy to any workspace',
]);
$this
->drupalGet('/admin/structure/deployment/add');
$web_assert
->pageTextContains('Deploy changes from local My Workspace workspace to Stage workspace');
}
}