View source
<?php
namespace Drupal\Tests\workflows_field\Kernel;
use Drupal\node\Entity\Node;
use Drupal\workflows\Entity\Workflow;
use Drupal\workflows_field\Plugin\Field\FieldType\WorkflowsFieldItem;
class WorkflowsFieldTest extends WorkflowsTestBase {
public function testOptionsProvider() {
$node = Node::create([
'title' => 'Foo',
'type' => 'project',
'field_status' => 'in_discussion',
]);
$node
->save();
$this
->assertEquals([
'implementing' => 'Implementing',
'approved' => 'Approved',
'rejected' => 'Rejected',
'planning' => 'Planning',
'in_discussion' => 'In Discussion',
], $node->field_status[0]
->getPossibleOptions());
$this
->assertEquals([
'approved' => 'Approved',
'rejected' => 'Rejected',
'in_discussion' => 'In Discussion',
], $node->field_status[0]
->getSettableOptions());
$this
->assertEquals([
'implementing',
'approved',
'rejected',
'planning',
'in_discussion',
], $node->field_status[0]
->getPossibleValues());
$this
->assertEquals([
'approved',
'rejected',
'in_discussion',
], $node->field_status[0]
->getSettableValues());
}
public function testOptionsProviderFilteredByUser() {
$node = Node::create([
'title' => 'Foo',
'type' => 'project',
'field_status' => 'in_discussion',
]);
$node
->save();
$this
->assertEquals([
'in_discussion' => 'In Discussion',
], $node->field_status[0]
->getSettableOptions($this
->createUser()));
$this
->assertEquals([
'in_discussion' => 'In Discussion',
'approved' => 'Approved',
], $node->field_status[0]
->getSettableOptions($this
->createUser([
'use bureaucracy_workflow transition approved_project',
])));
}
public function testFieldType() {
$node = Node::create([
'title' => 'Foo',
'type' => 'project',
'field_status' => 'in_discussion',
]);
$node
->save();
$this
->assertEquals([
'config' => [
'workflows.workflow.bureaucracy_workflow',
],
], WorkflowsFieldItem::calculateStorageDependencies($node->field_status
->getFieldDefinition()
->getFieldStorageDefinition()));
$this
->assertEquals('bureaucracy_workflow', $node->field_status[0]
->getWorkflow()
->id());
}
public function testWorkflowType() {
$type = Workflow::load('bureaucracy_workflow')
->getTypePlugin();
$this
->assertEquals('in_discussion', $type
->getInitialState()
->id());
}
}