<?php
-require_once 'CiviTest/CiviUnitTestCase.php';
/**
* Class CRM_Group_Page_AjaxTest
+ * @group headless
*/
class CRM_Group_Page_AjaxTest extends CiviUnitTestCase {
/**
protected $_permissionedGroup;
/**
* AS disabled group the contact has permission to.
- * @var unknown
+ * @var int
*/
protected $_permissionedDisabledGroup;
+ /**
+ * @var CRM_Utils_Hook_UnitTests
+ */
public $hookClass;
protected $_params = array();
* @param $permission
*/
public function setPermissionAndRequest($permission) {
- CRM_Core_Config::singleton()->userPermissionClass->permissions = array($permission);
+ CRM_Core_Config::singleton()->userPermissionClass->permissions = (array) $permission;
CRM_Contact_BAO_Group::getPermissionClause(TRUE);
global $_REQUEST;
$_REQUEST = $this->_params;
* @param $hook
*/
public function setHookAndRequest($permission, $hook) {
- CRM_Core_Config::singleton()->userPermissionClass->permissions = array($permission);
+ CRM_Core_Config::singleton()->userPermissionClass->permissions = (array) $permission;
$this->hookClass->setHook('civicrm_aclGroup', array($this, $hook));
CRM_Contact_BAO_Group::getPermissionClause(TRUE);
global $_REQUEST;
* Retrieve groups as 'view all contacts'
*/
public function testGroupListViewAllContacts() {
+ $this->setPermissionAndRequest(array('view all contacts', 'edit groups'));
+ list($groups, $total) = CRM_Group_Page_AJAX::getGroupList();
+ $this->assertEquals(2, $total);
+ $this->assertEquals('<span class="crm-editable crmf-title">pick-me-active</span>', $groups[2]['group_name']);
+ $this->assertEquals('<span class="crm-editable crmf-title">not-me-active</span>', $groups[4]['group_name']);
+ }
+
+ /**
+ * Check Group Edit w/o 'edit groups' permission.
+ */
+ public function testGroupEditWithAndWithoutPermission() {
$this->setPermissionAndRequest('view all contacts');
list($groups, $total) = CRM_Group_Page_AJAX::getGroupList();
$this->assertEquals(2, $total);
$this->assertEquals('pick-me-active', $groups[2]['group_name']);
$this->assertEquals('not-me-active', $groups[4]['group_name']);
+
+ // as per changes made in PR-6822
+ $this->setPermissionAndRequest(array('view all contacts', 'edit groups'));
+ list($groups, $total) = CRM_Group_Page_AJAX::getGroupList();
+ $this->assertEquals(2, $total);
+ $this->assertEquals('<span class="crm-editable crmf-title">pick-me-active</span>', $groups[2]['group_name']);
+ $this->assertEquals('<span class="crm-editable crmf-title">not-me-active</span>', $groups[4]['group_name']);
}
/**
*/
public function testGroupListViewAllContactsFoundTitle() {
$this->_params['title'] = 'p';
- $this->setPermissionAndRequest('view all contacts');
+ $this->setPermissionAndRequest(array('view all contacts', 'edit groups'));
list($groups, $total) = CRM_Group_Page_AJAX::getGroupList();
$this->assertEquals(2, $total);
- $this->assertEquals('pick-me-active', $groups[2]['group_name']);
- $this->assertEquals('pick-me-disabled', $groups[1]['group_name']);
+ $this->assertEquals('<span class="crm-editable crmf-title">pick-me-active</span>', $groups[2]['group_name']);
+ $this->assertEquals('<span class="crm-editable crmf-title">pick-me-disabled</span>', $groups[1]['group_name']);
}
/**
* Retrieve groups as 'edit all contacts'
*/
public function testGroupListEditAllContacts() {
- $this->setPermissionAndRequest('edit all contacts');
+ $this->setPermissionAndRequest(array('edit all contacts', 'edit groups'));
list($groups, $total) = CRM_Group_Page_AJAX::getGroupList();
$this->assertEquals(2, $total);
- $this->assertEquals('pick-me-active', $groups[2]['group_name']);
- $this->assertEquals('not-me-active', $groups[4]['group_name']);
+ $this->assertEquals('<span class="crm-editable crmf-title">pick-me-active</span>', $groups[2]['group_name']);
+ $this->assertEquals('<span class="crm-editable crmf-title">not-me-active</span>', $groups[4]['group_name']);
}
/**
*/
public function testGroupListViewAllContactsEnabled() {
$this->_params['status'] = 1;
- $this->setPermissionAndRequest('view all contacts');
+ $this->setPermissionAndRequest(array('view all contacts', 'edit groups'));
list($groups, $total) = CRM_Group_Page_AJAX::getGroupList();
$this->assertEquals(2, $total);
- $this->assertEquals('pick-me-active', $groups[2]['group_name']);
- $this->assertEquals('not-me-active', $groups[4]['group_name']);
+ $this->assertEquals('<span class="crm-editable crmf-title">pick-me-active</span>', $groups[2]['group_name']);
+ $this->assertEquals('<span class="crm-editable crmf-title">not-me-active</span>', $groups[4]['group_name']);
}
/**
*/
public function testGroupListViewAllContactsDisabled() {
$this->_params['status'] = 2;
- $this->setPermissionAndRequest('view all contacts');
+ $this->setPermissionAndRequest(array('view all contacts', 'edit groups'));
list($groups, $total) = CRM_Group_Page_AJAX::getGroupList();
$this->assertEquals(2, $total);
- $this->assertEquals('pick-me-disabled', $groups[1]['group_name']);
- $this->assertEquals('not-me-disabled', $groups[3]['group_name']);
+ $this->assertEquals('<span class="crm-editable crmf-title">pick-me-disabled</span>', $groups[1]['group_name']);
+ $this->assertEquals('<span class="crm-editable crmf-title">not-me-disabled</span>', $groups[3]['group_name']);
}
/**
public function testGroupListViewAllContactsDisabledNotFoundTitle() {
$this->_params['status'] = 2;
$this->_params['title'] = 'n';
- $this->setPermissionAndRequest('view all contacts');
+ $this->setPermissionAndRequest(array('view all contacts', 'edit groups'));
list($groups, $total) = CRM_Group_Page_AJAX::getGroupList();
$this->assertEquals(1, $total);
- $this->assertEquals('not-me-disabled', $groups[3]['group_name']);
+ $this->assertEquals('<span class="crm-editable crmf-title">not-me-disabled</span>', $groups[3]['group_name']);
}
/**
public function testGroupListViewAllContactsDisabledFoundTitle() {
$this->_params['status'] = 2;
$this->_params['title'] = 'p';
- $this->setPermissionAndRequest('view all contacts');
+ $this->setPermissionAndRequest(array('view all contacts', 'edit groups'));
list($groups, $total) = CRM_Group_Page_AJAX::getGroupList();
$this->assertEquals(1, $total);
- $this->assertEquals('pick-me-disabled', $groups[1]['group_name']);
+ $this->assertEquals('<span class="crm-editable crmf-title">pick-me-disabled</span>', $groups[1]['group_name']);
}
/**
*/
public function testGroupListViewAllContactsAll() {
$this->_params['status'] = 3;
- $this->setPermissionAndRequest('view all contacts');
+ $this->setPermissionAndRequest(array('view all contacts', 'edit groups'));
list($groups, $total) = CRM_Group_Page_AJAX::getGroupList();
$this->assertEquals(4, $total);
- $this->assertEquals('pick-me-disabled', $groups[1]['group_name']);
- $this->assertEquals('not-me-disabled', $groups[3]['group_name']);
- $this->assertEquals('pick-me-active', $groups[2]['group_name']);
- $this->assertEquals('not-me-active', $groups[4]['group_name']);
+ $this->assertEquals('<span class="crm-editable crmf-title">pick-me-disabled</span>', $groups[1]['group_name']);
+ $this->assertEquals('<span class="crm-editable crmf-title">not-me-disabled</span>', $groups[3]['group_name']);
+ $this->assertEquals('<span class="crm-editable crmf-title">pick-me-active</span>', $groups[2]['group_name']);
+ $this->assertEquals('<span class="crm-editable crmf-title">not-me-active</span>', $groups[4]['group_name']);
}
public function testTraditionalACL() {
$this->setupACL();
+ $this->setPermissionAndRequest('edit groups');
list($groups, $total) = CRM_Group_Page_AJAX::getGroupList();
$this->assertEquals(1, count($groups), 'Returned groups should exclude disabled by default');
$this->assertEquals(1, $total, 'Total needs to be set correctly');
- $this->assertEquals('pick-me-active', $groups[2]['group_name']);
+ $this->assertEquals('<span class="crm-editable crmf-title">pick-me-active</span>', $groups[2]['group_name']);
}
public function testTraditionalACLNotFoundTitle() {
public function testTraditionalACLFoundTitle() {
$this->_params['title'] = 'p';
$this->setupACL();
+ $this->setPermissionAndRequest('edit groups');
list($groups, $total) = CRM_Group_Page_AJAX::getGroupList();
$this->assertEquals(2, count($groups), 'Returned groups should exclude disabled by default');
$this->assertEquals(2, $total, 'Total needs to be set correctly');
- $this->assertEquals('pick-me-active', $groups[2]['group_name']);
- $this->assertEquals('pick-me-disabled', $groups[1]['group_name']);
+ $this->assertEquals('<span class="crm-editable crmf-title">pick-me-active</span>', $groups[2]['group_name']);
+ $this->assertEquals('<span class="crm-editable crmf-title">pick-me-disabled</span>', $groups[1]['group_name']);
}
public function testTraditionalACLDisabled() {
$this->_params['status'] = 2;
$this->setupACL();
+ $this->setPermissionAndRequest('edit groups');
list($groups, $total) = CRM_Group_Page_AJAX::getGroupList();
$this->assertEquals(1, count($groups), 'Returned groups should exclude disabled by default');
$this->assertEquals(1, $total, 'Total needs to be set correctly');
- $this->assertEquals('pick-me-disabled', $groups[1]['group_name']);
+ $this->assertEquals('<span class="crm-editable crmf-title">pick-me-disabled</span>', $groups[1]['group_name']);
}
public function testTraditionalACLDisabledFoundTitle() {
$this->_params['status'] = 2;
$this->_params['title'] = 'p';
$this->setupACL();
+ $this->setPermissionAndRequest('edit groups');
list($groups, $total) = CRM_Group_Page_AJAX::getGroupList();
$this->assertEquals(1, count($groups), 'Returned groups should exclude disabled by default');
$this->assertEquals(1, $total, 'Total needs to be set correctly');
- $this->assertEquals('pick-me-disabled', $groups[1]['group_name']);
+ $this->assertEquals('<span class="crm-editable crmf-title">pick-me-disabled</span>', $groups[1]['group_name']);
}
public function testTraditionalACLDisabledNotFoundTitle() {
public function testTraditionalACLEnabled() {
$this->_params['status'] = 1;
$this->setupACL();
+ $this->setPermissionAndRequest('edit groups');
list($groups, $total) = CRM_Group_Page_AJAX::getGroupList();
$this->assertEquals(1, count($groups), 'Returned groups should exclude disabled by default');
$this->assertEquals(1, $total, 'Total needs to be set correctly');
- $this->assertEquals('pick-me-active', $groups[2]['group_name']);
+ $this->assertEquals('<span class="crm-editable crmf-title">pick-me-active</span>', $groups[2]['group_name']);
}
public function testTraditionalACLAll() {
$this->_params['status'] = 3;
$this->setupACL();
+ $this->setPermissionAndRequest('edit groups');
list($groups, $total) = CRM_Group_Page_AJAX::getGroupList();
$this->assertEquals(2, count($groups), 'Returned groups should exclude disabled by default');
$this->assertEquals(2, $total, 'Total needs to be set correctly');
- $this->assertEquals('pick-me-active', $groups[2]['group_name']);
- $this->assertEquals('pick-me-disabled', $groups[1]['group_name']);
+ $this->assertEquals('<span class="crm-editable crmf-title">pick-me-active</span>', $groups[2]['group_name']);
+ $this->assertEquals('<span class="crm-editable crmf-title">pick-me-disabled</span>', $groups[1]['group_name']);
}
/**
*/
public function testGroupListAclGroupHookDisabled() {
$this->_params['status'] = 2;
- $this->setHookAndRequest('access CiviCRM', 'hook_civicrm_aclGroup');
+ $this->setHookAndRequest(array('access CiviCRM', 'edit groups'), 'hook_civicrm_aclGroup');
list($groups, $total) = CRM_Group_Page_AJAX::getGroupList();
$this->assertEquals(1, count($groups), 'Returned groups should exclude disabled by default');
$this->assertEquals(1, $total, 'Total needs to be set correctly');
- $this->assertEquals('pick-me-disabled', $groups[1]['group_name']);
+ $this->assertEquals('<span class="crm-editable crmf-title">pick-me-disabled</span>', $groups[1]['group_name']);
}
/**
public function testGroupListAclGroupHookDisabledFound() {
$this->_params['status'] = 2;
$this->_params['title'] = 'p';
- $this->setHookAndRequest('access CiviCRM', 'hook_civicrm_aclGroup');
+ $this->setHookAndRequest(array('access CiviCRM', 'edit groups'), 'hook_civicrm_aclGroup');
list($groups, $total) = CRM_Group_Page_AJAX::getGroupList();
$this->assertEquals(1, count($groups), 'Returned groups should exclude disabled by default');
$this->assertEquals(1, $total, 'Total needs to be set correctly');
- $this->assertEquals('pick-me-disabled', $groups[1]['group_name']);
+ $this->assertEquals('<span class="crm-editable crmf-title">pick-me-disabled</span>', $groups[1]['group_name']);
}
/**
* ACL Group hook.
*/
public function testGroupListAclGroupHook() {
- $this->setHookAndRequest('access CiviCRM', 'hook_civicrm_aclGroup');
+ $this->setHookAndRequest(array('access CiviCRM', 'edit groups'), 'hook_civicrm_aclGroup');
list($groups, $total) = CRM_Group_Page_AJAX::getGroupList();
$this->assertEquals(1, count($groups), 'Returned groups should exclude disabled by default');
$this->assertEquals(1, $total, 'Total needs to be set correctly');
- $this->assertEquals('pick-me-active', $groups[2]['group_name']);
+ $this->assertEquals('<span class="crm-editable crmf-title">pick-me-active</span>', $groups[2]['group_name']);
}
/**
*/
public function testGroupListAclGroupHookTitleFound() {
$this->_params['title'] = 'p';
- $this->setHookAndRequest('access CiviCRM', 'hook_civicrm_aclGroup');
+ $this->setHookAndRequest(array('access CiviCRM', 'edit groups'), 'hook_civicrm_aclGroup');
list($groups, $total) = CRM_Group_Page_AJAX::getGroupList();
$this->assertEquals(2, count($groups), 'Returned groups should exclude disabled by default');
$this->assertEquals(2, $total, 'Total needs to be set correctly');
- $this->assertEquals('pick-me-active', $groups[2]['group_name']);
- $this->assertEquals('pick-me-disabled', $groups[1]['group_name']);
+ $this->assertEquals('<span class="crm-editable crmf-title">pick-me-active</span>', $groups[2]['group_name']);
+ $this->assertEquals('<span class="crm-editable crmf-title">pick-me-disabled</span>', $groups[1]['group_name']);
}
/**
*/
public function testGroupListAclGroupHookAll() {
$this->_params['status'] = 3;
- $this->setHookAndRequest('access CiviCRM', 'hook_civicrm_aclGroup');
+ $this->setHookAndRequest(array('access CiviCRM', 'edit groups'), 'hook_civicrm_aclGroup');
list($groups, $total) = CRM_Group_Page_AJAX::getGroupList();
$this->assertEquals(2, count($groups), 'Returned groups should exclude disabled by default');
$this->assertEquals(2, $total, 'Total needs to be set correctly');
- $this->assertEquals('pick-me-active', $groups[2]['group_name']);
- $this->assertEquals('pick-me-disabled', $groups[1]['group_name']);
+ $this->assertEquals('<span class="crm-editable crmf-title">pick-me-active</span>', $groups[2]['group_name']);
+ $this->assertEquals('<span class="crm-editable crmf-title">pick-me-disabled</span>', $groups[1]['group_name']);
}
/**
*/
public function testGroupListAclGroupHookEnabled() {
$this->_params['status'] = 1;
- $this->setHookAndRequest('access CiviCRM', 'hook_civicrm_aclGroup');
+ $this->setHookAndRequest(array('access CiviCRM', 'edit groups'), 'hook_civicrm_aclGroup');
list($groups, $total) = CRM_Group_Page_AJAX::getGroupList();
$this->assertEquals(1, count($groups), 'Returned groups should exclude disabled by default');
$this->assertEquals(1, $total, 'Total needs to be set correctly');
- $this->assertEquals('pick-me-active', $groups[2]['group_name']);
+ $this->assertEquals('<span class="crm-editable crmf-title">pick-me-active</span>', $groups[2]['group_name']);
}
/**