WorkspaceTest.php in Workspace 8
File
tests/src/Functional/WorkspaceTest.php
View source
<?php
namespace Drupal\Tests\workspace\Functional;
use Drupal\Tests\BrowserTestBase;
class WorkspaceTest extends BrowserTestBase {
use WorkspaceTestUtilities;
public static $modules = [
'workspace',
];
public function setUp() {
parent::setUp();
$permissions = [
'access administration pages',
'administer site configuration',
'administer workspaces',
'create_workspace',
'edit_own_workspace',
];
$editor1 = $this
->drupalCreateUser($permissions);
$this
->drupalLogin($editor1);
}
public function testSpecialCharacters() {
$this
->createWorkspaceThroughUI('Workspace 1', 'a0_b1_');
$this
->drupalGet('/admin/structure/workspace/add');
$session = $this
->getSession();
$this
->assertEquals(200, $session
->getStatusCode());
$page = $session
->getPage();
$page
->fillField('label', 'workspace2');
$page
->fillField('machine_name', 'A!"£%^&*{}#~@?');
$page
->findButton(t('Save'))
->click();
$session
->getPage()
->hasContent("This value is not valid");
}
public function testWorkspaceCreation() {
$web_assert = $this
->assertSession();
$workspace_1 = $this
->createWorkspaceThroughUI('Workspace 1', 'workspace_1');
$workspace_2 = $this
->createWorkspaceThroughUI('Workspace 2', 'workspace_2');
$this
->drupalGet('/admin/structure/workspace');
$web_assert
->pageTextContains($workspace_1
->label());
$web_assert
->pageTextContains($workspace_2
->label());
$this
->drupalGet($workspace_1
->toUrl('edit-form')
->toString());
$web_assert
->fieldNotExists($workspace_1
->label());
$web_assert
->fieldExists($workspace_2
->label());
$this
->drupalGet($workspace_2
->toUrl('edit-form')
->toString());
$web_assert
->fieldExists($workspace_1
->label());
$web_assert
->fieldNotExists($workspace_2
->label());
$workspace_1
->setUnpublished()
->save();
$this
->drupalGet('/admin/structure/workspace');
$web_assert
->pageTextNotContains($workspace_1
->label());
$web_assert
->pageTextContains($workspace_2
->label());
$this
->drupalGet($workspace_1
->toUrl('edit-form')
->toString());
$web_assert
->fieldNotExists($workspace_1
->label());
$web_assert
->fieldExists($workspace_2
->label());
$this
->drupalGet($workspace_2
->toUrl('edit-form')
->toString());
$web_assert
->fieldNotExists($workspace_1
->label());
$web_assert
->fieldNotExists($workspace_2
->label());
}
}