]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/modules/Import/Bug61172Test.php
Release 6.5.15
[Github/sugarcrm.git] / tests / modules / Import / Bug61172Test.php
1 <?php
2 /*********************************************************************************
3  * By installing or using this file, you are confirming on behalf of the entity
4  * subscribed to the SugarCRM Inc. product ("Company") that Company is bound by
5  * the SugarCRM Inc. Master Subscription Agreement (“MSA”), which is viewable at:
6  * http://www.sugarcrm.com/master-subscription-agreement
7  *
8  * If Company is not bound by the MSA, then by installing or using this file
9  * you are agreeing unconditionally that Company will be bound by the MSA and
10  * certifying that you have authority to bind Company accordingly.
11  *
12  * Copyright (C) 2004-2013 SugarCRM Inc.  All rights reserved.
13  ********************************************************************************/
14
15
16 require_once('modules/Import/Importer.php');
17 require_once('modules/Import/maps/ImportMap.php');
18
19 /**
20  * Bug 61172
21  * saved import field mapping didn't work
22  *
23  * @ticket 61172
24  * @author ekolotaev@sugarcrm.com
25  *
26  */
27 class Bug61172Test extends Sugar_PHPUnit_Framework_TestCase
28 {
29     private $testFile;
30
31     public function setUp()
32     {
33         SugarTestHelper::setUp('current_user', array(true, 1));
34         $this->testFile = 'tests/modules/Tasks/Bug61172Test.csv';
35
36         $_REQUEST = array(
37             // user choice values
38             'has_header' => 'off',
39             'firstrow' => base64_encode(serialize(array('0' => 'Foo', '1' => 'Status'))),
40             'colnum_0'    => 'foo',
41             'colnum_1'    => 'status',
42             'columncount' => '2',
43             'custom_enclosure' => '&quot;',
44             'custom_delimiter' => ',',
45             'source' => 'csv',
46             'save_map_as' => 'Bug61172TestSaveMap',
47
48             // import settings values
49             'importlocale_charset' => 'UTF-8',
50             'importlocale_currency' => '-99',
51             'importlocale_dateformat' => 'd/m/Y',
52             'importlocale_dec_sep' => '.',
53             'importlocale_default_currency_significant_digits' => '2',
54             'importlocale_default_locale_name_format' => 's f l',
55             'importlocale_num_grp_sep' => ',',
56             'importlocale_timeformat' => 'H:i',
57             'importlocale_timezone' => 'Europe/Helsinki',
58             'import_module' => 'Leads',
59         );
60     }
61
62     public function tearDown()
63     {
64         SugarTestHelper::tearDown();
65         $_REQUEST = array();
66     }
67
68     public function testSaveMappingFileSavesNumberFieldAssociationCorrectly()
69     {
70         $lead = new Lead();
71         $importSource = new ImportFile($this->testFile, ',', '', false);
72         $importer = new Bug61172TestImporterMock($importSource, $lead);
73
74         $importer->saveMappingFile();
75         $mappingFile = new ImportMap();
76         $mappingFile->retrieve_by_string_fields(array('name' => $_REQUEST['save_map_as']));
77
78         $this->assertNotEmpty($mappingFile->content);
79
80         $contentFields = explode('&', $mappingFile->content);
81         $this->assertContains('1=status', $contentFields, "Field status should be associated with #1");
82
83         $mappingFile->mark_deleted($mappingFile->id);
84     }
85 }
86
87 class Bug61172TestImporterMock extends Importer
88 {
89     public function saveMappingFile()
90     {
91         parent::saveMappingFile();
92     }
93 }
94