Merge pull request #4606 from johanv/CRM-15636-price_set_event_and_contribution
[civicrm-core.git] / tests / phpunit / WebTest / Import / MultipleRelationshipTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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 along with this program; if not, contact CiviCRM LLC |
21 | at info[AT]civicrm[DOT]org. If you have questions about the |
22 | GNU Affero General Public License or the licensing of CiviCRM, |
23 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
24 +--------------------------------------------------------------------+
25 */
26
27 require_once 'WebTest/Import/ImportCiviSeleniumTestCase.php';
28
29 /**
30 * Class WebTest_Import_MultipleRelationshipTest
31 */
32 class WebTest_Import_MultipleRelationshipTest extends ImportCiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
38 /*
39 * Test Multiple Relationship import for Individuals.
40 */
41 public function testMultipleRelationshipImport() {
42 $this->webtestLogin();
43
44 // Get sample import data.
45 list($headers, $rows, $fieldMapper) = $this->_individualRelationshipCSVData();
46
47 // Import Individuals with multiple relationships
48 $this->importContacts($headers, $rows, 'Individual', 'Skip', $fieldMapper);
49 }
50
51 /*
52 * Helper function to provide data for multiple relationship import
53 * for Individuals.
54
55 */
56 /**
57 * @return array
58 */
59 public function _individualRelationshipCSVData() {
60
61 $headers = array(
62 'first_name' => 'First Name',
63 'middle_name' => 'Middle Name',
64 'last_name' => 'Last Name',
65 'email' => 'Email',
66 'phone' => 'Phone',
67 'address_1' => 'Additional Address 1',
68 'address_2' => 'Additional Address 2',
69 'city' => 'City',
70 'state' => 'State',
71 'country' => 'Country',
72 'contact_relationships' =>
73 array(
74 '4_a_b' => array('organization_name' => 'Organization Name',
75 'organization_email' => 'Organization Email',
76 'organization_add' => 'Organization Street Address',
77 'organization_city' => 'Organization City',
78 'organization_state' => 'Organization State',
79 'organization_country' => 'Organization Country',
80 ),
81 '7_a_b' => array(
82 'household_name' => 'Household Name',
83 'household_email' => 'Household Name',
84 'household_add' => 'Household Street Address',
85 'household_city' => 'Household City',
86 'household_state' => 'Household State',
87 'household_country' => 'Household Country',
88 ),
89 '2_a_b' => array(
90 'spouse_f_name' => 'Spouse First Name',
91 'spouse_l_name' => 'Spouse Last Name',
92 'spouse_email' => 'Spouse Email',
93 'spouse_add' => 'Spouse Street Address',
94 'spouse_city' => 'Spouse City',
95 'spouse_state' => 'Spouse State',
96 'spouse_country' => 'Spouse Country',
97 ),
98 ),
99 );
100
101 $rows = array(
102 array('first_name' => substr(sha1(rand()), 0, 7),
103 'middle_name' => substr(sha1(rand()), 0, 7),
104 'last_name' => 'Anderson',
105 'email' => substr(sha1(rand()), 0, 7) . '@example.com',
106 'phone' => '6949912154',
107 'address_1' => 'Add 1',
108 'address_2' => 'Add 2',
109 'city' => 'Watson',
110 'state' => 'NY',
111 'country' => 'United States',
112 'contact_relationships' =>
113 array('4_a_b' => array('organization_name' => 'Org ' . substr(sha1(rand()), 0, 7),
114 'organization_email' => substr(sha1(rand()), 0, 7) . 'org@example.org',
115 'organization_add' => 'Org Street Address',
116 'organization_city' => 'Org City',
117 'organization_state' => 'NY',
118 'organization_country' => 'United States',
119 ),
120 '7_a_b' => array('household_name' => 'House ' . substr(sha1(rand()), 0, 7),
121 'household_email' => substr(sha1(rand()), 0, 7) . 'house@example.org',
122 'household_add' => 'House Street Address',
123 'household_city' => 'House City',
124 'household_state' => 'NY',
125 'household_country' => 'United States',
126 ),
127 '2_a_b' => array('spouse_f_name' => substr(sha1(rand()), 0, 7),
128 'spouse_l_name' => substr(sha1(rand()), 0, 7),
129 'spouse_email' => substr(sha1(rand()), 0, 7) . 'spouse@example.org',
130 'spouse_add' => 'Spouse Street Address',
131 'spouse_city' => 'Spouse City',
132 'spouse_state' => 'NY',
133 'spouse_country' => 'United States',
134 ),
135 ),
136 ),
137 array('first_name' => substr(sha1(rand()), 0, 7),
138 'middle_name' => substr(sha1(rand()), 0, 7),
139 'last_name' => 'Summerson',
140 'email' => substr(sha1(rand()), 0, 7) . '@example.com',
141 'phone' => '6944412154',
142 'address_1' => 'Add 1',
143 'address_2' => 'Add 2',
144 'city' => 'Watson',
145 'state' => 'NY',
146 'country' => 'United States',
147 'contact_relationships' =>
148 array('4_a_b' => array('organization_name' => 'Org ' . substr(sha1(rand()), 0, 7),
149 'organization_email' => substr(sha1(rand()), 0, 7) . 'org@example.org',
150 'organization_add' => 'Org Street Address',
151 'organization_city' => 'Org City',
152 'organization_state' => 'NY',
153 'organization_country' => 'United States',
154 ),
155 '7_a_b' => array('household_name' => 'House ' . substr(sha1(rand()), 0, 7),
156 'household_email' => substr(sha1(rand()), 0, 7) . 'house@example.org',
157 'household_add' => 'House Street Address',
158 'household_city' => 'House City',
159 'household_state' => 'NY',
160 'household_country' => 'United States',
161 ),
162 '2_a_b' => array('spouse_f_name' => substr(sha1(rand()), 0, 7),
163 'spouse_l_name' => substr(sha1(rand()), 0, 7),
164 'spouse_email' => substr(sha1(rand()), 0, 7) . 'spouse@example.org',
165 'spouse_add' => 'Spouse Street Address',
166 'spouse_city' => 'Spouse City',
167 'spouse_state' => 'NY',
168 'spouse_country' => 'United States',
169 ),
170 ),
171 ),
172 );
173 // for Employee of relationship
174 $fieldMapper = array(
175 'mapper[10][0]' => '5_a_b',
176 'mapper[10][1]' => 'organization_name',
177 'mapper[11][0]' => '5_a_b',
178 'mapper[11][1]' => 'email',
179 'mapper[12][0]' => '5_a_b',
180 'mapper[12][1]' => 'street_address',
181 'mapper[13][0]' => '5_a_b',
182 'mapper[13][1]' => 'city',
183 'mapper[14][0]' => '5_a_b',
184 'mapper[14][1]' => 'state_province',
185 'mapper[15][0]' => '5_a_b',
186 'mapper[15][1]' => 'country',
187 // for Household Member of relationship
188 'mapper[16][0]' => '8_a_b',
189 'mapper[16][1]' => 'household_name',
190 'mapper[17][0]' => '8_a_b',
191 'mapper[17][1]' => 'email',
192 'mapper[18][0]' => '8_a_b',
193 'mapper[18][1]' => 'street_address',
194 'mapper[19][0]' => '8_a_b',
195 'mapper[19][1]' => 'city',
196 'mapper[20][0]' => '8_a_b',
197 'mapper[20][1]' => 'state_province',
198 'mapper[21][0]' => '8_a_b',
199 'mapper[21][1]' => 'country',
200 // for Spouse of relationship
201 'mapper[22][0]' => '2_a_b',
202 'mapper[22][1]' => 'first_name',
203 'mapper[23][0]' => '2_a_b',
204 'mapper[23][1]' => 'last_name',
205 'mapper[24][0]' => '2_a_b',
206 'mapper[24][1]' => 'email',
207 'mapper[25][0]' => '2_a_b',
208 'mapper[25][1]' => 'street_address',
209 'mapper[26][0]' => '2_a_b',
210 'mapper[26][1]' => 'city',
211 'mapper[27][0]' => '2_a_b',
212 'mapper[27][1]' => 'state_province',
213 'mapper[28][0]' => '2_a_b',
214 'mapper[28][1]' => 'country',
215 );
216
217 return array($headers, $rows, $fieldMapper);
218 }
219 }