View source
<?php
namespace Drupal\Tests\menu_link\Functional;
use Drupal\Tests\BrowserTestBase;
class MenuLinkFieldStandardTest extends BrowserTestBase {
protected $defaultTheme = 'stark';
protected static $modules = [
'menu_link',
];
protected $profile = 'standard';
protected $adminUser;
protected function loginUser() : void {
$perms = array_keys(\Drupal::service('user.permissions')
->getPermissions());
$this->adminUser = $this
->drupalCreateUser($perms);
$this
->drupalLogin($this->adminUser);
}
public function testLinkEdit() : void {
$node = $this
->drupalCreateNode([
'type' => 'article',
'title' => 'Foobar',
'promote' => 1,
'status' => 1,
]);
$this
->drupalGet("node/{$node->id()}/edit");
$this
->assertSession()
->checkboxNotChecked('edit-menu-link-0-enabled');
$title = $this
->randomString();
$edit = $this
->translatePostValues([
'menu_link' => [
0 => [
'enabled' => TRUE,
'title' => $title,
],
],
]);
$this
->drupalPostForm("node/{$node->id()}/edit", $edit, 'Save');
$this
->drupalGet("node/{$node->id()}/edit");
$this
->assertSession()
->checkboxNotChecked('edit-menu-link-0-enabled');
$this
->assertOptionSelected('edit-menu-link-0-menu-parent', 'main:');
$edit = $this
->translatePostValues([
'settings' => [
'available_menus' => [
'footer' => TRUE,
'main' => TRUE,
],
],
]);
$this
->drupalPostForm('admin/structure/types/manage/article/fields/node.article.menu_link', $edit, 'Save settings');
$this
->drupalGet("node/{$node->id()}/edit");
$this
->assertOptionSelected('edit-menu-link-0-menu-parent', 'main:');
$edit = $this
->translatePostValues([
'menu_link' => [
0 => [
'menu_parent' => 'footer:',
],
],
]);
$this
->drupalPostForm("node/{$node->id()}/edit", $edit, 'Save');
$this
->drupalGet("node/{$node->id()}/edit");
$this
->assertOptionSelected('edit-menu-link-0-menu-parent', 'footer:');
}
}