function EntityTranslationWorkflowsTest::testWorkflows

Test simple and editorial translation workflows.

File

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

Class

EntityTranslationWorkflowsTest
Tests entity translation workflows.

Namespace

Drupal\translation_entity\Tests

Code

function testWorkflows() {

  // Test workflows for the editor.
  $expected_status = array(
    'edit' => 200,
    'overview' => 403,
    'add_translation' => 403,
    'edit_translation' => 403,
  );
  $this
    ->assertWorkflows($this->editor, $expected_status);

  // Test workflows for the translator.
  $expected_status = array(
    'edit' => 403,
    'overview' => 200,
    'add_translation' => 200,
    'edit_translation' => 200,
  );
  $this
    ->assertWorkflows($this->translator, $expected_status);

  // Test workflows for the admin.
  $expected_status = array(
    'edit' => 200,
    'overview' => 200,
    'add_translation' => 200,
    'edit_translation' => 200,
  );
  $this
    ->assertWorkflows($this->administrator, $expected_status);

  // Check that translation permissions governate the associated operations.
  $ops = array(
    'create' => t('Add'),
    'update' => t('Edit'),
    'delete' => t('Delete'),
  );
  $translations_path = $this->controller
    ->getBasePath($this->entity) . "/translations";
  foreach ($ops as $current_op => $label) {
    $user = $this
      ->drupalCreateUser(array(
      $this
        ->getTranslatePermission(),
      "{$current_op} entity translations",
    ));
    $this
      ->drupalLogin($user);
    $this
      ->drupalGet($translations_path);
    foreach ($ops as $op => $label) {
      if ($op != $current_op) {
        $this
          ->assertNoLink($label, format_string('No %op link found.', array(
          '%op' => $label,
        )));
      }
      else {
        $this
          ->assertLink($label, 0, format_string('%op link found.', array(
          '%op' => $label,
        )));
      }
    }
  }
}