Tests the contextual links on a Views block.
public function testBlockContextualLinks() {
$this
->drupalLogin($this
->drupalCreateUser(array(
'administer views',
'access contextual links',
'administer blocks',
)));
$block = $this
->drupalPlaceBlock('views_block:test_view_block-block_1');
$this
->drupalGet('test-page');
$id = 'block:admin/structure/block/manage:' . $block
->id() . ':|views_ui:admin/structure/views/view:test_view_block:location=block&name=test_view_block&display_id=block_1';
// @see \Drupal\contextual\Tests\ContextualDynamicContextTest:assertContextualLinkPlaceHolder()
$this
->assertRaw('<div data-contextual-id="' . $id . '"></div>', format_string('Contextual link placeholder with id @id exists.', array(
'@id' => $id,
)));
// Get server-rendered contextual links.
// @see \Drupal\contextual\Tests\ContextualDynamicContextTest:renderContextualLinks()
$post = urlencode('ids[0]') . '=' . urlencode($id);
$response = $this
->curlExec(array(
CURLOPT_URL => url('contextual/render', array(
'absolute' => TRUE,
'query' => array(
'destination' => 'test-page',
),
)),
CURLOPT_POST => TRUE,
CURLOPT_POSTFIELDS => $post,
CURLOPT_HTTPHEADER => array(
'Accept: application/json',
'Content-Type: application/x-www-form-urlencoded',
),
));
$this
->assertResponse(200);
$json = drupal_json_decode($response);
$this
->assertIdentical($json[$id], '<ul class="contextual-links"><li class="block-configure odd first"><a href="' . base_path() . 'admin/structure/block/manage/' . $block
->id() . '?destination=test-page">Configure block</a></li><li class="views-ui-edit even last"><a href="' . base_path() . 'admin/structure/views/view/test_view_block/edit/block_1?destination=test-page">Edit view</a></li></ul>');
}