public function MenuLinkModalTest::testMenuLinkModal in Menu Link Modal 8.2
Same name and namespace in other branches
- 8 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 85
Class
- MenuLinkModalTest
- Tests link added in menu opens in modal with this module.
Namespace
Drupal\Tests\menu_link_modal\FunctionalJavascriptCode
public function testMenuLinkModal() {
// Create a new page node.
$this
->drupalGet('node/add/page');
$edit = [
'title[0][value]' => 'Test node for modal',
'body[0][value]' => $this
->randomString(),
];
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextContains(t('Basic page @title has been created.', [
'@title' => $edit['title[0][value]'],
]));
// Check that the node exists in the database.
$node = $this
->drupalGetNodeByTitle($edit['title[0][value]']);
$this
->assertNotEmpty($node, 'Node found in database.');
// Create a menu item with the link of recently created node.
$this
->drupalGet('admin/structure/menu/manage/main/add');
// Expand the details section.
$this
->click('#edit-modal-config');
$title = 'title modal';
$edit = [
'link[0][uri]' => '/node/' . $node
->id(),
'title[0][value]' => $title,
'open_modal' => 1,
];
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextContains('The menu link has been saved.');
$menu_links = \Drupal::entityTypeManager()
->getStorage('menu_link_content')
->loadByProperties([
'title' => $title,
]);
$menu_link = reset($menu_links);
$this
->assertNotEmpty($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);
}