You are here

public function MenuLinkModalTest::testMenuLinkModal in Menu Link Modal 8

Same name and namespace in other branches
  1. 8.2 tests/src/FunctionalJavascript/MenuLinkModalTest.php \Drupal\Tests\menu_link_modal\FunctionalJavascript\MenuLinkModalTest::testMenuLinkModal()

Tests if the link added in menu item opens with modal.

File

tests/src/FunctionalJavascript/MenuLinkModalTest.php, line 81

Class

MenuLinkModalTest
Tests link added in menu opens in modal with this module.

Namespace

Drupal\Tests\menu_link_modal\FunctionalJavascript

Code

public function testMenuLinkModal() {

  // Create a new page node.
  $this
    ->drupalGet('node/add/page');
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $edit = [
    'title[0][value]' => 'Test node for modal',
    'body[0][value]' => $this
      ->randomString(),
  ];
  $this
    ->drupalPostForm(NULL, $edit, t('Save'));
  $this
    ->assertText(t('Basic page @title has been created.', [
    '@title' => $edit['title[0][value]'],
  ]), 'Basic page created.');

  // Check that the node exists in the database.
  $node = $this
    ->drupalGetNodeByTitle($edit['title[0][value]']);
  $this
    ->assertTrue($node, 'Node found in database.');

  // Create a menu item with the link of recently created node.
  $this
    ->drupalGet('admin/structure/menu/manage/main/add');
  $this
    ->assertResponse(200);
  $title = 'title modal';
  $edit = [
    'link[0][uri]' => '/node/' . $node
      ->id(),
    'title[0][value]' => $title,
    'open_modal' => 1,
  ];
  $this
    ->drupalPostForm(NULL, $edit, t('Save'));
  $this
    ->assertText(t('The menu link has been saved.'));
  $menu_links = entity_load_multiple_by_properties('menu_link_content', [
    'title' => $title,
  ]);
  $menu_link = reset($menu_links);
  $this
    ->assertTrue($menu_link, 'Menu link was found in database.');

  // Add the main menu block, as provided by the Block module.
  $this
    ->placeBlock('system_menu_block:main');

  // Check if the link opens in modal while we are still login as admin.
  $this
    ->drupalGet('');
  $this
    ->checkModalFunctionality($node, $title);
  $this
    ->drupalLogout();

  // Check if the link opens in modal after logout.
  $this
    ->drupalGet('');
  $this
    ->checkModalFunctionality($node, $title);
}