4 * This file is part of CiviCRM
6 * CiviCRM is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Affero General Public License
8 * as published by the Free Software Foundation; either version 3 of
9 * the License, or (at your option) any later version.
11 * CiviCRM is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public
17 * License along with this program. If not, see
18 * <http://www.gnu.org/licenses/>.
22 * Test Activity Import Parser functions
27 class CRM_Activity_Import_Parser_ActivityTest
extends CiviUnitTestCase
{
28 use CRMTraits_Custom_CustomDataTrait
;
33 public function setUp():void
{
35 $this->createLoggedInUser();
39 * Clean up after test.
41 * @throws \CRM_Core_Exception
43 public function tearDown():void
{
44 $this->quickCleanup(['civicrm_contact', 'civicrm_activity', 'civicrm_activity_contact'], TRUE);
51 * So far this is just testing the class constructor & preparing for more
54 * @throws \API_Exception
55 * @throws \CRM_Core_Exception
56 * @throws \CiviCRM_API3_Exception
58 public function testImport(): void
{
59 $this->createCustomGroupWithFieldOfType(['extends' => 'Activity'], 'checkbox');
61 'activity_details' => 'fascinating',
62 'activity_type_id' => 1,
63 'activity_date_time' => '2010-01-06',
64 'target_contact_id' => $this->individualCreate(),
65 'activity_subject' => 'riveting stuff',
66 $this->getCustomFieldName('checkbox') => 'L',
68 $this->importValues($values);
69 $this->callAPISuccessGetSingle('Activity', [$this->getCustomFieldName('checkbox') => 'L']);
73 * Create an import object.
75 * @param array $fields
77 * @return \CRM_Activity_Import_Parser_Activity
79 protected function createImportObject(array $fields): \CRM_Activity_Import_Parser_Activity
{
80 // @todo Eyes are weary so sanity-check this later:
81 // This loop seems the same as array_values($fields)? And this appears
82 // to only be called from one place that already has them sequentially
83 // indexed so is it even needed?
85 foreach ($fields as $index => $field) {
86 $fieldMapper[] = $field;
88 $importer = new CRM_Activity_Import_Parser_Activity($fieldMapper);
96 * @param array $values
97 * @param int $expectedOutcome
99 protected function importValues(array $values, $expectedOutcome = 1): void
{
100 $importer = $this->createImportObject(array_keys($values));
101 $params = array_values($values);
102 CRM_Core_Session
::singleton()->set('dateTypes', 1);
103 $this->assertEquals($expectedOutcome, $importer->import(NULL, $params));