WorkspacePointerTest.php in Workspace 8
File
tests/src/Kernel/WorkspacePointerTest.php
View source
<?php
namespace Drupal\Tests\workspace\Kernel;
use Drupal\multiversion\Entity\Workspace;
use Drupal\multiversion\Entity\WorkspaceInterface;
use Drupal\multiversion\Entity\WorkspaceType;
use Drupal\workspace\Entity\WorkspacePointer;
use Drupal\KernelTests\KernelTestBase;
class WorkspacePointerTest extends KernelTestBase {
public static $modules = [
'workspace',
'replication',
'multiversion',
'key_value',
'serialization',
'user',
'system',
];
protected function setUp() {
parent::setUp();
$this
->installEntitySchema('workspace');
$this
->installEntitySchema('workspace_pointer');
$this
->installEntitySchema('user');
}
protected function createWorkspaceType() {
$workspace_type = WorkspaceType::create([
'id' => 'test',
'label' => 'Workspace bundle',
]);
$workspace_type
->save();
return $workspace_type;
}
protected function createWorkspace() {
$workspace = Workspace::create([
'type' => 'test',
'machine_name' => 'le_workspace',
'label' => 'Le Workspace',
]);
$workspace
->save();
return $workspace;
}
public function testCreationWithObject() {
$this
->createWorkspaceType();
$workspace = $this
->createWorkspace();
$pointer = WorkspacePointer::create();
$pointer
->setWorkspace($workspace);
$pointer
->save();
$id = $pointer
->id();
$pointer = WorkspacePointer::load($id);
$this
->assertEquals($workspace
->id(), $pointer
->getWorkspaceId());
$this
->assertEquals($workspace
->id(), $pointer
->getWorkspace()
->id());
}
public function testCreationWithId() {
$this
->createWorkspaceType();
$workspace = $this
->createWorkspace();
$pointer = WorkspacePointer::create();
$pointer
->setWorkspaceId($workspace
->id());
$pointer
->save();
$id = $pointer
->id();
$pointer = WorkspacePointer::load($id);
$this
->assertEquals($workspace
->id(), $pointer
->getWorkspaceId());
$this
->assertEquals($workspace
->id(), $pointer
->getWorkspace()
->id());
}
}