public function LingotekNotificationControllerTest::testCallbackNotCached in Lingotek Translation 8.2
Same name and namespace in other branches
- 4.0.x tests/src/Functional/Controller/LingotekNotificationControllerTest.php \Drupal\Tests\lingotek\Functional\Controller\LingotekNotificationControllerTest::testCallbackNotCached()
- 3.0.x tests/src/Functional/Controller/LingotekNotificationControllerTest.php \Drupal\Tests\lingotek\Functional\Controller\LingotekNotificationControllerTest::testCallbackNotCached()
- 3.1.x tests/src/Functional/Controller/LingotekNotificationControllerTest.php \Drupal\Tests\lingotek\Functional\Controller\LingotekNotificationControllerTest::testCallbackNotCached()
- 3.2.x tests/src/Functional/Controller/LingotekNotificationControllerTest.php \Drupal\Tests\lingotek\Functional\Controller\LingotekNotificationControllerTest::testCallbackNotCached()
- 3.3.x tests/src/Functional/Controller/LingotekNotificationControllerTest.php \Drupal\Tests\lingotek\Functional\Controller\LingotekNotificationControllerTest::testCallbackNotCached()
- 3.4.x tests/src/Functional/Controller/LingotekNotificationControllerTest.php \Drupal\Tests\lingotek\Functional\Controller\LingotekNotificationControllerTest::testCallbackNotCached()
- 3.5.x tests/src/Functional/Controller/LingotekNotificationControllerTest.php \Drupal\Tests\lingotek\Functional\Controller\LingotekNotificationControllerTest::testCallbackNotCached()
- 3.6.x tests/src/Functional/Controller/LingotekNotificationControllerTest.php \Drupal\Tests\lingotek\Functional\Controller\LingotekNotificationControllerTest::testCallbackNotCached()
- 3.7.x tests/src/Functional/Controller/LingotekNotificationControllerTest.php \Drupal\Tests\lingotek\Functional\Controller\LingotekNotificationControllerTest::testCallbackNotCached()
- 3.8.x tests/src/Functional/Controller/LingotekNotificationControllerTest.php \Drupal\Tests\lingotek\Functional\Controller\LingotekNotificationControllerTest::testCallbackNotCached()
Tests that a callback is never cached.
File
- tests/
src/ Functional/ Controller/ LingotekNotificationControllerTest.php, line 67
Class
- LingotekNotificationControllerTest
- Tests the notification controller.
Namespace
Drupal\Tests\lingotek\Functional\ControllerCode
public function testCallbackNotCached() {
// Login as admin.
$this
->drupalLogin($this->rootUser);
// 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);
/** @var \Drupal\node\NodeInterface $node */
$node = Node::load(1);
/** @var \Drupal\lingotek\LingotekContentTranslationServiceInterface $content_translation_service */
$content_translation_service = \Drupal::service('lingotek.content_translation');
// Assert the content is importing.
$this
->assertIdentical(Lingotek::STATUS_IMPORTING, $content_translation_service
->getSourceStatus($node));
$this
->goToContentBulkManagementForm();
// 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
->get($url, [
'headers' => [
'Accept' => 'application/json',
'Content-Type' => 'application/json',
],
'http_errors' => FALSE,
]);
$cache_control_header = $request
->getHeader('Cache-Control');
$this
->assertContains('max-age=0', $cache_control_header[0]);
$response = json_decode($request
->getBody(), TRUE);
$this
->verbose($request);
$this
->assertIdentical([
'es',
], $response['result']['request_translations'], 'Spanish language has been requested after notification automatically.');
// Simulate again the notification of content successfully uploaded.
$request = $this->client
->get($url, [
'headers' => [
'Accept' => 'application/json',
'Content-Type' => 'application/json',
],
'http_errors' => FALSE,
]);
$cache_control_header = $request
->getHeader('Cache-Control');
$this
->assertContains('max-age=0', $cache_control_header[0]);
$response = json_decode($request
->getBody(), TRUE);
$this
->verbose($request);
$this
->assertIdentical([
'es',
], $response['result']['request_translations'], 'Spanish language has been requested after notification automatically.');
}