Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
AccountAccountAffiliationImportTest.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 testSimpleUserImportWhereAllRowsSucceed()
50  {
51  Yii::app()->user->userModel = User::getByUsername('super');
52  $account = AccountTestHelper::
53  createAccountByNameForOwner('Account',
54  Yii::app()->user->userModel);
55  $account2 = AccountTestHelper::
56  createAccountByNameForOwner('Account2',
57  Yii::app()->user->userModel);
58  $accountAccountAffiliations = AccountAccountAffiliation::getAll();
59  $this->assertEquals(0, count($accountAccountAffiliations));
60  $import = new Import();
61  $serializedData['importRulesType'] = 'AccountAccountAffiliations';
62  $serializedData['firstRowIsHeaderRow'] = true;
63  $import->serializedData = serialize($serializedData);
64  $this->assertTrue($import->save());
65 
66  ImportTestHelper::
67  createTempTableByFileNameAndTableName('importTest.csv', $import->getTempTableName(), true,
68  Yii::getPathOfAlias('application.modules.accountAccountAffiliations.tests.unit.files'));
69 
70  //update the ids of the account column to match the parent account.
71  ZurmoRedBean::exec("update " . $import->getTempTableName() . " set column_0 = " .
72  $account->id . " where id != 1 limit 4");
73  ZurmoRedBean::exec("update " . $import->getTempTableName() . " set column_1 = " .
74  $account2->id . " where id != 1 limit 4");
75 
76  $this->assertEquals(4, ImportDatabaseUtil::getCount($import->getTempTableName())); // includes header rows.
77 
78  $mappingData = array(
79  'column_0' => ImportMappingUtil::makeHasOneColumnMappingData ('primaryAccount'),
80  'column_1' => ImportMappingUtil::makeHasOneColumnMappingData ('secondaryAccount')
81  );
82 
83  $importRules = ImportRulesUtil::makeImportRulesByType('AccountAccountAffiliations');
84  $page = 0;
85  $config = array('pagination' => array('pageSize' => 50)); //This way all rows are processed.
86  $dataProvider = new ImportDataProvider($import->getTempTableName(), true, $config);
87  $dataProvider->getPagination()->setCurrentPage($page);
88  $importResultsUtil = new ImportResultsUtil($import);
89  $messageLogger = new ImportMessageLogger();
91  $importRules,
92  $mappingData,
93  $importResultsUtil,
95  $messageLogger);
96  $importResultsUtil->processStatusAndMessagesForEachRow();
97 
98  //Confirm that 3 models where created.
99  $accountAccountAffiliations = AccountAccountAffiliation::getAll();
100  $this->assertEquals(3, count($accountAccountAffiliations));
101 
102  $this->assertTrue($accountAccountAffiliations[0]->primaryAccount->isSame($account));
103  $this->assertTrue($accountAccountAffiliations[0]->secondaryAccount->isSame($account2));
104 
105  $this->assertTrue($accountAccountAffiliations[1]->primaryAccount->isSame($account));
106  $this->assertTrue($accountAccountAffiliations[1]->secondaryAccount->isSame($account2));
107 
108  $this->assertTrue($accountAccountAffiliations[2]->primaryAccount->isSame($account));
109  $this->assertTrue($accountAccountAffiliations[2]->secondaryAccount->isSame($account2));
110 
111  //Confirm 3 rows were processed as 'created'.
112  $this->assertEquals(3, ImportDatabaseUtil::getCount($import->getTempTableName(), "status = "
113  . ImportRowDataResultsUtil::CREATED));
114 
115  //Confirm that 0 rows were processed as 'updated'.
116  $this->assertEquals(0, ImportDatabaseUtil::getCount($import->getTempTableName(), "status = "
117  . ImportRowDataResultsUtil::UPDATED));
118  }
119  }
120 ?>
static makeImportRulesByType($importRulesType)
static getByUsername($username)
Definition: User.php:49
static getCount($tableName, $where=null)
static importByDataProvider(ImportDataProvider $dataProvider, ImportRules $importRules, $mappingData, ImportResultsUtil $importResultsUtil, ExplicitReadWriteModelPermissions $explicitReadWriteModelPermissions, ImportMessageLogger $messageLogger)
Definition: ImportUtil.php:51
static makeHasOneColumnMappingData($attributeName, $type=RelatedModelValueTypeMappingRuleForm::ZURMO_MODEL_ID)
static getAll($orderBy=null, $sortDescending=false, $modelClassName=null)
Generated on Sun Jul 12 2020 07:10:28
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.