public function ContentTranslationContextualLinksTest::testContentTranslationContextualLinks in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/content_translation/src/Tests/ContentTranslationContextualLinksTest.php \Drupal\content_translation\Tests\ContentTranslationContextualLinksTest::testContentTranslationContextualLinks()
Tests that a contextual link is available for translating a node.
File
- core/
modules/ content_translation/ src/ Tests/ ContentTranslationContextualLinksTest.php, line 107 - Contains \Drupal\content_translation\Tests\ContentTranslationContextualLinksTest.
Class
- ContentTranslationContextualLinksTest
- Tests that contextual links are available for content translation.
Namespace
Drupal\content_translation\TestsCode
public function testContentTranslationContextualLinks() {
// Create a node.
$title = $this
->randomString();
$this
->drupalCreateNode(array(
'type' => $this->bundle,
'title' => $title,
'langcode' => 'en',
));
$node = $this
->drupalGetNodeByTitle($title);
// Use a UI form submission to make the node type and field translatable.
// This tests that caches are properly invalidated.
$this
->drupalLogin($this->rootUser);
$edit = array(
'entity_types[node]' => TRUE,
'settings[node][' . $this->bundle . '][settings][language][language_alterable]' => TRUE,
'settings[node][' . $this->bundle . '][translatable]' => TRUE,
'settings[node][' . $this->bundle . '][fields][field_test_text]' => TRUE,
);
$this
->drupalPostForm('admin/config/regional/content-language', $edit, t('Save configuration'));
$this
->drupalLogout();
// Check that the translate link appears on the node page.
$this
->drupalLogin($this->translator);
$translate_link = 'node/' . $node
->id() . '/translations';
$response = $this
->renderContextualLinks(array(
'node:node=1:',
), 'node/' . $node
->id());
$this
->assertResponse(200);
$json = Json::decode($response);
$this
->setRawContent($json['node:node=1:']);
$this
->assertLinkByHref($translate_link, 0, 'The contextual link to translate the node is shown.');
// Check that the link leads to the translate page.
$this
->drupalGet($translate_link);
$this
->assertRaw(t('Translations of %label', array(
'%label' => $node
->label(),
)), 'The contextual link leads to the translate page.');
}