You are here

public function LingotekNodeWhenFieldIsRemovedTest::testFieldIsRemoved in Lingotek Translation 3.4.x

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

Tests that we can translate after the field is removed.

File

tests/src/Functional/LingotekNodeWhenFieldIsRemovedTest.php, line 76

Class

LingotekNodeWhenFieldIsRemovedTest
Tests removing a field that was enabled for translation but it's not anymore.

Namespace

Drupal\Tests\lingotek\Functional

Code

public function testFieldIsRemoved() {
  $assert_session = $this
    ->assertSession();

  // This is a hack for avoiding writing different lingotek endpoint mocks.
  \Drupal::state()
    ->set('lingotek.uploaded_content_type', 'node+new_field');

  // Create a node.
  $edit = [];
  $edit['title[0][value]'] = 'Llamas are cool';
  $edit['body[0][value]'] = 'Llamas are very cool';
  $edit['new_field[0][value]'] = 'Llamas are very cool';
  $edit['langcode[0][value]'] = 'en';
  $edit['lingotek_translation_management[lingotek_translation_profile]'] = 'manual';
  $this
    ->saveAndPublishNodeForm($edit);
  $this
    ->goToContentBulkManagementForm();

  // Clicking English must init the upload of content.
  $this
    ->assertLingotekUploadLink();

  // And we cannot request yet a translation.
  $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'));

  // Check that only the configured fields have been uploaded.
  $data = json_decode(\Drupal::state()
    ->get('lingotek.uploaded_content', '[]'), TRUE);
  $this
    ->assertUploadedDataFieldCount($data, 3);
  $this
    ->assertTrue(isset($data['title'][0]['value']));
  $this
    ->assertEqual(1, count($data['body'][0]));
  $this
    ->assertTrue(isset($data['body'][0]['value']));
  $this
    ->assertEqual(1, count($data['new_field'][0]));
  $this
    ->assertTrue(isset($data['new_field'][0]['value']));

  // There is a link for checking status.
  $this
    ->assertLingotekCheckSourceStatusLink();

  // And we can already request a translation.
  $this
    ->assertLingotekRequestTranslationLink('es_MX');
  $this
    ->clickLink('EN');
  $this
    ->assertText('The import for node Llamas are cool is complete.');

  // Now we remove the field!
  $this
    ->removeField('node', 'article', 'new_field');

  // The field is not enabled anymore.

  /** @var \Drupal\lingotek\LingotekConfigurationServiceInterface $lingotek_config */
  $lingotek_config = \Drupal::service('lingotek.configuration');
  $this
    ->assertFalse($lingotek_config
    ->isFieldLingotekEnabled('node', 'article', 'new_field'), 'The field was disabled from Lingotek when deleted');
  $this
    ->goToContentBulkManagementForm();

  // Request the Spanish translation.
  $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'));

  // Check status of the Spanish translation.
  $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.');

  // Download the Spanish translation.
  $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'));

  // Now the link is to the workbench, and it opens in a new tab.
  $this
    ->assertLingotekWorkbenchLink('es_MX');

  // Open the node and it works.
  $this
    ->clickLink('Llamas are cool');
  $this
    ->clickLink('Translate');
  $this
    ->clickLink('Las llamas son chulas');
  $this
    ->assertText('Las llamas son muy chulas');
}