function MenuTreeStorageTest::testLoadByProperties

Same name in other branches
  1. 8.9.x core/tests/Drupal/KernelTests/Core/Menu/MenuTreeStorageTest.php \Drupal\KernelTests\Core\Menu\MenuTreeStorageTest::testLoadByProperties()
  2. 10 core/tests/Drupal/KernelTests/Core/Menu/MenuTreeStorageTest.php \Drupal\KernelTests\Core\Menu\MenuTreeStorageTest::testLoadByProperties()
  3. 11.x 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 351

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->assertMatchesRegularExpression('/^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->assertEquals('menu1', $links['test_link.1']['menu_name']);
    $this->assertEquals('test', $links['test_link.1']['route_name']);
}

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