View source
<?php
namespace Drupal\Tests\menu_link_modal\FunctionalJavascript;
use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
class MenuLinkModalTest extends JavascriptTestBase {
protected $adminUser;
public static $modules = [
'block',
'node',
'datetime',
'menu_link_content',
'menu_ui',
'menu_link_modal',
];
protected $profile = 'minimal';
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() {
parent::setUp();
if ($this->profile != 'standard') {
$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');
$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.');
$node = $this
->drupalGetNodeByTitle($edit['title[0][value]']);
$this
->assertTrue($node, 'Node found in database.');
$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.');
$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());
}
}