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
28 * Test APIv3 civicrm_action_schedule functions
30 * @package CiviCRM_APIv3
31 * @subpackage API_ActionSchedule
34 class api_v3_ActionScheduleTest
extends CiviUnitTestCase
{
37 protected $_entity = 'action_schedule';
40 * Test setup for every test.
42 public function setUp() {
44 $this->useTransaction(TRUE);
48 * Test simple create action schedule.
50 * @dataProvider versionThreeAndFour
52 public function testSimpleActionScheduleCreate($version) {
53 $this->_apiversion
= $version;
54 $oldCount = CRM_Core_DAO
::singleValueQuery('select count(*) from civicrm_action_schedule');
55 $activityContacts = CRM_Activity_BAO_ActivityContact
::buildOptions('record_type_id', 'validate');
56 $assigneeID = CRM_Utils_Array
::key('Activity Assignees', $activityContacts);
57 $title = "simpleActionSchedule" . substr(sha1(rand()), 0, 7);
60 'recipient' => $assigneeID,
62 'entity_value' => 'Meeting',
63 'entity_status' => 'Scheduled',
65 'record_activity' => 1,
66 'start_action_date' => 'activity_date_time',
67 'mapping_id' => CRM_Activity_ActionMapping
::ACTIVITY_MAPPING_ID
,
69 $actionSchedule = $this->callAPISuccess('action_schedule', 'create', $params);
70 $this->assertTrue(is_numeric($actionSchedule['id']));
71 $this->assertTrue($actionSchedule['id'] > 0);
72 $newCount = CRM_Core_DAO
::singleValueQuery('select count(*) from civicrm_action_schedule');
73 $this->assertEquals($oldCount +
1, $newCount);
77 * Check if required fields are not passed.
79 * @dataProvider versionThreeAndFour
81 public function testActionScheduleCreateWithoutRequired($version) {
82 $this->_apiversion
= $version;
84 'subject' => 'this case should fail',
85 'scheduled_date_time' => date('Ymd'),
87 $this->callAPIFailure('activity', 'create', $params);
91 * Test create with scheduled dates.
93 * @dataProvider versionThreeAndFour
95 public function testActionScheduleWithScheduledDatesCreate($version) {
96 $this->_apiversion
= $version;
97 $oldCount = CRM_Core_DAO
::singleValueQuery('select count(*) from civicrm_action_schedule');
98 $activityContacts = CRM_Activity_BAO_ActivityContact
::buildOptions('record_type_id', 'validate');
99 $assigneeID = CRM_Utils_Array
::key('Activity Assignees', $activityContacts);
100 $title = "simpleActionSchedule" . substr(sha1(rand()), 0, 7);
103 'recipient' => $assigneeID,
105 'entity_value' => 'Meeting',
106 'entity_status' => 'Scheduled',
108 'record_activity' => 1,
109 'mapping_id' => CRM_Activity_ActionMapping
::ACTIVITY_MAPPING_ID
,
110 'start_action_offset' => 3,
111 'start_action_unit' => 'day',
112 'start_action_condition' => 'before',
113 'start_action_date' => 'activity_date_time',
115 'repetition_frequency_unit' => 'day',
116 'repetition_frequency_interval' => 3,
117 'end_frequency_unit' => 'hour',
118 'end_frequency_interval' => 0,
119 'end_action' => 'before',
120 'end_date' => 'activity_date_time',
121 'body_html' => 'Test description',
122 'subject' => 'Test subject',
124 $actionSchedule = $this->callAPISuccess('action_schedule', 'create', $params);
125 $this->assertTrue(is_numeric($actionSchedule['id']));
126 $this->assertTrue($actionSchedule['id'] > 0);
127 $this->assertEquals($actionSchedule['values'][$actionSchedule['id']]['start_action_offset'], $params['start_action_offset']);
128 $newCount = CRM_Core_DAO
::singleValueQuery('select count(*) from civicrm_action_schedule');
129 $this->assertEquals($oldCount +
1, $newCount);