public function DisplayBlockTest::testBlockContextualLinks in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/block/src/Tests/Views/DisplayBlockTest.php \Drupal\block\Tests\Views\DisplayBlockTest::testBlockContextualLinks()
Tests the contextual links on a Views block.
File
- core/
modules/ block/ src/ Tests/ Views/ DisplayBlockTest.php, line 354 - Contains \Drupal\block\Tests\Views\DisplayBlockTest.
Class
- DisplayBlockTest
- Tests the block display plugin.
Namespace
Drupal\block\Tests\ViewsCode
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');
$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';
$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';
// @see \Drupal\contextual\Tests\ContextualDynamicContextTest:assertContextualLinkPlaceHolder()
$this
->assertRaw('<div' . new Attribute(array(
'data-contextual-id' => $id,
)) . '></div>', format_string('Contextual link placeholder with id @id exists.', array(
'@id' => $id,
)));
$this
->assertRaw('<div' . new Attribute(array(
'data-contextual-id' => $cached_id,
)) . '></div>', format_string('Contextual link placeholder with id @id exists.', array(
'@id' => $cached_id,
)));
// Get server-rendered contextual links.
// @see \Drupal\contextual\Tests\ContextualDynamicContextTest:renderContextualLinks()
$post = array(
'ids[0]' => $id,
'ids[1]' => $cached_id,
);
$response = $this
->drupalPostWithFormat('contextual/render', 'json', $post, array(
'query' => array(
'destination' => 'test-page',
),
));
$this
->assertResponse(200);
$json = Json::decode($response);
$this
->assertIdentical($json[$id], '<ul class="contextual-links"><li class="block-configure"><a href="' . base_path() . 'admin/structure/block/manage/' . $block
->id() . '">Configure block</a></li><li class="entityviewedit-form"><a href="' . base_path() . 'admin/structure/views/view/test_view_block/edit/block_1">Edit view</a></li></ul>');
$this
->assertIdentical($json[$cached_id], '<ul class="contextual-links"><li class="block-configure"><a href="' . base_path() . 'admin/structure/block/manage/' . $cached_block
->id() . '">Configure block</a></li><li class="entityviewedit-form"><a href="' . base_path() . 'admin/structure/views/view/test_view_block/edit/block_1">Edit view</a></li></ul>');
}