View source
<?php
namespace Drupal\Tests\workspaces\Functional;
use Drupal\Tests\BrowserTestBase;
class WorkspaceTest extends BrowserTestBase {
use WorkspaceTestUtilities;
public static $modules = [
'workspaces',
'toolbar',
'field_ui',
];
protected $defaultTheme = 'stark';
protected $editor1;
protected $editor2;
public function setUp() {
parent::setUp();
$permissions = [
'access administration pages',
'administer site configuration',
'create workspace',
'edit own workspace',
'edit any workspace',
'view own workspace',
'access toolbar',
];
$this->editor1 = $this
->drupalCreateUser($permissions);
$this->editor2 = $this
->drupalCreateUser($permissions);
}
public function testSpecialCharacters() {
$this
->drupalLogin($this->editor1);
$this
->createWorkspaceThroughUi('Workspace 1', 'a0_$()+-/');
$this
->drupalGet('/admin/config/workflow/workspaces/add');
$this
->assertSession()
->statusCodeEquals(200);
$page = $this
->getSession()
->getPage();
$page
->fillField('label', 'workspace2');
$page
->fillField('id', 'A!"£%^&*{}#~@?');
$page
->findButton('Save')
->click();
$page
->hasContent("This value is not valid");
}
public function testWorkspaceToolbar() {
$this
->drupalLogin($this->editor1);
$this
->drupalPostForm('/admin/config/workflow/workspaces/add', [
'id' => 'test_workspace',
'label' => 'Test workspace',
], 'Save');
$this
->drupalPostForm('/admin/config/workflow/workspaces/manage/test_workspace/activate', [], 'Confirm');
$this
->drupalGet('<front>');
$page = $this
->getSession()
->getPage();
$this
->assertTrue($page
->hasLink('Test workspace'));
$this
->drupalPostForm('/admin/config/workflow/workspaces/manage/test_workspace/edit', [
'label' => 'New name',
], 'Save');
$this
->drupalGet('<front>');
$page = $this
->getSession()
->getPage();
$this
->assertTrue($page
->hasLink('New name'));
}
public function testWorkspaceOwner() {
$this
->drupalLogin($this->editor1);
$this
->drupalPostForm('/admin/config/workflow/workspaces/add', [
'id' => 'test_workspace',
'label' => 'Test workspace',
], 'Save');
$storage = \Drupal::entityTypeManager()
->getStorage('workspace');
$test_workspace = $storage
->load('test_workspace');
$this
->assertEquals($this->editor1
->id(), $test_workspace
->getOwnerId());
$this
->drupalPostForm('/admin/config/workflow/workspaces/manage/test_workspace/edit', [
'uid[0][target_id]' => $this->editor2
->getAccountName(),
], 'Save');
$test_workspace = $storage
->loadUnchanged('test_workspace');
$this
->assertEquals($this->editor2
->id(), $test_workspace
->getOwnerId());
}
public function testWorkspaceFormRevisions() {
$this
->drupalLogin($this->editor1);
$storage = \Drupal::entityTypeManager()
->getStorage('workspace');
$stage_workspace = $storage
->load('stage');
$this
->assertEquals('1', $stage_workspace
->getRevisionId());
$this
->drupalPostForm($stage_workspace
->toUrl('edit-form')
->toString(), [], 'Save');
$stage_workspace = $storage
->loadUnchanged('stage');
$this
->assertEquals('2', $stage_workspace
->getRevisionId());
}
public function testWorkspaceFieldUi() {
$user = $this
->drupalCreateUser([
'administer workspaces',
'access administration pages',
'administer site configuration',
'administer workspace fields',
'administer workspace display',
'administer workspace form display',
]);
$this
->drupalLogin($user);
$this
->drupalGet('admin/config/workflow/workspaces/fields');
$this
->assertSession()
->statusCodeEquals(200);
$field_name = mb_strtolower($this
->randomMachineName());
$field_label = $this
->randomMachineName();
$edit = [
'new_storage_type' => 'string',
'label' => $field_label,
'field_name' => $field_name,
];
$this
->drupalPostForm("admin/config/workflow/workspaces/fields/add-field", $edit, 'Save and continue');
$page = $this
->getSession()
->getPage();
$page
->pressButton('Save field settings');
$page
->pressButton('Save settings');
$this
->drupalGet('admin/config/workflow/workspaces/form-display');
$this
->assertText($field_label);
$this
->drupalGet('admin/config/workflow/workspaces/display');
$this
->assertText($field_label);
}
}