Skip to content
Snippets Groups Projects
Commit 07328690 authored by Tim Otten's avatar Tim Otten
Browse files

Merge pull request #2136 from vivekarora/CRM-13615-UnitTest

CRM-13615 - Action schedule API modifications
parents 7c127703 f54c2beb
No related branches found
No related tags found
No related merge requests found
......@@ -60,6 +60,16 @@ function civicrm_api3_action_schedule_get($params) {
* {@getfields action_schedule_create}
*/
function civicrm_api3_action_schedule_create($params) {
if (!CRM_Utils_Array::value('id', $params)) {
// an update does not require any mandatory parameters
civicrm_api3_verify_one_mandatory($params,
NULL,
array(
'title','mapping_id', 'entity_status', 'entity_value',
)
);
}
$ids = array();
if (isset($params['id']) && !CRM_Utils_Rule::integer($params['id'])) {
return civicrm_api3_create_error('Invalid value for ID');
......@@ -103,4 +113,6 @@ function _civicrm_api3_action_schedule_create_spec(&$params) {
*/
function civicrm_api3_action_schedule_delete($params) {
return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params);
}
\ No newline at end of file
}
......@@ -39,6 +39,7 @@ class api_v3_ActionScheduleTest extends CiviUnitTestCase {
protected $_apiversion = 3;
public $_eNoticeCompliant = TRUE;
/**
* Test setup for every test
*
......@@ -65,21 +66,82 @@ class api_v3_ActionScheduleTest extends CiviUnitTestCase {
}
function testActionScheduleCreate() {
function testSimpleActionScheduleCreate() {
$oldCount = CRM_Core_DAO::singleValueQuery('select count(*) from civicrm_action_schedule');
$activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
$assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
$targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
$scheduledStatus = CRM_Core_OptionGroup::getValue('activity_status', 'Scheduled', 'name');
$mappingId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_ActionMapping', 'activity_type', 'id', 'entity_value');
$activityTypeId = CRM_Core_OptionGroup::getValue('activity_type', "Meeting", 'name');
$title = "simpleActionSchedule".substr(sha1(rand()), 0, 7);
$params = array(
'title' => 'simpleAction',
'entity_value' => '46',
'title' => $title,
'recipient' => $assigneeID,
'limit_to' => 1,
'entity_value' => $activityTypeId,
'entity_status' => $scheduledStatus,
'is_active' => 1,
'record_activity' => 1,
'mapping_id' => $mappingId,
);
$actionSchedule = $this->callAPISuccess('action_schedule', 'create', $params);
$this->assertTrue(is_numeric($actionSchedule['id']), "In line " . __LINE__);
$this->assertTrue($actionSchedule['id'] > 0, "In line " . __LINE__);
$newCount = CRM_Core_DAO::singleValueQuery('select count(*) from civicrm_action_schedule');
$this->assertEquals($oldCount+1, $newCount);
}
/**
* check if required fields are not passed
*/
function testActionScheduleCreateWithoutRequired() {
$params = array(
'subject' => 'this case should fail',
'scheduled_date_time' => date('Ymd'),
);
$result = $this->callAPIFailure('activity', 'create', $params);
}
function testActionScheduleWithScheduledDatesCreate() {
$oldCount = CRM_Core_DAO::singleValueQuery('select count(*) from civicrm_action_schedule');
$activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
$assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
$targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
$scheduledStatus = CRM_Core_OptionGroup::getValue('activity_status', 'Scheduled', 'name');
$mappingId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_ActionMapping', 'activity_type', 'id', 'entity_value');
$activityTypeId = CRM_Core_OptionGroup::getValue('activity_type', "Meeting", 'name');
$title = "simpleActionSchedule".substr(sha1(rand()), 0, 7);
$params = array(
'title' => $title,
'recipient' => $assigneeID,
'limit_to' => 1,
'entity_value' => $activityTypeId,
'entity_status' => $scheduledStatus,
'is_active' => 1,
'record_activity' => 1,
'mapping_id' => $mappingId,
'start_action_offset' => 3,
'start_action_unit' => 'day',
'start_action_condition' => 'before',
'start_action_date' => 'activity_date_time',
'is_repeat' => 1,
'repetition_frequency_unit'=> 'day',
'repetition_frequency_interval' => 3,
'end_frequency_unit' => 'hour',
'end_frequency_interval' => 0,
'end_action' => 'before',
'end_date' => 'activity_date_time',
'body_html' => 'Test description',
'subject' => 'Test subject'
);
$actionSchedule = $this->callAPISuccess('action_schedule', 'create', $params);
$this->assertTrue(is_numeric($actionSchedule['id']), "In line " . __LINE__);
$this->assertTrue($actionSchedule['id'] > 0, "In line " . __LINE__);
$this->assertEquals($actionSchedule['values'][$actionSchedule['id']]['start_action_offset'][0], $params['start_action_offset']);
$newCount = CRM_Core_DAO::singleValueQuery('select count(*) from civicrm_action_schedule');
$this->assertEquals($oldCount+1, $newCount);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment