You are here

public function MenuTreeStorageTest::testLoadByProperties in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Menu/MenuTreeStorageTest.php \Drupal\KernelTests\Core\Menu\MenuTreeStorageTest::testLoadByProperties()

Tests MenuTreeStorage::loadByProperties().

File

core/tests/Drupal/KernelTests/Core/Menu/MenuTreeStorageTest.php, line 344

Class

MenuTreeStorageTest
Tests the menu tree storage.

Namespace

Drupal\KernelTests\Core\Menu

Code

public function testLoadByProperties() {
  $tests = [
    [
      'foo' => 'bar',
    ],
    [
      0 => 'wrong',
    ],
  ];
  $message = 'An invalid property name throws an exception.';
  foreach ($tests as $properties) {
    try {
      $this->treeStorage
        ->loadByProperties($properties);
      $this
        ->fail($message);
    } catch (\InvalidArgumentException $e) {
      $this
        ->assertRegExp('/^An invalid property name, .+ was specified. Allowed property names are:/', $e
        ->getMessage(), 'Found expected exception message.');
    }
  }
  $this
    ->addMenuLink('test_link.1', '', 'test', [], 'menu1');
  $properties = [
    'menu_name' => 'menu1',
  ];
  $links = $this->treeStorage
    ->loadByProperties($properties);
  $this
    ->assertEqual('menu1', $links['test_link.1']['menu_name']);
  $this
    ->assertEqual('test', $links['test_link.1']['route_name']);
}