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>
18 <icon>admin/small/foo.png</icon>
23 $xml = simplexml_load_string($xmlString);
25 CRM_Core_Menu
::readXML($xml, $menu);
26 $this->assertTrue(isset($menu['civicrm/foo/bar']));
27 $this->assertEquals('Foo Bar', $menu['civicrm/foo/bar']['title']);
28 $this->assertEquals('The foo is one with the bar.', $menu['civicrm/foo/bar']['desc']);
29 $this->assertEquals('CRM_Foo_Page_Bar', $menu['civicrm/foo/bar']['page_callback']);
30 $this->assertEquals('Customize Data and Screens', $menu['civicrm/foo/bar']['adminGroup']);
31 $this->assertEquals('admin/small/foo.png', $menu['civicrm/foo/bar']['icon']);
32 $this->assertEquals('10', $menu['civicrm/foo/bar']['weight']);
33 $this->assertTrue(!isset($menu['civicrm/foo/bar']['ids_arguments']));
36 public function testReadXML_IDS() {
37 $xmlString = '<?xml version="1.0" encoding="iso-8859-1" ?>
40 <path>civicrm/foo/bar</path>
41 <title>Foo Bar</title>
45 <exception>gamma</exception>
50 $xml = simplexml_load_string($xmlString);
52 CRM_Core_Menu
::readXML($xml, $menu);
53 $this->assertTrue(isset($menu['civicrm/foo/bar']));
54 $this->assertEquals('Foo Bar', $menu['civicrm/foo/bar']['title']);
55 $this->assertEquals(array('alpha', 'beta'), $menu['civicrm/foo/bar']['ids_arguments']['json']);
56 $this->assertEquals(array('gamma'), $menu['civicrm/foo/bar']['ids_arguments']['exceptions']);
57 $this->assertEquals(array(), $menu['civicrm/foo/bar']['ids_arguments']['html']);
59 $idsConfig = CRM_Core_IDS
::createRouteConfig($menu['civicrm/foo/bar']);
61 $this->assertTrue(in_array('alpha', $idsConfig['General']['json']));
63 $this->assertTrue(in_array('beta', $idsConfig['General']['json']));
65 $this->assertTrue(in_array('gamma', $idsConfig['General']['exceptions']));
67 $this->assertTrue(in_array('thankyou_text', $idsConfig['General']['exceptions']));
71 * Check that novel data elements in the menu are correctly
74 public function testModuleData() {
75 CRM_Core_Menu
::store(TRUE);
76 $item = CRM_Core_Menu
::get('civicrm/case');
77 $this->assertFalse(isset($item['ids_arguments']['exceptions']));
78 $this->assertFalse(isset($item['whimsy']));
80 CRM_Utils_Hook
::singleton()->setHook('civicrm_alterMenu', function(&$items) {
81 $items['civicrm/case']['ids_arguments']['exceptions'][] = 'foobar';
82 $items['civicrm/case']['whimsy'] = 'godliness';
85 CRM_Core_Menu
::store(TRUE);
86 $item = CRM_Core_Menu
::get('civicrm/case');
87 $this->assertTrue(in_array('foobar', $item['ids_arguments']['exceptions']));
88 $this->assertEquals('godliness', $item['whimsy']);
94 public function pathArguments() {
95 // array(0 => string $input, 1 => array $expectedOutput)
97 //$cases[] = array(NULL, array());
98 //$cases[] = array('', array());
99 //$cases[] = array('freestanding', array('freestanding' => NULL));
100 $cases[] = array('addSequence=1', array('addSequence' => '1'));
101 $cases[] = array('attachUpload=1', array('attachUpload' => '1'));
102 $cases[] = array('mode=256', array('mode' => '256'));
104 'mode=256,addSequence=1,attachUpload=1',
105 array('mode' => '256', 'addSequence' => '1', 'attachUpload' => 1),
108 'mode=256,urlToSession=a:b:c:d',
111 'urlToSession' => array(
112 array('urlVar' => 'a', 'sessionVar' => 'b', 'type' => 'c', 'default' => 'd'),
117 'mode=256,urlToSession=a:b:c:d;z:y:x:w',
120 'urlToSession' => array(
121 array('urlVar' => 'a', 'sessionVar' => 'b', 'type' => 'c', 'default' => 'd'),
122 array('urlVar' => 'z', 'sessionVar' => 'y', 'type' => 'x', 'default' => 'w'),
126 $cases[] = array('url=whiz!;.:#=%/|+bang?', array('url' => 'whiz!;.:#=%/|+bang?'));
131 * @param $inputString
132 * @param $expectedArray
133 * @dataProvider pathArguments
135 public function testGetArrayForPathArgs($inputString, $expectedArray) {
136 $actual = CRM_Core_Menu
::getArrayForPathArgs($inputString);
137 $this->assertEquals($expectedArray, $actual);