You are here

public function LingotekWorkbenchModerationSettingsTest::testWorkbenchModerationSettings in Lingotek Translation 8.2

Same name and namespace in other branches
  1. 4.0.x tests/src/Functional/LingotekWorkbenchModerationSettingsTest.php \Drupal\Tests\lingotek\Functional\LingotekWorkbenchModerationSettingsTest::testWorkbenchModerationSettings()
  2. 3.1.x tests/src/Functional/LingotekWorkbenchModerationSettingsTest.php \Drupal\Tests\lingotek\Functional\LingotekWorkbenchModerationSettingsTest::testWorkbenchModerationSettings()
  3. 3.2.x tests/src/Functional/LingotekWorkbenchModerationSettingsTest.php \Drupal\Tests\lingotek\Functional\LingotekWorkbenchModerationSettingsTest::testWorkbenchModerationSettings()
  4. 3.3.x tests/src/Functional/LingotekWorkbenchModerationSettingsTest.php \Drupal\Tests\lingotek\Functional\LingotekWorkbenchModerationSettingsTest::testWorkbenchModerationSettings()
  5. 3.4.x tests/src/Functional/LingotekWorkbenchModerationSettingsTest.php \Drupal\Tests\lingotek\Functional\LingotekWorkbenchModerationSettingsTest::testWorkbenchModerationSettings()
  6. 3.5.x tests/src/Functional/LingotekWorkbenchModerationSettingsTest.php \Drupal\Tests\lingotek\Functional\LingotekWorkbenchModerationSettingsTest::testWorkbenchModerationSettings()
  7. 3.6.x tests/src/Functional/LingotekWorkbenchModerationSettingsTest.php \Drupal\Tests\lingotek\Functional\LingotekWorkbenchModerationSettingsTest::testWorkbenchModerationSettings()
  8. 3.7.x tests/src/Functional/LingotekWorkbenchModerationSettingsTest.php \Drupal\Tests\lingotek\Functional\LingotekWorkbenchModerationSettingsTest::testWorkbenchModerationSettings()
  9. 3.8.x tests/src/Functional/LingotekWorkbenchModerationSettingsTest.php \Drupal\Tests\lingotek\Functional\LingotekWorkbenchModerationSettingsTest::testWorkbenchModerationSettings()

Tests that the workbench moderation settings are stored correctly.

File

tests/src/Functional/LingotekWorkbenchModerationSettingsTest.php, line 73

Class

LingotekWorkbenchModerationSettingsTest
Tests setting up the integration with workbench moderation.

Namespace

Drupal\Tests\lingotek\Functional

Code

