All Data Structures Functions Variables Pages
TaskImportTest.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  $tasks = Task::getAll();
52  $this->assertEquals(0, count($tasks));
53  $import = new Import();
54  $serializedData['importRulesType'] = 'Tasks';
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.tasks.tests.unit.files'));
62 
63  $this->assertEquals(4, ImportDatabaseUtil::getCount($import->getTempTableName())); // includes header rows.
64 
65  $mappingData = array(
67  'column_1' => ImportMappingUtil::makeDateTimeColumnMappingData ('dueDateTime'),
68  'column_2' => ImportMappingUtil::makeDateTimeColumnMappingData ('completedDateTime'),
69  'column_3' => ImportMappingUtil::makeIntegerColumnMappingData ('status'),
70  'column_4' => ImportMappingUtil::makeModelDerivedColumnMappingData ('AccountDerived'),
71  'column_5' => ImportMappingUtil::makeModelDerivedColumnMappingData ('ContactDerived'),
72  'column_6' => ImportMappingUtil::makeModelDerivedColumnMappingData ('OpportunityDerived'),
73  'column_7' => ImportMappingUtil::makeTextAreaColumnMappingData ('description'),
74  );
75 
76  $importRules = ImportRulesUtil::makeImportRulesByType('Tasks');
77  $page = 0;
78  $config = array('pagination' => array('pageSize' => 50)); //This way all rows are processed.
79  $dataProvider = new ImportDataProvider($import->getTempTableName(), true, $config);
80  $dataProvider->getPagination()->setCurrentPage($page);
81  $importResultsUtil = new ImportResultsUtil($import);
82  $actionDateTime = substr(DateTimeUtil::convertTimestampToDbFormatDateTime(time()), 0, -3);
83  $messageLogger = new ImportMessageLogger();
85  $importRules,
86  $mappingData,
87  $importResultsUtil,
89  $messageLogger);
90  $importResultsUtil->processStatusAndMessagesForEachRow();
91 
92  //Confirm that 3 models where created.
93  $tasks = Task::getAll();
94  $this->assertEquals(3, count($tasks));
95 
96  $tasks = Task::getByName('task1');
97  $this->assertEquals(1, count($tasks[0]));
98  $this->assertEquals(1, count($tasks[0]->activityItems));
99  $this->assertEquals('testAccount', $tasks[0]->activityItems[0]->name);
100  $this->assertEquals('Account', get_class($tasks[0]->activityItems[0]));
101  $this->assertFalse ((bool)$tasks[0]->completed);
102  $this->assertEquals (Task::STATUS_NEW, $tasks[0]->status);
103  $this->assertEquals($actionDateTime, substr($tasks[0]->latestDateTime, 0, -3));
104 
105  $tasks = Task::getByName('task2');
106  $this->assertEquals(1, count($tasks[0]));
107  $this->assertEquals(1, count($tasks[0]->activityItems));
108  $this->assertEquals('testContact', $tasks[0]->activityItems[0]->firstName);
109  $this->assertEquals('Contact', get_class($tasks[0]->activityItems[0]));
110  $this->assertTrue ((bool)$tasks[0]->completed);
111  $this->assertEquals (Task::STATUS_COMPLETED, $tasks[0]->status);
112  $this->assertEquals('2011-12-22 06:03', substr($tasks[0]->latestDateTime, 0, -3));
113 
114  $tasks = Task::getByName('task3');
115  $this->assertEquals(1, count($tasks[0]));
116  $this->assertEquals(1, count($tasks[0]->activityItems));
117  $this->assertEquals('testOpportunity', $tasks[0]->activityItems[0]->name);
118  $this->assertEquals('Opportunity', get_class($tasks[0]->activityItems[0]));
119  $this->assertFalse ((bool)$tasks[0]->completed);
120  $this->assertEquals (Task::STATUS_IN_PROGRESS, $tasks[0]->status);
121  //Not checking the minutes because sometimes it was failing for one minute
122  $this->assertEquals(substr($actionDateTime, 0, -2), substr($tasks[0]->latestDateTime, 0, -5));
123 
124  //Confirm 10 rows were processed as 'created'.
125  $this->assertEquals(3, ImportDatabaseUtil::getCount($import->getTempTableName(), "status = "
126  . ImportRowDataResultsUtil::CREATED));
127 
128  //Confirm that 0 rows were processed as 'updated'.
129  $this->assertEquals(0, ImportDatabaseUtil::getCount($import->getTempTableName(), "status = "
130  . ImportRowDataResultsUtil::UPDATED));
131 
132  //Confirm 2 rows were processed as 'errors'.
133  $this->assertEquals(0, ImportDatabaseUtil::getCount($import->getTempTableName(), "status = "
134  . ImportRowDataResultsUtil::ERROR));
135 
136  $beansWithErrors = ImportDatabaseUtil::getSubset($import->getTempTableName(), "status = "
137  . ImportRowDataResultsUtil::ERROR);
138  $this->assertEquals(0, count($beansWithErrors));
139  }
140  }
141 ?>
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 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 31 2020 07:10:35