You are here

function ContentTranslationWorkflowsTest::testWorkflows in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/content_translation/src/Tests/ContentTranslationWorkflowsTest.php \Drupal\content_translation\Tests\ContentTranslationWorkflowsTest::testWorkflows()

Test simple and editorial translation workflows.

File

core/modules/content_translation/src/Tests/ContentTranslationWorkflowsTest.php, line 84
Contains \Drupal\content_translation\Tests\ContentTranslationWorkflowsTest.

Class

ContentTranslationWorkflowsTest
Tests the content translation workflows for the test entity.

Namespace

Drupal\content_translation\Tests

Code

function testWorkflows() {

  // Test workflows for the editor.
  $expected_status = [
    'edit' => 200,
    'delete' => 200,
    'overview' => 403,
    'add_translation' => 403,
    'edit_translation' => 403,
    'delete_translation' => 403,
  ];
  $this
    ->doTestWorkflows($this->editor, $expected_status);

  // Test workflows for the translator.
  $expected_status = [
    'edit' => 403,
    'delete' => 403,
    'overview' => 200,
    'add_translation' => 200,
    'edit_translation' => 200,
    'delete_translation' => 200,
  ];
  $this
    ->doTestWorkflows($this->translator, $expected_status);

  // Test workflows for the admin.
  $expected_status = [
    'edit' => 200,
    'delete' => 200,
    'overview' => 200,
    'add_translation' => 200,
    'edit_translation' => 403,
    'delete_translation' => 403,
  ];
  $this
    ->doTestWorkflows($this->administrator, $expected_status);

  // Check that translation permissions allow the associated operations.
  $ops = array(
    'create' => t('Add'),
    'update' => t('Edit'),
    'delete' => t('Delete'),
  );
  $translations_url = $this->entity
    ->urlInfo('drupal:content-translation-overview');
  foreach ($ops as $current_op => $item) {
    $user = $this
      ->drupalCreateUser(array(
      $this
        ->getTranslatePermission(),
      "{$current_op} content translations",
      'view test entity',
    ));
    $this
      ->drupalLogin($user);
    $this
      ->drupalGet($translations_url);

    // Make sure that the user.permissions cache context and the cache tags
    // for the entity are present.
    $this
      ->assertCacheContext('user.permissions');
    foreach ($this->entity
      ->getCacheTags() as $cache_tag) {
      $this
        ->assertCacheTag($cache_tag);
    }
    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,
        )));
      }
    }
  }
}