You are here

public function MenuTreeStorageTest::testLoadByProperties in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Menu/MenuTreeStorageTest.php \Drupal\system\Tests\Menu\MenuTreeStorageTest::testLoadByProperties()

Tests MenuTreeStorage::loadByProperties().

File

core/modules/system/src/Tests/Menu/MenuTreeStorageTest.php, line 356
Contains \Drupal\system\Tests\Menu\MenuTreeStorageTest.

Class

MenuTreeStorageTest
Tests the menu tree storage.

Namespace

Drupal\system\Tests\Menu

Code

public function testLoadByProperties() {
  $tests = array(
    array(
      'foo' => 'bar',
    ),
    array(
      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
        ->assertTrue(preg_match('/^An invalid property name, .+ was specified. Allowed property names are:/', $e
        ->getMessage()), 'Found expected exception message.');
      $this
        ->pass($message);
    }
  }
  $this
    ->addMenuLink('test_link.1', '', 'test', array(), 'menu1');
  $properties = array(
    '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']);
}