public function ViewsModerationStateFilterTest::testStateFilterStatesList in Drupal 8
Same name and namespace in other branches
- 9 core/modules/content_moderation/tests/src/Kernel/ViewsModerationStateFilterTest.php \Drupal\Tests\content_moderation\Kernel\ViewsModerationStateFilterTest::testStateFilterStatesList()
Tests the list of states in the filter plugin.
File
- core/
modules/ content_moderation/ tests/ src/ Kernel/ ViewsModerationStateFilterTest.php, line 245
Class
- ViewsModerationStateFilterTest
- Tests the views 'moderation_state_filter' filter plugin.
Namespace
Drupal\Tests\content_moderation\KernelCode
public function testStateFilterStatesList() {
// By default a view of nodes will not have states to filter.
$workflow = Workflow::load('editorial');
$workflow
->getTypePlugin()
->removeEntityTypeAndBundle('node', 'example');
$workflow
->save();
$this
->assertPluginStates([]);
// Adding a content type to the editorial workflow will enable all of the
// editorial states.
$workflow
->getTypePlugin()
->addEntityTypeAndBundle('node', 'example');
$workflow
->save();
$this
->assertPluginStates([
'Editorial' => [
'editorial-draft' => 'Draft',
'editorial-published' => 'Published',
'editorial-archived' => 'Archived',
],
]);
// Adding a workflow which is not content moderation will not add any
// additional states to the views filter.
$workflow = Workflow::create([
'id' => 'test',
'type' => 'workflow_type_complex_test',
]);
$workflow
->getTypePlugin()
->addState('draft', 'Draft');
$workflow
->save();
$this
->assertPluginStates([
'Editorial' => [
'editorial-draft' => 'Draft',
'editorial-published' => 'Published',
'editorial-archived' => 'Archived',
],
]);
// Adding a new content moderation workflow will add additional states to
// filter.
$workflow = Workflow::create([
'id' => 'moderation_test',
'type' => 'content_moderation',
'label' => 'Moderation test',
]);
$workflow
->getTypePlugin()
->addState('foo', 'Foo State');
$workflow
->getTypePlugin()
->addEntityTypeAndBundle('node', 'example');
$workflow
->save();
$this
->assertPluginStates([
'Editorial' => [
'editorial-draft' => 'Draft',
'editorial-published' => 'Published',
'editorial-archived' => 'Archived',
],
'Moderation test' => [
'moderation_test-foo' => 'Foo State',
'moderation_test-draft' => 'Draft',
'moderation_test-published' => 'Published',
],
]);
// Deleting a workflow will remove the states from the filter.
$workflow = Workflow::load('moderation_test');
$workflow
->delete();
$this
->assertPluginStates([
'Editorial' => [
'editorial-draft' => 'Draft',
'editorial-published' => 'Published',
'editorial-archived' => 'Archived',
],
]);
// Deleting a state from a workflow will remove the state from the filter.
$workflow = Workflow::load('editorial');
$workflow
->getTypePlugin()
->deleteState('archived');
$workflow
->save();
$this
->assertPluginStates([
'Editorial' => [
'editorial-draft' => 'Draft',
'editorial-published' => 'Published',
],
]);
}