View source
<?php
namespace Drupal\Tests\content_translation\Functional;
use Drupal\field\Entity\FieldConfig;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\Tests\BrowserTestBase;
class ContentTranslationContextualLinksTest extends BrowserTestBase {
protected $bundle;
protected $defaultTheme = 'stark';
protected $contentType;
protected $translator;
protected $langcodes;
public static $modules = [
'content_translation',
'contextual',
'node',
];
protected $profile = 'testing';
protected function setUp() {
parent::setUp();
$this->langcodes = [
\Drupal::languageManager()
->getDefaultLanguage()
->getId(),
'es',
];
ConfigurableLanguage::createFromLangcode('es')
->save();
$this->bundle = $this
->randomMachineName();
$this->contentType = $this
->drupalCreateContentType([
'type' => $this->bundle,
]);
FieldStorageConfig::create([
'field_name' => 'field_test_text',
'entity_type' => 'node',
'type' => 'text',
'cardinality' => 1,
])
->save();
FieldConfig::create([
'entity_type' => 'node',
'field_name' => 'field_test_text',
'bundle' => $this->bundle,
'label' => 'Test text-field',
])
->save();
$this->container
->get('entity_display.repository')
->getFormDisplay('node', $this->bundle)
->setComponent('field_test_text', [
'type' => 'text_textfield',
'weight' => 0,
])
->save();
$permissions = [
'access contextual links',
'administer nodes',
"edit any {$this->bundle} content",
'translate any entity',
];
$this->translator = $this
->drupalCreateUser($permissions);
}
public function testContentTranslationContextualLinks() {
$title = $this
->randomString();
$this
->drupalCreateNode([
'type' => $this->bundle,
'title' => $title,
'langcode' => 'en',
]);
$node = $this
->drupalGetNodeByTitle($title);
$this
->drupalLogin($this->rootUser);
$edit = [
'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();
$this
->drupalLogin($this->translator);
$translate_link = 'node/' . $node
->id() . '/translations';
$this
->drupalGet($translate_link);
$this
->assertRaw(t('Translations of %label', [
'%label' => $node
->label(),
]), 'The contextual link leads to the translate page.');
}
}