View source
<?php
namespace Drupal\Tests\multiple_node_menu\Functional;
use Drupal\Tests\BrowserTestBase;
class MultipleNodeMenuTestCase extends BrowserTestBase {
protected static $modules = [
'menu_ui',
'multiple_node_menu',
];
protected $profile = 'standard';
protected $adminUser;
public static function getInfo() {
return [
'name' => 'Multiple Node Menu',
'description' => 'Test adding, editing and deleting multiple menu links attachd to nodes.',
'group' => 'Multiple Node Menu',
];
}
public function setUp() : void {
parent::setUp();
$this->adminUser = $this
->drupalCreateUser([
'access administration pages',
'administer content types',
'administer menu',
'create page content',
'edit any page content',
'delete any page content',
]);
$this
->drupalLogin($this->adminUser);
}
public function testNodeFormWidget() {
$this
->drupalGet('admin/structure/types/manage/page');
$edit = [
'menu_options[main]' => 1,
];
$this
->submitForm($edit, 'Save content type');
$this
->drupalGet('admin/structure/types/manage/page');
$edit = [
'menu_parent' => 'main:',
];
$this
->submitForm($edit, 'Save content type');
$this
->drupalGet('node/add/page');
$node_title = $this
->randomString();
$edit = [
'title' => $node_title,
'body[0][value]' => $this
->randomString(),
'multiple_node_menu[enabled]' => TRUE,
'multiple_node_menu[add_link][link_title]' => $node_title,
'multiple_node_menu[add_link][weight]' => 5,
];
$this
->submitForm($edit, 'Save');
$node = $this
->drupalGetNodeByTitle($node_title);
$this
->drupalGet('');
$this
->assertSession()
->linkExists($node_title, 0, 'Menu link is present.');
$this
->drupalGet('node/' . $node
->id() . '/edit');
$option = $this
->assertSession()
->optionExists('edit-multiple-node-menu-current-links-0-weight', 5);
static::assertTrue($option
->isChecked());
$new_link_title = $this
->randomString();
$edit = [
'multiple_node_menu[add_link][link_title]' => $new_link_title,
'multiple_node_menu[add_link][weight]' => -5,
];
$this
->submitForm($edit, 'Add new menu link');
$this
->submitForm([], 'Save');
$this
->drupalGet('');
$this
->assertLink($new_link_title, 0);
$this
->drupalGet('node/' . $node
->id() . '/edit');
$edit = [
'multiple_node_menu[current_links][0][enabled]' => FALSE,
];
$this
->submitForm($edit, 'Save');
$this
->drupalGet('');
$this
->assertNoLink($node_title);
$this
->drupalGet('node/' . $node
->id() . '/edit');
$this
->submitForm([], 'Delete');
$this
->submitForm([], 'Save');
$this
->drupalGet('');
$this
->assertNoLink($node_title);
$this
->assertNoLink($new_link_title);
$this
->drupalGet('node/' . $node
->id() . '/edit');
$edit = [
'multiple_node_menu[enabled]' => TRUE,
'multiple_node_menu[current_links][0][enabled]' => TRUE,
];
$this
->submitForm($edit, 'Save');
$this
->drupalGet('');
$this
->assertLink($node_title, 0);
$this
->drupalGet('node/' . $node
->id() . '/edit');
$edit = [
'multiple_node_menu[enabled]' => FALSE,
];
$this
->submitForm($edit, 'Save');
$this
->drupalGet('');
$this
->assertNoLink($node_title);
}
}