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 | |
acb109b7 | 32 | * @group headless |
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 | ||
e790a8cb | 40 | /** |
11e974ee | 41 | * Test setup for every test. |
e790a8cb | 42 | */ |
43 | public function setUp() { | |
e790a8cb | 44 | parent::setUp(); |
a12797ee | 45 | $this->useTransaction(TRUE); |
e790a8cb | 46 | } |
47 | ||
11e974ee EM |
48 | /** |
49 | * Test simple create action schedule. | |
50 | */ | |
00be9182 | 51 | public function testSimpleActionScheduleCreate() { |
66908675 E |
52 | $oldCount = CRM_Core_DAO::singleValueQuery('select count(*) from civicrm_action_schedule'); |
53 | $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name'); | |
54 | $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts); | |
92fcb95f | 55 | $title = "simpleActionSchedule" . substr(sha1(rand()), 0, 7); |
66908675 | 56 | $params = array( |
f54c2beb | 57 | 'title' => $title, |
66908675 E |
58 | 'recipient' => $assigneeID, |
59 | 'limit_to' => 1, | |
d66c61b6 | 60 | 'entity_value' => 'Meeting', |
61 | 'entity_status' => 'Scheduled', | |
66908675 E |
62 | 'is_active' => 1, |
63 | 'record_activity' => 1, | |
ded34eb1 | 64 | 'start_action_date' => 'activity_date_time', |
46f5566c | 65 | 'mapping_id' => CRM_Activity_ActionMapping::ACTIVITY_MAPPING_ID, |
e790a8cb | 66 | ); |
66908675 | 67 | $actionSchedule = $this->callAPISuccess('action_schedule', 'create', $params); |
11e974ee EM |
68 | $this->assertTrue(is_numeric($actionSchedule['id'])); |
69 | $this->assertTrue($actionSchedule['id'] > 0); | |
66908675 | 70 | $newCount = CRM_Core_DAO::singleValueQuery('select count(*) from civicrm_action_schedule'); |
6c6e6187 | 71 | $this->assertEquals($oldCount + 1, $newCount); |
e790a8cb | 72 | } |
66908675 | 73 | |
f54c2beb | 74 | /** |
11e974ee | 75 | * Check if required fields are not passed. |
f54c2beb | 76 | */ |
00be9182 | 77 | public function testActionScheduleCreateWithoutRequired() { |
66908675 | 78 | $params = array( |
92915c55 TO |
79 | 'subject' => 'this case should fail', |
80 | 'scheduled_date_time' => date('Ymd'), | |
66908675 | 81 | ); |
f0be539a | 82 | $this->callAPIFailure('activity', 'create', $params); |
f54c2beb | 83 | } |
66908675 | 84 | |
f0be539a | 85 | /** |
11e974ee | 86 | * Test create with scheduled dates. |
f0be539a | 87 | */ |
00be9182 | 88 | public function testActionScheduleWithScheduledDatesCreate() { |
66908675 E |
89 | $oldCount = CRM_Core_DAO::singleValueQuery('select count(*) from civicrm_action_schedule'); |
90 | $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name'); | |
91 | $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts); | |
92fcb95f | 92 | $title = "simpleActionSchedule" . substr(sha1(rand()), 0, 7); |
66908675 | 93 | $params = array( |
f54c2beb | 94 | 'title' => $title, |
66908675 E |
95 | 'recipient' => $assigneeID, |
96 | 'limit_to' => 1, | |
d66c61b6 | 97 | 'entity_value' => 'Meeting', |
98 | 'entity_status' => 'Scheduled', | |
66908675 E |
99 | 'is_active' => 1, |
100 | 'record_activity' => 1, | |
46f5566c | 101 | 'mapping_id' => CRM_Activity_ActionMapping::ACTIVITY_MAPPING_ID, |
66908675 E |
102 | 'start_action_offset' => 3, |
103 | 'start_action_unit' => 'day', | |
104 | 'start_action_condition' => 'before', | |
105 | 'start_action_date' => 'activity_date_time', | |
106 | 'is_repeat' => 1, | |
6c6e6187 | 107 | 'repetition_frequency_unit' => 'day', |
66908675 E |
108 | 'repetition_frequency_interval' => 3, |
109 | 'end_frequency_unit' => 'hour', | |
110 | 'end_frequency_interval' => 0, | |
111 | 'end_action' => 'before', | |
112 | 'end_date' => 'activity_date_time', | |
113 | 'body_html' => 'Test description', | |
21dfd5f5 | 114 | 'subject' => 'Test subject', |
f54c2beb | 115 | ); |
66908675 | 116 | $actionSchedule = $this->callAPISuccess('action_schedule', 'create', $params); |
11e974ee EM |
117 | $this->assertTrue(is_numeric($actionSchedule['id'])); |
118 | $this->assertTrue($actionSchedule['id'] > 0); | |
66908675 E |
119 | $this->assertEquals($actionSchedule['values'][$actionSchedule['id']]['start_action_offset'][0], $params['start_action_offset']); |
120 | $newCount = CRM_Core_DAO::singleValueQuery('select count(*) from civicrm_action_schedule'); | |
6c6e6187 | 121 | $this->assertEquals($oldCount + 1, $newCount); |
66908675 | 122 | |
f54c2beb | 123 | } |
e790a8cb | 124 | |
125 | } |