4 * File for the TestActionSchedule class
8 * CiviCRM is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Affero General Public License
10 * as published by the Free Software Foundation; either version 3 of
11 * the License, or (at your option) any later version.
13 * CiviCRM is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Affero General Public License for more details.
18 * You should have received a copy of the GNU Affero General Public
19 * License along with this program. If not, see
20 * <http://www.gnu.org/licenses/>.
24 * Include class definitions
26 require_once 'CiviTest/CiviUnitTestCase.php';
30 * Test APIv3 civicrm_action_schedule functions
32 * @package CiviCRM_APIv3
33 * @subpackage API_ActionSchedule
35 class api_v3_ActionScheduleTest
extends CiviUnitTestCase
{
38 protected $_entity = 'action_schedule';
39 protected $_apiversion = 3;
42 * Test setup for every test.
44 public function setUp() {
46 $this->useTransaction(TRUE);
50 * Test simple create action schedule.
52 public function testSimpleActionScheduleCreate() {
53 $oldCount = CRM_Core_DAO
::singleValueQuery('select count(*) from civicrm_action_schedule');
54 $activityContacts = CRM_Core_OptionGroup
::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
55 $assigneeID = CRM_Utils_Array
::key('Activity Assignees', $activityContacts);
56 $scheduledStatus = CRM_Core_OptionGroup
::getValue('activity_status', 'Scheduled', 'name');
57 $activityTypeId = CRM_Core_OptionGroup
::getValue('activity_type', "Meeting", 'name');
58 $title = "simpleActionSchedule" . substr(sha1(rand()), 0, 7);
61 'recipient' => $assigneeID,
63 'entity_value' => $activityTypeId,
64 'entity_status' => $scheduledStatus,
66 'record_activity' => 1,
67 'start_action_date' => 'activity_date_time',
68 'mapping_id' => CRM_Activity_ActionMapping
::ACTIVITY_MAPPING_ID
,
70 $actionSchedule = $this->callAPISuccess('action_schedule', 'create', $params);
71 $this->assertTrue(is_numeric($actionSchedule['id']));
72 $this->assertTrue($actionSchedule['id'] > 0);
73 $newCount = CRM_Core_DAO
::singleValueQuery('select count(*) from civicrm_action_schedule');
74 $this->assertEquals($oldCount +
1, $newCount);
78 * Check if required fields are not passed.
80 public function testActionScheduleCreateWithoutRequired() {
82 'subject' => 'this case should fail',
83 'scheduled_date_time' => date('Ymd'),
85 $this->callAPIFailure('activity', 'create', $params);
89 * Test create with scheduled dates.
91 public function testActionScheduleWithScheduledDatesCreate() {
92 $oldCount = CRM_Core_DAO
::singleValueQuery('select count(*) from civicrm_action_schedule');
93 $activityContacts = CRM_Core_OptionGroup
::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
94 $assigneeID = CRM_Utils_Array
::key('Activity Assignees', $activityContacts);
95 $scheduledStatus = CRM_Core_OptionGroup
::getValue('activity_status', 'Scheduled', 'name');
96 $activityTypeId = CRM_Core_OptionGroup
::getValue('activity_type', "Meeting", 'name');
97 $title = "simpleActionSchedule" . substr(sha1(rand()), 0, 7);
100 'recipient' => $assigneeID,
102 'entity_value' => $activityTypeId,
103 'entity_status' => $scheduledStatus,
105 'record_activity' => 1,
106 'mapping_id' => CRM_Activity_ActionMapping
::ACTIVITY_MAPPING_ID
,
107 'start_action_offset' => 3,
108 'start_action_unit' => 'day',
109 'start_action_condition' => 'before',
110 'start_action_date' => 'activity_date_time',
112 'repetition_frequency_unit' => 'day',
113 'repetition_frequency_interval' => 3,
114 'end_frequency_unit' => 'hour',
115 'end_frequency_interval' => 0,
116 'end_action' => 'before',
117 'end_date' => 'activity_date_time',
118 'body_html' => 'Test description',
119 'subject' => 'Test subject',
121 $actionSchedule = $this->callAPISuccess('action_schedule', 'create', $params);
122 $this->assertTrue(is_numeric($actionSchedule['id']));
123 $this->assertTrue($actionSchedule['id'] > 0);
124 $this->assertEquals($actionSchedule['values'][$actionSchedule['id']]['start_action_offset'][0], $params['start_action_offset']);
125 $newCount = CRM_Core_DAO
::singleValueQuery('select count(*) from civicrm_action_schedule');
126 $this->assertEquals($oldCount +
1, $newCount);