function ViewsModerationStateFilterTest::testStateFilterStatesList

Same name and namespace in other branches
  1. 9 core/modules/content_moderation/tests/src/Kernel/ViewsModerationStateFilterTest.php \Drupal\Tests\content_moderation\Kernel\ViewsModerationStateFilterTest::testStateFilterStatesList()
  2. 8.9.x core/modules/content_moderation/tests/src/Kernel/ViewsModerationStateFilterTest.php \Drupal\Tests\content_moderation\Kernel\ViewsModerationStateFilterTest::testStateFilterStatesList()
  3. 10 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 278

Class

ViewsModerationStateFilterTest
Tests the views 'moderation_state_filter' filter plugin.

Namespace

Drupal\Tests\content_moderation\Kernel

Code

public function testStateFilterStatesList() : void {
    // 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',
        'label' => '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',
        ],
    ]);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.