Commit a04820c1 authored by alexpott's avatar alexpott

Issue #2302165 followup by cilefen, pwolanin | kgoel: Fixed Only allow loading...

Issue #2302165 followup by cilefen, pwolanin | kgoel: Fixed Only allow loading by plugin definition properties.
parent 717243cc
......@@ -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)));
}
......
......@@ -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']);
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment