*
* Here we ensure we are starting from a default report navigation.
*/
- public function setUp() {
+ public function setUp(): void {
parent::setUp();
CRM_Core_BAO_Navigation::rebuildReportsNavigation(CRM_Core_Config::domainID());
}
* by rebuilding reports.
*/
public function testNoDuplicateAllReportsLink() {
- $existing_links = $this->callAPISuccess('Navigation', 'get', array('label' => 'All Reports', 'sequential' => 1));
+ $existing_links = $this->callAPISuccess('Navigation', 'get', ['label' => 'All Reports', 'sequential' => 1]);
$this->assertNotEquals($existing_links['values'][0]['parent_id'], $existing_links['values'][1]['parent_id']);
CRM_Core_BAO_Navigation::rebuildReportsNavigation(CRM_Core_Config::domainID());
- $new_links = $this->callAPISuccess('Navigation', 'get', array('label' => 'All Reports', 'sequential' => 1));
+ $new_links = $this->callAPISuccess('Navigation', 'get', ['label' => 'All Reports', 'sequential' => 1]);
$this->assertEquals($existing_links['values'][0]['parent_id'], $new_links['values'][0]['parent_id']);
$this->assertEquals($existing_links['values'][1]['parent_id'], $new_links['values'][1]['parent_id']);
}
$name = "Test Menu Link {$random_string}";
$url = "civicrm/test/{$random_string}";
$url_params = "reset=1";
- $params = array(
+ $params = [
'name' => $name,
'label' => ts($name),
'url' => "{$url}?{$url_params}",
'parent_id' => NULL,
'is_active' => TRUE,
- 'permission' => array(
+ 'permission' => [
'access CiviCRM',
- ),
- );
+ ],
+ ];
CRM_Core_BAO_Navigation::add($params);
$new_nav = CRM_Core_BAO_Navigation::getNavItemByUrl($url, $url_params);
$this->assertObjectHasAttribute('id', $new_nav);
$name = "Test Menu Link {$random_string}";
$url = "civicrm/test/{$random_string}";
$url_params = "reset=1&output=criteria";
- $params = array(
+ $params = [
'name' => $name,
'label' => ts($name),
'url' => "{$url}?{$url_params}",
'parent_id' => NULL,
'is_active' => TRUE,
- 'permission' => array(
+ 'permission' => [
'access CiviCRM',
- ),
- );
+ ],
+ ];
CRM_Core_BAO_Navigation::add($params);
$new_nav = CRM_Core_BAO_Navigation::getNavItemByUrl($url, 'reset=1%');
$this->assertObjectHasAttribute('id', $new_nav);
* everywhere. They should be unchanged.
*/
public function testFixNavigationMenu_preserveIDs() {
- $input[10] = array(
- 'attributes' => array(
+ $input[10] = [
+ 'attributes' => [
'label' => 'Custom Menu Entry',
'parentID' => NULL,
'navID' => 10,
'active' => 1,
- ),
- 'child' => array(
- '11' => array(
- 'attributes' => array(
+ ],
+ 'child' => [
+ '11' => [
+ 'attributes' => [
'label' => 'Custom Child Menu',
'parentID' => 10,
'navID' => 11,
- ),
+ ],
'child' => NULL,
- ),
- ),
- );
+ ],
+ ],
+ ];
$output = $input;
CRM_Core_BAO_Navigation::fixNavigationMenu($output);
* should be filled in, and others should be preserved.
*/
public function testFixNavigationMenu_inferIDs() {
- $input[10] = array(
- 'attributes' => array(
+ $input[10] = [
+ 'attributes' => [
'label' => 'Custom Menu Entry',
'parentID' => NULL,
'navID' => 10,
'active' => 1,
- ),
- 'child' => array(
- '0' => array(
- 'attributes' => array(
+ ],
+ 'child' => [
+ '0' => [
+ 'attributes' => [
'label' => 'Custom Child Menu',
- ),
+ ],
'child' => NULL,
- ),
- '100' => array(
- 'attributes' => array(
+ ],
+ '100' => [
+ 'attributes' => [
'label' => 'Custom Child Menu 2',
'navID' => 100,
- ),
+ ],
'child' => NULL,
- ),
- ),
- );
+ ],
+ ],
+ ];
$output = $input;
CRM_Core_BAO_Navigation::fixNavigationMenu($output);
}
public function testFixNavigationMenu_inferIDs_deep() {
- $input[10] = array(
- 'attributes' => array(
+ $input[10] = [
+ 'attributes' => [
'label' => 'Custom Menu Entry',
'parentID' => NULL,
'navID' => 10,
'active' => 1,
- ),
- 'child' => array(
- '0' => array(
- 'attributes' => array(
+ ],
+ 'child' => [
+ '0' => [
+ 'attributes' => [
'label' => 'Custom Child Menu',
- ),
- 'child' => array(
- '100' => array(
- 'attributes' => array(
+ ],
+ 'child' => [
+ '100' => [
+ 'attributes' => [
'label' => 'Custom Child Menu 2',
'navID' => 100,
- ),
+ ],
'child' => NULL,
- ),
- ),
- ),
- ),
- );
+ ],
+ ],
+ ],
+ ],
+ ];
$output = $input;
CRM_Core_BAO_Navigation::fixNavigationMenu($output);
CRM_Core_BAO_ConfigSetting::disableComponent('CiviContribute');
$this->assertFalse(CRM_Core_BAO_Navigation::checkPermission($menuItem));
+
+ CRM_Core_BAO_ConfigSetting::enableComponent('CiviMail');
+ CRM_Core_Config::singleton()->userPermissionClass->permissions = ['access CiviMail', 'delete in CiviMail'];
+ $menuItem = [
+ 'permission' => 'access CiviMail, delete in CiviMail',
+ 'operator' => 'AND',
+ ];
+ $this->assertTrue(CRM_Core_BAO_Navigation::checkPermission($menuItem));
+ $menuItem['operator'] = 'OR';
+ $this->assertTrue(CRM_Core_BAO_Navigation::checkPermission($menuItem));
+ CRM_Core_Config::singleton()->userPermissionClass->permissions = ['delete in CiviMail'];
+ $this->assertTrue(CRM_Core_BAO_Navigation::checkPermission($menuItem));
+ CRM_Core_Config::singleton()->userPermissionClass->permissions = ['access CiviCRM'];
+ $this->assertFalse(CRM_Core_BAO_Navigation::checkPermission($menuItem));
+ CRM_Core_Config::singleton()->userPermissionClass->permissions = ['access CiviMail', 'delete in CiviMail'];
+ CRM_Core_BAO_ConfigSetting::disableComponent('CiviMail');
+ $this->assertFalse(CRM_Core_BAO_Navigation::checkPermission($menuItem));
}
}