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