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