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']);
60 $this->assertTrue(in_array('alpha', $idsConfig['General']['json'])); // XML
61 $this->assertTrue(in_array('beta', $idsConfig['General']['json'])); // XML
62 $this->assertTrue(in_array('gamma', $idsConfig['General']['exceptions'])); // XML
63 $this->assertTrue(in_array('thankyou_text', $idsConfig['General']['exceptions'])); // Inherited
67 * Check that novel data elements in the menu are correctly
70 public function testModuleData() {
71 CRM_Core_Menu
::store(TRUE);
72 $item = CRM_Core_Menu
::get('civicrm/case');
73 $this->assertFalse(isset($item['ids_arguments']['exceptions']));
74 $this->assertFalse(isset($item['whimsy']));
76 CRM_Utils_Hook
::singleton()->setHook('civicrm_alterMenu', function(&$items){
77 $items['civicrm/case']['ids_arguments']['exceptions'][] = 'foobar';
78 $items['civicrm/case']['whimsy'] = 'godliness';
81 CRM_Core_Menu
::store(TRUE);
82 $item = CRM_Core_Menu
::get('civicrm/case');
83 $this->assertTrue(in_array('foobar', $item['ids_arguments']['exceptions']));
84 $this->assertEquals('godliness', $item['whimsy']);
90 public function pathArguments() {
91 $cases = array(); // array(0 => string $input, 1 => array $expectedOutput)
92 //$cases[] = array(NULL, array());
93 //$cases[] = array('', array());
94 //$cases[] = array('freestanding', array('freestanding' => NULL));
95 $cases[] = array('addSequence=1', array('addSequence' => '1'));
96 $cases[] = array('attachUpload=1', array('attachUpload' => '1'));
97 $cases[] = array('mode=256', array('mode' => '256'));
99 'mode=256,addSequence=1,attachUpload=1',
100 array('mode' => '256', 'addSequence' => '1', 'attachUpload' => 1),
103 'mode=256,urlToSession=a:b:c:d',
106 'urlToSession' => array(
107 array('urlVar' => 'a', 'sessionVar' => 'b', 'type' => 'c', 'default' => 'd'),
112 'mode=256,urlToSession=a:b:c:d;z:y:x:w',
115 'urlToSession' => array(
116 array('urlVar' => 'a', 'sessionVar' => 'b', 'type' => 'c', 'default' => 'd'),
117 array('urlVar' => 'z', 'sessionVar' => 'y', 'type' => 'x', 'default' => 'w'),
121 $cases[] = array('url=whiz!;.:#=%/|+bang?', array('url' => 'whiz!;.:#=%/|+bang?'));
126 * @param $inputString
127 * @param $expectedArray
128 * @dataProvider pathArguments
130 public function testGetArrayForPathArgs($inputString, $expectedArray) {
131 $actual = CRM_Core_Menu
::getArrayForPathArgs($inputString);
132 $this->assertEquals($expectedArray, $actual);