Merge remote-tracking branch 'upstream/4.4' into 4.4-master-2014-02-03-14-48-25
[civicrm-core.git] / tests / phpunit / api / v3 / MailingTest.php
1 <?php
2 /*
3 * File for the TestMailing class
4 *
5 * (PHP 5)
6 *
7 * @package CiviCRM
8 *
9 * This file is part of CiviCRM
10 *
11 * CiviCRM is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Affero General Public License
13 * as published by the Free Software Foundation; either version 3 of
14 * the License, or (at your option) any later version.
15 *
16 * CiviCRM is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Affero General Public License for more details.
20 *
21 * You should have received a copy of the GNU Affero General Public
22 * License along with this program. If not, see
23 * <http://www.gnu.org/licenses/>.
24 */
25
26 require_once 'CiviTest/CiviUnitTestCase.php';
27
28
29 /**
30 * Test APIv3 civicrm_mailing_* functions
31 *
32 * @package CiviCRM
33 */
34 class api_v3_MailingTest extends CiviUnitTestCase {
35 protected $_groupID;
36 protected $_email;
37 protected $_apiversion = 3;
38 protected $_params = array();
39 protected $_entity = 'Mailing';
40
41
42 function get_info() {
43 return array(
44 'name' => 'Mailer',
45 'description' => 'Test all Mailer methods.',
46 'group' => 'CiviCRM API Tests',
47 );
48 }
49
50 function setUp() {
51 parent::setUp();
52 $this->_groupID = $this->groupCreate();
53 $this->_email = 'test@test.test';
54 $this->_params = array(
55 'subject' => 'maild',
56 'body_text' => 'bdkfhdskfhduew',
57 'name' => 'mailing name',
58 'created_id' => 1,
59 );
60 }
61
62 function tearDown() {
63 $this->groupDelete($this->_groupID);
64 }
65
66 /**
67 * Test civicrm_mailing_create
68 */
69 public function testMailerCreateSuccess() {
70 $result = $this->callAPIAndDocument('mailing', 'create', $this->_params, __FUNCTION__, __FILE__);
71 $jobs = $this->callAPISuccess('mailing_job', 'get', array('mailing_id' => $result['id']));
72 $this->assertEquals(1, $jobs['count']);
73 unset($this->_params['created_id']); // return isn't working on this in getAndCheck so lets not check it for now
74 $this->getAndCheck($this->_params, $result['id'], 'mailing');
75 }
76
77 /**
78 * Test civicrm_mailing_delete
79 */
80 public function testMailerDeleteSuccess() {
81 $result = $this->callAPISuccess($this->_entity, 'create', $this->_params);
82 $jobs = $this->callAPIAndDocument($this->_entity, 'delete', array('id' => $result['id']), __FUNCTION__, __FILE__);
83 $this->assertAPIDeleted($this->_entity, $result['id']);
84 }
85
86 //@ todo tests below here are all failure tests which are not hugely useful - need success tests
87
88 //------------ civicrm_mailing_event_bounce methods------------
89
90 /**
91 * Test civicrm_mailing_event_bounce with wrong params.
92 * Note that tests like this are slightly better than no test but an
93 * api function cannot be considered supported / 'part of the api' without a
94 * success test
95 */
96 public function testMailerBounceWrongParams() {
97 $params = array(
98 'job_id' => 'Wrong ID',
99 'event_queue_id' => 'Wrong ID',
100 'hash' => 'Wrong Hash',
101 'body' => 'Body...',
102 'time_stamp' => '20111109212100',
103 );
104 $result = $this->callAPIFailure('mailing_event', 'bounce', $params,
105 'Queue event could not be found'
106 );
107 }
108
109 //----------- civicrm_mailing_event_confirm methods -----------
110
111 /**
112 * Test civicrm_mailing_event_confirm with wrong params.
113 * Note that tests like this are slightly better than no test but an
114 * api function cannot be considered supported / 'part of the api' without a
115 * success test
116 */
117 public function testMailerConfirmWrongParams() {
118 $params = array(
119 'contact_id' => 'Wrong ID',
120 'subscribe_id' => 'Wrong ID',
121 'hash' => 'Wrong Hash',
122 'event_subscribe_id' => '123',
123 'time_stamp' => '20111111010101',
124 );
125 $result = $this->callAPIFailure('mailing_event', 'confirm', $params,
126 'Confirmation failed'
127 );
128 }
129
130 //---------- civicrm_mailing_event_reply methods -----------
131
132 /**
133 * Test civicrm_mailing_event_reply with wrong params.
134 *
135 * Note that tests like this are slightly better than no test but an
136 * api function cannot be considered supported / 'part of the api' without a
137 * success test
138 */
139 public function testMailerReplyWrongParams() {
140 $params = array(
141 'job_id' => 'Wrong ID',
142 'event_queue_id' => 'Wrong ID',
143 'hash' => 'Wrong Hash',
144 'bodyTxt' => 'Body...',
145 'replyTo' => $this->_email,
146 'time_stamp' => '20111111010101',
147 );
148 $result = $this->callAPIFailure('mailing_event', 'reply', $params,
149 'Queue event could not be found'
150 );
151 }
152
153
154 //----------- civicrm_mailing_event_forward methods ----------
155
156 /**
157 * Test civicrm_mailing_event_forward with wrong params.
158 * Note that tests like this are slightly better than no test but an
159 * api function cannot be considered supported / 'part of the api' without a
160 * success test
161 */
162 public function testMailerForwardWrongParams() {
163 $params = array(
164 'job_id' => 'Wrong ID',
165 'event_queue_id' => 'Wrong ID',
166 'hash' => 'Wrong Hash',
167 'email' => $this->_email,
168 'time_stamp' => '20111111010101',
169 );
170 $result = $this->callAPIFailure('mailing_event', 'forward', $params,
171 'Queue event could not be found'
172 );
173 }
174
175 //----------- civicrm_mailing_create ----------
176
177 }