function MenuLinkContentUpdateTest::testPublishedEntityKeyAddition

Tests the addition of the publishing status entity key.

See also

menu_link_content_update_8601()

File

core/modules/menu_link_content/tests/src/Functional/Update/MenuLinkContentUpdateTest.php, line 33

Class

MenuLinkContentUpdateTest
Tests the upgrade path for custom menu links.

Namespace

Drupal\Tests\menu_link_content\Functional\Update

Code

public function testPublishedEntityKeyAddition() {
  $this->runUpdates();
  // Log in as user 1.
  $account = User::load(1);
  $account->passRaw = 'drupal';
  $this->drupalLogin($account);
  // Make sure our custom menu link exists.
  $assert_session = $this->assertSession();
  $this->drupalGet('admin/structure/menu/item/1/edit');
  $assert_session->checkboxChecked('edit-enabled-value');
  // Check that custom menu links can be created, saved and then loaded.
  $storage = \Drupal::entityTypeManager()->getStorage('menu_link_content');
  /** @var \Drupal\menu_link_content\Entity\MenuLinkContent $menu_link */
  $menu_link = $storage->create([
    'menu_name' => 'main',
    'link' => 'route:user.page',
    'title' => 'Pineapple',
  ]);
  $menu_link->save();
  $menu_link = $storage->loadUnchanged($menu_link->id());
  $this->assertEquals('main', $menu_link->getMenuName());
  $this->assertEquals('Pineapple', $menu_link->label());
  $this->assertEquals('route:user.page', $menu_link->link->uri);
  $this->assertTrue($menu_link->isPublished());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.