parent::tearDown();
}
- /**
- * Setup or clean up SMS tests
- * @param bool $teardown
- *
- * @throws \CiviCRM_API3_Exception
- */
- public function setupForSmsTests($teardown = FALSE) {
- require_once 'CiviTest/CiviTestSMSProvider.php';
-
- // Option value params for CiviTestSMSProvider
- $groupID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'sms_provider_name', 'id', 'name');
- $params = array(
- 'option_group_id' => $groupID,
- 'label' => 'unittestSMS',
- 'value' => 'unit.test.sms',
- 'name' => 'CiviTestSMSProvider',
- 'is_default' => 1,
- 'is_active' => 1,
- 'version' => 3,
- );
-
- if ($teardown) {
- // Test completed, delete provider
- $providerOptionValueResult = civicrm_api3('option_value', 'get', $params);
- civicrm_api3('option_value', 'delete', array('id' => $providerOptionValueResult['id']));
- return;
- }
-
- // Create an SMS provider "CiviTestSMSProvider". Civi handles "CiviTestSMSProvider" as a special case and allows it to be instantiated
- // in CRM/Sms/Provider.php even though it is not an extension.
- civicrm_api3('option_value', 'create', $params);
- }
-
/**
* Test case for create() method.
*/
'contact_id' => $contactId,
'context' => 'activity',
);
- foreach (array(CRM_Activity_BAO_Activity::getActivities($params)) as $activities) {
- //verify target count
- $this->assertEquals($targetCount, $activities[1]['target_contact_counter']);
- $this->assertEquals([$targetContactIDs[0] => 'Anderson, Anthony'], $activities[1]['target_contact_name']);
- }
-
+ $activities = CRM_Activity_BAO_Activity::getActivities($params);
+ //verify target count
+ $this->assertEquals($targetCount, $activities[1]['target_contact_count']);
+ $this->assertEquals([$targetContactIDs[0] => 'Anderson, Anthony'], $activities[1]['target_contact_name']);
+ $this->assertEquals('Anderson, Anthony', $activities[1]['source_contact_name']);
+ $this->assertEquals('Anderson, Anthony', $activities[1]['assignee_contact_name'][4]);
}
/**
/**
* Test getActivities BAO method.
*/
- public function testGetActivitiesforContactSummary() {
+ public function testGetActivitiesForContactSummary() {
$this->createTestActivities();
$contactID = 9;
//since we are loading activities from dataset, we know total number of activities for this contact
// 5 activities, Contact Summary should show all activities
$count = 5;
- foreach (array(CRM_Activity_BAO_Activity::getActivities($params)) as $activities) {
-
- $this->assertEquals($count, count($activities));
-
- foreach ($activities as $key => $value) {
- $this->assertEquals($value['subject'], "subject {$key}", 'Verify activity subject is correct.');
+ $activities = CRM_Activity_BAO_Activity::getActivities($params);
+ $this->assertEquals($count, count($activities));
+ foreach ($activities as $key => $value) {
+ $this->assertEquals($value['subject'], "subject {$key}", 'Verify activity subject is correct.');
- if ($key > 8) {
- $this->assertEquals($value['status_id'], 2, 'Verify all activities are scheduled.');
- }
- else {
- $this->assertEquals($value['status_id'], 1, 'Verify all activities are scheduled.');
- }
+ if ($key > 8) {
+ $this->assertEquals($value['status_id'], 2, 'Verify all activities are scheduled.');
+ }
+ else {
+ $this->assertEquals($value['status_id'], 1, 'Verify all activities are scheduled.');
+ }
- if ($key > 8) {
- $this->assertEquals($value['activity_type_id'], 1, 'Verify activity type is correct.');
- }
- else {
- $this->assertEquals($value['activity_type_id'], 2, 'Verify activity type is correct.');
- }
+ if ($key === 12) {
+ $this->assertEquals($value['activity_type'], 'Bulk Email', 'Verify activity type is correct.');
+ $this->assertEquals('(2 recipients)', $value['recipients']);
+ $targetContactID = key($value['target_contact_name']);
+ // The 2 targets have ids 10 & 11. Since they are not sorted it could be either on some systems.
+ $this->assertTrue(in_array($targetContactID, [10, 11]));
+ }
+ elseif ($key > 8) {
+ $this->assertEquals($value['activity_type_id'], 1, 'Verify activity type is correct.');
+ }
+ else {
+ $this->assertEquals($value['activity_type_id'], 2, 'Verify activity type is correct.');
+ }
- if ($key == 3) {
- $this->assertArrayHasKey($contactID, $value['target_contact_name']);
- }
- elseif ($key == 4) {
- $this->assertArrayHasKey($contactID, $value['assignee_contact_name']);
- }
+ if ($key == 3) {
+ $this->assertEquals([$contactID => 'Test Contact ' . $contactID], $value['target_contact_name']);
+ }
+ elseif ($key == 4) {
+ $this->assertArrayHasKey($contactID, $value['assignee_contact_name']);
}
}
}
public function testSendSMSWithoutPermission() {
$dummy = NULL;
$session = CRM_Core_Session::singleton();
- $config = &CRM_Core_Config::singleton();
- $config->userPermissionClass->permissions = array('access CiviCRM');
+ CRM_Core_Config::singleton()->userPermissionClass->permissions = array('access CiviCRM');
CRM_Activity_BAO_Activity::sendSMS(
$dummy,
dirname(__FILE__) . '/activities_for_dashboard_count.xml'
)
);
+ // Make changes to improve variation in php since the xml method is brittle & relies on option values being unchanged.
+ $this->callAPISuccess('Activity', 'create', ['id' => 12, 'activity_type_id' => 'Bulk Email']);
}
}