Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
AccountContactAffiliationImportTest.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  Yii::import('application.modules.contacts.data.*');
48  $defaultDataMaker = new ContactsDefaultDataMaker();
49  $defaultDataMaker->make();
50  Yii::import('application.modules.accountContactAffiliations.data.*');
51  $defaultDataMaker = new AccountContactAffiliationsDefaultDataMaker();
52  $defaultDataMaker->make();
53  Currency::getAll(); //forces base currency to be created.
55  }
56 
57  public function testSimpleUserImportWhereAllRowsSucceed()
58  {
59  Yii::app()->user->userModel = User::getByUsername('super');
60  $account = AccountTestHelper::
61  createAccountByNameForOwner('Account',
62  Yii::app()->user->userModel);
63  $contact = ContactTestHelper::
64  createContactByNameForOwner('Contact',
65  Yii::app()->user->userModel);
66  $accountContactAffiliations = AccountContactAffiliation::getAll();
67  $this->assertEquals(0, count($accountContactAffiliations));
68  $import = new Import();
69  $serializedData['importRulesType'] = 'AccountContactAffiliations';
70  $serializedData['firstRowIsHeaderRow'] = true;
71  $import->serializedData = serialize($serializedData);
72  $this->assertTrue($import->save());
73 
74  ImportTestHelper::
75  createTempTableByFileNameAndTableName('importTest.csv', $import->getTempTableName(), true,
76  Yii::getPathOfAlias('application.modules.accountContactAffiliations.tests.unit.files'));
77 
78  //update the ids of the account column to match the parent account.
79  ZurmoRedBean::exec("update " . $import->getTempTableName() . " set column_2 = " .
80  $account->id . " where id != 1 limit 4");
81  ZurmoRedBean::exec("update " . $import->getTempTableName() . " set column_1 = " .
82  $contact->id . " where id != 1 limit 4");
83 
84  $this->assertEquals(4, ImportDatabaseUtil::getCount($import->getTempTableName())); // includes header rows.
85 
86  $mappingData = array(
88  'column_1' => ImportMappingUtil::makeHasOneColumnMappingData ('contact'),
89  'column_2' => ImportMappingUtil::makeHasOneColumnMappingData ('account'),
90  );
91 
92  $importRules = ImportRulesUtil::makeImportRulesByType('AccountContactAffiliations');
93  $page = 0;
94  $config = array('pagination' => array('pageSize' => 50)); //This way all rows are processed.
95  $dataProvider = new ImportDataProvider($import->getTempTableName(), true, $config);
96  $dataProvider->getPagination()->setCurrentPage($page);
97  $importResultsUtil = new ImportResultsUtil($import);
98  $messageLogger = new ImportMessageLogger();
100  $importRules,
101  $mappingData,
102  $importResultsUtil,
104  $messageLogger);
105  $importResultsUtil->processStatusAndMessagesForEachRow();
106 
107  //Confirm that 3 models where created.
108  $accountContactAffiliations = AccountContactAffiliation::getAll();
109  $this->assertEquals(3, count($accountContactAffiliations));
110 
111  $this->assertEquals('0', $accountContactAffiliations[0]->primary);
112  $this->assertTrue($accountContactAffiliations[0]->account->isSame($account));
113  $this->assertTrue($accountContactAffiliations[0]->contact->isSame($contact));
114  $this->assertEquals('', $accountContactAffiliations[0]->role->value);
115 
116  $this->assertEquals('0', $accountContactAffiliations[1]->primary);
117  $this->assertTrue($accountContactAffiliations[1]->account->isSame($account));
118  $this->assertTrue($accountContactAffiliations[1]->contact->isSame($contact));
119  $this->assertEquals('Support', $accountContactAffiliations[1]->role->value);
120 
121  $this->assertEquals('0', $accountContactAffiliations[2]->primary);
122  $this->assertTrue($accountContactAffiliations[2]->account->isSame($account));
123  $this->assertTrue($accountContactAffiliations[2]->contact->isSame($contact));
124  $this->assertEquals('Technical', $accountContactAffiliations[2]->role->value);
125 
126  //Confirm 3 rows were processed as 'created'.
127  $this->assertEquals(3, ImportDatabaseUtil::getCount($import->getTempTableName(), "status = "
128  . ImportRowDataResultsUtil::CREATED));
129 
130  //Confirm that 0 rows were processed as 'updated'.
131  $this->assertEquals(0, ImportDatabaseUtil::getCount($import->getTempTableName(), "status = "
132  . ImportRowDataResultsUtil::UPDATED));
133  }
134  }
135 ?>
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 loadStartingData()
static makeDropDownColumnMappingData($attributeName, $defaultValue=null, $customFieldsInstructionData=null)
static getAll($orderBy=null, $sortDescending=false, $modelClassName=null, $buildFirstCurrency=true)
Definition: Currency.php:107
static makeHasOneColumnMappingData($attributeName, $type=RelatedModelValueTypeMappingRuleForm::ZURMO_MODEL_ID)
static getAll($orderBy=null, $sortDescending=false, $modelClassName=null)
Generated on Tue Jul 7 2020 07:10:30
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.