WebTest Fixes 4.5
[civicrm-core.git] / tests / phpunit / WebTest / Import / SavedMappingTest.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
06a1bc01 4 | CiviCRM version 4.5 |
6a488035 5 +--------------------------------------------------------------------+
06a1bc01 6 | Copyright CiviCRM LLC (c) 2004-2014 |
6a488035
TO
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 27require_once 'WebTest/Import/ImportCiviSeleniumTestCase.php';
e9479dcf
EM
28
29/**
30 * Class WebTest_Import_SavedMapping
31 */
025a13f3 32class WebTest_Import_SavedMappingTest extends ImportCiviSeleniumTestCase {
6a488035 33
6a488035
TO
34 protected function setUp() {
35 parent::setUp();
36 }
37
38 /*
39 * Function to test Saved Import Mapping for Individuals.
40 */
41 function testSaveIndividualMapping() {
42
6a488035
TO
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(
aeaa5f5d
JP
59 'mapper[0][0]' => 'prefix_id',
60 'mapper[4][0]' => 'suffix_id',
6a488035
TO
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]' => 'city',
68 'mapper[9][1]' => '5',
69 'mapper[10][0]' => 'state_province',
70 'mapper[10][1]' => '5',
71 'mapper[11][0]' => 'country',
72 'mapper[11][1]' => '5',
73 );
74
75 // Import and check Individual contacts in Skip mode.
76 $this->importContacts($headers, $rows, 'Individual', 'Skip', $fieldMapper, $other);
77
78 list($headers, $rows) = $this->_individualCSVData();
79
80 // Sending Mapped Name for Re-use
81 $other = array('useMappingName' => $mappingName);
82 $this->importContacts($headers, $rows, 'Individual', 'Skip', array(), $other);
83 }
84
85 /*
86 * Helper function to provide csv data for Individuals contact import.
87 */
4cbe18b8
EM
88 /**
89 * @return array
90 */
6a488035
TO
91 function _individualCSVData() {
92 $headers = array(
93 'individual_prefix' => 'Individual Prefix',
94 'first_name' => 'First Name',
95 'middle_name' => 'Middle Name',
96 'last_name' => 'Last Name',
97 'individual_suffix' => 'Individual Suffix',
98 'email' => 'Email',
99 'phone' => 'Phone',
100 'address_1' => 'Additional Address 1',
101 'address_2' => 'Additional Address 2',
102 'city' => 'City',
103 'state' => 'State',
104 'country' => 'Country',
105 );
106
107 $rows = array(
108 array(
109 'individual_prefix' => 'Mr.',
110 'first_name' => substr(sha1(rand()), 0, 7),
111 'middle_name' => substr(sha1(rand()), 0, 7),
112 'last_name' => 'Anderson',
113 'individual_suffix' => 'Jr.',
114 'email' => substr(sha1(rand()), 0, 7) . '@example.com',
115 'phone' => '6949912154',
116 'address_1' => 'Add 1',
117 'address_2' => 'Add 2',
118 'city' => 'Watson',
119 'state' => 'NY',
120 'country' => 'United States',
121 ),
122 array(
123 'individual_prefix' => 'Mr.',
124 'first_name' => substr(sha1(rand()), 0, 7),
125 'middle_name' => substr(sha1(rand()), 0, 7),
126 'last_name' => 'Summerson',
127 'individual_suffix' => 'Jr.',
128 'email' => substr(sha1(rand()), 0, 7) . '@example.com',
129 'phone' => '6944412154',
130 'address_1' => 'Add 1',
131 'address_2' => 'Add 2',
132 'city' => 'Watson',
133 'state' => 'NY',
134 'country' => 'United States',
135 ),
136 );
137
138 return array($headers, $rows);
139 }
140}
141