View source  
  <?php
namespace Drupal\Tests\lingotek\Functional;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\lingotek\Lingotek;
use Drupal\Tests\field\Traits\EntityReferenceTestTrait;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\language\Entity\ContentLanguageSettings;
use Drupal\taxonomy\Entity\Term;
use Drupal\Tests\taxonomy\Traits\TaxonomyTestTrait;
class LingotekNodeManageTranslationTabTest extends LingotekTestBase {
  use TaxonomyTestTrait;
  use EntityReferenceTestTrait;
  
  public static $modules = [
    'block',
    'node',
    'taxonomy',
  ];
  
  protected $vocabulary;
  protected function setUp() : void {
    parent::setUp();
    
    $this
      ->drupalPlaceBlock('local_tasks_block', [
      'region' => 'content',
      'weight' => -10,
    ]);
    $this
      ->drupalPlaceBlock('page_title_block', [
      'region' => 'content',
      'weight' => -5,
    ]);
    $this->vocabulary = $this
      ->createVocabulary();
    
    $this
      ->drupalCreateContentType([
      'type' => 'article',
      'name' => 'Article',
    ]);
    $handler_settings = [
      'target_bundles' => [
        $this->vocabulary
          ->id() => $this->vocabulary
          ->id(),
      ],
      'auto_create' => TRUE,
    ];
    $this
      ->createEntityReferenceField('node', 'article', 'field_tags', 'Tags', 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
    EntityFormDisplay::load('node.article.default')
      ->setComponent('field_tags', [
      'type' => 'entity_reference_autocomplete_tags',
    ])
      ->save();
    EntityViewDisplay::load('node.article.default')
      ->setComponent('field_tags')
      ->save();
    $this
      ->createEntityReferenceField('taxonomy_term', $this->vocabulary
      ->id(), 'field_tags', 'Tags', 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
    $entity_form_display = EntityFormDisplay::load('taxonomy_term' . '.' . $this->vocabulary
      ->id() . '.' . 'default');
    if (!$entity_form_display) {
      $entity_form_display = EntityFormDisplay::create([
        'targetEntityType' => 'taxonomy_term',
        'bundle' => $this->vocabulary
          ->id(),
        'mode' => 'default',
        'status' => TRUE,
      ]);
    }
    $entity_form_display
      ->setComponent('field_tags', [
      'type' => 'entity_reference_autocomplete_tags',
    ])
      ->save();
    $display = EntityViewDisplay::load('taxonomy_term' . '.' . $this->vocabulary
      ->id() . '.' . 'default');
    if (!$display) {
      $display = EntityViewDisplay::create([
        'targetEntityType' => 'taxonomy_term',
        'bundle' => $this->vocabulary
          ->id(),
        'mode' => 'default',
        'status' => TRUE,
      ]);
    }
    $display
      ->setComponent('field_tags')
      ->save();
    
    ConfigurableLanguage::createFromLangcode('es')
      ->setThirdPartySetting('lingotek', 'locale', 'es_MX')
      ->save();
    
    ContentLanguageSettings::loadByEntityTypeBundle('node', 'article')
      ->setLanguageAlterable(TRUE)
      ->save();
    ContentLanguageSettings::loadByEntityTypeBundle('taxonomy_term', $this->vocabulary
      ->id())
      ->setLanguageAlterable(TRUE)
      ->save();
    \Drupal::service('content_translation.manager')
      ->setEnabled('node', 'article', TRUE);
    \Drupal::service('content_translation.manager')
      ->setEnabled('taxonomy_term', $this->vocabulary
      ->id(), TRUE);
    drupal_static_reset();
    \Drupal::entityTypeManager()
      ->clearCachedDefinitions();
    $this
      ->applyEntityUpdates();
    
    $this
      ->rebuildContainer();
    $bundle = $this->vocabulary
      ->id();
    $this
      ->saveLingotekContentTranslationSettings([
      'node' => [
        'article' => [
          'profiles' => 'automatic',
          'fields' => [
            'title' => 1,
            'body' => 1,
          ],
        ],
      ],
      'taxonomy_term' => [
        $bundle => [
          'profiles' => 'manual',
          'fields' => [
            'name' => 1,
            'description' => 1,
          ],
        ],
      ],
    ]);
  }
  
  public function testNodeTranslationUsingLinks() {
    
    $this
      ->drupalLogin($this->rootUser);
    
    $edit = [];
    $edit['title[0][value]'] = 'Llamas are cool';
    $edit['body[0][value]'] = 'Llamas are very cool';
    $edit['field_tags[target_id]'] = implode(',', [
      'Camelid',
      'Herbivorous',
    ]);
    $edit['langcode[0][value]'] = 'en';
    $edit['lingotek_translation_management[lingotek_translation_profile]'] = 'manual';
    $this
      ->saveAndPublishNodeForm($edit);
    $this
      ->createRelatedTermsForTestingDepth();
    
    $this
      ->drupalLogin($this->translationManagerUser);
    
    $this
      ->drupalGet('node/1');
    $this
      ->clickLink('Manage Translations');
    $this
      ->assertText('Llamas are cool');
    $this
      ->assertText('Camelid');
    $this
      ->assertText('Herbivorous');
    
    $this
      ->assertNoText('Hominid');
    
    $this
      ->assertNoText('Ruminant');
    $this
      ->drupalPostForm(NULL, [
      'depth' => 2,
    ], 'Apply');
    $this
      ->assertText('Llamas are cool');
    $this
      ->assertText('Camelid');
    $this
      ->assertText('Herbivorous');
    
    $this
      ->assertText('Hominid');
    
    $this
      ->assertNoText('Ruminant');
    $this
      ->drupalPostForm(NULL, [
      'depth' => 3,
    ], 'Apply');
    $this
      ->assertText('Llamas are cool');
    $this
      ->assertText('Camelid');
    $this
      ->assertText('Herbivorous');
    
    $this
      ->assertText('Hominid');
    
    $this
      ->assertText('Ruminant');
    
    $this
      ->assertLingotekUploadLink();
    
    $this
      ->assertNoLingotekRequestTranslationLink('es_MX');
    $this
      ->clickLink('EN');
    $this
      ->assertText('Node Llamas are cool has been uploaded.');
    $this
      ->assertIdentical('en_US', \Drupal::state()
      ->get('lingotek.uploaded_locale'));
    
    $this
      ->assertLingotekCheckSourceStatusLink();
    
    $this
      ->assertLingotekRequestTranslationLink('es_MX');
    $this
      ->clickLink('EN');
    $this
      ->assertText('The import for node Llamas are cool is complete.');
    
    $this
      ->assertLingotekRequestTranslationLink('es_MX');
    $this
      ->clickLink('ES');
    $this
      ->assertText("Locale 'es_MX' was added as a translation target for node Llamas are cool.");
    $this
      ->assertIdentical('es_MX', \Drupal::state()
      ->get('lingotek.added_target_locale'));
    
    $this
      ->assertLingotekCheckTargetStatusLink('es_MX');
    $this
      ->clickLink('ES');
    $this
      ->assertIdentical('es_MX', \Drupal::state()
      ->get('lingotek.checked_target_locale'));
    $this
      ->assertText('The es_MX translation for node Llamas are cool is ready for download.');
    
    $this
      ->assertLingotekDownloadTargetLink('es_MX');
    $this
      ->clickLink('ES');
    $this
      ->assertText('The translation of node Llamas are cool into es_MX has been downloaded.');
    $this
      ->assertIdentical('es_MX', \Drupal::state()
      ->get('lingotek.downloaded_locale'));
    
    $this
      ->assertLingotekWorkbenchLink('es_MX');
  }
  
  public function testNodeTranslationMessageWhenBundleNotTranslatable() {
    $assert_session = $this
      ->assertSession();
    
    $this
      ->drupalCreateContentType([
      'type' => 'page',
      'name' => 'Page',
    ]);
    
    $edit = [];
    $edit['title[0][value]'] = 'Pages are cool';
    $edit['body[0][value]'] = 'Pages are very cool';
    $this
      ->drupalPostForm('node/add/page', $edit, t('Save'));
    
    $this
      ->drupalGet('node/1');
    $this
      ->clickLink('Manage Translations');
    $assert_session
      ->pageTextContains('Not enabled');
    $this
      ->clickLink('EN');
    $assert_session
      ->pageTextContains('Cannot upload Page Pages are cool. That Content type is not enabled for translation.');
    $edit = [
      'table[node:1]' => TRUE,
      $this
        ->getBulkOperationFormName() => $this
        ->getBulkOperationNameForUpload('node'),
    ];
    $this
      ->drupalPostForm(NULL, $edit, $this
      ->getApplyActionsButtonLabel());
    $this
      ->assertIdentical(NULL, \Drupal::state()
      ->get('lingotek.uploaded_locale'));
    $assert_session
      ->pageTextContains('Cannot upload Page Pages are cool. That Content type is not enabled for translation.');
  }
  
  public function testNodeTranslationMessageWhenBundleNotConfigured() {
    $assert_session = $this
      ->assertSession();
    
    $this
      ->drupalCreateContentType([
      'type' => 'page',
      'name' => 'Page',
    ]);
    
    ContentLanguageSettings::loadByEntityTypeBundle('node', 'page')
      ->setLanguageAlterable(TRUE)
      ->save();
    \Drupal::service('content_translation.manager')
      ->setEnabled('node', 'page', TRUE);
    
    $edit = [];
    $edit['title[0][value]'] = 'Pages are cool';
    $edit['body[0][value]'] = 'Pages are very cool';
    $edit['langcode[0][value]'] = 'en';
    $this
      ->drupalPostForm('node/add/page', $edit, t('Save'));
    
    $this
      ->drupalGet('node/1');
    $this
      ->clickLink('Manage Translations');
    $assert_session
      ->pageTextContains('Not enabled');
    $this
      ->clickLink('EN');
    $assert_session
      ->pageTextContains('Cannot upload Page Pages are cool. That Content type is not enabled for Lingotek translation.');
    $edit = [
      'table[node:1]' => TRUE,
      $this
        ->getBulkOperationFormName() => $this
        ->getBulkOperationNameForUpload('node'),
    ];
    $this
      ->drupalPostForm(NULL, $edit, $this
      ->getApplyActionsButtonLabel());
    $this
      ->assertIdentical(NULL, \Drupal::state()
      ->get('lingotek.uploaded_locale'));
    $assert_session
      ->pageTextContains('Cannot upload Page Pages are cool. That Content type is not enabled for Lingotek translation.');
  }
  
  public function testNodeTranslationUsingActions() {
    
    $this
      ->drupalLogin($this->rootUser);
    
    ConfigurableLanguage::createFromLangcode('de')
      ->setThirdPartySetting('lingotek', 'locale', 'de_AT')
      ->save();
    
    $edit = [];
    $edit['title[0][value]'] = 'Llamas are cool';
    $edit['body[0][value]'] = 'Llamas are very cool';
    $edit['langcode[0][value]'] = 'en';
    $edit['field_tags[target_id]'] = implode(',', [
      'Camelid',
      'Herbivorous',
    ]);
    $edit['lingotek_translation_management[lingotek_translation_profile]'] = 'manual';
    $this
      ->saveAndPublishNodeForm($edit);
    $this
      ->createRelatedTermsForTestingDepth();
    
    $this
      ->drupalLogin($this->translationManagerUser);
    
    $this
      ->drupalGet('node/1');
    $this
      ->clickLink('Manage Translations');
    $this
      ->assertText('Llamas are cool');
    $this
      ->assertText('Camelid');
    $this
      ->assertText('Herbivorous');
    
    $this
      ->assertNoText('Hominid');
    
    $this
      ->assertNoText('Ruminant');
    
    $this
      ->assertLingotekUploadLink();
    $edit = [
      'table[node:1]' => TRUE,
      $this
        ->getBulkOperationFormName() => $this
        ->getBulkOperationNameForUpload('node'),
    ];
    $this
      ->drupalPostForm(NULL, $edit, $this
      ->getApplyActionsButtonLabel());
    $this
      ->assertIdentical('en_US', \Drupal::state()
      ->get('lingotek.uploaded_locale'));
    
    $this
      ->assertLingotekCheckSourceStatusLink();
    $edit = [
      'table[node:1]' => TRUE,
      $this
        ->getBulkOperationFormName() => $this
        ->getBulkOperationNameForCheckUpload('node'),
    ];
    $this
      ->drupalPostForm(NULL, $edit, $this
      ->getApplyActionsButtonLabel());
    
    $this
      ->assertLingotekRequestTranslationLink('de_AT');
    $edit = [
      'table[node:1]' => TRUE,
      $this
        ->getBulkOperationFormName() => $this
        ->getBulkOperationNameForRequestTranslation('de', 'node'),
    ];
    $this
      ->drupalPostForm(NULL, $edit, $this
      ->getApplyActionsButtonLabel());
    $this
      ->assertIdentical('de_AT', \Drupal::state()
      ->get('lingotek.added_target_locale'));
    
    $this
      ->assertLingotekCheckTargetStatusLink('de_AT');
    $edit = [
      'table[node:1]' => TRUE,
      $this
        ->getBulkOperationFormName() => $this
        ->getBulkOperationNameForCheckTranslation('de', 'node'),
    ];
    $this
      ->drupalPostForm(NULL, $edit, $this
      ->getApplyActionsButtonLabel());
    $this
      ->assertIdentical('de_AT', \Drupal::state()
      ->get('lingotek.checked_target_locale'));
    
    $this
      ->assertLingotekDownloadTargetLink('de_AT');
    $edit = [
      'table[node:1]' => TRUE,
      $this
        ->getBulkOperationFormName() => $this
        ->getBulkOperationNameForDownloadTranslation('de', 'node'),
    ];
    $this
      ->drupalPostForm(NULL, $edit, $this
      ->getApplyActionsButtonLabel());
    $this
      ->assertIdentical('de_AT', \Drupal::state()
      ->get('lingotek.downloaded_locale'));
    
    $this
      ->assertLingotekWorkbenchLink('de_AT');
  }
  
  public function testJobIdOnUpload() {
    
    $edit = [];
    $edit['title[0][value]'] = 'Llamas are cool';
    $edit['body[0][value]'] = 'Llamas are very cool';
    $edit['langcode[0][value]'] = 'en';
    $edit['lingotek_translation_management[lingotek_translation_profile]'] = 'manual';
    $this
      ->saveAndPublishNodeForm($edit);
    $this
      ->goToContentBulkManagementForm();
    
    $this
      ->assertLingotekUploadLink(1);
    $edit = [
      'table[node:1]' => TRUE,
      'job_id' => 'my_custom_job_id',
      $this
        ->getBulkOperationFormName() => $this
        ->getBulkOperationNameForUpload('node'),
    ];
    $this
      ->drupalPostForm(NULL, $edit, $this
      ->getApplyActionsButtonLabel());
    $this
      ->assertIdentical('en_US', \Drupal::state()
      ->get('lingotek.uploaded_locale'));
    $this
      ->assertIdentical('my_custom_job_id', \Drupal::state()
      ->get('lingotek.uploaded_job_id'));
    
    $this
      ->assertText('Job ID');
    $this
      ->assertText('my_custom_job_id');
  }
  
  public function testAssignJobIds() {
    
    $edit = [];
    $edit['title[0][value]'] = 'Llamas are cool';
    $edit['body[0][value]'] = 'Llamas are very cool';
    $edit['langcode[0][value]'] = 'en';
    $edit['field_tags[target_id]'] = implode(',', [
      'Camelid',
      'Herbivorous',
    ]);
    $edit['lingotek_translation_management[lingotek_translation_profile]'] = 'manual';
    $this
      ->saveAndPublishNodeForm($edit);
    $this
      ->goToContentBulkManagementForm();
    
    $this
      ->assertLingotekUploadLink(1, 'node');
    $this
      ->assertLingotekUploadLink(1, 'taxonomy_term', NULL, 'node');
    $edit = [
      'table[node:1]' => TRUE,
      'table[taxonomy_term:1]' => TRUE,
      $this
        ->getBulkOperationFormName() => $this
        ->getBulkOperationNameForAssignJobId('node'),
    ];
    $this
      ->drupalPostForm(NULL, $edit, $this
      ->getApplyActionsButtonLabel());
    $edit = [
      'job_id' => 'my_custom_job_id',
    ];
    $this
      ->drupalPostForm(NULL, $edit, 'Assign Job ID');
    $this
      ->assertText('Job ID was assigned successfully.');
    
    $this
      ->assertNull(\Drupal::state()
      ->get('lingotek.uploaded_title'));
    $this
      ->assertNull(\Drupal::state()
      ->get('lingotek.uploaded_job_id'));
    
    $this
      ->assertText('my_custom_job_id');
    
    $this
      ->clickLink('EN');
    $this
      ->assertText('Node Llamas are cool has been uploaded.');
    
    \Drupal::state()
      ->resetCache();
    $this
      ->assertIdentical(\Drupal::state()
      ->get('lingotek.uploaded_job_id'), 'my_custom_job_id');
    
    $edit = [
      'table[node:1]' => TRUE,
      'table[taxonomy_term:1]' => TRUE,
      $this
        ->getBulkOperationFormName() => $this
        ->getBulkOperationNameForAssignJobId('node'),
    ];
    $this
      ->drupalPostForm(NULL, $edit, $this
      ->getApplyActionsButtonLabel());
    $edit = [
      'job_id' => 'other_job_id',
    ];
    $this
      ->drupalPostForm(NULL, $edit, 'Assign Job ID');
    $this
      ->assertText('Job ID was assigned successfully.');
    
    \Drupal::state()
      ->resetCache();
    $this
      ->assertNotNull(\Drupal::state()
      ->get('lingotek.uploaded_title'));
    $this
      ->assertNotNull(\Drupal::state()
      ->get('lingotek.uploaded_content'));
    $this
      ->assertEquals('my_custom_job_id', \Drupal::state()
      ->get('lingotek.uploaded_job_id'));
  }
  
  public function testAssignJobIdsWithTMSUpdate() {
    
    $edit = [];
    $edit['title[0][value]'] = 'Llamas are cool';
    $edit['body[0][value]'] = 'Llamas are very cool';
    $edit['langcode[0][value]'] = 'en';
    $edit['field_tags[target_id]'] = implode(',', [
      'Camelid',
      'Herbivorous',
    ]);
    $edit['lingotek_translation_management[lingotek_translation_profile]'] = 'manual';
    $this
      ->saveAndPublishNodeForm($edit);
    $this
      ->goToContentBulkManagementForm();
    
    $this
      ->assertLingotekUploadLink(1, 'node');
    $this
      ->assertLingotekUploadLink(1, 'taxonomy_term', NULL, 'node');
    $edit = [
      'table[node:1]' => TRUE,
      'table[taxonomy_term:1]' => TRUE,
      $this
        ->getBulkOperationFormName() => $this
        ->getBulkOperationNameForAssignJobId('node'),
    ];
    $this
      ->drupalPostForm(NULL, $edit, $this
      ->getApplyActionsButtonLabel());
    $edit = [
      'job_id' => 'my_custom_job_id',
      'update_tms' => 1,
    ];
    $this
      ->drupalPostForm(NULL, $edit, 'Assign Job ID');
    $this
      ->assertText('Job ID was assigned successfully.');
    
    \Drupal::state()
      ->resetCache();
    $this
      ->assertNull(\Drupal::state()
      ->get('lingotek.uploaded_title'));
    $this
      ->assertNull(\Drupal::state()
      ->get('lingotek.uploaded_content'));
    $this
      ->assertNull(\Drupal::state()
      ->get('lingotek.uploaded_job_id'));
    
    $this
      ->assertText('my_custom_job_id');
    
    $this
      ->clickLink('EN');
    $this
      ->assertText('Node Llamas are cool has been uploaded.');
    
    \Drupal::state()
      ->resetCache();
    $this
      ->assertIdentical(\Drupal::state()
      ->get('lingotek.uploaded_job_id'), 'my_custom_job_id');
    
    $edit = [
      'table[node:1]' => TRUE,
      'table[taxonomy_term:1]' => TRUE,
      $this
        ->getBulkOperationFormName() => $this
        ->getBulkOperationNameForAssignJobId('node'),
    ];
    $this
      ->drupalPostForm(NULL, $edit, $this
      ->getApplyActionsButtonLabel());
    $edit = [
      'job_id' => 'other_job_id',
      'update_tms' => 1,
    ];
    $this
      ->drupalPostForm(NULL, $edit, 'Assign Job ID');
    $this
      ->assertText('Job ID was assigned successfully.');
    
    \Drupal::state()
      ->resetCache();
    $this
      ->assertNull(\Drupal::state()
      ->get('lingotek.uploaded_title'));
    $this
      ->assertIdentical(\Drupal::state()
      ->get('lingotek.uploaded_job_id'), 'other_job_id');
  }
  
  public function testAssignInvalidJobIdsWithTMSUpdate() {
    
    $edit = [];
    $edit['title[0][value]'] = 'Llamas are cool';
    $edit['body[0][value]'] = 'Llamas are very cool';
    $edit['langcode[0][value]'] = 'en';
    $edit['field_tags[target_id]'] = implode(',', [
      'Camelid',
      'Herbivorous',
    ]);
    $edit['lingotek_translation_management[lingotek_translation_profile]'] = 'manual';
    $this
      ->saveAndPublishNodeForm($edit);
    $this
      ->goToContentBulkManagementForm();
    
    $this
      ->assertLingotekUploadLink(1, 'node');
    $this
      ->assertLingotekUploadLink(1, 'taxonomy_term', NULL, 'node');
    $this
      ->clickLink('EN');
    $edit = [
      'table[node:1]' => TRUE,
      'table[taxonomy_term:1]' => TRUE,
      $this
        ->getBulkOperationFormName() => $this
        ->getBulkOperationNameForAssignJobId('node'),
    ];
    $this
      ->drupalPostForm(NULL, $edit, $this
      ->getApplyActionsButtonLabel());
    $edit = [
      'job_id' => 'my\\invalid\\id',
      'update_tms' => 1,
    ];
    $this
      ->drupalPostForm(NULL, $edit, 'Assign Job ID');
    $this
      ->assertText('The job ID name cannot contain invalid chars as "/" or "\\".');
    
    $this
      ->assertNull(\Drupal::state()
      ->get('lingotek.uploaded_job_id'));
    $edit = [
      'job_id' => 'my/invalid/id',
      'update_tms' => 1,
    ];
    $this
      ->drupalPostForm(NULL, $edit, 'Assign Job ID');
    $this
      ->assertText('The job ID name cannot contain invalid chars as "/" or "\\".');
    
    $this
      ->assertNull(\Drupal::state()
      ->get('lingotek.uploaded_job_id'));
  }
  
  public function testCancelAssignJobIds() {
    
    $edit = [];
    $edit['title[0][value]'] = 'Llamas are cool';
    $edit['body[0][value]'] = 'Llamas are very cool';
    $edit['langcode[0][value]'] = 'en';
    $edit['field_tags[target_id]'] = implode(',', [
      'Camelid',
      'Herbivorous',
    ]);
    $edit['lingotek_translation_management[lingotek_translation_profile]'] = 'manual';
    $this
      ->saveAndPublishNodeForm($edit);
    $this
      ->goToContentBulkManagementForm();
    
    $this
      ->assertLingotekUploadLink(1, 'node');
    $this
      ->assertLingotekUploadLink(1, 'taxonomy_term', NULL, 'node');
    
    $edit = [
      'table[taxonomy_term:1]' => TRUE,
      $this
        ->getBulkOperationFormName() => $this
        ->getBulkOperationNameForAssignJobId('node'),
    ];
    $this
      ->drupalPostForm(NULL, $edit, $this
      ->getApplyActionsButtonLabel());
    $this
      ->assertText('Camelid');
    $this
      ->assertNoText('Llamas are cool');
    $this
      ->drupalPostForm(NULL, [], 'Cancel');
    $edit = [
      'table[node:1]' => TRUE,
      $this
        ->getBulkOperationFormName() => $this
        ->getBulkOperationNameForAssignJobId('node'),
    ];
    $this
      ->drupalPostForm(NULL, $edit, $this
      ->getApplyActionsButtonLabel());
    $this
      ->assertNoText('Camelid');
    $this
      ->assertText('Llamas are cool');
  }
  
  public function testResetAssignJobIds() {
    
    $edit = [];
    $edit['title[0][value]'] = 'Llamas are cool';
    $edit['body[0][value]'] = 'Llamas are very cool';
    $edit['langcode[0][value]'] = 'en';
    $edit['field_tags[target_id]'] = implode(',', [
      'Camelid',
      'Herbivorous',
    ]);
    $edit['lingotek_translation_management[lingotek_translation_profile]'] = 'manual';
    $this
      ->saveAndPublishNodeForm($edit);
    $this
      ->goToContentBulkManagementForm();
    
    $this
      ->assertLingotekUploadLink(1, 'node');
    $this
      ->assertLingotekUploadLink(1, 'taxonomy_term', NULL, 'node');
    
    $edit = [
      'table[taxonomy_term:1]' => TRUE,
      $this
        ->getBulkOperationFormName() => $this
        ->getBulkOperationNameForAssignJobId('node'),
    ];
    $this
      ->drupalPostForm(NULL, $edit, $this
      ->getApplyActionsButtonLabel());
    $this
      ->assertText('Camelid');
    $this
      ->assertNoText('Llamas are cool');
    $this
      ->goToContentBulkManagementForm();
    $edit = [
      'table[node:1]' => TRUE,
      $this
        ->getBulkOperationFormName() => $this
        ->getBulkOperationNameForAssignJobId('node'),
    ];
    $this
      ->drupalPostForm(NULL, $edit, $this
      ->getApplyActionsButtonLabel());
    $this
      ->assertNoText('Camelid');
    $this
      ->assertText('Llamas are cool');
  }
  
  public function testClearJobIds() {
    
    $edit = [];
    $edit['title[0][value]'] = 'Llamas are cool';
    $edit['body[0][value]'] = 'Llamas are very cool';
    $edit['langcode[0][value]'] = 'en';
    $edit['field_tags[target_id]'] = implode(',', [
      'Camelid',
      'Herbivorous',
    ]);
    $edit['lingotek_translation_management[lingotek_translation_profile]'] = 'manual';
    $this
      ->saveAndPublishNodeForm($edit);
    $this
      ->goToContentBulkManagementForm();
    
    $this
      ->assertLingotekUploadLink(1, 'node');
    $this
      ->assertLingotekUploadLink(1, 'taxonomy_term', NULL, 'node');
    $this
      ->clickLink('EN');
    $edit = [
      'table[node:1]' => TRUE,
      $this
        ->getBulkOperationFormName() => $this
        ->getBulkOperationNameForAssignJobId('node'),
    ];
    $this
      ->drupalPostForm(NULL, $edit, $this
      ->getApplyActionsButtonLabel());
    $edit = [
      'job_id' => 'my_custom_job_id_1',
      'update_tms' => 1,
    ];
    $this
      ->drupalPostForm(NULL, $edit, 'Assign Job ID');
    $this
      ->assertText('Job ID was assigned successfully.');
    $edit = [
      'table[taxonomy_term:1]' => TRUE,
      $this
        ->getBulkOperationFormName() => $this
        ->getBulkOperationNameForAssignJobId('node'),
    ];
    $this
      ->drupalPostForm(NULL, $edit, $this
      ->getApplyActionsButtonLabel());
    $edit = [
      'job_id' => 'my_custom_job_id_2',
      'update_tms' => 1,
    ];
    $this
      ->drupalPostForm(NULL, $edit, 'Assign Job ID');
    $this
      ->assertText('Job ID was assigned successfully.');
    
    $this
      ->assertText('my_custom_job_id_1');
    $this
      ->assertText('my_custom_job_id_2');
    $edit = [
      'table[node:1]' => TRUE,
      'table[taxonomy_term:1]' => TRUE,
      $this
        ->getBulkOperationFormName() => $this
        ->getBulkOperationNameForClearJobId('node'),
    ];
    $this
      ->drupalPostForm(NULL, $edit, $this
      ->getApplyActionsButtonLabel());
    $this
      ->drupalPostForm(NULL, [], 'Clear Job ID');
    $this
      ->assertText('Job ID was cleared successfully.');
    
    \Drupal::state()
      ->resetCache();
    $this
      ->assertEquals('my_custom_job_id_1', \Drupal::state()
      ->get('lingotek.uploaded_job_id'));
    
    $this
      ->assertNoText('my_custom_job_id_1');
    $this
      ->assertNoText('my_custom_job_id_2');
  }
  
  public function testClearJobIdsWithTMSUpdate() {
    
    $edit = [];
    $edit['title[0][value]'] = 'Llamas are cool';
    $edit['body[0][value]'] = 'Llamas are very cool';
    $edit['langcode[0][value]'] = 'en';
    $edit['field_tags[target_id]'] = implode(',', [
      'Camelid',
      'Herbivorous',
    ]);
    $edit['lingotek_translation_management[lingotek_translation_profile]'] = 'manual';
    $this
      ->saveAndPublishNodeForm($edit);
    $this
      ->goToContentBulkManagementForm();
    
    $this
      ->assertLingotekUploadLink(1, 'node');
    $this
      ->assertLingotekUploadLink(1, 'taxonomy_term', NULL, 'node');
    $this
      ->clickLink('EN');
    $edit = [
      'table[node:1]' => TRUE,
      $this
        ->getBulkOperationFormName() => $this
        ->getBulkOperationNameForAssignJobId('node'),
    ];
    $this
      ->drupalPostForm(NULL, $edit, $this
      ->getApplyActionsButtonLabel());
    $edit = [
      'job_id' => 'my_custom_job_id_1',
      'update_tms' => 1,
    ];
    $this
      ->drupalPostForm(NULL, $edit, 'Assign Job ID');
    $this
      ->assertText('Job ID was assigned successfully.');
    $edit = [
      'table[taxonomy_term:1]' => TRUE,
      $this
        ->getBulkOperationFormName() => $this
        ->getBulkOperationNameForAssignJobId('node'),
    ];
    $this
      ->drupalPostForm(NULL, $edit, $this
      ->getApplyActionsButtonLabel());
    $edit = [
      'job_id' => 'my_custom_job_id_2',
      'update_tms' => 1,
    ];
    $this
      ->drupalPostForm(NULL, $edit, 'Assign Job ID');
    $this
      ->assertText('Job ID was assigned successfully.');
    
    $this
      ->assertText('my_custom_job_id_1');
    $this
      ->assertText('my_custom_job_id_2');
    $edit = [
      'table[node:1]' => TRUE,
      'table[taxonomy_term:1]' => TRUE,
      $this
        ->getBulkOperationFormName() => $this
        ->getBulkOperationNameForClearJobId('node'),
    ];
    $this
      ->drupalPostForm(NULL, $edit, $this
      ->getApplyActionsButtonLabel());
    $this
      ->drupalPostForm(NULL, [
      'update_tms' => 1,
    ], 'Clear Job ID');
    $this
      ->assertText('Job ID was cleared successfully.');
    
    \Drupal::state()
      ->resetCache();
    $this
      ->assertEquals('', \Drupal::state()
      ->get('lingotek.uploaded_job_id'));
    
    $this
      ->assertNoText('my_custom_job_id_1');
    $this
      ->assertNoText('my_custom_job_id_2');
  }
  public function testCorrectTargetsInNonSourceLanguage() {
    $this
      ->testNodeTranslationUsingLinks();
    
    ConfigurableLanguage::createFromLangcode('de')
      ->setThirdPartySetting('lingotek', 'locale', 'de_DE')
      ->save();
    $this
      ->goToContentBulkManagementForm('node');
    $this
      ->assertSourceStatus('EN', Lingotek::STATUS_CURRENT);
    $this
      ->assertTargetStatus('ES', Lingotek::STATUS_CURRENT);
    $this
      ->assertTargetStatus('DE', Lingotek::STATUS_REQUEST);
    $this
      ->assertNoTargetStatus('EN', Lingotek::STATUS_CURRENT);
    $this
      ->goToContentBulkManagementForm('node', 'es');
    $this
      ->assertSourceStatus('EN', Lingotek::STATUS_CURRENT);
    $this
      ->assertTargetStatus('ES', Lingotek::STATUS_CURRENT);
    $this
      ->assertTargetStatus('DE', Lingotek::STATUS_REQUEST);
    $this
      ->assertNoTargetStatus('EN', Lingotek::STATUS_CURRENT);
  }
  
  public function testEmbeddedContentInSeparateListing() {
    $assert_session = $this
      ->assertSession();
    
    $edit = [];
    $edit['title[0][value]'] = 'Llamas are cool';
    $edit['body[0][value]'] = 'Llamas are very cool';
    $edit['field_tags[target_id]'] = implode(',', [
      'Camelid',
      'Herbivorous',
    ]);
    $edit['langcode[0][value]'] = 'en';
    $edit['lingotek_translation_management[lingotek_translation_profile]'] = 'manual';
    $this
      ->saveAndPublishNodeForm($edit);
    $this
      ->createRelatedTermsForTestingDepth();
    
    $this
      ->drupalGet('node/1');
    $this
      ->clickLink('Manage Translations');
    $assert_session
      ->elementContains('css', 'table#edit-table', 'Llamas are cool');
    
    $assert_session
      ->elementContains('css', 'table#edit-table', 'Camelid');
    $assert_session
      ->elementContains('css', 'table#edit-table', 'Herbivorous');
    
    $assert_session
      ->elementNotContains('css', 'table#edit-table', 'Hominid');
    
    $assert_session
      ->elementNotContains('css', 'table#edit-table', 'Ruminant');
    $this
      ->drupalPostForm(NULL, [
      'depth' => 2,
    ], 'Apply');
    $assert_session
      ->elementContains('css', 'table#edit-table', 'Llamas are cool');
    
    $assert_session
      ->elementContains('css', 'table#edit-table', 'Camelid');
    $assert_session
      ->elementContains('css', 'table#edit-table', 'Herbivorous');
    
    $assert_session
      ->elementContains('css', 'table#edit-table', 'Hominid');
    
    $assert_session
      ->elementNotContains('css', 'table#edit-table', 'Ruminant');
    $this
      ->drupalPostForm(NULL, [
      'depth' => 3,
    ], 'Apply');
    $assert_session
      ->elementContains('css', 'table#edit-table', 'Llamas are cool');
    
    $assert_session
      ->elementContains('css', 'table#edit-table', 'Camelid');
    $assert_session
      ->elementContains('css', 'table#edit-table', 'Herbivorous');
    
    $assert_session
      ->elementContains('css', 'table#edit-table', 'Hominid');
    
    $assert_session
      ->elementContains('css', 'table#edit-table', 'Ruminant');
    
    $this
      ->saveLingotekContentTranslationSettings([
      'node' => [
        'article' => [
          'profiles' => 'automatic',
          'fields' => [
            'title' => 1,
            'body' => 1,
            'field_tags' => 1,
          ],
        ],
      ],
    ]);
    $this
      ->drupalGet('node/1');
    $this
      ->clickLink('Manage Translations');
    $assert_session
      ->elementContains('css', 'table#edit-table', 'Llamas are cool');
    
    $assert_session
      ->elementNotContains('css', 'table#edit-table', 'Camelid');
    $assert_session
      ->elementNotContains('css', 'table#edit-table', 'Herbivorous');
    
    $assert_session
      ->elementNotContains('css', 'table#edit-table', 'Hominid');
    
    $assert_session
      ->elementNotContains('css', 'table#edit-table', 'Ruminant');
    
    $assert_session
      ->elementContains('css', 'details#edit-related table', 'Camelid');
    $assert_session
      ->elementContains('css', 'details#edit-related table', 'Herbivorous');
    
    $assert_session
      ->elementNotContains('css', 'details#edit-related table', 'Hominid');
    
    $assert_session
      ->elementNotContains('css', 'details#edit-related table', 'Ruminant');
  }
  
  protected function getContentBulkManagementFormUrl($entity_type_id = 'node', $prefix = NULL) {
    return ($prefix === NULL ? '' : '/' . $prefix) . '/' . $entity_type_id . '/1/manage';
  }
  
  protected function createRelatedTermsForTestingDepth() {
    $term3 = Term::create([
      'name' => 'Hominid',
      'vid' => $this->vocabulary
        ->id(),
    ]);
    $term3
      ->save();
    $term2 = Term::load(2);
    $term2->field_tags = $term3;
    $term2
      ->save();
    $term4 = Term::create([
      'name' => 'Ruminant',
      'vid' => $this->vocabulary
        ->id(),
    ]);
    $term4
      ->save();
    $term3 = Term::load(3);
    $term3->field_tags = $term4;
    $term3
      ->save();
  }
}