From 5bfe764cfcdcefb9bdede60854d31f5186623702 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Fri, 21 Jul 2017 20:00:39 -0700 Subject: [PATCH] CRM-20926 - CRM_Core_MenuTest - Add basic test for XML parsing --- CRM/Core/Menu.php | 16 +++++++++++++--- tests/phpunit/CRM/Core/MenuTest.php | 26 ++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/CRM/Core/Menu.php b/CRM/Core/Menu.php index fa14fcfae0..a1574e7137 100644 --- a/CRM/Core/Menu.php +++ b/CRM/Core/Menu.php @@ -105,15 +105,25 @@ class CRM_Core_Menu { * Read menu. * * @param string $name - * @param string $menu + * File name + * @param array $menu + * An alterable list of menu items. * * @throws Exception */ public static function read($name, &$menu) { + $xml = simplexml_load_file($name); + self::readXML($xml, $menu); + } + /** + * @param SimpleXMLElement $xml + * An XML document defining a list of menu items. + * @param array $menu + * An alterable list of menu items. + */ + public static function readXML($xml, &$menu) { $config = CRM_Core_Config::singleton(); - - $xml = simplexml_load_file($name); foreach ($xml->item as $item) { if (!(string ) $item->path) { CRM_Core_Error::debug('i', $item); diff --git a/tests/phpunit/CRM/Core/MenuTest.php b/tests/phpunit/CRM/Core/MenuTest.php index 360198e22a..da803b0a10 100644 --- a/tests/phpunit/CRM/Core/MenuTest.php +++ b/tests/phpunit/CRM/Core/MenuTest.php @@ -6,6 +6,32 @@ */ class CRM_Core_MenuTest extends CiviUnitTestCase { + public function testReadXML() { + $xmlString = ' + + + civicrm/foo/bar + Foo Bar + The foo is one with the bar. + CRM_Foo_Page_Bar + Customize Data and Screens + admin/small/foo.png + 10 + + + '; + $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('The foo is one with the bar.', $menu['civicrm/foo/bar']['desc']); + $this->assertEquals('CRM_Foo_Page_Bar', $menu['civicrm/foo/bar']['page_callback']); + $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']); + } + /** * Check that novel data elements in the menu are correctly * stored and loaded. -- 2.25.1