X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=tests%2Fphpunit%2FCRM%2FCore%2FMenuTest.php;h=1b6a7d311ae6eddbbf17c5dd84cffc2dfa95f812;hb=bff4492ddf285d10960af4ce0848c3185b457c7f;hp=b48a5f5cd42abdc5de1c4cc0b97db37c9eb859ca;hpb=e68d4035151c218b5e504883725fecd62eaea4ac;p=civicrm-core.git diff --git a/tests/phpunit/CRM/Core/MenuTest.php b/tests/phpunit/CRM/Core/MenuTest.php index b48a5f5cd4..1b6a7d311a 100644 --- a/tests/phpunit/CRM/Core/MenuTest.php +++ b/tests/phpunit/CRM/Core/MenuTest.php @@ -6,6 +6,84 @@ */ class CRM_Core_MenuTest extends CiviUnitTestCase { + public function testReadXML() { + $xmlString = ' +
+ '; + $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']); + $this->assertTrue(!isset($menu['civicrm/foo/bar']['ids_arguments'])); + } + + public function testReadXML_IDS() { + $xmlString = ' + + '; + $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']['exceptions']); + $this->assertEquals(array(), $menu['civicrm/foo/bar']['ids_arguments']['html']); + + $idsConfig = CRM_Core_IDS::createRouteConfig($menu['civicrm/foo/bar']); + $this->assertTrue(in_array('alpha', $idsConfig['General']['json'])); // XML + $this->assertTrue(in_array('beta', $idsConfig['General']['json'])); // XML + $this->assertTrue(in_array('gamma', $idsConfig['General']['exceptions'])); // XML + $this->assertTrue(in_array('thankyou_text', $idsConfig['General']['exceptions'])); // Inherited + } + + /** + * Check that novel data elements in the menu are correctly + * stored and loaded. + */ + public function testModuleData() { + CRM_Core_Menu::store(TRUE); + $item = CRM_Core_Menu::get('civicrm/case'); + $this->assertFalse(isset($item['ids_arguments']['exceptions'])); + $this->assertFalse(isset($item['whimsy'])); + + CRM_Utils_Hook::singleton()->setHook('civicrm_alterMenu', function(&$items){ + $items['civicrm/case']['ids_arguments']['exceptions'][] = 'foobar'; + $items['civicrm/case']['whimsy'] = 'godliness'; + }); + + CRM_Core_Menu::store(TRUE); + $item = CRM_Core_Menu::get('civicrm/case'); + $this->assertTrue(in_array('foobar', $item['ids_arguments']['exceptions'])); + $this->assertEquals('godliness', $item['whimsy']); + } + /** * @return array */