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 | * | |
31 | * @package CiviCRM_APIv3 | |
32 | * @subpackage API_ActionSchedule | |
33 | */ | |
34 | ||
35 | class api_v3_ActionScheduleTest extends CiviUnitTestCase { | |
36 | protected $_params; | |
37 | protected $_params2; | |
38 | protected $_entity = 'action_schedule'; | |
39 | protected $_apiversion = 3; | |
40 | ||
b7c9bc4c | 41 | |
66908675 | 42 | |
e790a8cb | 43 | /** |
44 | * Test setup for every test | |
45 | * | |
46 | * Connect to the database, truncate the tables that will be used | |
47 | * and redirect stdin to a temporary file | |
48 | */ | |
49 | public function setUp() { | |
50 | // Connect to the database | |
51 | parent::setUp(); | |
52 | ||
53 | } | |
54 | ||
55 | /** | |
56 | * Tears down the fixture, for example, closes a network connection. | |
57 | * This method is called after a test is executed. | |
58 | * | |
59 | * @access protected | |
60 | */ | |
61 | function tearDown() { | |
62 | $tablesToTruncate = array( | |
63 | 'civicrm_action_schedule', | |
64 | ); | |
65 | $this->quickCleanup($tablesToTruncate, TRUE); | |
66 | } | |
67 | ||
66908675 | 68 | |
f54c2beb | 69 | function testSimpleActionScheduleCreate() { |
66908675 E |
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); | |
78 | $params = array( | |
f54c2beb | 79 | 'title' => $title, |
66908675 E |
80 | 'recipient' => $assigneeID, |
81 | 'limit_to' => 1, | |
82 | 'entity_value' => $activityTypeId, | |
83 | 'entity_status' => $scheduledStatus, | |
84 | 'is_active' => 1, | |
85 | 'record_activity' => 1, | |
ded34eb1 | 86 | 'start_action_date' => 'activity_date_time', |
66908675 | 87 | 'mapping_id' => $mappingId, |
e790a8cb | 88 | ); |
66908675 E |
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); | |
e790a8cb | 94 | } |
66908675 | 95 | |
f54c2beb | 96 | /** |
100fef9d | 97 | * Check if required fields are not passed |
f54c2beb | 98 | */ |
99 | function testActionScheduleCreateWithoutRequired() { | |
66908675 E |
100 | $params = array( |
101 | 'subject' => 'this case should fail', | |
102 | 'scheduled_date_time' => date('Ymd'), | |
103 | ); | |
104 | $result = $this->callAPIFailure('activity', 'create', $params); | |
f54c2beb | 105 | } |
66908675 | 106 | |
f54c2beb | 107 | function testActionScheduleWithScheduledDatesCreate() { |
66908675 E |
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); | |
116 | $params = array( | |
f54c2beb | 117 | 'title' => $title, |
66908675 E |
118 | 'recipient' => $assigneeID, |
119 | 'limit_to' => 1, | |
120 | 'entity_value' => $activityTypeId, | |
121 | 'entity_status' => $scheduledStatus, | |
122 | 'is_active' => 1, | |
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', | |
129 | 'is_repeat' => 1, | |
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' | |
f54c2beb | 138 | ); |
66908675 E |
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); | |
145 | ||
f54c2beb | 146 | } |
e790a8cb | 147 | |
148 | } |