You are here

function MenuWebTestBase::assertMenuLink in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/menu_ui/src/Tests/MenuWebTestBase.php \Drupal\menu_ui\Tests\MenuWebTestBase::assertMenuLink()

Fetches the menu item from the database and compares it to expected item.

Parameters

int $menu_plugin_id: Menu item id.

array $expected_item: Array containing properties to verify.

5 calls to MenuWebTestBase::assertMenuLink()
MenuLanguageTest::testMenuLanguage in core/modules/menu_ui/src/Tests/MenuLanguageTest.php
Tests menu language settings and the defaults for menu link items.
MenuTest::addMenuLink in core/modules/menu_ui/src/Tests/MenuTest.php
Adds a menu link using the UI.
MenuTest::disableMenuLink in core/modules/menu_ui/src/Tests/MenuTest.php
Disables a menu link.
MenuTest::doMenuTests in core/modules/menu_ui/src/Tests/MenuTest.php
Tests menu functionality.
MenuTest::enableMenuLink in core/modules/menu_ui/src/Tests/MenuTest.php
Enables a menu link.

File

core/modules/menu_ui/src/Tests/MenuWebTestBase.php, line 32
Contains \Drupal\menu_ui\Tests\MenuWebTestBase.

Class

MenuWebTestBase
Base class for menu web tests.

Namespace

Drupal\menu_ui\Tests

Code

function assertMenuLink($menu_plugin_id, array $expected_item) {

  // Retrieve menu link.

  /** @var \Drupal\Core\Menu\MenuLinkManagerInterface $menu_link_manager */
  $menu_link_manager = \Drupal::service('plugin.manager.menu.link');
  $menu_link_manager
    ->resetDefinitions();

  // Reset the static load cache.
  \Drupal::entityManager()
    ->getStorage('menu_link_content')
    ->resetCache();
  $definition = $menu_link_manager
    ->getDefinition($menu_plugin_id);
  $entity = NULL;

  // Pull the path from the menu link content.
  if (strpos($menu_plugin_id, 'menu_link_content') === 0) {
    list(, $uuid) = explode(':', $menu_plugin_id, 2);

    /** @var \Drupal\menu_link_content\Entity\MenuLinkContent $entity */
    $entity = \Drupal::entityManager()
      ->loadEntityByUuid('menu_link_content', $uuid);
  }
  if (isset($expected_item['children'])) {
    $child_ids = array_values($menu_link_manager
      ->getChildIds($menu_plugin_id));
    sort($expected_item['children']);
    if ($child_ids) {
      sort($child_ids);
    }
    $this
      ->assertEqual($expected_item['children'], $child_ids);
    unset($expected_item['children']);
  }
  if (isset($expected_item['parents'])) {
    $parent_ids = array_values($menu_link_manager
      ->getParentIds($menu_plugin_id));
    $this
      ->assertEqual($expected_item['parents'], $parent_ids);
    unset($expected_item['parents']);
  }
  if (isset($expected_item['langcode']) && $entity) {
    $this
      ->assertEqual($entity->langcode->value, $expected_item['langcode']);
    unset($expected_item['langcode']);
  }
  if (isset($expected_item['enabled']) && $entity) {
    $this
      ->assertEqual($entity->enabled->value, $expected_item['enabled']);
    unset($expected_item['enabled']);
  }
  foreach ($expected_item as $key => $value) {
    $this
      ->assertTrue(isset($definition[$key]));
    $this
      ->assertEqual($definition[$key], $value);
  }
}