You are here

public function LingotekMetadataEditFormTest::testMetadataEditForm in Lingotek Translation 8

Tests that if debug is not enabled, metadata tab is not available.

File

src/Tests/Form/LingotekMetadataEditFormTest.php, line 101

Class

LingotekMetadataEditFormTest
Tests the Lingotek metadata form.

Namespace

Drupal\lingotek\Tests\Form

Code

public function testMetadataEditForm() {

  // Enable debug operations.
  $this
    ->drupalPostForm('admin/lingotek/settings', [], 'Enable debug operations');

  // Create a node.
  $edit = array();
  $edit['title[0][value]'] = 'Llamas are cool';
  $edit['body[0][value]'] = 'Llamas are very cool';
  $edit['langcode[0][value]'] = 'en';
  $edit['lingotek_translation_profile'] = 'automatic';
  $this
    ->drupalPostForm('node/add/article', $edit, t('Save and publish'));

  // The metadata local task should be visible.
  $this
    ->drupalGet('/node/1');
  $this
    ->clickLink(t('Lingotek Metadata'));
  $this
    ->assertUrl('/node/1/metadata', [], 'Metadata local task enables the metadata form.');

  // Assert that the values are correct.
  $this
    ->assertFieldById('edit-lingotek-document-id', 'dummy-document-hash-id');
  $this
    ->assertOptionSelected('edit-lingotek-source-status', Lingotek::STATUS_IMPORTING);
  $this
    ->assertOptionSelected('edit-en', Lingotek::STATUS_IMPORTING);
  $this
    ->assertOptionSelected('edit-es', Lingotek::STATUS_REQUEST);
  $edit = [
    'lingotek_document_id' => 'another-id',
    'lingotek_source_status' => Lingotek::STATUS_UNTRACKED,
    'en' => Lingotek::STATUS_UNTRACKED,
    'es' => Lingotek::STATUS_READY,
  ];
  $this
    ->drupalPostForm(NULL, $edit, 'Save metadata');

  // Assert that the values are correct.
  $this
    ->assertFieldById('edit-lingotek-document-id', 'another-id');

  // ToDo: We should avoid that an upload is triggered, even if using automatic profile.
  // $this->assertOptionSelected('edit-lingotek-source-status', Lingotek::STATUS_CURRENT);
  $this
    ->assertOptionSelected('edit-lingotek-source-status', Lingotek::STATUS_UNTRACKED);
  $this
    ->assertOptionSelected('edit-en', Lingotek::STATUS_UNTRACKED);
  $this
    ->assertOptionSelected('edit-es', Lingotek::STATUS_READY);

  /** @var LingotekContentTranslationServiceInterface $content_translation_service */
  $content_translation_service = \Drupal::service('lingotek.content_translation');
  $node = Node::load(1);

  // Assert that the values are correct in the service.
  $this
    ->assertIdentical('another-id', $content_translation_service
    ->getDocumentId($node));

  // ToDo: We should avoid that an upload is triggered, even if using automatic profile.
  // $this->assertIdentical(Lingotek::STATUS_CURRENT, $content_translation_service->getSourceStatus($node));
  $this
    ->assertIdentical(Lingotek::STATUS_UNTRACKED, $content_translation_service
    ->getSourceStatus($node));
  $this
    ->assertIdentical(Lingotek::STATUS_UNTRACKED, $content_translation_service
    ->getTargetStatus($node, 'en'));
  $this
    ->assertIdentical(Lingotek::STATUS_READY, $content_translation_service
    ->getTargetStatus($node, 'es'));
}