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