Merge pull request #1020 from lcdservices/CRM-12814
[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;
38
39 function get_info() {
40 return array(
41 'name' => 'Mailer',
42 'description' => 'Test all Mailer methods.',
43 'group' => 'CiviCRM API Tests',
44 );
45 }
46
47 function setUp() {
48 parent::setUp();
49 $this->_apiversion = 3;
50 $this->_groupID = $this->groupCreate(NULL);
51 $this->_email = 'test@test.test';
52 }
53
54 function tearDown() {
55 $this->groupDelete($this->_groupID);
56 }
57
58 /**
59 * Test civicrm_mailing_create
60 */
61 public function testMailerCreateSuccess() {
62 $params = array(
63 'subject' => 'maild',
64 'body_text' => 'bdkfhdskfhduew',
65 'version' => 3,
66 'name' => 'mailing name',
67 'created_id' => 1,
68 );
69 $result = civicrm_api('mailing', 'create', $params);
70 $this->documentMe($params, $result, __FUNCTION__, __FILE__);
71 $jobs = civicrm_api('mailing_job', 'get', array('version' =>3, 'mailing_id' => $result['id']));
72 $this->assertAPISuccess($jobs);
73 $this->assertEquals(1, $jobs['count']);
74 $this->assertAPISuccess($result, 'In line ' . __LINE__);
75 unset($params['created_id']);// return isn't working on this in getAndCheck so lets not check it for now
76 $this->getAndCheck($params, $result['id'], 'mailing');
77 }
78
79
80 //@ todo tests below here are all failure tests which are not hugely useful - need success tests
81
82 //------------ civicrm_mailing_event_bounce methods------------
83
84 /**
85 * Test civicrm_mailing_event_bounce with wrong params.
86 */
87 public function testMailerBounceWrongParams() {
88 $params = array(
89 'job_id' => 'Wrong ID',
90 'event_queue_id' => 'Wrong ID',
91 'hash' => 'Wrong Hash',
92 'body' => 'Body...',
93 'version' => '3',
94 'time_stamp' => '20111109212100',
95 );
96 $result = civicrm_api('mailing_event', 'bounce', $params);
97 $this->assertAPIFailure($result, 'In line ' . __LINE__);
98 $this->assertEquals($result['error_message'], 'Queue event could not be found', 'In line ' . __LINE__);
99 }
100
101 //----------- civicrm_mailing_event_confirm methods -----------
102
103 /**
104 * Test civicrm_mailing_event_confirm with wrong params.
105 */
106 public function testMailerConfirmWrongParams() {
107 $params = array(
108 'contact_id' => 'Wrong ID',
109 'subscribe_id' => 'Wrong ID',
110 'hash' => 'Wrong Hash',
111 'event_subscribe_id' => '123',
112 'time_stamp' => '20111111010101',
113 'version' => 3,
114 );
115 $result = civicrm_api('mailing_event', 'confirm', $params);
116 $this->assertAPIFailure($result, 'In line ' . __LINE__);
117 $this->assertEquals($result['error_message'], 'Confirmation failed', 'In line ' . __LINE__);
118 }
119
120 //---------- civicrm_mailing_event_reply methods -----------
121
122 /**
123 * Test civicrm_mailing_event_reply with wrong params.
124 */
125 public function testMailerReplyWrongParams() {
126 $params = array(
127 'job_id' => 'Wrong ID',
128 'event_queue_id' => 'Wrong ID',
129 'hash' => 'Wrong Hash',
130 'bodyTxt' => 'Body...',
131 'replyTo' => $this->_email,
132 'time_stamp' => '20111111010101',
133 'version' => 3,
134 );
135 $result = civicrm_api('mailing_event', 'reply', $params);
136 $this->assertAPIFailure($result, 'In line ' . __LINE__);
137 $this->assertEquals($result['error_message'], 'Queue event could not be found', 'In line ' . __LINE__);
138 }
139
140
141 //----------- civicrm_mailing_event_forward methods ----------
142
143 /**
144 * Test civicrm_mailing_event_forward with wrong params.
145 */
146 public function testMailerForwardWrongParams() {
147 $params = array(
148 'job_id' => 'Wrong ID',
149 'event_queue_id' => 'Wrong ID',
150 'hash' => 'Wrong Hash',
151 'email' => $this->_email,
152 'time_stamp' => '20111111010101',
153 'version' => 3,
154 );
155 $result = civicrm_api('mailing_event', 'forward', $params);
156 $this->assertAPIFailure($result, 'In line ' . __LINE__);
157 $this->assertEquals($result['error_message'], 'Queue event could not be found', 'In line ' . __LINE__);
158 }
159
160
161 //----------- civicrm_mailing_create ----------
162
163 }