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']);
36 * Check that novel data elements in the menu are correctly
39 public function testModuleData() {
40 CRM_Core_Menu
::store(TRUE);
41 $item = CRM_Core_Menu
::get('civicrm/case');
42 $this->assertFalse(isset($item['ids_arguments']['exception']));
43 $this->assertFalse(isset($item['whimsy']));
45 CRM_Utils_Hook
::singleton()->setHook('civicrm_alterMenu', function(&$items){
46 $items['civicrm/case']['ids_arguments']['exception'][] = 'foobar';
47 $items['civicrm/case']['whimsy'] = 'godliness';
50 CRM_Core_Menu
::store(TRUE);
51 $item = CRM_Core_Menu
::get('civicrm/case');
52 $this->assertTrue(in_array('foobar', $item['ids_arguments']['exception']));
53 $this->assertEquals('godliness', $item['whimsy']);
59 public function pathArguments() {
60 $cases = array(); // array(0 => string $input, 1 => array $expectedOutput)
61 //$cases[] = array(NULL, array());
62 //$cases[] = array('', array());
63 //$cases[] = array('freestanding', array('freestanding' => NULL));
64 $cases[] = array('addSequence=1', array('addSequence' => '1'));
65 $cases[] = array('attachUpload=1', array('attachUpload' => '1'));
66 $cases[] = array('mode=256', array('mode' => '256'));
68 'mode=256,addSequence=1,attachUpload=1',
69 array('mode' => '256', 'addSequence' => '1', 'attachUpload' => 1),
72 'mode=256,urlToSession=a:b:c:d',
75 'urlToSession' => array(
76 array('urlVar' => 'a', 'sessionVar' => 'b', 'type' => 'c', 'default' => 'd'),
81 'mode=256,urlToSession=a:b:c:d;z:y:x:w',
84 'urlToSession' => array(
85 array('urlVar' => 'a', 'sessionVar' => 'b', 'type' => 'c', 'default' => 'd'),
86 array('urlVar' => 'z', 'sessionVar' => 'y', 'type' => 'x', 'default' => 'w'),
90 $cases[] = array('url=whiz!;.:#=%/|+bang?', array('url' => 'whiz!;.:#=%/|+bang?'));
96 * @param $expectedArray
97 * @dataProvider pathArguments
99 public function testGetArrayForPathArgs($inputString, $expectedArray) {
100 $actual = CRM_Core_Menu
::getArrayForPathArgs($inputString);
101 $this->assertEquals($expectedArray, $actual);