Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / content_translation / tests / src / FunctionalJavascript / ContentTranslationContextualLinksTest.php
1 <?php
2
3 namespace Drupal\Tests\content_translation\FunctionalJavascript;
4
5 use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
6 use Drupal\language\Entity\ConfigurableLanguage;
7
8 /**
9  * Tests that contextual links are available for content translation.
10  *
11  * @group content_translation
12  */
13 class ContentTranslationContextualLinksTest extends JavascriptTestBase {
14
15   /**
16    * The 'translator' user to use during testing.
17    *
18    * @var \Drupal\user\UserInterface
19    */
20   protected $translator;
21
22   /**
23    * {@inheritdoc}
24    */
25   public static $modules = ['content_translation', 'contextual', 'node'];
26
27   /**
28    * {@inheritdoc}
29    */
30   protected function setUp() {
31     parent::setUp();
32
33     // Set up an additional language.
34     ConfigurableLanguage::createFromLangcode('es')->save();
35
36     // Create a content type.
37     $this->drupalCreateContentType(['type' => 'page']);
38
39     // Enable content translation.
40     $this->drupalLogin($this->rootUser);
41     $this->drupalGet('admin/config/regional/content-language');
42     $edit = [
43       'entity_types[node]' => TRUE,
44       'settings[node][page][translatable]' => TRUE,
45     ];
46     $this->drupalPostForm(NULL, $edit, t('Save configuration'));
47     $this->drupalLogout();
48
49     // Create a translator user.
50     $permissions = [
51       'access contextual links',
52       'administer nodes',
53       'edit any page content',
54       'translate any entity',
55     ];
56     $this->translator = $this->drupalCreateUser($permissions);
57   }
58
59   /**
60    * Tests that a contextual link is available for translating a node.
61    */
62   public function testContentTranslationContextualLinks() {
63     $node = $this->drupalCreateNode(['type' => 'page', 'title' => 'Test']);
64
65     // Check that the translate link appears on the node page.
66     $this->drupalLogin($this->translator);
67     $this->drupalGet('node/' . $node->id());
68     $link = $this->assertSession()->waitForElement('css', '[data-contextual-id^="node:node=1"] .contextual-links a:contains("Translate")');
69     $this->assertContains('node/1/translations', $link->getAttribute('href'));
70   }
71
72 }