public function LingotekContentTypeNotificationCallbackTest::testDocumentUpdated in Lingotek Translation 3.5.x
Same name and namespace in other branches
- 8.2 tests/src/Functional/LingotekContentTypeNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekContentTypeNotificationCallbackTest::testDocumentUpdated()
- 4.0.x tests/src/Functional/LingotekContentTypeNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekContentTypeNotificationCallbackTest::testDocumentUpdated()
- 3.0.x tests/src/Functional/LingotekContentTypeNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekContentTypeNotificationCallbackTest::testDocumentUpdated()
- 3.1.x tests/src/Functional/LingotekContentTypeNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekContentTypeNotificationCallbackTest::testDocumentUpdated()
- 3.2.x tests/src/Functional/LingotekContentTypeNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekContentTypeNotificationCallbackTest::testDocumentUpdated()
- 3.3.x tests/src/Functional/LingotekContentTypeNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekContentTypeNotificationCallbackTest::testDocumentUpdated()
- 3.4.x tests/src/Functional/LingotekContentTypeNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekContentTypeNotificationCallbackTest::testDocumentUpdated()
- 3.6.x tests/src/Functional/LingotekContentTypeNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekContentTypeNotificationCallbackTest::testDocumentUpdated()
- 3.7.x tests/src/Functional/LingotekContentTypeNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekContentTypeNotificationCallbackTest::testDocumentUpdated()
- 3.8.x tests/src/Functional/LingotekContentTypeNotificationCallbackTest.php \Drupal\Tests\lingotek\Functional\LingotekContentTypeNotificationCallbackTest::testDocumentUpdated()
Tests that a document_updated callback is handled after document update.
File
- tests/
src/ Functional/ LingotekContentTypeNotificationCallbackTest.php, line 1746
Class
- LingotekContentTypeNotificationCallbackTest
- Tests translating a content type using the notification callback.
Namespace
Drupal\Tests\lingotek\FunctionalCode
public function testDocumentUpdated() {
// Login as admin.
$this
->drupalLogin($this->rootUser);
// Enable translation for the current entity type and ensure the change is
// picked up.
$this
->saveLingotekConfigTranslationSettings([
'node_type' => 'automatic',
]);
// Create Article node types. We use the form at least once to ensure that
// we don't break anything. E.g. see https://www.drupal.org/node/2645202.
$this
->drupalPostForm('/admin/structure/types/add', [
'type' => 'article',
'name' => 'Article',
], 'Save content type');
/** @var \Drupal\Core\Config\Entity\ConfigEntityStorageInterface $node_storage */
$node_storage = $this->container
->get('entity_type.manager')
->getStorage('node_type');
/** @var \Drupal\lingotek\LingotekConfigTranslationServiceInterface $config_translation_service */
$config_translation_service = \Drupal::service('lingotek.config_translation');
$entity = $node_storage
->load('article');
// Assert the content is importing.
$this
->assertIdentical(Lingotek::STATUS_IMPORTING, $config_translation_service
->getSourceStatus($entity));
$this
->assertIdentical($config_translation_service
->getDocumentId($entity), 'dummy-document-hash-id');
$this
->goToConfigBulkManagementForm('node_type');
// Simulate the notification of content successfully uploaded.
$url = Url::fromRoute('lingotek.notify', [], [
'query' => [
'project_id' => 'test_project',
'document_id' => 'dummy-document-hash-id',
'complete' => 'false',
'type' => 'document_uploaded',
'progress' => '0',
],
])
->setAbsolute()
->toString();
$request = $this->client
->post($url, [
'cookies' => $this->cookies,
'headers' => [
'Accept' => 'application/json',
'Content-Type' => 'application/json',
],
'http_errors' => FALSE,
]);
$response = json_decode($request
->getBody(), TRUE);
$this
->verbose($request);
$this
->assertIdentical([
'es',
], $response['result']['request_translations'], 'Spanish language has been requested after notification automatically.');
$this
->goToConfigBulkManagementForm('node_type');
$entity = $node_storage
->load('article');
// Assert the content is imported.
$this
->assertIdentical(Lingotek::STATUS_CURRENT, $config_translation_service
->getSourceStatus($entity));
// Assert the target is pending.
$this
->assertIdentical(Lingotek::STATUS_PENDING, $config_translation_service
->getTargetStatus($entity, 'es'));
// Edit the node.
$this
->drupalPostForm('/admin/structure/types/manage/article', [
'name' => 'Article EDITED',
], 'Save content type');
$this
->goToConfigBulkManagementForm('node_type');
$entity = $node_storage
->load('article');
// Assert the content is importing.
$this
->assertIdentical(Lingotek::STATUS_IMPORTING, $config_translation_service
->getSourceStatus($entity));
// Assert the target is pending.
$this
->assertIdentical(Lingotek::STATUS_PENDING, $config_translation_service
->getTargetStatus($entity, 'es'));
// Assert the document id changed.
$this
->assertIdentical($config_translation_service
->getDocumentId($entity), 'dummy-document-hash-id-1');
// Simulate the notification of content successfully updated.
$url = Url::fromRoute('lingotek.notify', [], [
'query' => [
'project_id' => 'test_project',
'document_id' => 'dummy-document-hash-id-1',
'complete' => 'false',
'type' => 'document_updated',
'progress' => '100',
],
])
->setAbsolute()
->toString();
$request = $this->client
->post($url, [
'cookies' => $this->cookies,
'headers' => [
'Accept' => 'application/json',
'Content-Type' => 'application/json',
],
'http_errors' => FALSE,
]);
$response = json_decode($request
->getBody(), TRUE);
$this
->verbose($request);
$this
->goToConfigBulkManagementForm('node_type');
$entity = $node_storage
->load('article');
// Assert the document id and the CURRENT status.
$this
->assertEquals($config_translation_service
->getDocumentId($entity), 'dummy-document-hash-id-1');
$this
->assertIdentical(Lingotek::STATUS_CURRENT, $config_translation_service
->getSourceStatus($entity));
}