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