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 map field.
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 * @throws \CRM_Core_Exception
53 * @throws \CiviCRM_API3_Exception
55 public function testSubmit($params, $mapper, $expecteds = []) {
56 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');
57 $form = $this->getFormObject('CRM_Contact_Import_Form_MapField');
58 /* @var CRM_Contact_Import_Form_MapField $form */
59 $form->set('contactType', CRM_Import_Parser
::CONTACT_INDIVIDUAL
);
60 $form->_columnNames
= ['nada', 'first_name', 'last_name', 'address'];
61 $form->set('importTableName', 'civicrm_import_job_xxx');
63 $form->submit($params, $mapper);
65 CRM_Core_DAO
::executeQuery("DROP TABLE civicrm_import_job_xxx");
66 if (!empty($expecteds)) {
67 foreach ($expecteds as $expected) {
68 $result = $this->callAPISuccess($expected['entity'], 'get', array_merge($expected['values'], ['sequential' => 1]));
69 $this->assertEquals($expected['count'], $result['count']);
70 if (isset($expected['result'])) {
71 foreach ($expected['result'] as $key => $expectedValues) {
72 foreach ($expectedValues as $valueKey => $value) {
73 $this->assertEquals($value, $result['values'][$key][$valueKey]);
79 $this->quickCleanup(['civicrm_mapping', 'civicrm_mapping_field']);
83 * Get data to pass through submit function.
87 public function getSubmitData() {
91 'saveMappingName' => '',
92 'saveMappingDesc' => '',
95 0 => [0 => 'do_not_import'],
96 1 => [0 => 'first_name'],
97 2 => [0 => 'last_name'],
98 3 => [0 => 'street_address', 1 => 2],
103 'saveMappingName' => 'new mapping',
104 'saveMappingDesc' => 'save it',
108 0 => [0 => 'do_not_import'],
109 1 => [0 => 'first_name'],
110 2 => [0 => 'last_name'],
111 3 => [0 => 'street_address', 1 => 2],
114 ['entity' => 'mapping', 'count' => 1, 'values' => ['name' => 'new mapping']],
121 0 => ['name' => '- do not import -'],
122 1 => ['name' => 'First Name'],
123 2 => ['name' => 'Last Name'],
124 3 => ['name' => 'Street Address', 'location_type_id' => 2],
133 * Instantiate form object
135 * @param string $class
136 * @param array $formValues
137 * @param string $pageName
138 * @return \CRM_Core_Form
139 * @throws \CRM_Core_Exception
141 public function getFormObject($class, $formValues = [], $pageName = '') {
142 $form = parent
::getFormObject($class);
143 $contactFields = CRM_Contact_BAO_Contact
::importableFields();
145 foreach ($contactFields as $name => $field) {
146 $fields[$name] = $field['title'];
148 $form->set('fields', $fields);