public function testWorkbenchModerationSettings() {
  $vocabulary_id = $this->vocabulary
    ->id();
  $this
    ->drupalGet('admin/lingotek/settings');

  // We don't have any fields for configuring workbench moderation until it's
  // enabled.
  $this
    ->assertNoField('node[article][moderation][upload_status]', 'The field for setting the state when a content should be uploaded does not exist as workbench moderation is not enabled for this bundle.');
  $this
    ->assertNoField('node[article][moderation][download_transition]', 'The field for setting the transition that must happen after download does not exist as workbench moderation is not enabled for this bundle.');
  $this
    ->assertNoField('node[page][moderation][upload_status]', 'The field for setting the state when a content should be uploaded does not exist as workbench moderation is not enabled for this bundle.');
  $this
    ->assertNoField('node[page][moderation][download_transition]', 'The field for setting the transition that must happen after download does not exist as workbench moderation is not enabled for this bundle.');

  // We show a message and link for enabling it.
  $this
    ->assertText('This entity bundle is not enabled for moderation with workbench_moderation. You can change its settings here.');
  $this
    ->assertLinkByHref('/admin/structure/types/manage/article/moderation');
  $this
    ->assertLinkByHref('/admin/structure/types/manage/page/moderation');

  // Let's enable it for articles.
  $this
    ->enableModerationThroughUI('article', [
    'draft',
    'needs_review',
    'published',
  ], 'draft');
  $this
    ->drupalGet('admin/lingotek/settings');

  // Assert the fields for setting up the integration exist and they have
  // sensible defaults.
  $this
    ->assertField('node[article][moderation][upload_status]', 'The field for setting the state when a content should be uploaded exists.');
  $this
    ->assertField('node[article][moderation][download_transition]', 'The field for setting the transition that must happen after download exists.');
  $this
    ->assertOptionSelected('edit-node-article-moderation-upload-status', 'published', 'The default value is a published one.');
  $this
    ->assertOptionSelected('edit-node-article-moderation-download-transition', 'published_published', 'The default transition is from published to published.');

  // The content types without moderation enabled should show a link instead
  // for configuring them.
  $this
    ->assertNoField('node[page][moderation][upload_status]', 'The field for setting the state when a content should be uploaded does not exist as workbench moderation is not enabled for this bundle.');
  $this
    ->assertNoField('node[page][moderation][download_transition]', 'The field for setting the transition that must happen after download does not exist as workbench moderation is not enabled for this bundle.');
  $this
    ->assertText('This entity bundle is not enabled for moderation with workbench_moderation. You can change its settings here.');
  $this
    ->assertNoLinkByHref('/admin/structure/types/manage/article/moderation');
  $this
    ->assertLinkByHref('/admin/structure/types/manage/page/moderation');

  // Let's save the settings for articles.
  $this
    ->saveLingotekContentTranslationSettings([
    'node' => [
      'article' => [
        'profiles' => 'automatic',
        'fields' => [
          'title' => 1,
        ],
        'moderation' => [
          'upload_status' => 'draft',
          'download_transition' => 'draft_needs_review',
        ],
      ],
    ],
  ]);

  // Assert the values are saved.
  $this
    ->assertOptionSelected('edit-node-article-moderation-upload-status', 'draft', 'The desired status for upload is stored correctly.');
  $this
    ->assertOptionSelected('edit-node-article-moderation-download-transition', 'draft_needs_review', 'The desired transition after download is stored correctly.');
  $this
    ->assertNoField("taxonomy_term[{$vocabulary_id}][moderation][upload_status]", 'The field for setting the state when a content should be uploaded does not exist as workbench moderation is not available for this entity type.');
  $this
    ->assertNoField("taxonomy_term[{$vocabulary_id}][moderation][download_transition]", 'The field for setting the transition that must happen after download does not exist as workbench moderation is not available for this entity type.');

  // In Drupal 8.7 and above taxonomy terms are moderable.
  if (floatval(\Drupal::VERSION) >= 8.699999999999999) {
    $this
      ->assertLinkByHref("/admin/structure/taxonomy/manage/{$vocabulary_id}/moderation");
  }
  else {

    // Taxonomy terms cannot be moderated.
    $this
      ->assertNoLinkByHref("/admin/structure/taxonomy/manage/{$vocabulary_id}/moderation");
  }

  // Users cannot be moderated.
  $this
    ->assertNoField("user[user][moderation][upload_status]", 'The field for setting the state when a content should be uploaded does not exist as workbench moderation is not available for this entity type.');
  $this
    ->assertNoField("user[user][moderation][download_transition]", 'The field for setting the transition that must happen after download does not exist as workbench moderation is not available for this entity type.');
  $this
    ->assertNoLinkByHref("/admin/structure/user/manage/user/moderation");
  $header = $this
    ->xpath("//details[@id='edit-entity-node']//th[text()='Workbench Moderation']");
  $this
    ->assertEqual(count($header), 1, 'There is a Workbench Moderation column for content.');
  $header = $this
    ->xpath("//details[@id='edit-entity-taxonomy-term']//th[text()='Workbench Moderation']");

  // In Drupal 8.7 and above taxonomy terms are moderable.
  if (floatval(\Drupal::VERSION) >= 8.699999999999999) {
    $this
      ->assertEqual(count($header), 1, 'There is a Workbench Moderation column for terms.');
  }
  else {
    $this
      ->assertEqual(count($header), 0, 'There is no Workbench Moderation column for terms.');
  }
  $header = $this
    ->xpath("//details[@id='edit-entity-user']//th[text()='Workbench Moderation']");
  $this
    ->assertEqual(count($header), 0, 'There is no Workbench Moderation column for users.');
}