2 /*********************************************************************************
3 * SugarCRM Community Edition is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
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.
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
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
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.
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.
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 ********************************************************************************/
41 * @brief Try to compare dates in different formats
44 class Bug43716Test extends Sugar_PHPUnit_Framework_TestCase
46 private $backup = array();
48 private $upgradeHistory = null;
49 private $moreResetPatch = null;
50 private $patchToCheck = null;
51 private $moreResetPatchFile = '';
52 private $patchToCheckFile = '';
53 private $filenamePostfix = '-restore';
56 * @brief create user, two patches with different dates
59 public function setUp()
61 $this->user = SugarTestUserUtilities::createAnonymousUser();
62 $this->upgradeHistory = new UpgradeHistory();
63 if (isset($GLOBALS['current_user']))
65 $this->backup['current_user'] = $GLOBALS['current_user'];
67 $GLOBALS['current_user'] = $this->user;
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';
78 $this->moreResetPatchFile = $this->moreResetPatch->filename.'.'.$i;
81 while (is_file($this->moreResetPatchFile.$this->filenamePostfix));
82 $f = fopen($this->moreResetPatchFile.$this->filenamePostfix, 'w+');
84 $this->moreResetPatch->filename = $this->moreResetPatchFile.'.html';
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);
95 $this->patchToCheckFile = $this->patchToCheck->filename.'.'.$i;
98 while (is_file($this->patchToCheckFile.$this->filenamePostfix));
99 $f = fopen($this->patchToCheckFile.$this->filenamePostfix, 'w+');
101 $this->patchToCheck->filename = $this->patchToCheckFile.'.html';
104 * @brief formats of date and time for testing
107 public function getUninstallAvailable()
109 $dateFormats = array_keys($GLOBALS['sugar_config']['date_formats']);
110 $timeFormats = array_keys($GLOBALS['sugar_config']['time_formats']);
112 foreach ($dateFormats as $dateFormat)
114 foreach ($timeFormats as $timeFormat) {
115 $return[] = array($dateFormat, $timeFormat);
122 * @brief creation of two dates in local format and try to compare they through UninstallAvailable
123 * @dataProvider getUninstallAvailable
126 * @param string $dateFormat date format
127 * @param string $timeFormat time format
130 public function testUninstallAvailable($dateFormat, $timeFormat)
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);
138 $this->upgradeHistory->UninstallAvailable(array($this->moreResetPatch), $this->patchToCheck),
139 'UninstallAvailable should return false'
144 * @brief remove user and patches information
147 public function tearDown()
149 unlink($this->moreResetPatchFile.$this->filenamePostfix);
150 unlink($this->patchToCheckFile.$this->filenamePostfix);
151 unset($this->upgradeHistory);
152 SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
154 unset($GLOBALS['current_user']);
155 foreach ($this->backup as $k => $v)