public function MenuTreeStorageTest::testLoadByProperties in Drupal 9
Same name and namespace in other branches
- 8 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\MenuCode
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']);
}