From 4535c1f5e7f9e3a4584fb0d4a23b2a581f5408ec Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Fri, 21 Jul 2017 20:15:30 -0700 Subject: [PATCH] CRM-20926 - CRM_Core_Menu - Parse XML element --- CRM/Core/Menu.php | 13 +++++++++++++ tests/phpunit/CRM/Core/MenuTest.php | 25 +++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/CRM/Core/Menu.php b/CRM/Core/Menu.php index a1574e7137..3622008ec0 100644 --- a/CRM/Core/Menu.php +++ b/CRM/Core/Menu.php @@ -132,6 +132,19 @@ class CRM_Core_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; diff --git a/tests/phpunit/CRM/Core/MenuTest.php b/tests/phpunit/CRM/Core/MenuTest.php index da803b0a10..559ada49f4 100644 --- a/tests/phpunit/CRM/Core/MenuTest.php +++ b/tests/phpunit/CRM/Core/MenuTest.php @@ -30,6 +30,31 @@ class CRM_Core_MenuTest extends CiviUnitTestCase { $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 = ' + + + civicrm/foo/bar + Foo Bar + + alpha + beta + gamma + + + + '; + $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']); } /** -- 2.25.1