return $getCount ? count($activities) : $activities;
}
$activityIDs = explode(',', $activityIDs);
- }
-
- // CRM-20441 Check if user has access to the activities.
- // This is a temporary fix we need to figure out the rules around
- // the right permissions to access Activities.
- // This attpemts to reduce fatal errors in 4.7.19 RC.
- if (!empty($activityIDs)) {
- foreach ($activityIDs as $key => $activityId) {
- try {
- civicrm_api3('Activity', 'get', array('id' => $activityId, 'check_permissions' => 1));
- }
- catch (Exception $e) {
- unset($activityIDs[$key]);
+ // CRM-20441 Check if user has access to the activities.
+ // This is a temporary fix we need to figure out the rules around
+ // the right permissions to access Activities.
+ // This attempts to reduce fatal errors in 4.7.19 RC.
+ if (!empty($activityIDs)) {
+ foreach ($activityIDs as $key => $activityId) {
+ try {
+ civicrm_api3('Activity', 'get', array('id' => $activityId, 'check_permissions' => 1));
+ }
+ catch (Exception $e) {
+ unset($activityIDs[$key]);
+ }
}
}
- }
- if (empty($activityIDs)) {
- return $getCount ? count($activities) : $activities;
+ if (empty($activityIDs)) {
+ return $getCount ? count($activities) : $activities;
+ }
}
// fetch all active activity types
* Test getActivities BAO method for getting count.
*/
public function testGetActivitiesCountForAdminDashboard() {
- $op = new PHPUnit_Extensions_Database_Operation_Insert();
- $op->execute($this->_dbconn,
- $this->createFlatXMLDataSet(
- dirname(__FILE__) . '/activities_for_dashboard_count.xml'
- )
- );
-
- $params = array(
- 'contact_id' => NULL,
- 'admin' => TRUE,
- 'caseId' => NULL,
- 'context' => 'home',
- 'activity_type_id' => NULL,
- 'offset' => 0,
- 'rowCount' => 0,
- 'sort' => NULL,
- );
- $activityCount = CRM_Activity_BAO_Activity::getActivities($params, TRUE);
-
- //since we are loading activities from dataset, we know total number of activities
- // 8 schedule activities that should be shown on dashboard
- $count = 8;
- $this->assertEquals($count, $activityCount);
+ $this->setUpForActivityDashboardTests();
+ $activityCount = CRM_Activity_BAO_Activity::getActivities($this->_params, TRUE);
+ $this->assertEquals(8, $activityCount);
}
/**
* Test getActivities BAO method.
*/
public function testGetActivitiesForAdminDashboard() {
- $op = new PHPUnit_Extensions_Database_Operation_Insert();
- $op->execute($this->_dbconn,
- $this->createFlatXMLDataSet(
- dirname(__FILE__) . '/activities_for_dashboard_count.xml'
- )
- );
-
- $params = array(
- 'contact_id' => NULL,
- 'admin' => TRUE,
- 'caseId' => NULL,
- 'context' => 'home',
- 'activity_type_id' => NULL,
- 'offset' => 0,
- 'rowCount' => 0,
- 'sort' => NULL,
- );
- $activities = CRM_Activity_BAO_Activity::getActivities($params);
+ $this->setUpForActivityDashboardTests();
+ $activities = CRM_Activity_BAO_Activity::getActivities($this->_params);
//since we are loading activities from dataset, we know total number of activities
// with no contact ID and there should be 8 schedule activities shown on dashboard
}
}
+ /**
+ * Test getActivities BAO method.
+ */
+ public function testGetActivitiesForAdminDashboardNoViewContacts() {
+ CRM_Core_Config::singleton()->userPermissionClass->permissions = array('access CiviCRM');
+ $this->setUpForActivityDashboardTests();
+ $activities = CRM_Activity_BAO_Activity::getActivities($this->_params);
+ $this->assertEquals(0, count($activities));
+
+ }
+
/**
* Test getActivities BAO method.
*/
// to change the domain setting, which isn't straight forward in test environment
}
+ /**
+ * Set up for testing activity queries.
+ */
+ protected function setUpForActivityDashboardTests() {
+ $op = new PHPUnit_Extensions_Database_Operation_Insert();
+ $op->execute($this->_dbconn,
+ $this->createFlatXMLDataSet(
+ dirname(__FILE__) . '/activities_for_dashboard_count.xml'
+ )
+ );
+
+ $this->_params = array(
+ 'contact_id' => NULL,
+ 'admin' => TRUE,
+ 'caseId' => NULL,
+ 'context' => 'home',
+ 'activity_type_id' => NULL,
+ 'offset' => 0,
+ 'rowCount' => 0,
+ 'sort' => NULL,
+ );
+ }
+
}