]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/modules/Administration/Bug43716Test.php
Release 6.5.10
[Github/sugarcrm.git] / tests / modules / Administration / Bug43716Test.php
1 <?php
2 /*********************************************************************************
3  * SugarCRM Community Edition is a customer relationship management program developed by
4  * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc.
5  * 
6  * This program 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 SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
11  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12  * 
13  * This program 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 SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
24  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
25  * 
26  * The interactive user interfaces in modified source and object code 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 "Powered by
32  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
33  * technical reasons, the Appropriate Legal Notices must display the words
34  * "Powered by SugarCRM".
35  ********************************************************************************/
36
37
38
39
40 /**
41  * @brief Try to compare dates in different formats
42  * @ticket 43716
43  */
44 class Bug43716Test extends Sugar_PHPUnit_Framework_TestCase
45 {
46     private $backup = array();
47     private $user = null;
48     private $upgradeHistory = null;
49     private $moreResetPatch = null;
50     private $patchToCheck = null;
51     private $moreResetPatchFile = '';
52     private $patchToCheckFile = '';
53     private $filenamePostfix = '-restore';
54
55     /**
56      * @brief create user, two patches with different dates
57      * @return void
58      */
59     public function setUp()
60     {
61         $this->user = SugarTestUserUtilities::createAnonymousUser();
62         $this->upgradeHistory = new UpgradeHistory();
63         if (isset($GLOBALS['current_user']))
64         {
65             $this->backup['current_user'] = $GLOBALS['current_user'];
66         }
67         $GLOBALS['current_user'] = $this->user;
68
69         $this->moreResetPatch=new stdClass();
70         $this->moreResetPatch->id = 'moreResetPatch-id';
71         $this->moreResetPatch->id_name = 'moreResetPatch-id_name';
72         $this->moreResetPatch->name = 'moreResetPatch-name';
73         $this->moreResetPatch->timestamp = mktime(0, 0, 0, 1, 1, 2006);
74         $this->moreResetPatch->filename = 'moreResetPatch-filename';
75         $i=0;
76         do
77         {
78             $this->moreResetPatchFile = $this->moreResetPatch->filename.'.'.$i;
79             ++$i;
80         }
81         while (is_file($this->moreResetPatchFile.$this->filenamePostfix));
82         $f = fopen($this->moreResetPatchFile.$this->filenamePostfix, 'w+');
83         fclose($f);
84         $this->moreResetPatch->filename = $this->moreResetPatchFile.'.html';
85
86         $this->patchToCheck=new stdClass();
87         $this->patchToCheck->id = 'patchToCheck-id';
88         $this->patchToCheck->id_name = 'patchToCheck-id_name';
89         $this->patchToCheck->name = 'patchToCheck-name';
90         $this->patchToCheck->filename = 'patchToCheck-filename';
91         $this->patchToCheck->timestamp = mktime(23, 59, 59, 12, 25, 2004);
92         $i=0;
93         do
94         {
95             $this->patchToCheckFile = $this->patchToCheck->filename.'.'.$i;
96             ++$i;
97         }
98         while (is_file($this->patchToCheckFile.$this->filenamePostfix));
99         $f = fopen($this->patchToCheckFile.$this->filenamePostfix, 'w+');
100         fclose($f);
101         $this->patchToCheck->filename = $this->patchToCheckFile.'.html';
102     }
103     /**
104      * @brief formats of date and time for testing
105      * @return array
106      */
107     public function getUninstallAvailable()
108     {
109         $dateFormats = array_keys($GLOBALS['sugar_config']['date_formats']);
110         $timeFormats = array_keys($GLOBALS['sugar_config']['time_formats']);
111         $return = array();
112         foreach ($dateFormats as $dateFormat)
113         {
114             foreach ($timeFormats as $timeFormat) {
115                 $return[] = array($dateFormat, $timeFormat);
116             }
117         }
118         return $return;
119     }
120
121     /**
122      * @brief creation of two dates in local format and try to compare they through UninstallAvailable
123      * @dataProvider getUninstallAvailable
124      * @group 43716
125      *
126      * @param string $dateFormat date format
127      * @param string $timeFormat time format
128      * @return void
129      */
130         public function testUninstallAvailable($dateFormat, $timeFormat)
131         {
132         $this->moreResetPatch->date_entered = date($dateFormat.' '.$timeFormat, $this->moreResetPatch->timestamp);
133         $this->patchToCheck->date_entered = date($dateFormat.' '.$timeFormat, $this->patchToCheck->timestamp);
134         $this->user->setPreference('datef', $dateFormat);
135         $this->user->setPreference('timef', $timeFormat);
136
137         $this->assertFalse(
138             $this->upgradeHistory->UninstallAvailable(array($this->moreResetPatch), $this->patchToCheck),
139             'UninstallAvailable should return false'
140         );
141         }
142
143     /**
144      * @brief remove user and patches information
145      * @return void
146      */
147     public function tearDown()
148     {
149         unlink($this->moreResetPatchFile.$this->filenamePostfix);
150         unlink($this->patchToCheckFile.$this->filenamePostfix);
151         unset($this->upgradeHistory);
152         SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
153         unset($this->user);
154         unset($GLOBALS['current_user']);
155         foreach ($this->backup as $k => $v)
156         {
157             global $$k;
158             $$k = $v;
159             $GLOBALS[$k] = $$k;
160         }
161     }
162 }