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