You are here

protected function ModerationStateTestBase::enableModerationThroughUi in Workbench Moderation 8

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

Parameters

string $content_type_id: Machine name.

string[] $allowed_states: Array of allowed state IDs.

string $default_state: Default state.

2 calls to ModerationStateTestBase::enableModerationThroughUi()
ModerationStateNodeTypeTest::testEnablingOnExistingContent in tests/src/Functional/ModerationStateNodeTypeTest.php
A node type without moderation state enabled.
ModerationStateTestBase::createContentTypeFromUi in tests/src/Functional/ModerationStateTestBase.php
Creates a content-type from the UI.

File

tests/src/Functional/ModerationStateTestBase.php, line 120

Class

ModerationStateTestBase
Defines a base class for moderation state tests.

Namespace

Drupal\Tests\workbench_moderation\Functional

Code

protected function enableModerationThroughUi($content_type_id, array $allowed_states, $default_state) {
  $this
    ->drupalGet('admin/structure/types/manage/' . $content_type_id . '/moderation');
  $this
    ->assertFieldByName('enable_moderation_state');
  $this
    ->assertNoFieldChecked('edit-enable-moderation-state');
  $edit['enable_moderation_state'] = 1;

  /** @var \Drupal\workbench_moderation\Entity\ModerationState $state */
  foreach (ModerationState::loadMultiple() as $id => $state) {
    $key = $state
      ->isPublishedState() ? 'allowed_moderation_states_published[' . $state
      ->id() . ']' : 'allowed_moderation_states_unpublished[' . $state
      ->id() . ']';
    $edit[$key] = (int) in_array($id, $allowed_states);
  }
  $edit['default_moderation_state'] = $default_state;
  $this
    ->drupalPostForm(NULL, $edit, t('Save'));
}