diff --git a/core/lib/Drupal/Core/Menu/MenuTreeStorage.php b/core/lib/Drupal/Core/Menu/MenuTreeStorage.php index c1c137f2ded62c50425b1a23b069987c25ed0600..2f127efa8fd4f8f5f4dc32f798b28d4bb57b28ba 100644 --- a/core/lib/Drupal/Core/Menu/MenuTreeStorage.php +++ b/core/lib/Drupal/Core/Menu/MenuTreeStorage.php @@ -638,7 +638,7 @@ public function loadByProperties(array $properties) { $query = $this->connection->select($this->table, $this->options); $query->fields($this->table, $this->definitionFields()); foreach ($properties as $name => $value) { - if (!in_array($name, $this->definitionFields())) { + if (!in_array($name, $this->definitionFields(), TRUE)) { $fields = implode(', ', $this->definitionFields()); throw new \InvalidArgumentException(String::format('An invalid property name, @name was specified. Allowed property names are: @fields.', array('@name' => $name, '@fields' => $fields))); } diff --git a/core/modules/system/src/Tests/Menu/MenuTreeStorageTest.php b/core/modules/system/src/Tests/Menu/MenuTreeStorageTest.php index 7f39b377f8e1e37331453cb286e6a19041371bae..b1ebda653db1e6c39ad5a15a1d7c6acc20b82674 100644 --- a/core/modules/system/src/Tests/Menu/MenuTreeStorageTest.php +++ b/core/modules/system/src/Tests/Menu/MenuTreeStorageTest.php @@ -303,23 +303,26 @@ public function testSubtreeHeight() { * Tests MenuTreeStorage::loadByProperties(). */ public function testLoadByProperties() { - $properties = array('foo' => 'bar'); + $tests = array( + array('foo' => 'bar'), + array(0 => 'wrong'), + ); $msg = 'An invalid property name throws an exception.'; - try { - $this->treeStorage->loadByProperties($properties); - $this->fail($msg); - } - catch (\InvalidArgumentException $e) { - $this->assertEqual( - 'An invalid property name, foo was specified. Allowed property names are: menu_name, route_name, route_parameters, url, title, title_arguments, title_context, description, parent, weight, options, expanded, hidden, provider, metadata, class, form_class, id.', - $e->getMessage() - ); - $this->pass($msg); + foreach ($tests as $properties) { + try { + $this->treeStorage->loadByProperties($properties); + $this->fail($msg); + } + 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($msg); + } } - $this->addMenuLink(1); - $properties = array(array('menu_name' => 'tools')); + $this->addMenuLink('test_link.1', '', 'test', array(), 'menu1'); + $properties = array('menu_name' => 'menu1'); $links = $this->treeStorage->loadByProperties($properties); - $this->assertEqual('tools', $links[1]['menu_name']); + $this->assertEqual('menu1', $links['test_link.1']['menu_name']); + $this->assertEqual('test', $links['test_link.1']['route_name']); } /**