Commit | Line | Data |
---|---|---|
e790a8cb | 1 | <?php |
2 | /** | |
11e974ee EM |
3 | * @file |
4 | * File for the TestActionSchedule class | |
e790a8cb | 5 | * |
6 | * (PHP 5) | |
7 | * | |
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. | |
12 | * | |
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. | |
17 | * | |
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/>. | |
21 | */ | |
22 | ||
23 | /** | |
24 | * Include class definitions | |
25 | */ | |
e790a8cb | 26 | |
27 | /** | |
28 | * Test APIv3 civicrm_action_schedule functions | |
29 | * | |
6c6e6187 TO |
30 | * @package CiviCRM_APIv3 |
31 | * @subpackage API_ActionSchedule | |
e790a8cb | 32 | */ |
e790a8cb | 33 | class api_v3_ActionScheduleTest extends CiviUnitTestCase { |
34 | protected $_params; | |
35 | protected $_params2; | |
36 | protected $_entity = 'action_schedule'; | |
37 | protected $_apiversion = 3; | |
38 | ||
e790a8cb | 39 | /** |
11e974ee | 40 | * Test setup for every test. |
e790a8cb | 41 | */ |
42 | public function setUp() { | |
e790a8cb | 43 | parent::setUp(); |
a12797ee | 44 | $this->useTransaction(TRUE); |
e790a8cb | 45 | } |
46 | ||
11e974ee EM |
47 | /** |
48 | * Test simple create action schedule. | |
49 | */ | |
00be9182 | 50 | public function testSimpleActionScheduleCreate() { |
66908675 E |
51 | $oldCount = CRM_Core_DAO::singleValueQuery('select count(*) from civicrm_action_schedule'); |
52 | $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name'); | |
53 | $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts); | |
66908675 | 54 | $scheduledStatus = CRM_Core_OptionGroup::getValue('activity_status', 'Scheduled', 'name'); |
66908675 | 55 | $activityTypeId = CRM_Core_OptionGroup::getValue('activity_type', "Meeting", 'name'); |
92fcb95f | 56 | $title = "simpleActionSchedule" . substr(sha1(rand()), 0, 7); |
66908675 | 57 | $params = array( |
f54c2beb | 58 | 'title' => $title, |
66908675 E |
59 | 'recipient' => $assigneeID, |
60 | 'limit_to' => 1, | |
61 | 'entity_value' => $activityTypeId, | |
62 | 'entity_status' => $scheduledStatus, | |
63 | 'is_active' => 1, | |
64 | 'record_activity' => 1, | |
ded34eb1 | 65 | 'start_action_date' => 'activity_date_time', |
46f5566c | 66 | 'mapping_id' => CRM_Activity_ActionMapping::ACTIVITY_MAPPING_ID, |
e790a8cb | 67 | ); |
66908675 | 68 | $actionSchedule = $this->callAPISuccess('action_schedule', 'create', $params); |
11e974ee EM |
69 | $this->assertTrue(is_numeric($actionSchedule['id'])); |
70 | $this->assertTrue($actionSchedule['id'] > 0); | |
66908675 | 71 | $newCount = CRM_Core_DAO::singleValueQuery('select count(*) from civicrm_action_schedule'); |
6c6e6187 | 72 | $this->assertEquals($oldCount + 1, $newCount); |
e790a8cb | 73 | } |
66908675 | 74 | |
f54c2beb | 75 | /** |
11e974ee | 76 | * Check if required fields are not passed. |
f54c2beb | 77 | */ |
00be9182 | 78 | public function testActionScheduleCreateWithoutRequired() { |
66908675 | 79 | $params = array( |
92915c55 TO |
80 | 'subject' => 'this case should fail', |
81 | 'scheduled_date_time' => date('Ymd'), | |
66908675 | 82 | ); |
f0be539a | 83 | $this->callAPIFailure('activity', 'create', $params); |
f54c2beb | 84 | } |
66908675 | 85 | |
f0be539a | 86 | /** |
11e974ee | 87 | * Test create with scheduled dates. |
f0be539a | 88 | */ |
00be9182 | 89 | public function testActionScheduleWithScheduledDatesCreate() { |
66908675 E |
90 | $oldCount = CRM_Core_DAO::singleValueQuery('select count(*) from civicrm_action_schedule'); |
91 | $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name'); | |
92 | $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts); | |
66908675 | 93 | $scheduledStatus = CRM_Core_OptionGroup::getValue('activity_status', 'Scheduled', 'name'); |
66908675 | 94 | $activityTypeId = CRM_Core_OptionGroup::getValue('activity_type', "Meeting", 'name'); |
92fcb95f | 95 | $title = "simpleActionSchedule" . substr(sha1(rand()), 0, 7); |
66908675 | 96 | $params = array( |
f54c2beb | 97 | 'title' => $title, |
66908675 E |
98 | 'recipient' => $assigneeID, |
99 | 'limit_to' => 1, | |
100 | 'entity_value' => $activityTypeId, | |
101 | 'entity_status' => $scheduledStatus, | |
102 | 'is_active' => 1, | |
103 | 'record_activity' => 1, | |
46f5566c | 104 | 'mapping_id' => CRM_Activity_ActionMapping::ACTIVITY_MAPPING_ID, |
66908675 E |
105 | 'start_action_offset' => 3, |
106 | 'start_action_unit' => 'day', | |
107 | 'start_action_condition' => 'before', | |
108 | 'start_action_date' => 'activity_date_time', | |
109 | 'is_repeat' => 1, | |
6c6e6187 | 110 | 'repetition_frequency_unit' => 'day', |
66908675 E |
111 | 'repetition_frequency_interval' => 3, |
112 | 'end_frequency_unit' => 'hour', | |
113 | 'end_frequency_interval' => 0, | |
114 | 'end_action' => 'before', | |
115 | 'end_date' => 'activity_date_time', | |
116 | 'body_html' => 'Test description', | |
21dfd5f5 | 117 | 'subject' => 'Test subject', |
f54c2beb | 118 | ); |
66908675 | 119 | $actionSchedule = $this->callAPISuccess('action_schedule', 'create', $params); |
11e974ee EM |
120 | $this->assertTrue(is_numeric($actionSchedule['id'])); |
121 | $this->assertTrue($actionSchedule['id'] > 0); | |
66908675 E |
122 | $this->assertEquals($actionSchedule['values'][$actionSchedule['id']]['start_action_offset'][0], $params['start_action_offset']); |
123 | $newCount = CRM_Core_DAO::singleValueQuery('select count(*) from civicrm_action_schedule'); | |
6c6e6187 | 124 | $this->assertEquals($oldCount + 1, $newCount); |
66908675 | 125 | |
f54c2beb | 126 | } |
e790a8cb | 127 | |
128 | } |