summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2017-03-28 14:25:09 (GMT)
committerAlex Pott2017-03-28 14:25:09 (GMT)
commit488a6b142a2f17411d0c05a282f7fdcac984f058 (patch)
tree4a1e73965862909090705ad708feeb5273f934a5
parent956497377e82b861e4a405051b8b779dde313575 (diff)
Issue #2650910 by drpal, Anishnirmal, markdorison, Tom Robert, psend, yannickoo, rachel_norfolk, Wim Leers, droplet: Contextual links button is always rendered even when no links are available (with warm client-side cache)
-rw-r--r--core/modules/contextual/js/contextual.js2
-rw-r--r--core/modules/contextual/tests/src/FunctionalJavascript/ContextualLinksTest.php62
2 files changed, 63 insertions, 1 deletions
diff --git a/core/modules/contextual/js/contextual.js b/core/modules/contextual/js/contextual.js
index 7f93a15..558ea10 100644
--- a/core/modules/contextual/js/contextual.js
+++ b/core/modules/contextual/js/contextual.js
@@ -163,7 +163,7 @@
// Update all contextual links placeholders whose HTML is cached.
var uncachedIDs = _.filter(ids, function initIfCached(contextualID) {
var html = storage.getItem('Drupal.contextual.' + contextualID);
- if (html !== null) {
+ if (html && html.length) {
// Initialize after the current execution cycle, to make the AJAX
// request for retrieving the uncached contextual links as soon as
// possible, but also to ensure that other Drupal behaviors have had
diff --git a/core/modules/contextual/tests/src/FunctionalJavascript/ContextualLinksTest.php b/core/modules/contextual/tests/src/FunctionalJavascript/ContextualLinksTest.php
new file mode 100644
index 0000000..12ce10d
--- /dev/null
+++ b/core/modules/contextual/tests/src/FunctionalJavascript/ContextualLinksTest.php
@@ -0,0 +1,62 @@
+<?php
+
+namespace Drupal\Tests\contextual\FunctionalJavascript;
+
+use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
+use Drupal\user\Entity\Role;
+
+/**
+ * Tests the UI for correct contextual links.
+ *
+ * @group contextual
+ */
+class ContextualLinksTest extends JavascriptTestBase {
+
+ /**
+ * {@inheritdoc}
+ */
+ public static $modules = ['block', 'contextual'];
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function setUp() {
+ parent::setUp();
+
+ $this->placeBlock('system_branding_block', ['id' => 'branding']);
+ }
+
+ /**
+ * 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);
+
+ // Ensure visibility remains correct after cached paged load.
+ $this->drupalGet('user');
+ $contextualLinks = $this->assertSession()->waitForElement('css', '.contextual button');
+ $this->assertEmpty($contextualLinks);
+
+ // Grant permissions to use contextual links on blocks.
+ $this->grantPermissions(Role::load(Role::AUTHENTICATED_ID), [
+ 'access contextual links',
+ 'administer blocks',
+ ]);
+
+ $this->drupalGet('user');
+ $contextualLinks = $this->assertSession()->waitForElement('css', '.contextual button');
+ $this->assertNotEmpty($contextualLinks);
+
+ // Ensure visibility remains correct after cached paged load.
+ $this->drupalGet('user');
+ $contextualLinks = $this->assertSession()->waitForElement('css', '.contextual button');
+ $this->assertNotEmpty($contextualLinks);
+ }
+
+}