All Data Structures Functions Variables Pages
NoteImportTest.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  }
46 
47  public function testSimpleUserImportWhereAllRowsSucceed()
48  {
49  Yii::app()->user->userModel = User::getByUsername('super');
50 
51  $notes = Note::getAll();
52  $this->assertEquals(0, count($notes));
53  $import = new Import();
54  $serializedData['importRulesType'] = 'Notes';
55  $serializedData['firstRowIsHeaderRow'] = true;
56  $import->serializedData = serialize($serializedData);
57  $this->assertTrue($import->save());
58 
59  ImportTestHelper::
60  createTempTableByFileNameAndTableName('simpleImportTest.csv', $import->getTempTableName(), true,
61  Yii::getPathOfAlias('application.modules.notes.tests.unit.files'));
62 
63  $this->assertEquals(4, ImportDatabaseUtil::getCount($import->getTempTableName())); // includes header rows.
64 
65  $mappingData = array(
66  'column_0' => ImportMappingUtil::makeTextAreaColumnMappingData ('description'),
67  'column_1' => ImportMappingUtil::makeDateTimeColumnMappingData ('occurredOnDateTime'),
68  'column_2' => ImportMappingUtil::makeModelDerivedColumnMappingData ('AccountDerived'),
69  'column_3' => ImportMappingUtil::makeModelDerivedColumnMappingData ('ContactDerived'),
70  'column_4' => ImportMappingUtil::makeModelDerivedColumnMappingData ('OpportunityDerived'),
71  );
72 
73  $importRules = ImportRulesUtil::makeImportRulesByType('Notes');
74  $page = 0;
75  $config = array('pagination' => array('pageSize' => 50)); //This way all rows are processed.
76  $dataProvider = new ImportDataProvider($import->getTempTableName(), true, $config);
77  $dataProvider->getPagination()->setCurrentPage($page);
78  $importResultsUtil = new ImportResultsUtil($import);
79  $messageLogger = new ImportMessageLogger();
81  $importRules,
82  $mappingData,
83  $importResultsUtil,
85  $messageLogger);
86  $importResultsUtil->processStatusAndMessagesForEachRow();
87 
88  //Confirm that 3 models where created.
89  $notes = Note::getAll();
90  $this->assertEquals(3, count($notes));
91 
92  $notes = Note::getByName('note1');
93  $this->assertEquals(1, count($notes[0]));
94  $this->assertEquals(1, count($notes[0]->activityItems));
95  $this->assertEquals('testAccount', $notes[0]->activityItems[0]->name);
96  $this->assertEquals('Account', get_class($notes[0]->activityItems[0]));
97  $this->assertEquals('2011-12-22 05:03', substr($notes[0]->latestDateTime, 0, -3));
98 
99  $notes = Note::getByName('note2');
100  $this->assertEquals(1, count($notes[0]));
101  $this->assertEquals(1, count($notes[0]->activityItems));
102  $this->assertEquals('testContact', $notes[0]->activityItems[0]->firstName);
103  $this->assertEquals('Contact', get_class($notes[0]->activityItems[0]));
104  $this->assertEquals('2011-12-22 05:03', substr($notes[0]->latestDateTime, 0, -3));
105 
106  $notes = Note::getByName('note3');
107  $this->assertEquals(1, count($notes[0]));
108  $this->assertEquals(1, count($notes[0]->activityItems));
109  $this->assertEquals('testOpportunity', $notes[0]->activityItems[0]->name);
110  $this->assertEquals('Opportunity', get_class($notes[0]->activityItems[0]));
111  $this->assertEquals('2011-12-22 06:03', substr($notes[0]->latestDateTime, 0, -3));
112 
113  //Confirm 10 rows were processed as 'created'.
114  $this->assertEquals(3, ImportDatabaseUtil::getCount($import->getTempTableName(), "status = "
115  . ImportRowDataResultsUtil::CREATED));
116 
117  //Confirm that 0 rows were processed as 'updated'.
118  $this->assertEquals(0, ImportDatabaseUtil::getCount($import->getTempTableName(), "status = "
119  . ImportRowDataResultsUtil::UPDATED));
120 
121  //Confirm 2 rows were processed as 'errors'.
122  $this->assertEquals(0, ImportDatabaseUtil::getCount($import->getTempTableName(), "status = "
123  . ImportRowDataResultsUtil::ERROR));
124 
125  $beansWithErrors = ImportDatabaseUtil::getSubset($import->getTempTableName(), "status = "
126  . ImportRowDataResultsUtil::ERROR);
127  $this->assertEquals(0, count($beansWithErrors));
128  }
129  }
130 ?>
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 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 Sun May 24 2020 07:10:33