You are here

public function ModerationStateTestBase::enableModerationThroughUi in Drupal 10

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

Enable moderation for a specified content type, using the UI.

Parameters

string $content_type_id: Machine name.

string $workflow_id: The workflow to attach to the bundle.

File

core/modules/content_moderation/tests/src/Functional/ModerationStateTestBase.php, line 137

Class

ModerationStateTestBase
Defines a base class for moderation state tests.

Namespace

Drupal\Tests\content_moderation\Functional

Code

public function enableModerationThroughUi($content_type_id, $workflow_id = 'editorial') {
  $this
    ->drupalGet('/admin/config/workflow/workflows');
  $this
    ->assertSession()
    ->linkByHrefExists('admin/config/workflow/workflows/manage/' . $workflow_id);
  $edit['bundles[' . $content_type_id . ']'] = TRUE;
  $this
    ->drupalGet('admin/config/workflow/workflows/manage/' . $workflow_id . '/type/node');
  $this
    ->submitForm($edit, 'Save');

  // Ensure the parent environment is up-to-date.
  // @see content_moderation_workflow_insert()
  \Drupal::service('entity_type.bundle.info')
    ->clearCachedBundles();
  \Drupal::service('entity_field.manager')
    ->clearCachedFieldDefinitions();

  /** @var \Drupal\Core\Routing\RouteBuilderInterface $router_builder */
  $router_builder = $this->container
    ->get('router.builder');
  $router_builder
    ->rebuildIfNeeded();
}