3 namespace Drupal\Tests\workspaces\Functional;
5 use Drupal\Tests\BrowserTestBase;
8 * Test the workspace entity.
12 class WorkspaceTest extends BrowserTestBase {
14 use WorkspaceTestUtilities;
19 public static $modules = ['workspaces'];
24 * @var \Drupal\user\Entity\User
31 * @var \Drupal\user\Entity\User
38 public function setUp() {
41 'access administration pages',
42 'administer site configuration',
48 $this->editor1 = $this->drupalCreateUser($permissions);
49 $this->editor2 = $this->drupalCreateUser($permissions);
53 * Test creating a workspace with special characters.
55 public function testSpecialCharacters() {
56 $this->drupalLogin($this->editor1);
58 // Test a valid workspace name.
59 $this->createWorkspaceThroughUi('Workspace 1', 'a0_$()+-/');
61 // Test and invalid workspace name.
62 $this->drupalGet('/admin/config/workflow/workspaces/add');
63 $this->assertSession()->statusCodeEquals(200);
65 $page = $this->getSession()->getPage();
66 $page->fillField('label', 'workspace2');
67 $page->fillField('id', 'A!"£%^&*{}#~@?');
68 $page->findButton('Save')->click();
69 $page->hasContent("This value is not valid");
73 * Test changing the owner of a workspace.
75 public function testWorkspaceOwner() {
76 $this->drupalLogin($this->editor1);
78 $this->drupalPostForm('/admin/config/workflow/workspaces/add', [
79 'id' => 'test_workspace',
80 'label' => 'Test workspace',
83 $storage = \Drupal::entityTypeManager()->getStorage('workspace');
84 $test_workspace = $storage->load('test_workspace');
85 $this->assertEquals($this->editor1->id(), $test_workspace->getOwnerId());
87 $this->drupalPostForm('/admin/config/workflow/workspaces/manage/test_workspace/edit', [
88 'uid[0][target_id]' => $this->editor2->getUsername(),
91 $test_workspace = $storage->loadUnchanged('test_workspace');
92 $this->assertEquals($this->editor2->id(), $test_workspace->getOwnerId());
96 * Tests that editing a workspace creates a new revision.
98 public function testWorkspaceFormRevisions() {
99 $this->drupalLogin($this->editor1);
100 $storage = \Drupal::entityTypeManager()->getStorage('workspace');
102 // The current live workspace entity should be revision 1.
103 $live_workspace = $storage->load('live');
104 $this->assertEquals('1', $live_workspace->getRevisionId());
106 // Re-save the live workspace via the UI to create revision 3.
107 $this->drupalPostForm($live_workspace->url('edit-form'), [], 'Save');
108 $live_workspace = $storage->loadUnchanged('live');
109 $this->assertEquals('3', $live_workspace->getRevisionId());