Skip to content

Commit

Permalink
CRM-20926 - CRM_Core_Menu - Parse XML element <ids_arguments>
Browse files Browse the repository at this point in the history
  • Loading branch information
totten committed Aug 4, 2017
1 parent 5bfe764 commit 4535c1f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
13 changes: 13 additions & 0 deletions CRM/Core/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,19 @@ public static function readXML($xml, &$menu) {
$path = (string ) $item->path;
$menu[$path] = array();
unset($item->path);

if ($item->ids_arguments) {
$ids = array();
foreach (array('json', 'html', 'exception') as $type) {
$ids[$type] = array();
foreach ($item->ids_arguments->{$type} as $value) {
$ids[$type][] = (string) $value;
}
}
$menu[$path]['ids_arguments'] = $ids;
unset($item->ids_arguments);
}

foreach ($item as $key => $value) {
$key = (string ) $key;
$value = (string ) $value;
Expand Down
25 changes: 25 additions & 0 deletions tests/phpunit/CRM/Core/MenuTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,31 @@ public function testReadXML() {
$this->assertEquals('Customize Data and Screens', $menu['civicrm/foo/bar']['adminGroup']);
$this->assertEquals('admin/small/foo.png', $menu['civicrm/foo/bar']['icon']);
$this->assertEquals('10', $menu['civicrm/foo/bar']['weight']);
$this->assertTrue(!isset($menu['civicrm/foo/bar']['ids_arguments']));
}

public function testReadXML_IDS() {
$xmlString = '<?xml version="1.0" encoding="iso-8859-1" ?>
<menu>
<item>
<path>civicrm/foo/bar</path>
<title>Foo Bar</title>
<ids_arguments>
<json>alpha</json>
<json>beta</json>
<html>gamma</html>
</ids_arguments>
</item>
</menu>
';
$xml = simplexml_load_string($xmlString);
$menu = array();
CRM_Core_Menu::readXML($xml, $menu);
$this->assertTrue(isset($menu['civicrm/foo/bar']));
$this->assertEquals('Foo Bar', $menu['civicrm/foo/bar']['title']);
$this->assertEquals(array('alpha', 'beta'), $menu['civicrm/foo/bar']['ids_arguments']['json']);
$this->assertEquals(array('gamma'), $menu['civicrm/foo/bar']['ids_arguments']['html']);
$this->assertEquals(array(), $menu['civicrm/foo/bar']['ids_arguments']['exception']);
}

/**
Expand Down

0 comments on commit 4535c1f

Please sign in to comment.