3 * File for the TestActionSchedule class
7 * CiviCRM is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Affero General Public License
9 * as published by the Free Software Foundation; either version 3 of
10 * the License, or (at your option) any later version.
12 * CiviCRM is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public
18 * License along with this program. If not, see
19 * <http://www.gnu.org/licenses/>.
23 * Include class definitions
25 require_once 'CiviTest/CiviUnitTestCase.php';
29 * Test APIv3 civicrm_action_schedule functions
31 * @package CiviCRM_APIv3
32 * @subpackage API_ActionSchedule
35 class api_v3_ActionScheduleTest
extends CiviUnitTestCase
{
38 protected $_entity = 'action_schedule';
39 protected $_apiversion = 3;
44 * Test setup for every test
46 * Connect to the database, truncate the tables that will be used
47 * and redirect stdin to a temporary file
49 public function setUp() {
50 // Connect to the database
56 * Tears down the fixture, for example, closes a network connection.
57 * This method is called after a test is executed.
62 $tablesToTruncate = array(
63 'civicrm_action_schedule',
65 $this->quickCleanup($tablesToTruncate, TRUE);
69 function testSimpleActionScheduleCreate() {
70 $oldCount = CRM_Core_DAO
::singleValueQuery('select count(*) from civicrm_action_schedule');
71 $activityContacts = CRM_Core_OptionGroup
::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
72 $assigneeID = CRM_Utils_Array
::key('Activity Assignees', $activityContacts);
73 $targetID = CRM_Utils_Array
::key('Activity Targets', $activityContacts);
74 $scheduledStatus = CRM_Core_OptionGroup
::getValue('activity_status', 'Scheduled', 'name');
75 $mappingId = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_ActionMapping', 'activity_type', 'id', 'entity_value');
76 $activityTypeId = CRM_Core_OptionGroup
::getValue('activity_type', "Meeting", 'name');
77 $title = "simpleActionSchedule".substr(sha1(rand()), 0, 7);
80 'recipient' => $assigneeID,
82 'entity_value' => $activityTypeId,
83 'entity_status' => $scheduledStatus,
85 'record_activity' => 1,
86 'start_action_date' => 'activity_date_time',
87 'mapping_id' => $mappingId,
89 $actionSchedule = $this->callAPISuccess('action_schedule', 'create', $params);
90 $this->assertTrue(is_numeric($actionSchedule['id']), "In line " . __LINE__
);
91 $this->assertTrue($actionSchedule['id'] > 0, "In line " . __LINE__
);
92 $newCount = CRM_Core_DAO
::singleValueQuery('select count(*) from civicrm_action_schedule');
93 $this->assertEquals($oldCount+
1, $newCount);
97 * check if required fields are not passed
99 function testActionScheduleCreateWithoutRequired() {
101 'subject' => 'this case should fail',
102 'scheduled_date_time' => date('Ymd'),
104 $result = $this->callAPIFailure('activity', 'create', $params);
107 function testActionScheduleWithScheduledDatesCreate() {
108 $oldCount = CRM_Core_DAO
::singleValueQuery('select count(*) from civicrm_action_schedule');
109 $activityContacts = CRM_Core_OptionGroup
::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
110 $assigneeID = CRM_Utils_Array
::key('Activity Assignees', $activityContacts);
111 $targetID = CRM_Utils_Array
::key('Activity Targets', $activityContacts);
112 $scheduledStatus = CRM_Core_OptionGroup
::getValue('activity_status', 'Scheduled', 'name');
113 $mappingId = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_ActionMapping', 'activity_type', 'id', 'entity_value');
114 $activityTypeId = CRM_Core_OptionGroup
::getValue('activity_type', "Meeting", 'name');
115 $title = "simpleActionSchedule".substr(sha1(rand()), 0, 7);
118 'recipient' => $assigneeID,
120 'entity_value' => $activityTypeId,
121 'entity_status' => $scheduledStatus,
123 'record_activity' => 1,
124 'mapping_id' => $mappingId,
125 'start_action_offset' => 3,
126 'start_action_unit' => 'day',
127 'start_action_condition' => 'before',
128 'start_action_date' => 'activity_date_time',
130 'repetition_frequency_unit'=> 'day',
131 'repetition_frequency_interval' => 3,
132 'end_frequency_unit' => 'hour',
133 'end_frequency_interval' => 0,
134 'end_action' => 'before',
135 'end_date' => 'activity_date_time',
136 'body_html' => 'Test description',
137 'subject' => 'Test subject'
139 $actionSchedule = $this->callAPISuccess('action_schedule', 'create', $params);
140 $this->assertTrue(is_numeric($actionSchedule['id']), "In line " . __LINE__
);
141 $this->assertTrue($actionSchedule['id'] > 0, "In line " . __LINE__
);
142 $this->assertEquals($actionSchedule['values'][$actionSchedule['id']]['start_action_offset'][0], $params['start_action_offset']);
143 $newCount = CRM_Core_DAO
::singleValueQuery('select count(*) from civicrm_action_schedule');
144 $this->assertEquals($oldCount+
1, $newCount);