You are here

public function MenuTest::testBlockContextualLinks in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/menu_ui/src/Tests/MenuTest.php \Drupal\menu_ui\Tests\MenuTest::testBlockContextualLinks()

Tests the contextual links on a menu block.

File

core/modules/menu_ui/src/Tests/MenuTest.php, line 570
Contains \Drupal\menu_ui\Tests\MenuTest.

Class

MenuTest
Add a custom menu, add menu links to the custom menu and Tools menu, check their data, and delete them using the UI.

Namespace

Drupal\menu_ui\Tests

Code

public function testBlockContextualLinks() {
  $this
    ->drupalLogin($this
    ->drupalCreateUser(array(
    'administer menu',
    'access contextual links',
    'administer blocks',
  )));
  $custom_menu = $this
    ->addCustomMenu();
  $this
    ->addMenuLink('', '/', $custom_menu
    ->id());
  $block = $this
    ->drupalPlaceBlock('system_menu_block:' . $custom_menu
    ->id(), array(
    'label' => 'Custom menu',
    'provider' => 'system',
  ));
  $this
    ->drupalGet('test-page');
  $id = 'block:block=' . $block
    ->id() . ':langcode=en|menu:menu=' . $custom_menu
    ->id() . ':langcode=en';

  // @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 = array(
    'ids[0]' => $id,
  );
  $response = $this
    ->drupalPost('contextual/render', 'application/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="entitymenuedit-form"><a href="' . base_path() . 'admin/structure/menu/manage/' . $custom_menu
    ->id() . '">Edit menu</a></li></ul>');
}