3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
30 * File for the CRM_Contact_Import_Form_MapFieldTest class.
34 * Test contact import mapfield.
39 class CRM_Contact_Import_Form_MapFieldTest
extends CiviUnitTestCase
{
42 * Test the form loads without error / notice and mappings are assigned.
44 * (Added in conjunction with fixed noting on mapping assignment).
46 * @dataProvider getSubmitData
48 * @param array $params
49 * @param array $mapper
50 * @param array $expecteds
52 public function testSubmit($params, $mapper, $expecteds = []) {
53 CRM_Core_DAO
::executeQuery("CREATE TABLE IF NOT EXISTS civicrm_import_job_xxx (`nada` text, `first_name` text, `last_name` text, `address` text) ENGINE=InnoDB DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci");
54 $form = $this->getFormObject('CRM_Contact_Import_Form_MapField');
55 $form->set('contactType', CRM_Import_Parser
::CONTACT_INDIVIDUAL
);
56 $form->_columnNames
= ['nada', 'first_name', 'last_name', 'address'];
57 $form->set('importTableName', 'civicrm_import_job_xxx');
59 $form->submit($params, $mapper);
61 CRM_Core_DAO
::executeQuery("DROP TABLE civicrm_import_job_xxx");
62 if (!empty($expecteds)) {
63 foreach ($expecteds as $expected) {
64 $result = $this->callAPISuccess($expected['entity'], 'get', array_merge($expected['values'], ['sequential' => 1]));
65 $this->assertEquals($expected['count'], $result['count']);
66 if (isset($expected['result'])) {
67 foreach ($expected['result'] as $key => $expectedValues) {
68 foreach ($expectedValues as $valueKey => $value) {
69 $this->assertEquals($value, $result['values'][$key][$valueKey]);
75 $this->quickCleanup(['civicrm_mapping', 'civicrm_mapping_field']);
79 * Get data to pass through submit function.
83 public function getSubmitData() {
87 'saveMappingName' => '',
88 'saveMappingDesc' => '',
91 0 => [0 => 'do_not_import'],
92 1 => [0 => 'first_name'],
93 2 => [0 => 'last_name'],
94 3 => [0 => 'street_address', 1 => 2],
99 'saveMappingName' => 'new mapping',
100 'saveMappingDesc' => 'save it',
104 0 => [0 => 'do_not_import'],
105 1 => [0 => 'first_name'],
106 2 => [0 => 'last_name'],
107 3 => [0 => 'street_address', 1 => 2],
110 ['entity' => 'mapping', 'count' => 1, 'values' => ['name' => 'new mapping']],
117 0 => ['name' => '- do not import -'],
118 1 => ['name' => 'First Name'],
119 2 => ['name' => 'Last Name'],
120 3 => ['name' => 'Street Address', 'location_type_id' => 2],
129 * Instantiate form object
131 * @param string $class
132 * @param array $formValues
133 * @param string $pageName
134 * @return \CRM_Core_Form
135 * @throws \CRM_Core_Exception
137 public function getFormObject($class, $formValues = [], $pageName = '') {
138 $form = parent
::getFormObject($class);
139 $contactFields = CRM_Contact_BAO_Contact
::importableFields();
141 foreach ($contactFields as $name => $field) {
142 $fields[$name] = $field['title'];
144 $form->set('fields', $fields);