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 | |
41 | public $_eNoticeCompliant = TRUE; |
f54c2beb |
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 | |
68 | |
f54c2beb |
69 | function testSimpleActionScheduleCreate() { |
e790a8cb |
70 | $oldCount = CRM_Core_DAO::singleValueQuery('select count(*) from civicrm_action_schedule'); |
f54c2beb |
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); |
e790a8cb |
78 | $params = array( |
f54c2beb |
79 | 'title' => $title, |
80 | 'recipient' => $assigneeID, |
81 | 'limit_to' => 1, |
82 | 'entity_value' => $activityTypeId, |
83 | 'entity_status' => $scheduledStatus, |
84 | 'is_active' => 1, |
85 | 'record_activity' => 1, |
86 | 'mapping_id' => $mappingId, |
e790a8cb |
87 | ); |
e790a8cb |
88 | $actionSchedule = $this->callAPISuccess('action_schedule', 'create', $params); |
89 | $this->assertTrue(is_numeric($actionSchedule['id']), "In line " . __LINE__); |
90 | $this->assertTrue($actionSchedule['id'] > 0, "In line " . __LINE__); |
91 | $newCount = CRM_Core_DAO::singleValueQuery('select count(*) from civicrm_action_schedule'); |
92 | $this->assertEquals($oldCount+1, $newCount); |
e790a8cb |
93 | } |
f54c2beb |
94 | |
95 | /** |
96 | * check if required fields are not passed |
97 | */ |
98 | function testActionScheduleCreateWithoutRequired() { |
99 | $params = array( |
100 | 'subject' => 'this case should fail', |
101 | 'scheduled_date_time' => date('Ymd'), |
102 | ); |
103 | $result = $this->callAPIFailure('activity', 'create', $params); |
104 | } |
105 | |
106 | function testActionScheduleWithScheduledDatesCreate() { |
107 | $oldCount = CRM_Core_DAO::singleValueQuery('select count(*) from civicrm_action_schedule'); |
108 | $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name'); |
109 | $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts); |
110 | $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts); |
111 | $scheduledStatus = CRM_Core_OptionGroup::getValue('activity_status', 'Scheduled', 'name'); |
112 | $mappingId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_ActionMapping', 'activity_type', 'id', 'entity_value'); |
113 | $activityTypeId = CRM_Core_OptionGroup::getValue('activity_type', "Meeting", 'name'); |
114 | $title = "simpleActionSchedule".substr(sha1(rand()), 0, 7); |
115 | $params = array( |
116 | 'title' => $title, |
117 | 'recipient' => $assigneeID, |
118 | 'limit_to' => 1, |
119 | 'entity_value' => $activityTypeId, |
120 | 'entity_status' => $scheduledStatus, |
121 | 'is_active' => 1, |
122 | 'record_activity' => 1, |
123 | 'mapping_id' => $mappingId, |
124 | 'start_action_offset' => 3, |
125 | 'start_action_unit' => 'day', |
126 | 'start_action_condition' => 'before', |
127 | 'start_action_date' => 'activity_date_time', |
128 | 'is_repeat' => 1, |
129 | 'repetition_frequency_unit'=> 'day', |
130 | 'repetition_frequency_interval' => 3, |
131 | 'end_frequency_unit' => 'hour', |
132 | 'end_frequency_interval' => 0, |
133 | 'end_action' => 'before', |
134 | 'end_date' => 'activity_date_time', |
135 | 'body_html' => 'Test description', |
136 | 'subject' => 'Test subject' |
137 | ); |
138 | $actionSchedule = $this->callAPISuccess('action_schedule', 'create', $params); |
139 | $this->assertTrue(is_numeric($actionSchedule['id']), "In line " . __LINE__); |
140 | $this->assertTrue($actionSchedule['id'] > 0, "In line " . __LINE__); |
141 | $this->assertEquals($actionSchedule['values'][$actionSchedule['id']]['start_action_offset'][0], $params['start_action_offset']); |
142 | $newCount = CRM_Core_DAO::singleValueQuery('select count(*) from civicrm_action_schedule'); |
143 | $this->assertEquals($oldCount+1, $newCount); |
144 | |
145 | } |
e790a8cb |
146 | |
147 | } |