You are here

public function MenuLinkFieldStandardTest::testLinkEdit in Menu Link (Field) 8

Same name and namespace in other branches
  1. 2.0.x tests/src/Functional/MenuLinkFieldStandardTest.php \Drupal\Tests\menu_link\Functional\MenuLinkFieldStandardTest::testLinkEdit()

Tests field CRUD on the node form and field configurations.

File

tests/src/Functional/MenuLinkFieldStandardTest.php, line 48

Class

MenuLinkFieldStandardTest
Tests menu link field functionality.

Namespace

Drupal\Tests\menu_link\Functional

Code

public function testLinkEdit() : void {

  // Ensure that the field_menu link got created.
  $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:');

  // Enable another menu.
  $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:');
}