CRM-19464 Enable use of 'Supplemental Address 3'
[civicrm-core.git] / tests / phpunit / WebTest / Import / SavedMappingTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
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_SavedMapping
31 */
32 class WebTest_Import_SavedMappingTest extends ImportCiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
38 /**
39 * Test Saved Import Mapping for Individuals.
40 */
41 public function testSaveIndividualMapping() {
42
43 // Logging in.
44 $this->webtestLogin();
45
46 // Get sample import data.
47 list($headers, $rows) = $this->_individualCSVData();
48
49 // Create New Mapping Name
50 $mappingName = 'contactimport_' . substr(sha1(rand()), 0, 7);
51
52 $other = array(
53 'saveMapping' => TRUE,
54 'saveMappingName' => $mappingName,
55 );
56
57 // Map Fields
58 $fieldMapper = array(
59 'mapper[0][0]' => 'prefix_id',
60 'mapper[4][0]' => 'suffix_id',
61 'mapper[6][0]' => 'phone',
62 'mapper[6][1]' => '5',
63 'mapper[7][0]' => 'supplemental_address_1',
64 'mapper[7][1]' => '5',
65 'mapper[8][0]' => 'supplemental_address_2',
66 'mapper[8][1]' => '5',
67 'mapper[9][0]' => 'supplemental_address_3',
68 'mapper[9][1]' => '5',
69 'mapper[10][0]' => 'city',
70 'mapper[10][1]' => '5',
71 'mapper[11][0]' => 'state_province',
72 'mapper[11][1]' => '5',
73 'mapper[12][0]' => 'country',
74 'mapper[12][1]' => '5',
75 );
76
77 // Import and check Individual contacts in Skip mode.
78 $this->importContacts($headers, $rows, 'Individual', 'Skip', $fieldMapper, $other);
79
80 list($headers, $rows) = $this->_individualCSVData();
81
82 // Sending Mapped Name for Re-use
83 $other = array('useMappingName' => $mappingName);
84 $this->importContacts($headers, $rows, 'Individual', 'Skip', array(), $other);
85 }
86
87 /**
88 * Helper function to provide csv data for Individuals contact import.
89 *
90 * @return array
91 */
92 public function _individualCSVData() {
93 $headers = array(
94 'individual_prefix' => 'Individual Prefix',
95 'first_name' => 'First Name',
96 'middle_name' => 'Middle Name',
97 'last_name' => 'Last Name',
98 'individual_suffix' => 'Individual Suffix',
99 'email' => 'Email',
100 'phone' => 'Phone',
101 'address_1' => 'Additional Address 1',
102 'address_2' => 'Additional Address 2',
103 'city' => 'City',
104 'state' => 'State',
105 'country' => 'Country',
106 );
107
108 $rows = array(
109 array(
110 'individual_prefix' => 'Mr.',
111 'first_name' => substr(sha1(rand()), 0, 7),
112 'middle_name' => substr(sha1(rand()), 0, 7),
113 'last_name' => 'Anderson',
114 'individual_suffix' => 'Jr.',
115 'email' => substr(sha1(rand()), 0, 7) . '@example.com',
116 'phone' => '6949912154',
117 'address_1' => 'Add 1',
118 'address_2' => 'Add 2',
119 'city' => 'Watson',
120 'state' => 'NY',
121 'country' => 'UNITED STATES',
122 ),
123 array(
124 'individual_prefix' => 'Mr.',
125 'first_name' => substr(sha1(rand()), 0, 7),
126 'middle_name' => substr(sha1(rand()), 0, 7),
127 'last_name' => 'Summerson',
128 'individual_suffix' => 'Jr.',
129 'email' => substr(sha1(rand()), 0, 7) . '@example.com',
130 'phone' => '6944412154',
131 'address_1' => 'Add 1',
132 'address_2' => 'Add 2',
133 'city' => 'Watson',
134 'state' => 'NY',
135 'country' => 'UNITED STATES',
136 ),
137 );
138
139 return array($headers, $rows);
140 }
141
142 }