Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / contextual / tests / src / FunctionalJavascript / ContextualLinksTest.php
index 12ce10db8bd2b5cac2086fa995e421bb637049b8..a24d2bae5978c3bdcea34379f6e6a17e4e2c67fd 100644 (file)
@@ -12,6 +12,8 @@ use Drupal\user\Entity\Role;
  */
 class ContextualLinksTest extends JavascriptTestBase {
 
+  use ContextualLinkClickTrait;
+
   /**
    * {@inheritdoc}
    */
@@ -23,6 +25,7 @@ class ContextualLinksTest extends JavascriptTestBase {
   protected function setUp() {
     parent::setUp();
 
+    $this->drupalLogin($this->createUser(['access contextual links']));
     $this->placeBlock('system_branding_block', ['id' => 'branding']);
   }
 
@@ -30,10 +33,6 @@ class ContextualLinksTest extends JavascriptTestBase {
    * Tests the visibility of contextual links.
    */
   public function testContextualLinksVisibility() {
-    $this->drupalLogin($this->drupalCreateUser([
-      'access contextual links'
-    ]));
-
     $this->drupalGet('user');
     $contextualLinks = $this->assertSession()->waitForElement('css', '.contextual button');
     $this->assertEmpty($contextualLinks);
@@ -59,4 +58,27 @@ class ContextualLinksTest extends JavascriptTestBase {
     $this->assertNotEmpty($contextualLinks);
   }
 
+  /**
+   * Test clicking contextual links.
+   */
+  public function testContextualLinksClick() {
+    $this->container->get('module_installer')->install(['contextual_test']);
+    // Test clicking contextual link without toolbar.
+    $this->drupalGet('user');
+    $this->assertSession()->assertWaitOnAjaxRequest();
+    $this->clickContextualLink('#block-branding', 'Test Link');
+    $this->assertSession()->pageTextContains('Everything is contextual!');
+
+    // Test clicking contextual link with toolbar.
+    $this->container->get('module_installer')->install(['toolbar']);
+    $this->grantPermissions(Role::load(Role::AUTHENTICATED_ID), ['access toolbar']);
+    $this->drupalGet('user');
+    $this->assertSession()->assertWaitOnAjaxRequest();
+
+    // Click "Edit" in toolbar to show contextual links.
+    $this->getSession()->getPage()->find('css', '.contextual-toolbar-tab button')->press();
+    $this->clickContextualLink('#block-branding', 'Test Link', FALSE);
+    $this->assertSession()->pageTextContains('Everything is contextual!');
+  }
+
 }