You are here

public function LingotekNodeBulkProfileTest::testChangeTranslationProfileBulk in Lingotek Translation 8

Tests that the tranlsation profiles can be updated with the bulk acitons.

File

src/Tests/LingotekNodeBulkProfileTest.php, line 64

Class

LingotekNodeBulkProfileTest
Tests translating a node using the bulk management form.

Namespace

Drupal\lingotek\Tests

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 = array();
    $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_profile'] = 'manual';
    $this
      ->drupalPostForm('node/add/article', $edit, t('Save and publish'));
    $nodes[$i] = $edit;
  }
  $this
    ->goToContentBulkManagementForm();
  $basepath = \Drupal::request()
    ->getBasePath();

  // I can init the upload of content.
  $this
    ->assertLinkByHref($basepath . '/admin/lingotek/entity/upload/node/1?destination=' . $basepath . '/admin/lingotek/manage/node');
  $this
    ->assertLinkByHref($basepath . '/admin/lingotek/entity/upload/node/2?destination=' . $basepath . '/admin/lingotek/manage/node');
  $this
    ->assertLinkByHref($basepath . '/admin/lingotek/entity/upload/node/3?destination=' . $basepath . '/admin/lingotek/manage/node');
  $edit = [
    'table[1]' => TRUE,
    // Node 1.
    'table[2]' => TRUE,
    // Node 2.
    'table[3]' => TRUE,
    // Node 3.
    'operation' => 'upload',
  ];
  $this
    ->drupalPostForm(NULL, $edit, t('Execute'));
  $this
    ->assertIdentical('en_US', \Drupal::state()
    ->get('lingotek.uploaded_locale'));

  // I can check current status.
  $this
    ->assertLinkByHref($basepath . '/admin/lingotek/entity/check_upload/dummy-document-hash-id?destination=' . $basepath . '/admin/lingotek/manage/node');
  $edit = [
    'table[1]' => TRUE,
    // Node 1.
    'table[2]' => TRUE,
    // Node 2.
    'table[3]' => TRUE,
    // Node 3.
    'operation' => 'check_upload',
  ];
  $this
    ->drupalPostForm(NULL, $edit, t('Execute'));

  // 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.');
  $edit = [
    'table[1]' => TRUE,
    // Node 1.
    'table[2]' => TRUE,
    // Node 2.
    'table[3]' => TRUE,
    // Node 3.
    'operation' => 'change_profile:automatic',
  ];
  $this
    ->drupalPostForm(NULL, $edit, t('Execute'));

  // 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,
    // Node 2.
    'operation' => 'change_profile:manual',
  ];
  $this
    ->drupalPostForm(NULL, $edit, t('Execute'));

  // 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.');
  $edit = [
    'table[1]' => TRUE,
    // Node 1.
    'table[2]' => TRUE,
    // Node 2.
    'table[3]' => TRUE,
    // Node 3.
    'operation' => 'change_profile:disabled',
  ];
  $this
    ->drupalPostForm(NULL, $edit, t('Execute'));

  // 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.');
}