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)

8.4.x
Alex Pott 2017-03-28 15:25:09 +01:00
parent 956497377e
commit 488a6b142a
2 changed files with 63 additions and 1 deletions

View File

@ -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

View File

@ -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);
}
}