View source
<?php
namespace Drupal\Tests\menu_link_modal\FunctionalJavascript;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
class MenuLinkModalTest extends WebDriverTestBase {
protected $adminUser;
protected static $modules = [
'block',
'node',
'datetime',
'menu_link_content',
'menu_ui',
'menu_link_modal',
];
protected $profile = 'minimal';
protected $defaultTheme = 'stark';
protected $permissions = [
'administer nodes',
'create page content',
'edit own page content',
'access administration pages',
'access content overview',
'administer menu',
'link to any page',
];
protected function setUp() : void {
parent::setUp();
$this
->drupalCreateContentType([
'type' => 'page',
'name' => 'Basic page',
'display_submitted' => FALSE,
]);
$this->adminUser = $this
->drupalCreateUser($this->permissions);
$this
->drupalLogin($this->adminUser);
}
public function testMenuLinkModal() {
$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]'],
]));
$node = $this
->drupalGetNodeByTitle($edit['title[0][value]']);
$this
->assertNotEmpty($node, 'Node found in database.');
$this
->drupalGet('admin/structure/menu/manage/main/add');
$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.');
$this
->placeBlock('system_menu_block:main');
$this
->drupalGet('');
$this
->checkModalFunctionality($node, $title);
$this
->drupalLogout();
$this
->drupalGet('');
$this
->checkModalFunctionality($node, $title);
}
protected function checkModalFunctionality($node, $title) {
$assert = $this
->assertSession();
$this
->clickLink($title);
$this
->assertNotEmpty($assert
->waitForElementVisible('css', '.ui-dialog'));
$assert
->elementContains('css', 'span.ui-dialog-title', $node
->label());
}
}