Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
MeetingImportTest.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  Yii::app()->timeZoneHelper->load();
45  MeetingTestHelper::createCategories();
46  }
47 
48  public function testSimpleUserImportWhereAllRowsSucceed()
49  {
50  Yii::app()->user->userModel = User::getByUsername('super');
51 
52  $meetings = Meeting::getAll();
53  $this->assertEquals(0, count($meetings));
54  $import = new Import();
55  $serializedData['importRulesType'] = 'Meetings';
56  $serializedData['firstRowIsHeaderRow'] = true;
57  $import->serializedData = serialize($serializedData);
58  $this->assertTrue($import->save());
59 
60  ImportTestHelper::
61  createTempTableByFileNameAndTableName('importAnalyzerTest.csv', $import->getTempTableName(), true,
62  Yii::getPathOfAlias('application.modules.meetings.tests.unit.files'));
63 
64  $this->assertEquals(4, ImportDatabaseUtil::getCount($import->getTempTableName())); // includes header rows.
65 
66  $mappingData = array(
68  'column_1' => ImportMappingUtil::makeStringColumnMappingData ('location'),
69  'column_2' => ImportMappingUtil::makeDateTimeColumnMappingData ('startDateTime'),
70  'column_3' => ImportMappingUtil::makeDateTimeColumnMappingData ('endDateTime'),
71  'column_4' => ImportMappingUtil::makeDropDownColumnMappingData ('category'),
72  'column_5' => ImportMappingUtil::makeModelDerivedColumnMappingData ('AccountDerived'),
73  'column_6' => ImportMappingUtil::makeModelDerivedColumnMappingData ('ContactDerived'),
74  'column_7' => ImportMappingUtil::makeModelDerivedColumnMappingData ('OpportunityDerived'),
75  'column_8' => ImportMappingUtil::makeTextAreaColumnMappingData ('description'),
76  );
77 
78  $importRules = ImportRulesUtil::makeImportRulesByType('Meetings');
79  $page = 0;
80  $config = array('pagination' => array('pageSize' => 50)); //This way all rows are processed.
81  $dataProvider = new ImportDataProvider($import->getTempTableName(), true, $config);
82  $dataProvider->getPagination()->setCurrentPage($page);
83  $importResultsUtil = new ImportResultsUtil($import);
84  $messageLogger = new ImportMessageLogger();
86  $importRules,
87  $mappingData,
88  $importResultsUtil,
90  $messageLogger);
91  $importResultsUtil->processStatusAndMessagesForEachRow();
92 
93  //Confirm that 3 models where created.
94  $meetings = Meeting::getAll();
95  $this->assertEquals(3, count($meetings));
96 
97  $meetings = Meeting::getByName('meeting1');
98  $this->assertEquals(1, count($meetings[0]));
99  $this->assertEquals(1, count($meetings[0]->activityItems));
100  $this->assertEquals('testAccount', $meetings[0]->activityItems[0]->name);
101  $this->assertEquals('Account', get_class($meetings[0]->activityItems[0]));
102  $this->assertEquals('2011-12-22 05:03', substr($meetings[0]->latestDateTime, 0, -3));
103 
104  $meetings = Meeting::getByName('meeting2');
105  $this->assertEquals(1, count($meetings[0]));
106  $this->assertEquals(1, count($meetings[0]->activityItems));
107  $this->assertEquals('testContact', $meetings[0]->activityItems[0]->firstName);
108  $this->assertEquals('Contact', get_class($meetings[0]->activityItems[0]));
109  $this->assertEquals('2011-12-22 05:03', substr($meetings[0]->latestDateTime, 0, -3));
110 
111  $meetings = Meeting::getByName('meeting3');
112  $this->assertEquals(1, count($meetings[0]));
113  $this->assertEquals(1, count($meetings[0]->activityItems));
114  $this->assertEquals('testOpportunity', $meetings[0]->activityItems[0]->name);
115  $this->assertEquals('Opportunity', get_class($meetings[0]->activityItems[0]));
116  $this->assertEquals('2011-12-22 06:03', substr($meetings[0]->latestDateTime, 0, -3));
117 
118  //Confirm 10 rows were processed as 'created'.
119  $this->assertEquals(3, ImportDatabaseUtil::getCount($import->getTempTableName(), "status = "
120  . ImportRowDataResultsUtil::CREATED));
121 
122  //Confirm that 0 rows were processed as 'updated'.
123  $this->assertEquals(0, ImportDatabaseUtil::getCount($import->getTempTableName(), "status = "
124  . ImportRowDataResultsUtil::UPDATED));
125 
126  //Confirm 2 rows were processed as 'errors'.
127  $this->assertEquals(0, ImportDatabaseUtil::getCount($import->getTempTableName(), "status = "
128  . ImportRowDataResultsUtil::ERROR));
129 
130  $beansWithErrors = ImportDatabaseUtil::getSubset($import->getTempTableName(), "status = "
131  . ImportRowDataResultsUtil::ERROR);
132  $this->assertEquals(0, count($beansWithErrors));
133  }
134  }
135 ?>
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 importByDataProvider(ImportDataProvider $dataProvider, ImportRules $importRules, $mappingData, ImportResultsUtil $importResultsUtil, ExplicitReadWriteModelPermissions $explicitReadWriteModelPermissions, ImportMessageLogger $messageLogger)
Definition: ImportUtil.php:51
static makeStringColumnMappingData($attributeName, $defaultValue=null)
static makeDropDownColumnMappingData($attributeName, $defaultValue=null, $customFieldsInstructionData=null)
static getSubset($tableName, $where=null, $count=null, $offset=null)
static makeModelDerivedColumnMappingData($derivedAttributeName, $type=IdValueTypeMappingRuleForm::EXTERNAL_SYSTEM_ID)
static getAll($orderBy=null, $sortDescending=false, $modelClassName=null)
static makeTextAreaColumnMappingData($attributeName)
Generated on Tue Jul 7 2020 07:10:34
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.