3 namespace Drupal\Tests\content_translation\Functional;
5 use Drupal\field\Entity\FieldConfig;
6 use Drupal\language\Entity\ConfigurableLanguage;
7 use Drupal\field\Entity\FieldStorageConfig;
8 use Drupal\Tests\BrowserTestBase;
11 * Tests that contextual links are available for content translation.
13 * @group content_translation
15 class ContentTranslationContextualLinksTest extends BrowserTestBase {
18 * The bundle being tested.
25 * The content type being tested.
27 * @var \Drupal\node\Entity\NodeType
29 protected $contentType;
32 * The 'translator' user to use during testing.
34 * @var \Drupal\user\UserInterface
36 protected $translator;
39 * The enabled languages.
50 public static $modules = ['content_translation', 'contextual', 'node'];
53 * The profile to install as a basis for testing.
57 protected $profile = 'testing';
59 protected function setUp() {
61 // Set up an additional language.
62 $this->langcodes = [\Drupal::languageManager()->getDefaultLanguage()->getId(), 'es'];
63 ConfigurableLanguage::createFromLangcode('es')->save();
65 // Create a content type.
66 $this->bundle = $this->randomMachineName();
67 $this->contentType = $this->drupalCreateContentType(['type' => $this->bundle]);
69 // Add a field to the content type. The field is not yet translatable.
70 FieldStorageConfig::create([
71 'field_name' => 'field_test_text',
72 'entity_type' => 'node',
77 'entity_type' => 'node',
78 'field_name' => 'field_test_text',
79 'bundle' => $this->bundle,
80 'label' => 'Test text-field',
82 entity_get_form_display('node', $this->bundle, 'default')
83 ->setComponent('field_test_text', [
84 'type' => 'text_textfield',
89 // Create a translator user.
91 'access contextual links',
93 "edit any $this->bundle content",
94 'translate any entity',
96 $this->translator = $this->drupalCreateUser($permissions);
100 * Tests that a contextual link is available for translating a node.
102 public function testContentTranslationContextualLinks() {
104 $title = $this->randomString();
105 $this->drupalCreateNode(['type' => $this->bundle, 'title' => $title, 'langcode' => 'en']);
106 $node = $this->drupalGetNodeByTitle($title);
108 // Use a UI form submission to make the node type and field translatable.
109 // This tests that caches are properly invalidated.
110 $this->drupalLogin($this->rootUser);
112 'entity_types[node]' => TRUE,
113 'settings[node][' . $this->bundle . '][settings][language][language_alterable]' => TRUE,
114 'settings[node][' . $this->bundle . '][translatable]' => TRUE,
115 'settings[node][' . $this->bundle . '][fields][field_test_text]' => TRUE,
117 $this->drupalPostForm('admin/config/regional/content-language', $edit, t('Save configuration'));
118 $this->drupalLogout();
120 // Check that the link leads to the translate page.
121 $this->drupalLogin($this->translator);
122 $translate_link = 'node/' . $node->id() . '/translations';
123 $this->drupalGet($translate_link);
124 $this->assertRaw(t('Translations of %label', ['%label' => $node->label()]), 'The contextual link leads to the translate page.');