You are here

public function LingotekNodeBulkProfileTest::testChangeTranslationProfileBulk in Lingotek Translation 3.6.x

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

Tests that the translation profiles can be updated with the bulk actions.

File

tests/src/Functional/LingotekNodeBulkProfileTest.php, line 56

Class

LingotekNodeBulkProfileTest
Tests changing a profile using the bulk management form.

Namespace

Drupal\Tests\lingotek\Functional

Code

public function testChangeTranslationProfileBulk() {

  // Login as admin.
  $this
    ->drupalLogin($this->rootUser);

  // Create three nodes.
  $nodes = [];

  // Create a node.
  for ($i = 1; $i < 4; $i++) {
    $edit = [];
    $edit['title[0][value]'] = 'Llamas are cool ' . $i;
    $edit['body[0][value]'] = 'Llamas are very cool ' . $i;
    $edit['langcode[0][value]'] = 'en';
    $edit['lingotek_translation_management[lingotek_translation_profile]'] = 'manual';
    $this
      ->saveAndPublishNodeForm($edit);
    $nodes[$i] = $edit;
  }
  $this
    ->goToContentBulkManagementForm();

  // I can init the upload of content.
  $this
    ->assertLingotekUploadLink(1);
  $this
    ->assertLingotekUploadLink(2);
  $this
    ->assertLingotekUploadLink(3);
  $edit = [
    'table[1]' => TRUE,
    'table[2]' => TRUE,
    'table[3]' => TRUE,
    $this
      ->getBulkOperationFormName() => $this
      ->getBulkOperationNameForUpload('node'),
  ];
  $this
    ->drupalPostForm(NULL, $edit, $this
    ->getApplyActionsButtonLabel());
  $this
    ->assertIdentical('en_US', \Drupal::state()
    ->get('lingotek.uploaded_locale'));

  // I can check current status.
  $this
    ->assertLingotekCheckSourceStatusLink();
  $key = $this
    ->getBulkSelectionKey('en', 1);
  $edit = [
    $key => TRUE,
    'table[2]' => TRUE,
    'table[3]' => TRUE,
    $this
      ->getBulkOperationFormName() => $this
      ->getBulkOperationNameForCheckUpload('node'),
  ];
  $this
    ->drupalPostForm(NULL, $edit, $this
    ->getApplyActionsButtonLabel());

  // Check that there are three nodes with the Manual Profile
  $manual_profile = $this
    ->xpath("//td[contains(text(), 'Manual')]");
  $this
    ->assertEqual(count($manual_profile), 3, 'There are three nodes with the Manual Profile set.');
  $key = $this
    ->getBulkSelectionKey('en', 1);
  $edit = [
    $key => TRUE,
    'table[2]' => TRUE,
    'table[3]' => TRUE,
    $this
      ->getBulkOperationFormName() => 'change_profile:automatic',
  ];
  $this
    ->drupalPostForm(NULL, $edit, $this
    ->getApplyActionsButtonLabel());

  // Check that there are three nodes with the Automatic Profile
  $automatic_profile = $this
    ->xpath("//td[contains(text(), 'Automatic')]");
  $this
    ->assertEqual(count($automatic_profile), 3, 'There are three nodes with the Automatic Profile set.');
  $edit = [
    'table[2]' => TRUE,
    $this
      ->getBulkOperationFormName() => 'change_profile:manual',
  ];
  $this
    ->drupalPostForm(NULL, $edit, $this
    ->getApplyActionsButtonLabel());

  // Check that there is one node with the Manual Profile
  // Check that there are two nodes with the Automatic Profile
  $manual_profile = $this
    ->xpath("//td[contains(text(), 'Manual')]");
  $this
    ->assertEqual(count($manual_profile), 1, 'There is one node with the Manual Profile set.');
  $automatic_profile = $this
    ->xpath("//td[contains(text(), 'Automatic')]");
  $this
    ->assertEqual(count($automatic_profile), 2, 'There are two nodes with the Automatic Profile set.');
  $key = $this
    ->getBulkSelectionKey('en', 1);
  $edit = [
    $key => TRUE,
    'table[2]' => TRUE,
    'table[3]' => TRUE,
    $this
      ->getBulkOperationFormName() => 'change_profile:disabled',
  ];
  $this
    ->drupalPostForm(NULL, $edit, $this
    ->getApplyActionsButtonLabel());

  // Check that there are three nodes with the Disabled Profile
  $disabled_profile = $this
    ->xpath("//td[contains(text(), 'Disabled')]");
  $this
    ->assertEqual(count($disabled_profile), 3, 'There are three nodes with the Disabled Profile set.');

  /** @var \Drupal\lingotek\LingotekContentTranslationServiceInterface $content_translation_service */
  $content_translation_service = \Drupal::service('lingotek.content_translation');
  $this
    ->goToContentBulkManagementForm();
  for ($i = 1; $i < 4; $i++) {
    $node = Node::load($i);
    $this
      ->assertIdentical(Lingotek::STATUS_DISABLED, $content_translation_service
      ->getSourceStatus($node));
    $this
      ->assertIdentical(Lingotek::STATUS_DISABLED, $content_translation_service
      ->getTargetStatus($node, 'en'));
    $this
      ->assertIdentical(Lingotek::STATUS_DISABLED, $content_translation_service
      ->getTargetStatus($node, 'es'));
  }
  $key = $this
    ->getBulkSelectionKey('en', 1);
  $edit = [
    $key => TRUE,
    'table[2]' => TRUE,
    'table[3]' => TRUE,
    $this
      ->getBulkOperationFormName() => $this
      ->getBulkOperationNameForUpload('node'),
  ];
  $this
    ->drupalPostForm(NULL, $edit, $this
    ->getApplyActionsButtonLabel());
  for ($i = 1; $i < 4; $i++) {
    $node = Node::load($i);
    $this
      ->assertIdentical(Lingotek::STATUS_DISABLED, $content_translation_service
      ->getSourceStatus($node));
    $this
      ->assertIdentical(Lingotek::STATUS_DISABLED, $content_translation_service
      ->getTargetStatus($node, 'en'));
    $this
      ->assertIdentical(Lingotek::STATUS_DISABLED, $content_translation_service
      ->getTargetStatus($node, 'es'));
  }
  $key = $this
    ->getBulkSelectionKey('en', 1);
  $edit = [
    $key => TRUE,
    'table[2]' => TRUE,
    'table[3]' => TRUE,
    $this
      ->getBulkOperationFormName() => $this
      ->getBulkOperationNameForCheckUpload('node'),
  ];
  $this
    ->drupalPostForm(NULL, $edit, $this
    ->getApplyActionsButtonLabel());
  for ($i = 1; $i < 4; $i++) {
    $node = Node::load($i);
    $this
      ->assertIdentical(Lingotek::STATUS_DISABLED, $content_translation_service
      ->getSourceStatus($node));
    $this
      ->assertIdentical(Lingotek::STATUS_DISABLED, $content_translation_service
      ->getTargetStatus($node, 'en'));
    $this
      ->assertIdentical(Lingotek::STATUS_DISABLED, $content_translation_service
      ->getTargetStatus($node, 'es'));
  }
  $key = $this
    ->getBulkSelectionKey('en', 1);
  $edit = [
    $key => TRUE,
    'table[2]' => TRUE,
    'table[3]' => TRUE,
    $this
      ->getBulkOperationFormName() => $this
      ->getBulkOperationNameForRequestTranslations('node'),
  ];
  $this
    ->drupalPostForm(NULL, $edit, $this
    ->getApplyActionsButtonLabel());
  for ($i = 1; $i < 4; $i++) {
    $node = Node::load($i);
    $this
      ->assertIdentical(Lingotek::STATUS_DISABLED, $content_translation_service
      ->getSourceStatus($node));
    $this
      ->assertIdentical(Lingotek::STATUS_DISABLED, $content_translation_service
      ->getTargetStatus($node, 'en'));
    $this
      ->assertIdentical(Lingotek::STATUS_DISABLED, $content_translation_service
      ->getTargetStatus($node, 'es'));
  }
  $key = $this
    ->getBulkSelectionKey('en', 1);
  $edit = [
    $key => TRUE,
    'table[2]' => TRUE,
    'table[3]' => TRUE,
    $this
      ->getBulkOperationFormName() => $this
      ->getBulkOperationNameForCheckTranslations('node'),
  ];
  $this
    ->drupalPostForm(NULL, $edit, $this
    ->getApplyActionsButtonLabel());
  for ($i = 1; $i < 4; $i++) {
    $node = Node::load($i);
    $this
      ->assertIdentical(Lingotek::STATUS_DISABLED, $content_translation_service
      ->getSourceStatus($node));
    $this
      ->assertIdentical(Lingotek::STATUS_DISABLED, $content_translation_service
      ->getTargetStatus($node, 'en'));
    $this
      ->assertIdentical(Lingotek::STATUS_DISABLED, $content_translation_service
      ->getTargetStatus($node, 'es'));
  }
  $key = $this
    ->getBulkSelectionKey('en', 1);
  $edit = [
    $key => TRUE,
    'table[2]' => TRUE,
    'table[3]' => TRUE,
    $this
      ->getBulkOperationFormName() => $this
      ->getBulkOperationNameForDownloadTranslation('es', 'node'),
  ];
  $this
    ->drupalPostForm(NULL, $edit, $this
    ->getApplyActionsButtonLabel());
  for ($i = 1; $i < 4; $i++) {
    $node = Node::load($i);
    $this
      ->assertIdentical(Lingotek::STATUS_DISABLED, $content_translation_service
      ->getSourceStatus($node));
    $this
      ->assertIdentical(Lingotek::STATUS_DISABLED, $content_translation_service
      ->getTargetStatus($node, 'en'));
    $this
      ->assertIdentical(Lingotek::STATUS_DISABLED, $content_translation_service
      ->getTargetStatus($node, 'es'));
  }
  $key = $this
    ->getBulkSelectionKey('en', 1);
  $edit = [
    $key => TRUE,
    'table[2]' => TRUE,
    'table[3]' => TRUE,
    $this
      ->getBulkOperationFormName() => 'change_profile:automatic',
  ];
  $this
    ->drupalPostForm(NULL, $edit, $this
    ->getApplyActionsButtonLabel());

  // Check that there are three nodes with the Automatic Profile
  $automatic_profile = $this
    ->xpath("//td[contains(text(), 'Automatic')]");
  $this
    ->assertEqual(count($automatic_profile), 3, 'There are three nodes with the Automatic Profile set.');
  \Drupal::entityTypeManager()
    ->getStorage('node')
    ->resetCache();
  \Drupal::entityTypeManager()
    ->getStorage('lingotek_content_metadata')
    ->resetCache();
  for ($i = 1; $i < 4; $i++) {
    $node = Node::load($i);
    $this
      ->assertIdentical(Lingotek::STATUS_CURRENT, $content_translation_service
      ->getSourceStatus($node));
    $this
      ->assertIdentical(Lingotek::STATUS_CURRENT, $content_translation_service
      ->getTargetStatus($node, 'en'));
    $this
      ->assertIdentical(Lingotek::STATUS_READY, $content_translation_service
      ->getTargetStatus($node, 'es'));
  }
  $key = $this
    ->getBulkSelectionKey('en', 1);
  $edit = [
    $key => TRUE,
    'table[2]' => TRUE,
    'table[3]' => TRUE,
    $this
      ->getBulkOperationFormName() => $this
      ->getBulkOperationNameForUpload('node'),
  ];
  $this
    ->drupalPostForm(NULL, $edit, $this
    ->getApplyActionsButtonLabel());
  \Drupal::entityTypeManager()
    ->getStorage('node')
    ->resetCache();
  \Drupal::entityTypeManager()
    ->getStorage('lingotek_content_metadata')
    ->resetCache();
  for ($i = 1; $i < 4; $i++) {
    $node = Node::load($i);
    $this
      ->assertIdentical(Lingotek::STATUS_IMPORTING, $content_translation_service
      ->getSourceStatus($node));
    $this
      ->assertIdentical(Lingotek::STATUS_IMPORTING, $content_translation_service
      ->getTargetStatus($node, 'en'));
    $this
      ->assertIdentical(Lingotek::STATUS_PENDING, $content_translation_service
      ->getTargetStatus($node, 'es'));
  }
  $key = $this
    ->getBulkSelectionKey('en', 1);
  $edit = [
    $key => TRUE,
    'table[2]' => TRUE,
    'table[3]' => TRUE,
    $this
      ->getBulkOperationFormName() => $this
      ->getBulkOperationNameForCheckUpload('node'),
  ];
  $this
    ->drupalPostForm(NULL, $edit, $this
    ->getApplyActionsButtonLabel());
  \Drupal::entityTypeManager()
    ->getStorage('node')
    ->resetCache();
  \Drupal::entityTypeManager()
    ->getStorage('lingotek_content_metadata')
    ->resetCache();
  for ($i = 1; $i < 4; $i++) {
    $node = Node::load($i);
    $this
      ->assertIdentical(Lingotek::STATUS_CURRENT, $content_translation_service
      ->getSourceStatus($node));
    $this
      ->assertIdentical(Lingotek::STATUS_CURRENT, $content_translation_service
      ->getTargetStatus($node, 'en'));
    $this
      ->assertIdentical(Lingotek::STATUS_PENDING, $content_translation_service
      ->getTargetStatus($node, 'es'));
  }
  $key = $this
    ->getBulkSelectionKey('en', 1);
  $edit = [
    $key => TRUE,
    'table[2]' => TRUE,
    'table[3]' => TRUE,
    $this
      ->getBulkOperationFormName() => $this
      ->getBulkOperationNameForRequestTranslations('node'),
  ];
  $this
    ->drupalPostForm(NULL, $edit, $this
    ->getApplyActionsButtonLabel());
  \Drupal::entityTypeManager()
    ->getStorage('node')
    ->resetCache();
  \Drupal::entityTypeManager()
    ->getStorage('lingotek_content_metadata')
    ->resetCache();
  for ($i = 1; $i < 4; $i++) {
    $node = Node::load($i);
    $this
      ->assertIdentical(Lingotek::STATUS_CURRENT, $content_translation_service
      ->getSourceStatus($node));
    $this
      ->assertIdentical(Lingotek::STATUS_CURRENT, $content_translation_service
      ->getTargetStatus($node, 'en'));
    $this
      ->assertIdentical(Lingotek::STATUS_PENDING, $content_translation_service
      ->getTargetStatus($node, 'es'));
  }
  $key = $this
    ->getBulkSelectionKey('en', 1);
  $edit = [
    $key => TRUE,
    'table[2]' => TRUE,
    'table[3]' => TRUE,
    $this
      ->getBulkOperationFormName() => $this
      ->getBulkOperationNameForCheckTranslations('node'),
  ];
  $this
    ->drupalPostForm(NULL, $edit, $this
    ->getApplyActionsButtonLabel());
  \Drupal::entityTypeManager()
    ->getStorage('node')
    ->resetCache();
  \Drupal::entityTypeManager()
    ->getStorage('lingotek_content_metadata')
    ->resetCache();
  for ($i = 1; $i < 4; $i++) {
    $node = Node::load($i);
    $this
      ->assertIdentical(Lingotek::STATUS_CURRENT, $content_translation_service
      ->getSourceStatus($node));
    $this
      ->assertIdentical(Lingotek::STATUS_CURRENT, $content_translation_service
      ->getTargetStatus($node, 'en'));
    $this
      ->assertIdentical(Lingotek::STATUS_READY, $content_translation_service
      ->getTargetStatus($node, 'es'));
  }
  $key = $this
    ->getBulkSelectionKey('en', 1);
  $edit = [
    $key => TRUE,
    'table[2]' => TRUE,
    'table[3]' => TRUE,
    $this
      ->getBulkOperationFormName() => $this
      ->getBulkOperationNameForDownloadTranslations('node'),
  ];
  $this
    ->drupalPostForm(NULL, $edit, $this
    ->getApplyActionsButtonLabel());
  \Drupal::entityTypeManager()
    ->getStorage('node')
    ->resetCache();
  \Drupal::entityTypeManager()
    ->getStorage('lingotek_content_metadata')
    ->resetCache();
  for ($i = 1; $i < 4; $i++) {
    $node = Node::load($i);
    $this
      ->assertIdentical(Lingotek::STATUS_CURRENT, $content_translation_service
      ->getSourceStatus($node));
    $this
      ->assertIdentical(Lingotek::STATUS_CURRENT, $content_translation_service
      ->getTargetStatus($node, 'en'));
    $this
      ->assertIdentical(Lingotek::STATUS_READY, $content_translation_service
      ->getTargetStatus($node, 'es'));
  }

  // Edit the nodes.
  for ($i = 1; $i < 4; $i++) {
    $edit = [];
    $edit['lingotek_translation_management[lingotek_translation_profile]'] = Lingotek::PROFILE_DISABLED;
    $this
      ->saveAndKeepPublishedNodeForm($edit, $i);
  }
  $this
    ->goToContentBulkManagementForm();
  \Drupal::entityTypeManager()
    ->getStorage('node')
    ->resetCache();
  \Drupal::entityTypeManager()
    ->getStorage('lingotek_content_metadata')
    ->resetCache();
  for ($i = 1; $i < 4; $i++) {
    $node = Node::load($i);
    $this
      ->assertIdentical(Lingotek::STATUS_DISABLED, $content_translation_service
      ->getSourceStatus($node));
    $this
      ->assertIdentical(Lingotek::STATUS_DISABLED, $content_translation_service
      ->getTargetStatus($node, 'en'));
    $this
      ->assertIdentical(Lingotek::STATUS_DISABLED, $content_translation_service
      ->getTargetStatus($node, 'es'));
  }

  // Edit the nodes.
  for ($i = 1; $i < 4; $i++) {
    $edit = [];
    $edit['lingotek_translation_management[lingotek_translation_profile]'] = 'manual';
    $this
      ->saveAndKeepPublishedNodeForm($edit, $i);
  }
  $this
    ->goToContentBulkManagementForm();
  \Drupal::entityTypeManager()
    ->getStorage('node')
    ->resetCache();
  \Drupal::entityTypeManager()
    ->getStorage('lingotek_content_metadata')
    ->resetCache();
  for ($i = 1; $i < 4; $i++) {
    $node = Node::load($i);
    $this
      ->assertIdentical(Lingotek::STATUS_CURRENT, $content_translation_service
      ->getSourceStatus($node));
    $this
      ->assertIdentical(Lingotek::STATUS_CURRENT, $content_translation_service
      ->getTargetStatus($node, 'en'));
    $this
      ->assertIdentical(Lingotek::STATUS_READY, $content_translation_service
      ->getTargetStatus($node, 'es'));
  }
}