You are here

public function LingotekMetadataEditFormTest::testMetadataEditForm in Lingotek Translation 3.4.x

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

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

File

tests/src/Functional/Form/LingotekMetadataEditFormTest.php, line 103

Class

LingotekMetadataEditFormTest
Tests the Lingotek metadata form.

Namespace

Drupal\Tests\lingotek\Functional\Form

Code

public function testMetadataEditForm() {

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

  // Create a node.
  $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]'] = 'automatic';
  $this
    ->saveAndPublishNodeForm($edit);

  // 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);
  $this
    ->assertFieldById('edit-lingotek-job-id', '');
  $timestamp = \Drupal::time()
    ->getRequestTime();
  $this
    ->assertSession()
    ->fieldValueEquals('verbatim_area[verbatim]', <<<JSON
{
    "id": [
        {
            "value": "1"
        }
    ],
    "content_entity_type_id": [
        {
            "value": "node"
        }
    ],
    "content_entity_id": [
        {
            "value": "1"
        }
    ],
    "document_id": [
        {
            "value": "dummy-document-hash-id"
        }
    ],
    "hash": [],
    "profile": [
        {
            "target_id": "automatic"
        }
    ],
    "translation_source": [
        {
            "value": "en"
        }
    ],
    "translation_status": [
        {
            "value": "IMPORTING",
            "language": "en"
        },
        {
            "value": "REQUEST",
            "language": "es"
        }
    ],
    "job_id": [],
    "updated_timestamp": [],
    "uploaded_timestamp": [
        {
            "value": "{<span class="php-variable">$timestamp</span>}"
        }
    ]
}
JSON
);
  $this
    ->assertFieldByName('lingotek_translation_management[lingotek_translation_profile]', 'automatic');
  $edit = [
    'lingotek_document_id' => 'another-id',
    'lingotek_source_status' => Lingotek::STATUS_UNTRACKED,
    'en' => Lingotek::STATUS_UNTRACKED,
    'es' => Lingotek::STATUS_READY,
    'lingotek_job_id' => 'a new edited job id',
    'lingotek_translation_management[lingotek_translation_profile]' => 'manual',
  ];
  $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);
  $this
    ->assertFieldById('edit-lingotek-job-id', 'a new edited job id');
  $this
    ->assertSession()
    ->fieldValueEquals('verbatim_area[verbatim]', <<<JSON
{
    "id": [
        {
            "value": "1"
        }
    ],
    "content_entity_type_id": [
        {
            "value": "node"
        }
    ],
    "content_entity_id": [
        {
            "value": "1"
        }
    ],
    "document_id": [
        {
            "value": "another-id"
        }
    ],
    "hash": [],
    "profile": [
        {
            "target_id": "manual"
        }
    ],
    "translation_source": [
        {
            "value": "en"
        }
    ],
    "translation_status": [
        {
            "value": "UNTRACKED",
            "language": "en"
        },
        {
            "value": "READY",
            "language": "es"
        }
    ],
    "job_id": [
        {
            "value": "a new edited job id"
        }
    ],
    "updated_timestamp": [],
    "uploaded_timestamp": [
        {
            "value": "{<span class="php-variable">$timestamp</span>}"
        }
    ]
}
JSON
);
  $this
    ->assertFieldByName('lingotek_translation_management[lingotek_translation_profile]', 'manual');

  /** @var \Drupal\lingotek\LingotekConfigurationServiceInterface $configuration_service */
  $configuration_service = \Drupal::service('lingotek.configuration');

  /** @var \Drupal\lingotek\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));
  $this
    ->assertIdentical('manual', $configuration_service
    ->getEntityProfile($node, FALSE)
    ->id());

  // 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'));
  $metadata = LingotekContentMetadata::load(1);
  $this
    ->assertIdentical('a new edited job id', $metadata
    ->getJobId(), 'Lingotek metadata job id was saved correctly.');
}