function ViewsModerationStateFilterTest::testWorkflowChanges
Same name in other branches
- 8.9.x core/modules/content_moderation/tests/src/Functional/ViewsModerationStateFilterTest.php \Drupal\Tests\content_moderation\Functional\ViewsModerationStateFilterTest::testWorkflowChanges()
- 10 core/modules/content_moderation/tests/src/Functional/ViewsModerationStateFilterTest.php \Drupal\Tests\content_moderation\Functional\ViewsModerationStateFilterTest::testWorkflowChanges()
- 11.x core/modules/content_moderation/tests/src/Functional/ViewsModerationStateFilterTest.php \Drupal\Tests\content_moderation\Functional\ViewsModerationStateFilterTest::testWorkflowChanges()
Tests the moderation state filter when the configured workflow is changed.
@dataProvider providerTestWorkflowChanges
File
-
core/
modules/ content_moderation/ tests/ src/ Functional/ ViewsModerationStateFilterTest.php, line 171
Class
- ViewsModerationStateFilterTest
- Tests the views 'moderation_state_filter' filter plugin.
Namespace
Drupal\Tests\content_moderation\FunctionalCode
public function testWorkflowChanges($view_id) {
// First, apply the Editorial workflow to both of our content types.
$this->drupalGet('admin/config/workflow/workflows/manage/editorial/type/node');
$this->submitForm([
'bundles[example_a]' => TRUE,
'bundles[example_b]' => TRUE,
], 'Save');
\Drupal::service('entity_type.bundle.info')->clearCachedBundles();
// Update the view and make the default filter not exposed anymore,
// otherwise all results will be shown when there are no more moderated
// bundles left.
$this->drupalGet("admin/structure/views/nojs/handler/{$view_id}/default/filter/moderation_state");
$this->submitForm([], 'Hide filter');
$this->drupalGet("admin/structure/views/view/{$view_id}");
$this->submitForm([], 'Save');
// Add a few nodes in various moderation states.
$this->createNode([
'type' => 'example_a',
'moderation_state' => 'published',
]);
$this->createNode([
'type' => 'example_b',
'moderation_state' => 'published',
]);
$archived_node_a = $this->createNode([
'type' => 'example_a',
'moderation_state' => 'archived',
]);
$archived_node_b = $this->createNode([
'type' => 'example_b',
'moderation_state' => 'archived',
]);
// Configure the view to only show nodes in the 'archived' moderation state.
$edit['options[value][]'] = [
'editorial-archived',
];
$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');
// Check that only the archived nodes from both bundles are displayed by the
// view.
$view = $this->loadViewUnchanged($view_id);
$this->executeAndAssertIdenticalResultset($view, [
[
'nid' => $archived_node_a->id(),
],
[
'nid' => $archived_node_b->id(),
],
], [
'nid' => 'nid',
]);
// Remove the Editorial workflow from one of the bundles.
$this->drupalGet('admin/config/workflow/workflows/manage/editorial/type/node');
$this->submitForm([
'bundles[example_a]' => TRUE,
'bundles[example_b]' => FALSE,
], 'Save');
\Drupal::service('entity_type.bundle.info')->clearCachedBundles();
$view = $this->loadViewUnchanged($view_id);
$this->executeAndAssertIdenticalResultset($view, [
[
'nid' => $archived_node_a->id(),
],
], [
'nid' => 'nid',
]);
// Check that the view can still be edited and saved without any
// intervention.
$this->drupalGet("admin/structure/views/view/{$view_id}");
$this->submitForm([], 'Save');
// Remove the Editorial workflow from both bundles.
$this->drupalGet('admin/config/workflow/workflows/manage/editorial/type/node');
$this->submitForm([
'bundles[example_a]' => FALSE,
'bundles[example_b]' => FALSE,
], 'Save');
\Drupal::service('entity_type.bundle.info')->clearCachedBundles();
// Check that the view doesn't return any result.
$view = $this->loadViewUnchanged($view_id);
$this->executeAndAssertIdenticalResultset($view, [], []);
// Check that the view contains a broken filter, since the moderation_state
// field was removed from the entity type.
$this->drupalGet("admin/structure/views/view/{$view_id}");
$this->submitForm([], 'Save');
$this->assertSession()
->pageTextContains("Broken/missing handler");
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.