Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
namespace Drupal\Tests\workspace\Functional;
use Drupal\Tests\BrowserTestBase;
/**
* Test the workspace entity.
*
* @group workspace
*/
class WorkspaceTest extends BrowserTestBase {
use WorkspaceTestUtilities;
/**
* {@inheritdoc}
*/
public static $modules = ['workspace'];
/**
* A test user.
*
* @var \Drupal\user\Entity\User
*/
protected $editor1;
/**
* A test user.
*
* @var \Drupal\user\Entity\User
*/
protected $editor2;
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
$permissions = [
'access administration pages',
'administer site configuration',
'create workspace',
'edit own workspace',
'edit any workspace',
];
$this->editor1 = $this->drupalCreateUser($permissions);
$this->editor2 = $this->drupalCreateUser($permissions);
}
/**
* Test creating a workspace with special characters.
*/
public function testSpecialCharacters() {
$this->drupalLogin($this->editor1);
// Test a valid workspace name.
$this->createWorkspaceThroughUi('Workspace 1', 'a0_$()+-/');
// Test and invalid workspace name.
$this->drupalGet('/admin/config/workflow/workspace/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");
}
/**
* Test changing the owner of a workspace.
*/
public function testWorkspaceOwner() {
$this->drupalLogin($this->editor1);
$this->drupalPostForm('/admin/config/workflow/workspace/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/workspace/manage/test_workspace/edit', [
'uid[0][target_id]' => $this->editor2->getUsername(),
], 'Save');
$test_workspace = $storage->loadUnchanged('test_workspace');
$this->assertEquals($this->editor2->id(), $test_workspace->getOwnerId());
}
/**
* Tests that editing a workspace creates a new revision.
*/
public function testWorkspaceFormRevisions() {
$this->drupalLogin($this->editor1);
$storage = \Drupal::entityTypeManager()->getStorage('workspace');
// The current live workspace entity should be revision 1.
$live_workspace = $storage->load('live');
$this->assertEquals('1', $live_workspace->getRevisionId());
// Re-save the live workspace via the UI to create revision 3.
$this->drupalPostForm($live_workspace->url('edit-form'), [], 'Save');
$live_workspace = $storage->loadUnchanged('live');
$this->assertEquals('3', $live_workspace->getRevisionId());
}
}