Commit | Line | Data |
---|---|---|
2ede60ec DL |
1 | <?php |
2 | // $Id$ | |
3 | ||
4 | /* | |
5 | +--------------------------------------------------------------------+ | |
6 | | CiviCRM version 4.3 | | |
7 | +--------------------------------------------------------------------+ | |
8 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
9 | +--------------------------------------------------------------------+ | |
10 | | This file is a part of CiviCRM. | | |
11 | | | | |
12 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
13 | | under the terms of the GNU Affero General Public License | | |
14 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
15 | | | | |
16 | | CiviCRM is distributed in the hope that it will be useful, but | | |
17 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
18 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
19 | | See the GNU Affero General Public License for more details. | | |
20 | | | | |
21 | | You should have received a copy of the GNU Affero General Public | | |
22 | | License and the CiviCRM Licensing Exception along | | |
23 | | with this program; if not, contact CiviCRM LLC | | |
24 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
25 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
26 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
27 | +--------------------------------------------------------------------+ | |
28 | */ | |
29 | ||
30 | /** | |
31 | * File for the CiviCRM APIv3 job functions | |
32 | * | |
33 | * @package CiviCRM_APIv3 | |
34 | * @subpackage API_MailingContact | |
35 | * | |
36 | * @copyright CiviCRM LLC (c) 2004-2013 | |
37 | * @version $Id: Job.php 30879 2010-11-22 15:45:55Z shot $ | |
38 | * | |
39 | */ | |
40 | require_once 'CiviTest/CiviUnitTestCase.php'; | |
41 | class api_v3_MailingContactTest extends CiviUnitTestCase { | |
42 | protected $_apiversion; | |
43 | ||
44 | function setUp() { | |
45 | parent::setUp(); | |
2f26d849 | 46 | $this->_apiversion = 3; |
47 | $this->_entity = 'mailing'; | |
48 | $this->_contact_params = array( | |
49 | 'first_name' => 'abc1', | |
50 | 'contact_type' => 'Individual', | |
51 | 'last_name' => 'xyz1', | |
52 | 'version' => $this->_apiversion, | |
53 | ); | |
54 | $this->_contact = civicrm_api("contact", "create", $this->_contact_params); | |
55 | ||
56 | /*$this->quickCleanup( | |
2ede60ec DL |
57 | array( |
58 | 'civicrm_mailing', | |
59 | 'civicrm_job', | |
60 | 'civicrm_mailing_event_queue', | |
61 | 'civicrm_mailing_event_delivered', | |
62 | 'civicrm_mailing_event_bounced', | |
63 | ) | |
2f26d849 | 64 | );*/ |
2ede60ec DL |
65 | } |
66 | ||
67 | function tearDown() { | |
68 | parent::tearDown(); | |
2f26d849 | 69 | civicrm_api("contact", "delete", $this->_contact_id); |
70 | ||
2ede60ec | 71 | } |
2f26d849 | 72 | |
73 | /* | |
74 | * Test that the api responds correctly to null params | |
75 | */ | |
76 | ||
77 | public function testMailingNullParams() { | |
78 | $result = civicrm_api('MailingContact', 'get', null); | |
79 | $this->assertEquals($result['is_error'], 1, "In line " . __LINE__); | |
80 | } | |
81 | ||
82 | /* | |
83 | * Test that the api will return the proper error when you do not | |
84 | * supply the contact_id | |
85 | */ | |
86 | ||
87 | public function testMailingNoContactID() { | |
88 | $params = array( | |
89 | 'something' => 'This is not a real field', | |
90 | 'version' => $this->_apiversion, | |
2ede60ec | 91 | ); |
2f26d849 | 92 | |
93 | $result = civicrm_api('MailingContact', 'get', $params); | |
94 | $this->assertEquals($result['is_error'], 1, "In line " . __LINE__); | |
2ede60ec | 95 | } |
2f26d849 | 96 | |
97 | /* | |
98 | * Test that invalid contact_id return with proper error messages | |
99 | */ | |
100 | public function testMailingContactInvalidContactID() { | |
101 | $params = array( | |
102 | 'contact_id' => 'This is not a number', | |
103 | 'version' => $this->_apiversion, | |
104 | ); | |
105 | ||
106 | $result = civicrm_api('MailingContact', 'get', $params); | |
107 | $this->assertEquals($result['is_error'], 1, "In line " . __LINE__); | |
108 | } | |
109 | ||
110 | /* | |
111 | * Test that invalid types are returned with appropriate errors | |
112 | */ | |
113 | public function testMailingContactInvalidType() { | |
114 | $params = array( | |
115 | 'contact_id' => 23, | |
116 | 'type' => 'invalid', | |
117 | 'version' => $this->_apiversion, | |
118 | ); | |
119 | ||
120 | $result = civicrm_api('MailingContact', 'get', $params); | |
121 | $this->assertEquals($result['is_error'], 1, "In line " . __LINE__); | |
122 | } | |
123 | ||
124 | ||
125 | /* | |
126 | * Test that the API returns properly when there are no mailings | |
127 | * for a the given contact | |
128 | */ | |
129 | public function testMailingContactNoMailings() { | |
130 | $params = array( | |
131 | 'contact_id' => $this->_contact['id'], | |
132 | 'version' => $this->_apiversion, | |
133 | ); | |
134 | ||
135 | $result = civicrm_api('MailingContact', 'get', $params); | |
136 | ||
137 | $this->assertEquals($result['is_error'], 0, "In line " . __LINE__); | |
138 | $this->assertEquals($result['count'], 0, "In line " . __LINE__); | |
139 | $this->assertTrue(empty($result['values']), "In line " . __LINE__); | |
140 | } | |
141 | ||
142 | /* | |
143 | * Test that the API returns a mailing properly when there is only one | |
144 | */ | |
145 | public function testMailingContactDelivered() { | |
146 | $op = new PHPUnit_Extensions_Database_Operation_Insert(); | |
147 | //Create the User | |
148 | $op->execute($this->_dbconn, | |
149 | new PHPUnit_Extensions_Database_DataSet_XMLDataSet( | |
150 | dirname(__FILE__) . '/dataset/mailing_contact.xml' | |
151 | ) | |
152 | ); | |
153 | //~ Create the Mailing and connections to the user | |
154 | $op->execute($this->_dbconn, | |
155 | new PHPUnit_Extensions_Database_DataSet_XMLDataSet( | |
156 | dirname(__FILE__) . '/dataset/mailing_delivered.xml' | |
157 | ) | |
158 | ); | |
159 | ||
160 | $params = array( | |
161 | 'contact_id' => 23, | |
162 | 'type' => 'Delivered', | |
163 | 'version' => $this->_apiversion, | |
164 | ); | |
165 | ||
166 | $result = civicrm_api('MailingContact', 'get', $params); | |
167 | $this->assertEquals($result['is_error'], 0, "In line " . __LINE__); | |
168 | $this->assertEquals($result['count'], 1, "In line " . __LINE__); | |
169 | $this->assertFalse(empty($result['values']), "In line " . __LINE__); | |
170 | $this->assertEquals($result['values'][1]['mailing_id'], 1, "In line " . __LINE__); | |
171 | $this->assertEquals($result['values'][1]['subject'], "Some Subject", "In line " . __LINE__); | |
172 | $this->assertEquals($result['values'][1]['creator_id'], 1, "In line " . __LINE__); | |
173 | $this->assertEquals($result['values'][1]['creator_name'], "xyz1, abc1", "In line " . __LINE__); | |
174 | } | |
175 | ||
176 | ||
177 | /* | |
178 | * Test that the API returns only the "Bounced" mailings when instructed to do so | |
179 | */ | |
180 | function testMailingContactBounced( ) { | |
181 | $op = new PHPUnit_Extensions_Database_Operation_Insert(); | |
182 | //Create the User | |
183 | $op->execute($this->_dbconn, | |
184 | new PHPUnit_Extensions_Database_DataSet_XMLDataSet( | |
185 | dirname(__FILE__) . '/dataset/mailing_contact.xml' | |
186 | ) | |
187 | ); | |
188 | //~ Create the Mailing and connections to the user | |
189 | $op->execute($this->_dbconn, | |
190 | new PHPUnit_Extensions_Database_DataSet_XMLDataSet( | |
191 | dirname(__FILE__) . '/dataset/mailing_bounced.xml' | |
192 | ) | |
193 | ); | |
194 | ||
195 | $params = array( | |
196 | 'contact_id' => 23, | |
197 | 'type' => 'Bounced', | |
198 | 'version' => $this->_apiversion, | |
199 | ); | |
200 | ||
201 | $result = civicrm_api('MailingContact', 'get', $params); | |
202 | $this->assertEquals($result['is_error'], 0, "In line " . __LINE__); | |
203 | $this->assertEquals($result['count'], 1, "In line " . __LINE__); | |
204 | $this->assertFalse(empty($result['values']), "In line " . __LINE__); | |
205 | $this->assertEquals($result['values'][2]['mailing_id'], 2, "In line " . __LINE__); | |
206 | $this->assertEquals($result['values'][2]['subject'], "Some Subject", "In line " . __LINE__); | |
207 | $this->assertEquals($result['values'][2]['creator_id'], 1, "In line " . __LINE__); | |
208 | $this->assertEquals($result['values'][2]['creator_name'], "xyz1, abc1", "In line " . __LINE__); | |
209 | } | |
210 | ||
211 | ||
212 | ||
213 | } |