Commit | Line | Data |
---|---|---|
2ede60ec | 1 | <?php |
2ede60ec DL |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
06a1bc01 | 4 | | CiviCRM version 4.5 | |
2ede60ec | 5 | +--------------------------------------------------------------------+ |
06a1bc01 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
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 | * | |
06a1bc01 | 34 | * @copyright CiviCRM LLC (c) 2004-2014 |
2ede60ec DL |
35 | * @version $Id: Job.php 30879 2010-11-22 15:45:55Z shot $ |
36 | * | |
37 | */ | |
38 | require_once 'CiviTest/CiviUnitTestCase.php'; | |
39 | class api_v3_MailingContactTest extends CiviUnitTestCase { | |
4d88a37a | 40 | protected $_apiversion = 3; |
41 | protected $_entity = 'mailing'; | |
ef170fe0 | 42 | |
2ede60ec DL |
43 | function setUp() { |
44 | parent::setUp(); | |
4d88a37a | 45 | $params = array( |
2f26d849 | 46 | 'first_name' => 'abc1', |
47 | 'contact_type' => 'Individual', | |
48 | 'last_name' => 'xyz1', | |
2f26d849 | 49 | ); |
4d88a37a | 50 | $this->_contact = $this->callAPISuccess("contact", "create", $params); |
2ede60ec DL |
51 | } |
52 | ||
53 | function tearDown() { | |
4d88a37a | 54 | $this->callAPISuccess("contact", "delete", array('id' => $this->_contact['id'])); |
2ede60ec DL |
55 | parent::tearDown(); |
56 | } | |
b14ce773 | 57 | |
2f26d849 | 58 | /* |
59 | * Test that the api responds correctly to null params | |
4d88a37a | 60 | * Note to copy & pasters - tests like this that test the wrapper belong in the SyntaxConformance class |
61 | * (which already has a 'not array test) | |
62 | * I have left this here in case 'null' isn't covered in that class | |
63 | * but don't copy it only any other classes | |
2f26d849 | 64 | */ |
2f26d849 | 65 | public function testMailingNullParams() { |
d0e1eff2 | 66 | $result = $this->callAPIFailure('MailingContact', 'get', null); |
2f26d849 | 67 | } |
4d88a37a | 68 | |
b14ce773 | 69 | public function testMailingContactGetFields() { |
4d88a37a | 70 | $result = $this->callAPISuccess('MailingContact', 'getfields', array( |
71 | 'action' => 'get', | |
b14ce773 | 72 | ) |
73 | ); | |
b14ce773 | 74 | $this->assertEquals('Delivered', $result['values']['type']['api.default']); |
75 | } | |
76 | ||
4d88a37a | 77 | /** |
2f26d849 | 78 | * Test that the api will return the proper error when you do not |
79 | * supply the contact_id | |
4d88a37a | 80 | * Note to copy & pasters - test is of marginal if any value & testing of wrapper level functionaliy |
81 | * belongs in the SyntaxConformance class | |
2f26d849 | 82 | */ |
b14ce773 | 83 | |
2f26d849 | 84 | public function testMailingNoContactID() { |
85 | $params = array( | |
86 | 'something' => 'This is not a real field', | |
2ede60ec | 87 | ); |
d0e1eff2 | 88 | $result = $this->callAPIFailure('MailingContact', 'get', $params); |
2ede60ec | 89 | } |
b14ce773 | 90 | |
4d88a37a | 91 | /** |
2f26d849 | 92 | * Test that invalid contact_id return with proper error messages |
4d88a37a | 93 | * Note to copy & pasters - test is of marginal if any value & testing of wrapper level functionaliy |
94 | * belongs in the SyntaxConformance class | |
2f26d849 | 95 | */ |
96 | public function testMailingContactInvalidContactID() { | |
4d88a37a | 97 | $params = array('contact_id' => 'This is not a number',); |
98 | $result = $this->callAPIFailure('MailingContact', 'get', $params); | |
2f26d849 | 99 | } |
b14ce773 | 100 | |
4d88a37a | 101 | /** |
2f26d849 | 102 | * Test that invalid types are returned with appropriate errors |
103 | */ | |
104 | public function testMailingContactInvalidType() { | |
4d88a37a | 105 | $params = array( |
106 | 'contact_id' => 23, | |
107 | 'type' => 'invalid', | |
108 | ); | |
109 | $result = $this->callAPIFailure('MailingContact', 'get', $params); | |
2f26d849 | 110 | } |
b14ce773 | 111 | |
4d88a37a | 112 | /** |
2f26d849 | 113 | * Test that the API returns properly when there are no mailings |
114 | * for a the given contact | |
115 | */ | |
116 | public function testMailingContactNoMailings() { | |
117 | $params = array( | |
118 | 'contact_id' => $this->_contact['id'], | |
2f26d849 | 119 | ); |
4d88a37a | 120 | $result = $this->callAPISuccess('MailingContact', 'get', $params); |
2f26d849 | 121 | $this->assertEquals($result['count'], 0, "In line " . __LINE__); |
122 | $this->assertTrue(empty($result['values']), "In line " . __LINE__); | |
123 | } | |
b14ce773 | 124 | |
2f26d849 | 125 | /* |
126 | * Test that the API returns a mailing properly when there is only one | |
127 | */ | |
128 | public function testMailingContactDelivered() { | |
129 | $op = new PHPUnit_Extensions_Database_Operation_Insert(); | |
130 | //Create the User | |
131 | $op->execute($this->_dbconn, | |
132 | new PHPUnit_Extensions_Database_DataSet_XMLDataSet( | |
133 | dirname(__FILE__) . '/dataset/mailing_contact.xml' | |
134 | ) | |
135 | ); | |
136 | //~ Create the Mailing and connections to the user | |
137 | $op->execute($this->_dbconn, | |
138 | new PHPUnit_Extensions_Database_DataSet_XMLDataSet( | |
139 | dirname(__FILE__) . '/dataset/mailing_delivered.xml' | |
140 | ) | |
141 | ); | |
b14ce773 | 142 | |
2f26d849 | 143 | $params = array( |
144 | 'contact_id' => 23, | |
145 | 'type' => 'Delivered', | |
2f26d849 | 146 | ); |
147 | ||
4d88a37a | 148 | $result = $this->callAPISuccess('MailingContact', 'get', $params); |
149 | $count = $this->callAPISuccess('MailingContact', 'getcount', $params); | |
2f26d849 | 150 | $this->assertEquals($result['count'], 1, "In line " . __LINE__); |
fc334403 | 151 | $this->assertEquals($count, 1, "In line " . __LINE__); |
2f26d849 | 152 | $this->assertFalse(empty($result['values']), "In line " . __LINE__); |
153 | $this->assertEquals($result['values'][1]['mailing_id'], 1, "In line " . __LINE__); | |
154 | $this->assertEquals($result['values'][1]['subject'], "Some Subject", "In line " . __LINE__); | |
155 | $this->assertEquals($result['values'][1]['creator_id'], 1, "In line " . __LINE__); | |
156 | $this->assertEquals($result['values'][1]['creator_name'], "xyz1, abc1", "In line " . __LINE__); | |
157 | } | |
b14ce773 | 158 | |
159 | ||
2f26d849 | 160 | /* |
161 | * Test that the API returns only the "Bounced" mailings when instructed to do so | |
162 | */ | |
163 | function testMailingContactBounced( ) { | |
164 | $op = new PHPUnit_Extensions_Database_Operation_Insert(); | |
165 | //Create the User | |
166 | $op->execute($this->_dbconn, | |
167 | new PHPUnit_Extensions_Database_DataSet_XMLDataSet( | |
168 | dirname(__FILE__) . '/dataset/mailing_contact.xml' | |
169 | ) | |
170 | ); | |
171 | //~ Create the Mailing and connections to the user | |
172 | $op->execute($this->_dbconn, | |
173 | new PHPUnit_Extensions_Database_DataSet_XMLDataSet( | |
174 | dirname(__FILE__) . '/dataset/mailing_bounced.xml' | |
175 | ) | |
176 | ); | |
b14ce773 | 177 | |
2f26d849 | 178 | $params = array( |
179 | 'contact_id' => 23, | |
180 | 'type' => 'Bounced', | |
2f26d849 | 181 | ); |
182 | ||
4d88a37a | 183 | $result = $this->callAPISuccess('MailingContact', 'get', $params); |
2f26d849 | 184 | $this->assertEquals($result['count'], 1, "In line " . __LINE__); |
185 | $this->assertFalse(empty($result['values']), "In line " . __LINE__); | |
186 | $this->assertEquals($result['values'][2]['mailing_id'], 2, "In line " . __LINE__); | |
187 | $this->assertEquals($result['values'][2]['subject'], "Some Subject", "In line " . __LINE__); | |
188 | $this->assertEquals($result['values'][2]['creator_id'], 1, "In line " . __LINE__); | |
189 | $this->assertEquals($result['values'][2]['creator_name'], "xyz1, abc1", "In line " . __LINE__); | |
190 | } | |
2f26d849 | 191 | } |