You are here

trait MenuLinkWeightTestTrait in Menu Link Weight 8

Same name and namespace in other branches
  1. 8.2 tests/src/FunctionalJavascript/MenuLinkWeightTestTrait.php \Drupal\Tests\menu_link_weight\FunctionalJavascript\MenuLinkWeightTestTrait

Hierarchy

1 file declares its use of MenuLinkWeightTestTrait
MenuLinkWeightFunctionalTestBase.php in tests/src/Functional/MenuLinkWeightFunctionalTestBase.php

File

tests/src/FunctionalJavascript/MenuLinkWeightTestTrait.php, line 7

Namespace

Drupal\Tests\menu_link_weight\FunctionalJavascript
View source
trait MenuLinkWeightTestTrait {

  /**
   * Asserts the weight of a menu link.
   *
   * @param string $link_id
   *   The plugin ID of the link.
   * @param int $expected_weight
   *   The expected weight of the link.
   */
  protected function assertLinkWeight($link_id, $expected_weight) {
    $this->menuLinkManager
      ->resetDefinitions();

    // Retrieve the menu link.

    /** @var \Drupal\Core\Menu\MenuLinkInterface $link */
    $link = $this->menuLinkManager
      ->createInstance($link_id);
    $this
      ->assertEquals($expected_weight, $link
      ->getWeight());
  }

  /**
   * Load menu link for a given node.
   *
   * @param \Drupal\node\NodeInterface $node
   * @return \Drupal\Core\Menu\MenuLinkInterface|FALSE
   */
  protected function loadMenuLinkByNode(NodeInterface $node) {
    $links = $this->menuLinkManager
      ->loadLinksByRoute($node
      ->toUrl()
      ->getRouteName(), $node
      ->toUrl()
      ->getRouteParameters());
    return !empty($links) ? reset($links) : FALSE;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MenuLinkWeightTestTrait::assertLinkWeight protected function Asserts the weight of a menu link.
MenuLinkWeightTestTrait::loadMenuLinkByNode protected function Load menu link for a given node.