You are here

public function ViewsModerationStateFilterTest::testModerationStateFilterDependencyHandling in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/content_moderation/tests/src/Functional/ViewsModerationStateFilterTest.php \Drupal\Tests\content_moderation\Functional\ViewsModerationStateFilterTest::testModerationStateFilterDependencyHandling()

Tests the dependency handling of the moderation state filter.

@covers ::calculateDependencies @covers ::onDependencyRemoval

File

core/modules/content_moderation/tests/src/Functional/ViewsModerationStateFilterTest.php, line 86

Class

ViewsModerationStateFilterTest
Tests the views 'moderation_state_filter' filter plugin.

Namespace

Drupal\Tests\content_moderation\Functional

Code

public function testModerationStateFilterDependencyHandling() {

  // First, check that the view doesn't have any config dependency when there
  // are no states configured in the filter.
  $view_id = 'test_content_moderation_state_filter_base_table';
  $view = View::load($view_id);
  $this
    ->assertWorkflowDependencies([], $view);
  $this
    ->assertTrue($view
    ->status());

  // Configure the Editorial workflow for a node bundle, set the filter value
  // to use one of its states and check that the workflow is now a dependency
  // of the view.
  $this
    ->drupalGet('admin/config/workflow/workflows/manage/editorial/type/node');
  $this
    ->submitForm([
    'bundles[example_a]' => TRUE,
  ], 'Save');
  $edit['options[value][]'] = [
    'editorial-published',
  ];
  $this
    ->drupalGet("admin/structure/views/nojs/handler/{$view_id}/default/filter/moderation_state");
  $this
    ->submitForm($edit, 'Apply');
  $this
    ->drupalGet("admin/structure/views/view/{$view_id}");
  $this
    ->submitForm([], 'Save');
  $view = $this
    ->loadViewUnchanged($view_id);
  $this
    ->assertWorkflowDependencies([
    'editorial',
  ], $view);
  $this
    ->assertTrue($view
    ->status());

  // Create another workflow and repeat the checks above.
  $this
    ->drupalGet('admin/config/workflow/workflows/add');
  $this
    ->submitForm([
    'label' => 'Translation',
    'id' => 'translation',
    'workflow_type' => 'content_moderation',
  ], 'Save');
  $this
    ->drupalGet('admin/config/workflow/workflows/manage/translation/add_state');
  $this
    ->submitForm([
    'label' => 'Needs Review',
    'id' => 'needs_review',
  ], 'Save');
  $this
    ->drupalGet('admin/config/workflow/workflows/manage/translation/type/node');
  $this
    ->submitForm([
    'bundles[example_b]' => TRUE,
  ], 'Save');
  $edit['options[value][]'] = [
    'editorial-published',
    'translation-needs_review',
  ];
  $this
    ->drupalGet("admin/structure/views/nojs/handler/{$view_id}/default/filter/moderation_state");
  $this
    ->submitForm($edit, 'Apply');
  $this
    ->drupalGet("admin/structure/views/view/{$view_id}");
  $this
    ->submitForm([], 'Save');
  $view = $this
    ->loadViewUnchanged($view_id);
  $this
    ->assertWorkflowDependencies([
    'editorial',
    'translation',
  ], $view);
  $this
    ->assertTrue(isset($view
    ->getDisplay('default')['display_options']['filters']['moderation_state']));
  $this
    ->assertTrue($view
    ->status());

  // Remove the 'Translation' workflow.
  $this
    ->drupalGet('admin/config/workflow/workflows/manage/translation/delete');
  $this
    ->submitForm([], 'Delete');

  // Check that the view has been disabled, the filter has been deleted, the
  // view can be saved and there are no more config dependencies.
  $view = $this
    ->loadViewUnchanged($view_id);
  $this
    ->assertFalse($view
    ->status());
  $this
    ->assertFalse(isset($view
    ->getDisplay('default')['display_options']['filters']['moderation_state']));
  $this
    ->drupalGet("admin/structure/views/view/{$view_id}");
  $this
    ->submitForm([], 'Save');
  $this
    ->assertWorkflowDependencies([], $view);
}