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) { ...@@ -638,7 +638,7 @@ public function loadByProperties(array $properties) {
$query = $this->connection->select($this->table, $this->options); $query = $this->connection->select($this->table, $this->options);
$query->fields($this->table, $this->definitionFields()); $query->fields($this->table, $this->definitionFields());
foreach ($properties as $name => $value) { foreach ($properties as $name => $value) {
if (!in_array($name, $this->definitionFields())) { if (!in_array($name, $this->definitionFields(), TRUE)) {
$fields = implode(', ', $this->definitionFields()); $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))); 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() { ...@@ -303,23 +303,26 @@ public function testSubtreeHeight() {
* Tests MenuTreeStorage::loadByProperties(). * Tests MenuTreeStorage::loadByProperties().
*/ */
public function testLoadByProperties() { public function testLoadByProperties() {
$properties = array('foo' => 'bar'); $tests = array(
array('foo' => 'bar'),
array(0 => 'wrong'),
);
$msg = 'An invalid property name throws an exception.'; $msg = 'An invalid property name throws an exception.';
try { foreach ($tests as $properties) {
$this->treeStorage->loadByProperties($properties); try {
$this->fail($msg); $this->treeStorage->loadByProperties($properties);
} $this->fail($msg);
catch (\InvalidArgumentException $e) { }
$this->assertEqual( catch (\InvalidArgumentException $e) {
'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.', $this->assertTrue(preg_match('/^An invalid property name, .+ was specified. Allowed property names are:/', $e->getMessage()), 'Found expected exception message.');
$e->getMessage() $this->pass($msg);
); }
$this->pass($msg);
} }
$this->addMenuLink(1); $this->addMenuLink('test_link.1', '', 'test', array(), 'menu1');
$properties = array(array('menu_name' => 'tools')); $properties = array('menu_name' => 'menu1');
$links = $this->treeStorage->loadByProperties($properties); $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