4 * Class CRM_Core_MenuTest
7 class CRM_Core_MenuTest
extends CiviUnitTestCase
{
9 public function testReadXML() {
10 $xmlString = '<?xml version="1.0" encoding="iso-8859-1" ?>
13 <path>civicrm/foo/bar</path>
14 <title>Foo Bar</title>
15 <desc>The foo is one with the bar.</desc>
16 <page_callback>CRM_Foo_Page_Bar</page_callback>
17 <adminGroup>Customize Data and Screens</adminGroup>
22 $xml = simplexml_load_string($xmlString);
24 CRM_Core_Menu
::readXML($xml, $menu);
25 $this->assertTrue(isset($menu['civicrm/foo/bar']));
26 $this->assertEquals('Foo Bar', $menu['civicrm/foo/bar']['title']);
27 $this->assertEquals('The foo is one with the bar.', $menu['civicrm/foo/bar']['desc']);
28 $this->assertEquals('CRM_Foo_Page_Bar', $menu['civicrm/foo/bar']['page_callback']);
29 $this->assertEquals('Customize Data and Screens', $menu['civicrm/foo/bar']['adminGroup']);
30 $this->assertEquals('10', $menu['civicrm/foo/bar']['weight']);
31 $this->assertTrue(!isset($menu['civicrm/foo/bar']['ids_arguments']));
34 public function testReadXML_IDS() {
35 $xmlString = '<?xml version="1.0" encoding="iso-8859-1" ?>
38 <path>civicrm/foo/bar</path>
39 <title>Foo Bar</title>
43 <exception>gamma</exception>
48 $xml = simplexml_load_string($xmlString);
50 CRM_Core_Menu
::readXML($xml, $menu);
51 $this->assertTrue(isset($menu['civicrm/foo/bar']));
52 $this->assertEquals('Foo Bar', $menu['civicrm/foo/bar']['title']);
53 $this->assertEquals(['alpha', 'beta'], $menu['civicrm/foo/bar']['ids_arguments']['json']);
54 $this->assertEquals(['gamma'], $menu['civicrm/foo/bar']['ids_arguments']['exceptions']);
55 $this->assertEquals([], $menu['civicrm/foo/bar']['ids_arguments']['html']);
57 $idsConfig = CRM_Core_IDS
::createRouteConfig($menu['civicrm/foo/bar']);
59 $this->assertTrue(in_array('alpha', $idsConfig['General']['json']));
61 $this->assertTrue(in_array('beta', $idsConfig['General']['json']));
63 $this->assertTrue(in_array('gamma', $idsConfig['General']['exceptions']));
65 $this->assertTrue(in_array('thankyou_text', $idsConfig['General']['exceptions']));
69 * Check that novel data elements in the menu are correctly
72 public function testModuleData() {
73 CRM_Core_Menu
::store(TRUE);
74 $item = CRM_Core_Menu
::get('civicrm/case');
75 $this->assertFalse(isset($item['ids_arguments']['exceptions']));
76 $this->assertFalse(isset($item['whimsy']));
78 CRM_Utils_Hook
::singleton()->setHook('civicrm_alterMenu', function(&$items) {
79 $items['civicrm/case']['ids_arguments']['exceptions'][] = 'foobar';
80 $items['civicrm/case']['whimsy'] = 'godliness';
83 CRM_Core_Menu
::store(TRUE);
84 $item = CRM_Core_Menu
::get('civicrm/case');
85 $this->assertTrue(in_array('foobar', $item['ids_arguments']['exceptions']));
86 $this->assertEquals('godliness', $item['whimsy']);
92 public function pathArguments() {
93 // array(0 => string $input, 1 => array $expectedOutput)
95 //$cases[] = array(NULL, array());
96 //$cases[] = array('', array());
97 //$cases[] = array('freestanding', array('freestanding' => NULL));
98 $cases[] = ['addSequence=1', ['addSequence' => '1']];
99 $cases[] = ['attachUpload=1', ['attachUpload' => '1']];
100 $cases[] = ['mode=256', ['mode' => '256']];
102 'mode=256,addSequence=1,attachUpload=1',
103 ['mode' => '256', 'addSequence' => '1', 'attachUpload' => 1],
106 'mode=256,urlToSession=a:b:c:d',
110 ['urlVar' => 'a', 'sessionVar' => 'b', 'type' => 'c', 'default' => 'd'],
115 'mode=256,urlToSession=a:b:c:d;z:y:x:w',
119 ['urlVar' => 'a', 'sessionVar' => 'b', 'type' => 'c', 'default' => 'd'],
120 ['urlVar' => 'z', 'sessionVar' => 'y', 'type' => 'x', 'default' => 'w'],
124 $cases[] = ['url=whiz!;.:#=%/|+bang?', ['url' => 'whiz!;.:#=%/|+bang?']];
129 * @param $inputString
130 * @param $expectedArray
131 * @dataProvider pathArguments
133 public function testGetArrayForPathArgs($inputString, $expectedArray) {
134 $actual = CRM_Core_Menu
::getArrayForPathArgs($inputString);
135 $this->assertEquals($expectedArray, $actual);