Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
AccountImportTest.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  SecurityTestHelper::createSuperAdmin();
43  Yii::import('application.core.data.*');
44  Yii::import('application.modules.accounts.data.*');
45  $defaultDataMaker = new AccountsDefaultDataMaker();
46  $defaultDataMaker->make();
47  }
48 
49  public function testParentAccountHasCorrectAttributeImportType()
50  {
52  'Accounts', 'account');
53  $this->assertTrue($attributeImportRules instanceof AccountAttributeImportRules);
54  }
55 
56  public function testShortEmailIsValidEmail()
57  {
58  $validator = new CEmailValidator();
59  $validatedEmail = $validator->validateValue('a@a.com');
60  $this->assertTrue($validatedEmail);
61  }
62 
67  {
68  Yii::app()->user->userModel = User::getByUsername('super');
69  $parentAccount = AccountTestHelper::
70  createAccountByNameForOwner('parentAccount',
71  Yii::app()->user->userModel);
72  $parentAccountId = $parentAccount->id;
73  $accounts = Account::getAll();
74  $this->assertEquals(1, count($accounts));
75  $import = new Import();
76  $serializedData['importRulesType'] = 'Accounts';
77  $serializedData['firstRowIsHeaderRow'] = true;
78  $import->serializedData = serialize($serializedData);
79  $this->assertTrue($import->save());
80 
81  ImportTestHelper::
82  createTempTableByFileNameAndTableName('importTest.csv', $import->getTempTableName(), true,
83  Yii::getPathOfAlias('application.modules.accounts.tests.unit.files'));
84 
85  //update the ids of the account column to match the parent account.
86  ZurmoRedBean::exec("update " . $import->getTempTableName() . " set column_16 = " .
87  $parentAccount->id . " where id != 1 limit 4");
88  $this->assertEquals(4, ImportDatabaseUtil::getCount($import->getTempTableName())); // includes header rows.
89 
90  $mappingData = array(
92  'column_1' => ImportMappingUtil::makeStringColumnMappingData ('officePhone'),
93  'column_2' => ImportMappingUtil::makeStringColumnMappingData ('officeFax'),
94  'column_3' => ImportMappingUtil::makeIntegerColumnMappingData ('employees'),
95  'column_4' => ImportMappingUtil::makeUrlColumnMappingData ('website'),
96  'column_5' => ImportMappingUtil::makeFloatColumnMappingData ('annualRevenue'),
97  'column_6' => ImportMappingUtil::makeTextAreaColumnMappingData ('description'),
98  'column_7' => ImportMappingUtil::makeStringColumnMappingData ('billingAddress__city'),
99  'column_8' => ImportMappingUtil::makeStringColumnMappingData ('billingAddress__country'),
100  'column_9' => ImportMappingUtil::makeStringColumnMappingData ('billingAddress__postalCode'),
101  'column_10' => ImportMappingUtil::makeStringColumnMappingData ('billingAddress__state'),
102  'column_11' => ImportMappingUtil::makeStringColumnMappingData ('billingAddress__street1'),
103  'column_12' => ImportMappingUtil::makeStringColumnMappingData ('billingAddress__street2'),
104  'column_13' => ImportMappingUtil::makeEmailColumnMappingData ('primaryEmail__emailAddress'),
105  'column_14' => ImportMappingUtil::makeBooleanColumnMappingData ('primaryEmail__isInvalid'),
106  'column_15' => ImportMappingUtil::makeBooleanColumnMappingData ('primaryEmail__optOut'),
107  'column_16' => ImportMappingUtil::makeHasOneColumnMappingData ('account'),
108  'column_17' => ImportMappingUtil::makeDropDownColumnMappingData ('industry'),
109  'column_18' => ImportMappingUtil::makeDropDownColumnMappingData ('type'),
110  );
111 
112  $importRules = ImportRulesUtil::makeImportRulesByType('Accounts');
113  $page = 0;
114  $config = array('pagination' => array('pageSize' => 50)); //This way all rows are processed.
115  $dataProvider = new ImportDataProvider($import->getTempTableName(), true, $config);
116  $dataProvider->getPagination()->setCurrentPage($page);
117  $importResultsUtil = new ImportResultsUtil($import);
118  $messageLogger = new ImportMessageLogger();
119  ImportUtil::importByDataProvider($dataProvider,
120  $importRules,
121  $mappingData,
122  $importResultsUtil,
124  $messageLogger);
125  $importResultsUtil->processStatusAndMessagesForEachRow();
126 
127  //Confirm that 3 models where created.
128  $accounts = Account::getAll();
129  $this->assertEquals(4, count($accounts));
130 
131  $accounts = Account::getByName('account1');
132  $this->assertEquals(1, count($accounts[0]));
133  $this->assertEquals(123456, $accounts[0]->officePhone);
134  $this->assertEquals(555, $accounts[0]->officeFax);
135  $this->assertEquals(1, $accounts[0]->employees);
136  $this->assertEquals('http://www.account1.com', $accounts[0]->website);
137  $this->assertEquals(100, $accounts[0]->annualRevenue);
138  $this->assertEquals('desc1', $accounts[0]->description);
139  $this->assertEquals('city1', $accounts[0]->billingAddress->city);
140  $this->assertEquals('country1', $accounts[0]->billingAddress->country);
141  $this->assertEquals('postal1', $accounts[0]->billingAddress->postalCode);
142  $this->assertEquals('state1', $accounts[0]->billingAddress->state);
143  $this->assertEquals('street11', $accounts[0]->billingAddress->street1);
144  $this->assertEquals('street21', $accounts[0]->billingAddress->street2);
145  $this->assertEquals('a@a.com', $accounts[0]->primaryEmail->emailAddress);
146  $this->assertEquals(null, $accounts[0]->primaryEmail->isInvalid);
147  $this->assertEquals(null, $accounts[0]->primaryEmail->optOut);
148  $this->assertTrue($accounts[0]->account->isSame($parentAccount));
149  $this->assertEquals('Automotive', $accounts[0]->industry->value);
150  $this->assertEquals('Prospect', $accounts[0]->type->value);
151 
152  $accounts = Account::getByName('account2');
153  $this->assertEquals(1, count($accounts[0]));
154  $this->assertEquals(223456, $accounts[0]->officePhone);
155  $this->assertEquals(666, $accounts[0]->officeFax);
156  $this->assertEquals(2, $accounts[0]->employees);
157  $this->assertEquals('http://www.account2.com', $accounts[0]->website);
158  $this->assertEquals(200, $accounts[0]->annualRevenue);
159  $this->assertEquals('desc2', $accounts[0]->description);
160  $this->assertEquals('city2', $accounts[0]->billingAddress->city);
161  $this->assertEquals('country2', $accounts[0]->billingAddress->country);
162  $this->assertEquals('postal2', $accounts[0]->billingAddress->postalCode);
163  $this->assertEquals('state2', $accounts[0]->billingAddress->state);
164  $this->assertEquals('street12', $accounts[0]->billingAddress->street1);
165  $this->assertEquals('street22', $accounts[0]->billingAddress->street2);
166  $this->assertEquals('b@b.com', $accounts[0]->primaryEmail->emailAddress);
167  $this->assertEquals('1', $accounts[0]->primaryEmail->isInvalid);
168  $this->assertEquals('1', $accounts[0]->primaryEmail->optOut);
169  $this->assertTrue($accounts[0]->account->isSame($parentAccount));
170  $this->assertEquals('Banking', $accounts[0]->industry->value);
171  $this->assertEquals('Customer', $accounts[0]->type->value);
172 
173  $accounts = Account::getByName('account3');
174  $this->assertEquals(1, count($accounts[0]));
175  $this->assertEquals(323456, $accounts[0]->officePhone);
176  $this->assertEquals(777, $accounts[0]->officeFax);
177  $this->assertEquals(3, $accounts[0]->employees);
178  $this->assertEquals('http://www.account3.com', $accounts[0]->website);
179  $this->assertEquals(300, $accounts[0]->annualRevenue);
180  $this->assertEquals('desc3', $accounts[0]->description);
181  $this->assertEquals('city3', $accounts[0]->billingAddress->city);
182  $this->assertEquals('country3', $accounts[0]->billingAddress->country);
183  $this->assertEquals('postal3', $accounts[0]->billingAddress->postalCode);
184  $this->assertEquals('state3', $accounts[0]->billingAddress->state);
185  $this->assertEquals('street13', $accounts[0]->billingAddress->street1);
186  $this->assertEquals('street23', $accounts[0]->billingAddress->street2);
187  $this->assertEquals('c@c.com', $accounts[0]->primaryEmail->emailAddress);
188  $this->assertEquals(null, $accounts[0]->primaryEmail->isInvalid);
189  $this->assertEquals(null, $accounts[0]->primaryEmail->optOut);
190  $this->assertTrue($accounts[0]->account->isSame($parentAccount));
191  $this->assertEquals('Energy', $accounts[0]->industry->value);
192  $this->assertEquals('Vendor', $accounts[0]->type->value);
193 
194  //Confirm 10 rows were processed as 'created'.
195  $this->assertEquals(3, ImportDatabaseUtil::getCount($import->getTempTableName(), "status = "
196  . ImportRowDataResultsUtil::CREATED));
197 
198  //Confirm that 0 rows were processed as 'updated'.
199  $this->assertEquals(0, ImportDatabaseUtil::getCount($import->getTempTableName(), "status = "
200  . ImportRowDataResultsUtil::UPDATED));
201 
202  //Confirm 2 rows were processed as 'errors'.
203  $this->assertEquals(0, ImportDatabaseUtil::getCount($import->getTempTableName(), "status = "
204  . ImportRowDataResultsUtil::ERROR));
205 
206  $beansWithErrors = ImportDatabaseUtil::getSubset($import->getTempTableName(), "status = "
207  . ImportRowDataResultsUtil::ERROR);
208  $this->assertEquals(0, count($beansWithErrors));
209 
210  //test the parent account has 3 children
211  $parentAccount->forget();
212  $parentAccount = Account::getById($parentAccountId);
213  $this->assertEquals(3, $parentAccount->accounts->count());
214  }
215 
216  public function testImportWithLatestActivityDateTime()
217  {
218  Yii::app()->user->userModel = User::getByUsername('super');
219  $accounts = Account::deleteAll();
220  $import = new Import();
221  $serializedData['importRulesType'] = 'Accounts';
222  $serializedData['firstRowIsHeaderRow'] = true;
223  $import->serializedData = serialize($serializedData);
224  $this->assertTrue($import->save());
225 
226  ImportTestHelper::
227  createTempTableByFileNameAndTableName('importWithLatestActivityDateTimeTest.csv', $import->getTempTableName(), true,
228  Yii::getPathOfAlias('application.modules.accounts.tests.unit.files'));
229  $mappingData = array(
230  'column_0' => ImportMappingUtil::makeStringColumnMappingData ('name'),
231  'column_1' => ImportMappingUtil::makeDateTimeColumnMappingData ('latestActivityDateTime'),
232  );
233 
234  $importRules = ImportRulesUtil::makeImportRulesByType('Accounts');
235  $page = 0;
236  $config = array('pagination' => array('pageSize' => 50)); //This way all rows are processed.
237  $dataProvider = new ImportDataProvider($import->getTempTableName(), true, $config);
238  $dataProvider->getPagination()->setCurrentPage($page);
239  $importResultsUtil = new ImportResultsUtil($import);
240  $messageLogger = new ImportMessageLogger();
241  ImportUtil::importByDataProvider($dataProvider,
242  $importRules,
243  $mappingData,
244  $importResultsUtil,
246  $messageLogger);
247  $importResultsUtil->processStatusAndMessagesForEachRow();
248 
249  //Confirm that 2 models where created.
250  $accounts = Account::getAll();
251  $this->assertCount(2, $accounts);
252 
253  $accounts = Account::getByName('company1');
254  $this->assertEquals('2011-12-22 05:03', substr($accounts[0]->latestActivityDateTime, 0, -3));
255 
256  $accounts = Account::getByName('company2');
257  $this->assertNull($accounts[0]->latestActivityDateTime);
258 
259  //Confirm 2 rows were processed as 'created'.
260  $this->assertEquals(2, ImportDatabaseUtil::getCount($import->getTempTableName(), "status = "
261  . ImportRowDataResultsUtil::CREATED));
262 
263  //Confirm that 0 rows were processed as 'updated'.
264  $this->assertEquals(0, ImportDatabaseUtil::getCount($import->getTempTableName(), "status = "
265  . ImportRowDataResultsUtil::UPDATED));
266 
267  //Confirm 0 rows were processed as 'errors'.
268  $this->assertEquals(0, ImportDatabaseUtil::getCount($import->getTempTableName(), "status = "
269  . ImportRowDataResultsUtil::ERROR));
270 
271  $beansWithErrors = ImportDatabaseUtil::getSubset($import->getTempTableName(), "status = "
272  . ImportRowDataResultsUtil::ERROR);
273  $this->assertEquals(0, count($beansWithErrors));
274  }
275  }
276 ?>
static makeEmailColumnMappingData($attributeName, $defaultValue=null)
static makeImportRulesByType($importRulesType)
static getByUsername($username)
Definition: User.php:49
static makeDateTimeColumnMappingData($attributeName, $defaultValue=null, $format= 'MM-dd-yyyy hh:mm')
static getCount($tableName, $where=null)
static makeFloatColumnMappingData($attributeName, $defaultValue=null)
static importByDataProvider(ImportDataProvider $dataProvider, ImportRules $importRules, $mappingData, ImportResultsUtil $importResultsUtil, ExplicitReadWriteModelPermissions $explicitReadWriteModelPermissions, ImportMessageLogger $messageLogger)
Definition: ImportUtil.php:51
static makeByImportRulesTypeAndAttributeIndexOrDerivedType($importRulesType, $attributeIndexOrDerivedType, $penultimateModelClassName=null, $explicitReadWriteModelPermissions=null)
static makeStringColumnMappingData($attributeName, $defaultValue=null)
static makeDropDownColumnMappingData($attributeName, $defaultValue=null, $customFieldsInstructionData=null)
static getSubset($tableName, $where=null, $count=null, $offset=null)
static makeHasOneColumnMappingData($attributeName, $type=RelatedModelValueTypeMappingRuleForm::ZURMO_MODEL_ID)
static deleteAll()
static getById($id, $modelClassName=null)
static getAll($orderBy=null, $sortDescending=false, $modelClassName=null)
static makeTextAreaColumnMappingData($attributeName)
static makeUrlColumnMappingData($attributeName, $defaultValue=null)
Generated on Sat Jul 4 2020 07:10:29
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.