All Data Structures Functions Variables Pages
ContactsImportDataAnalyzerTest.php
1 <?php
2  /*********************************************************************************
3  * Zurmo is a customer relationship management program developed by
4  * Zurmo, Inc. Copyright (C) 2017 Zurmo Inc.
5  *
6  * Zurmo is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License version 3 as published by the
8  * Free Software Foundation with the addition of the following permission added
9  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10  * IN WHICH THE COPYRIGHT IS OWNED BY ZURMO, ZURMO DISCLAIMS THE WARRANTY
11  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12  *
13  * Zurmo is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Affero General Public License along with
19  * this program; if not, see http://www.gnu.org/licenses or write to the Free
20  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  * 02110-1301 USA.
22  *
23  * You can contact Zurmo, Inc. with a mailing address at 27 North Wacker Drive
24  * Suite 370 Chicago, IL 60606. or at email address contact@zurmo.com.
25  *
26  * The interactive user interfaces in original and modified versions
27  * of this program must display Appropriate Legal Notices, as required under
28  * Section 5 of the GNU Affero General Public License version 3.
29  *
30  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31  * these Appropriate Legal Notices must retain the display of the Zurmo
32  * logo and Zurmo copyright notice. If the display of the logo is not reasonably
33  * feasible for technical reasons, the Appropriate Legal Notices must display the words
34  * "Copyright Zurmo Inc. 2017. All rights reserved".
35  ********************************************************************************/
36 
38  {
39  public static function setUpBeforeClass()
40  {
41  parent::setUpBeforeClass();
42  $super = SecurityTestHelper::createSuperAdmin();
43  Yii::app()->user->userModel = $super;
45  }
46 
47  public function testImportDataAnalysisResults()
48  {
49  $super = User::getByUsername('super');
50  Yii::app()->user->userModel = $super;
51  $import = new Import();
52  $serializedData['importRulesType'] = 'Contacts';
53  $import->serializedData = serialize($serializedData);
54  $this->assertTrue($import->save());
55 
56  ImportTestHelper::
57  createTempTableByFileNameAndTableName('importAnalyzerTest.csv', $import->getTempTableName(), true,
58  Yii::getPathOfAlias('application.modules.contacts.tests.unit.files'));
59  $mappingData = array(
60  'column_0' => array('attributeIndexOrDerivedType' => 'ContactState',
61  'type' => 'importColumn',
62  'mappingRulesData' => array(
63  'DefaultContactStateIdMappingRuleForm' => array('defaultStateId' => null))),
64  );
65  $serializedData = unserialize($import->serializedData);
66  $serializedData['mappingData'] = $mappingData;
67  $import->serializedData = serialize($serializedData);
68  $this->assertTrue($import->save());
69 
70  $importRules = ImportRulesUtil::makeImportRulesByType('Contacts');
71  $config = array('pagination' => array('pageSize' => 15));
72  //This test csv has a header row.
73  $dataProvider = new ImportDataProvider($import->getTempTableName(), true, $config);
74 
75  //Run data analyzer
76  $importDataAnalyzer = new ImportDataAnalyzer($importRules, $dataProvider, $mappingData, array('column_0'));
77  $importDataAnalyzer->analyzePage();
78  $data = $dataProvider->getData();
79  $this->assertEquals(13, count($data));
80 
81  $compareData = array();
82  $compareData['column_0'] = array();
83  $compareData['column_0'][] = 'Is invalid.';
84  $this->assertEquals($compareData, unserialize($data[0]->serializedAnalysisMessages));
85  $this->assertEquals(ImportDataAnalyzer::STATUS_SKIP, $data[0]->analysisStatus);
86 
87  $compareData = array();
88  $compareData['column_0'] = array();
89  $compareData['column_0'][] = 'Is invalid.';
90  $this->assertEquals($compareData, unserialize($data[1]->serializedAnalysisMessages));
91  $this->assertEquals(ImportDataAnalyzer::STATUS_SKIP, $data[1]->analysisStatus);
92 
93  $compareData = array();
94  $compareData['column_0'] = array();
95  $compareData['column_0'][] = 'Is invalid.';
96  $this->assertEquals($compareData, unserialize($data[2]->serializedAnalysisMessages));
97  $this->assertEquals(ImportDataAnalyzer::STATUS_SKIP, $data[2]->analysisStatus);
98 
99  $this->assertNull($data[3]->serializedAnalysisMessages);
100  $this->assertEquals(ImportDataAnalyzer::STATUS_CLEAN, $data[3]->analysisStatus);
101 
102  $this->assertNull($data[4]->serializedAnalysisMessages);
103  $this->assertEquals(ImportDataAnalyzer::STATUS_CLEAN, $data[4]->analysisStatus);
104 
105  $this->assertNull($data[5]->serializedAnalysisMessages);
106  $this->assertEquals(ImportDataAnalyzer::STATUS_CLEAN, $data[5]->analysisStatus);
107 
108  $this->assertNull($data[6]->serializedAnalysisMessages);
109  $this->assertEquals(ImportDataAnalyzer::STATUS_CLEAN, $data[6]->analysisStatus);
110 
111  $this->assertNull($data[7]->serializedAnalysisMessages);
112  $this->assertEquals(ImportDataAnalyzer::STATUS_CLEAN, $data[7]->analysisStatus);
113 
114  $this->assertNull($data[8]->serializedAnalysisMessages);
115  $this->assertEquals(ImportDataAnalyzer::STATUS_CLEAN, $data[8]->analysisStatus);
116 
117  $this->assertNull($data[9]->serializedAnalysisMessages);
118  $this->assertEquals(ImportDataAnalyzer::STATUS_CLEAN, $data[9]->analysisStatus);
119 
120  $this->assertNull($data[10]->serializedAnalysisMessages);
121  $this->assertEquals(ImportDataAnalyzer::STATUS_CLEAN, $data[10]->analysisStatus);
122 
123  $this->assertNull($data[11]->serializedAnalysisMessages);
124  $this->assertEquals(ImportDataAnalyzer::STATUS_CLEAN, $data[11]->analysisStatus);
125 
126  $this->assertNull($data[12]->serializedAnalysisMessages);
127  $this->assertEquals(ImportDataAnalyzer::STATUS_CLEAN, $data[12]->analysisStatus);
128  }
129  }
130 ?>
static makeImportRulesByType($importRulesType)
static getByUsername($username)
Definition: User.php:49
static loadStartingData()
Generated on Mon May 25 2020 07:10:30