All Data Structures Functions Variables Pages
ImportWizardFormPostUtilTest.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 function testSanitizePostByTypeForSavingMappingData()
40  {
41  $language = Yii::app()->getLanguage();
42  $this->assertEquals($language, 'en');
43  $postData = array(
44  'column_0' => array('attributeIndexOrDerivedType' => 'date',
45  'mappingRulesData' => array(
46  'DefaultValueModelAttributeMappingRuleForm' =>
47  array('defaultValue' => '5/4/2011'))),
48  'column_1' => array('attributeIndexOrDerivedType' => 'dateTime',
49  'mappingRulesData' => array(
50  'DefaultValueModelAttributeMappingRuleForm' =>
51  array('defaultValue' => '5/4/2011 5:45 PM'))),
52  );
53  $sanitizedPostData = ImportWizardFormPostUtil::
54  sanitizePostByTypeForSavingMappingData('ImportModelTestItem', $postData);
55  $compareDateTime = DateTimeUtil::
57  $compareData = array(
58  'column_0' => array('attributeIndexOrDerivedType' => 'date',
59  'mappingRulesData' => array(
60  'DefaultValueModelAttributeMappingRuleForm' =>
61  array('defaultValue' => '2011-05-04'))),
62  'column_1' => array('attributeIndexOrDerivedType' => 'dateTime',
63  'mappingRulesData' => array(
64  'DefaultValueModelAttributeMappingRuleForm' =>
65  array('defaultValue' => $compareDateTime))),
66  );
67  $this->assertEquals($compareData, $sanitizedPostData);
68 
69  //now do German (de) to check a different locale.
70  Yii::app()->setLanguage('de');
71  $postData = array(
72  'column_0' => array('attributeIndexOrDerivedType' => 'date',
73  'mappingRulesData' => array(
74  'DefaultValueModelAttributeMappingRuleForm' =>
75  array('defaultValue' => '04.05.2011'))),
76  'column_1' => array('attributeIndexOrDerivedType' => 'dateTime',
77  'mappingRulesData' => array(
78  'DefaultValueModelAttributeMappingRuleForm' =>
79  array('defaultValue' => '04.05.2011 17:45'))),
80  );
81  $sanitizedPostData = ImportWizardFormPostUtil::
82  sanitizePostByTypeForSavingMappingData('ImportModelTestItem', $postData);
83  $compareDateTime = DateTimeUtil::
85  $compareData = array(
86  'column_0' => array('attributeIndexOrDerivedType' => 'date',
87  'mappingRulesData' => array(
88  'DefaultValueModelAttributeMappingRuleForm' =>
89  array('defaultValue' => '2011-05-04'))),
90  'column_1' => array('attributeIndexOrDerivedType' => 'dateTime',
91  'mappingRulesData' => array(
92  'DefaultValueModelAttributeMappingRuleForm' =>
93  array('defaultValue' => $compareDateTime))),
94  );
95  $this->assertEquals($compareData, $sanitizedPostData);
96 
97  //reset language back to english
98  Yii::app()->setLanguage('en');
99 
100  //test sanitizing a bad datetime
101  $postData = array(
102  'column_0' => array('attributeIndexOrDerivedType' => 'dateTime',
103  'mappingRulesData' => array(
104  'DefaultValueModelAttributeMappingRuleForm' =>
105  array('defaultValue' => 'wang chung'))),
106  );
107  $sanitizedPostData = ImportWizardFormPostUtil::
108  sanitizePostByTypeForSavingMappingData('ImportModelTestItem', $postData);
109  $this->assertNull($sanitizedPostData['column_0']['mappingRulesData']
110  ['DefaultValueModelAttributeMappingRuleForm']['defaultValue']);
111  //sanitize an empty datetime
112  $postData = array(
113  'column_0' => array('attributeIndexOrDerivedType' => 'dateTime',
114  'mappingRulesData' => array(
115  'DefaultValueModelAttributeMappingRuleForm' =>
116  array('defaultValue' => ''))),
117  );
118  $sanitizedPostData = ImportWizardFormPostUtil::
119  sanitizePostByTypeForSavingMappingData('ImportModelTestItem', $postData);
120  $this->assertEmpty($sanitizedPostData['column_0']['mappingRulesData']
121  ['DefaultValueModelAttributeMappingRuleForm']['defaultValue']);
122  }
123  }
124 ?>
static convertDateTimeLocaleFormattedDisplayToDbFormattedDateTimeWithSecondsAsZero($localeFormattedDateTime)
static sanitizePostByTypeForSavingMappingData($importRulesType, $postMappingData)
Generated on Fri Jun 5 2020 07:10:32