All Data Structures Functions Variables Pages
TasksImportDataAnalyzerTest.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;
44 
45  $accountTableName = Account::getTableName();
46  $contactTableName = Contact::getTableName();
47  $opportunityTableName = Opportunity::getTableName();
51  }
52 
53  public function testImportDataAnalysisResults()
54  {
55  $super = User::getByUsername('super');
56  Yii::app()->user->userModel = $super;
57  $import = new Import();
58  $serializedData['importRulesType'] = 'Tasks';
59  $import->serializedData = serialize($serializedData);
60  $this->assertTrue($import->save());
61 
62  $account1 = AccountTestHelper::createAccountByNameForOwner('account1', $super);
63  $account2 = AccountTestHelper::createAccountByNameForOwner('account2', $super);
64  $account3 = AccountTestHelper::createAccountByNameForOwner('account3', $super);
65 
66  $contact1 = ContactTestHelper::createContactByNameForOwner('contact1', $super);
67  $contact2 = ContactTestHelper::createContactByNameForOwner('contact2', $super);
68  $contact3 = ContactTestHelper::createContactByNameForOwner('contact3', $super);
69 
70  $opportunity1 = OpportunityTestHelper::createOpportunityByNameForOwner('opportunity1', $super);
71  $opportunity2 = OpportunityTestHelper::createOpportunityByNameForOwner('opportunity2', $super);
72  $opportunity3 = OpportunityTestHelper::createOpportunityByNameForOwner('opportunity3', $super);
73 
74  //Make models externally linked for testing.
75  ImportTestHelper::updateModelsExternalId($account2, 'ACC');
76  ImportTestHelper::updateModelsExternalId($contact2, 'CON');
77  ImportTestHelper::updateModelsExternalId($opportunity2, 'OPP');
78 
79  ImportTestHelper::
80  createTempTableByFileNameAndTableName('importAnalyzerTest.csv', $import->getTempTableName(), true,
81  Yii::getPathOfAlias('application.modules.tasks.tests.unit.files'));
82  ZurmoRedBean::exec("update " . $import->getTempTableName() . " set column_0 = " .
83  $account3->id . " where id != 1 limit 3");
84  ZurmoRedBean::exec("update " . $import->getTempTableName() . " set column_2 = " .
85  $contact3->id . " where id != 1 limit 4");
86  ZurmoRedBean::exec("update " . $import->getTempTableName() . " set column_4 = " .
87  $opportunity3->id . " where id != 1 limit 5");
88 
89  $mappingData = array(
90  'column_0' => ImportMappingUtil::makeModelDerivedColumnMappingData ('AccountDerived',
91  IdValueTypeMappingRuleForm::ZURMO_MODEL_ID),
92  'column_1' => ImportMappingUtil::makeModelDerivedColumnMappingData ('AccountDerived'),
93  'column_2' => ImportMappingUtil::makeModelDerivedColumnMappingData ('ContactDerived',
94  IdValueTypeMappingRuleForm::ZURMO_MODEL_ID),
95  'column_3' => ImportMappingUtil::makeModelDerivedColumnMappingData ('ContactDerived'),
96  'column_4' => ImportMappingUtil::makeModelDerivedColumnMappingData ('OpportunityDerived',
97  IdValueTypeMappingRuleForm::ZURMO_MODEL_ID),
98  'column_5' => ImportMappingUtil::makeModelDerivedColumnMappingData ('OpportunityDerived'),
99  'column_6' => ImportMappingUtil::makeIntegerColumnMappingData ('status'),
100  );
101  $serializedData = unserialize($import->serializedData);
102  $serializedData['mappingData'] = $mappingData;
103  $import->serializedData = serialize($serializedData);
104  $this->assertTrue($import->save());
105 
106  $importRules = ImportRulesUtil::makeImportRulesByType('Tasks');
107  $config = array('pagination' => array('pageSize' => 15));
108  //This test csv has a header row.
109  $dataProvider = new ImportDataProvider($import->getTempTableName(), true, $config);
110 
111  //Run data analyzer
112  $importDataAnalyzer = new ImportDataAnalyzer($importRules, $dataProvider, $mappingData,
113  array('column_0', 'column_1', 'column_2', 'column_3', 'column_4', 'column_5', 'column_6'));
114  $importDataAnalyzer->analyzePage();
115  $data = $dataProvider->getData();
116  $this->assertEquals(10, count($data));
117 
118  $compareData = array();
119  $compareData['column_0'][] = 'Is an existing record and will be updated.';
120  $compareData['column_1'][] = 'Was not found and this row will be skipped during import.';
121  $compareData['column_2'][] = 'Is an existing record and will be updated.';
122  $compareData['column_3'][] = 'Was not found and this row will be skipped during import.';
123  $compareData['column_4'][] = 'Is an existing record and will be updated.';
124  $compareData['column_5'][] = 'Was not found and this row will be skipped during import.';
125  $compareData['column_6'][] = 'Status specified is invalid and this row will be skipped during import.';
126  $this->assertEquals($compareData, unserialize($data[0]->serializedAnalysisMessages));
127  $this->assertEquals(ImportDataAnalyzer::STATUS_SKIP, $data[0]->analysisStatus);
128 
129  $compareData = array();
130  $compareData['column_0'][] = 'Is an existing record and will be updated.';
131  $compareData['column_1'][] = 'Is an existing record and will be updated.';
132  $compareData['column_2'][] = 'Is an existing record and will be updated.';
133  $compareData['column_3'][] = 'Was not found and this row will be skipped during import.';
134  $compareData['column_4'][] = 'Is an existing record and will be updated.';
135  $compareData['column_5'][] = 'Was not found and this row will be skipped during import.';
136  $compareData['column_6'][] = 'Status specified is invalid and this row will be skipped during import.';
137  $this->assertEquals($compareData, unserialize($data[1]->serializedAnalysisMessages));
138  $this->assertEquals(ImportDataAnalyzer::STATUS_SKIP, $data[1]->analysisStatus);
139 
140  $compareData = array();
141  $compareData['column_0'][] = 'Is an existing record and will be updated.';
142  $compareData['column_1'][] = 'Is an existing record and will be updated.';
143  $compareData['column_2'][] = 'Is an existing record and will be updated.';
144  $compareData['column_3'][] = 'Was not found and this row will be skipped during import.';
145  $compareData['column_4'][] = 'Is an existing record and will be updated.';
146  $compareData['column_5'][] = 'Was not found and this row will be skipped during import.';
147  $compareData['column_6'][] = 'Status specified is invalid and this row will be skipped during import.';
148  $this->assertEquals($compareData, unserialize($data[2]->serializedAnalysisMessages));
149  $this->assertEquals(ImportDataAnalyzer::STATUS_SKIP, $data[2]->analysisStatus);
150 
151  $compareData = array();
152  $compareData['column_0'][] = 'Was not found and this row will be skipped during import.';
153  $compareData['column_1'][] = 'Is an existing record and will be updated.';
154  $compareData['column_2'][] = 'Is an existing record and will be updated.';
155  $compareData['column_3'][] = 'Was not found and this row will be skipped during import.';
156  $compareData['column_4'][] = 'Is an existing record and will be updated.';
157  $compareData['column_5'][] = 'Was not found and this row will be skipped during import.';
158  $compareData['column_6'][] = 'Status specified is invalid and this row will be skipped during import.';
159  $this->assertEquals($compareData, unserialize($data[3]->serializedAnalysisMessages));
160  $this->assertEquals(ImportDataAnalyzer::STATUS_SKIP, $data[3]->analysisStatus);
161 
162  $compareData = array();
163  $compareData['column_0'][] = 'Was not found and this row will be skipped during import.';
164  $compareData['column_1'][] = 'Was not found and this row will be skipped during import.';
165  $compareData['column_2'][] = 'Was not found and this row will be skipped during import.';
166  $compareData['column_3'][] = 'Is an existing record and will be updated.';
167  $compareData['column_4'][] = 'Is an existing record and will be updated.';
168  $compareData['column_5'][] = 'Was not found and this row will be skipped during import.';
169  $compareData['column_6'][] = 'Status specified is invalid and this row will be skipped during import.';
170  $this->assertEquals($compareData, unserialize($data[4]->serializedAnalysisMessages));
171  $this->assertEquals(ImportDataAnalyzer::STATUS_SKIP, $data[4]->analysisStatus);
172 
173  $compareData = array();
174  $compareData['column_0'][] = 'Was not found and this row will be skipped during import.';
175  $compareData['column_1'][] = 'Was not found and this row will be skipped during import.';
176  $compareData['column_2'][] = 'Was not found and this row will be skipped during import.';
177  $compareData['column_3'][] = 'Is an existing record and will be updated.';
178  $compareData['column_4'][] = 'Was not found and this row will be skipped during import.';
179  $compareData['column_5'][] = 'Was not found and this row will be skipped during import.';
180  $compareData['column_6'][] = 'Status specified is invalid and this row will be skipped during import.';
181  $this->assertEquals($compareData, unserialize($data[5]->serializedAnalysisMessages));
182  $this->assertEquals(ImportDataAnalyzer::STATUS_SKIP, $data[5]->analysisStatus);
183 
184  $compareData = array();
185  $compareData['column_0'][] = 'Was not found and this row will be skipped during import.';
186  $compareData['column_1'][] = 'Was not found and this row will be skipped during import.';
187  $compareData['column_2'][] = 'Was not found and this row will be skipped during import.';
188  $compareData['column_3'][] = 'Is an existing record and will be updated.';
189  $compareData['column_4'][] = 'Was not found and this row will be skipped during import.';
190  $compareData['column_6'][] = 'Status specified is invalid and this row will be skipped during import.';
191  $compareData['column_5'][] = 'Is an existing record and will be updated.';
192  $this->assertEquals($compareData, unserialize($data[6]->serializedAnalysisMessages));
193  $this->assertEquals(ImportDataAnalyzer::STATUS_SKIP, $data[6]->analysisStatus);
194 
195  $compareData = array();
196  $compareData['column_0'][] = 'Was not found and this row will be skipped during import.';
197  $compareData['column_1'][] = 'Was not found and this row will be skipped during import.';
198  $compareData['column_2'][] = 'Was not found and this row will be skipped during import.';
199  $compareData['column_3'][] = 'Was not found and this row will be skipped during import.';
200  $compareData['column_4'][] = 'Was not found and this row will be skipped during import.';
201  $compareData['column_6'][] = 'Status specified is invalid and this row will be skipped during import.';
202  $compareData['column_5'][] = 'Is an existing record and will be updated.';
203  $this->assertEquals($compareData, unserialize($data[7]->serializedAnalysisMessages));
204  $this->assertEquals(ImportDataAnalyzer::STATUS_SKIP, $data[7]->analysisStatus);
205 
206  $compareData = array();
207  $compareData['column_0'][] = 'Was not found and this row will be skipped during import.';
208  $compareData['column_1'][] = 'Was not found and this row will be skipped during import.';
209  $compareData['column_2'][] = 'Was not found and this row will be skipped during import.';
210  $compareData['column_3'][] = 'Was not found and this row will be skipped during import.';
211  $compareData['column_4'][] = 'Was not found and this row will be skipped during import.';
212  $compareData['column_5'][] = 'Is an existing record and will be updated.';
213  $compareData['column_6'][] = 'Status specified is invalid and this row will be skipped during import.';
214  $this->assertEquals($compareData, unserialize($data[8]->serializedAnalysisMessages));
215  $this->assertEquals(ImportDataAnalyzer::STATUS_SKIP, $data[8]->analysisStatus);
216 
217  //Will result with no problems since it is all blank.
218  $this->assertFalse(unserialize($data[9]->serializedAnalysisMessages));
219  $this->assertEquals(ImportDataAnalyzer::STATUS_CLEAN, $data[9]->analysisStatus);
220  }
221  }
222 ?>
static makeImportRulesByType($importRulesType)
static getByUsername($username)
Definition: User.php:49
static addExternalIdColumnIfMissing($tableName, $maxLength=255, $columnName=null)
static makeModelDerivedColumnMappingData($derivedAttributeName, $type=IdValueTypeMappingRuleForm::EXTERNAL_SYSTEM_ID)
static getTableName()
Generated on Sat Feb 22 2020 07:10:33