protected function EntityTranslationWorkflowsTest::assertWorkflows

Checks that workflows have the expected behaviors for the given user.

Parameters

\Drupal\user\UserInterface $user: The user to test the workflow behavior against.

array $expected_status: The an associative array with the operation name as key and the expected status as value.

1 call to EntityTranslationWorkflowsTest::assertWorkflows()
EntityTranslationWorkflowsTest::testWorkflows in drupal/core/modules/translation_entity/lib/Drupal/translation_entity/Tests/EntityTranslationWorkflowsTest.php
Test simple and editorial translation workflows.

File

drupal/core/modules/translation_entity/lib/Drupal/translation_entity/Tests/EntityTranslationWorkflowsTest.php, line 118
Contains \Drupal\entity\Tests\EntityTranslationWorkflowsTest.

Class

EntityTranslationWorkflowsTest
Tests entity translation workflows.

Namespace

Drupal\translation_entity\Tests

Code

protected function assertWorkflows(UserInterface $user, $expected_status) {
  $default_langcode = $this->langcodes[0];
  $languages = language_list();
  $args = array(
    '@user_label' => $user->name,
  );
  $this
    ->drupalLogin($user);

  // Check whether the user is allowed to access the entity form in edit mode.
  $edit_path = $this->controller
    ->getEditPath($this->entity);
  $options = array(
    'language' => $languages[$default_langcode],
  );
  $this
    ->drupalGet($edit_path, $options);
  $this
    ->assertResponse($expected_status['edit'], format_string('The @user_label has the expected edit access.', $args));

  // Check whether the user is allowed to access the translation overview.
  $langcode = $this->langcodes[1];
  $translations_path = $this->controller
    ->getBasePath($this->entity) . "/translations";
  $options = array(
    'language' => $languages[$langcode],
  );
  $this
    ->drupalGet($translations_path, $options);
  $this
    ->assertResponse($expected_status['overview'], format_string('The @user_label has the expected translation overview access.', $args));

  // Check whether the user is allowed to create a translation.
  $add_translation_path = $translations_path . "/add/{$default_langcode}/{$langcode}";
  if ($expected_status['add_translation'] == 200) {
    $this
      ->clickLink('Add');
    $this
      ->assertUrl($add_translation_path, $options, 'The translation overview points to the translation form when creating translations.');

    // Check that the translation form does not contain shared elements for
    // translators.
    if ($expected_status['edit'] == 403) {
      $this
        ->assertNoSharedElements();
    }
  }
  else {
    $this
      ->drupalGet($add_translation_path, $options);
  }
  $this
    ->assertResponse($expected_status['add_translation'], format_string('The @user_label has the expected translation creation access.', $args));

  // Check whether the user is allowed to edit a translation.
  $langcode = $this->langcodes[2];
  $edit_translation_path = $translations_path . "/edit/{$langcode}";
  $options = array(
    'language' => $languages[$langcode],
  );
  if ($expected_status['edit_translation'] == 200) {
    $this
      ->drupalGet($translations_path, $options);
    $editor = $expected_status['edit'] == 200;
    if ($editor) {
      $this
        ->clickLink('Edit', 2);

      // An editor should be pointed to the entity form in multilingual mode.
      $this
        ->assertUrl($edit_path, $options, 'The translation overview points to the edit form for editors when editing translations.');
    }
    else {
      $this
        ->clickLink('Edit');

      // While a translator should be pointed to the translation form.
      $this
        ->assertUrl($edit_translation_path, $options, 'The translation overview points to the translation form for translators when editing translations.');

      // Check that the translation form does not contain shared elements.
      $this
        ->assertNoSharedElements();
    }
  }
  else {
    $this
      ->drupalGet($edit_translation_path, $options);
  }
  $this
    ->assertResponse($expected_status['edit_translation'], format_string('The @user_label has the expected translation creation access.', $args));
}