public function testBlockContextualLinks() { $this->
drupalLogin($this->
drupalCreateUser([ 'administer views',
'access contextual links',
'administer blocks',
]));
$block =
$this->
drupalPlaceBlock('views_block:test_view_block-block_1'
);
$cached_block =
$this->
drupalPlaceBlock('views_block:test_view_block-block_1'
);
$this->
drupalGet('test-page'
);
$id = 'block:block=' .
$block->
id() . ':langcode=en|entity.view.edit_form:view=test_view_block:location=block&name=test_view_block&display_id=block_1&langcode=en';
$id_token = Crypt::
hmacBase64($id, Settings::
getHashSalt() .
$this->container->
get('private_key'
)->
get());
$cached_id = 'block:block=' .
$cached_block->
id() . ':langcode=en|entity.view.edit_form:view=test_view_block:location=block&name=test_view_block&display_id=block_1&langcode=en';
$cached_id_token = Crypt::
hmacBase64($cached_id, Settings::
getHashSalt() .
$this->container->
get('private_key'
)->
get());
// @see \Drupal\contextual\Tests\ContextualDynamicContextTest:assertContextualLinkPlaceHolder()
// Check existence of the contextual link placeholders.
$this->
assertSession()->
responseContains('<div' .
new Attribute(['data-contextual-id' =>
$id, 'data-contextual-token' =>
$id_token, 'data-drupal-ajax-container' => ''
]) . '></div>'
);
$this->
assertSession()->
responseContains('<div' .
new Attribute(['data-contextual-id' =>
$cached_id, 'data-contextual-token' =>
$cached_id_token, 'data-drupal-ajax-container' => ''
]) . '></div>'
);
// Get server-rendered contextual links.
// @see \Drupal\contextual\Tests\ContextualDynamicContextTest:renderContextualLinks()
$post =
['ids[0]' =>
$id, 'ids[1]' =>
$cached_id, 'tokens[0]' =>
$id_token, 'tokens[1]' =>
$cached_id_token];
$url = 'contextual/render?_format=json,destination=test-page';