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