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 ********************************************************************************/
38 require_once "include/generic/LayoutManager.php";
39 require_once "include/generic/SugarWidgets/SugarWidgetFielddatetime.php";
41 class Bug48616Test extends PHPUnit_Framework_TestCase
43 var $sugarWidgetField;
45 public function setUp()
47 $this->sugarWidgetField = new SugarWidgetFieldDateTime48616Mock(new LayoutManager());
48 global $current_user, $timedate;
49 $timedate = TimeDate::getInstance();
50 $current_user = SugarTestUserUtilities::createAnonymousUser();
51 //$this->setOutputBuffering = false;
55 public function tearDown()
57 SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
60 public function testQueryFilterBefore()
62 $layout_def = array ('name' => 'donotinvoiceuntil_c', 'table_key' => 'self', 'qualifier_name' => 'before', 'input_name0' => 'Today', 'input_name1' => '01:00am', 'input_name2' => 'on', 'table_alias' => 'pordr_purchaseorders_cstm', 'column_key' => 'self:donotinvoiceuntil_c', 'type' => 'datetimecombo');
63 $filter = $this->sugarWidgetField->queryFilterBefore($layout_def);
64 if($GLOBALS['db']->getScriptName() == 'mysql')
66 $this->assertRegExp("/pordr_purchaseorders_cstm\.donotinvoiceuntil_c < \'\d{4}\-\d{1,2}-\d{1,2} \d{2}:\d{2}:\d{2}\'/", $filter);
69 else if($GLOBALS['db']->getScriptName() == 'db2') {
75 public function testQueryFilterAfter()
77 $layout_def = array ('name' => 'donotinvoiceuntil_c', 'table_key' => 'self', 'qualifier_name' => 'after', 'input_name0' => 'Today', 'input_name1' => '01:00am', 'input_name2' => 'on', 'table_alias' => 'pordr_purchaseorders_cstm', 'column_key' => 'self:donotinvoiceuntil_c', 'type' => 'datetimecombo');
78 $filter = $this->sugarWidgetField->queryFilterAfter($layout_def);
79 if($GLOBALS['db']->getScriptName() == 'mysql')
81 $this->assertRegExp("/pordr_purchaseorders_cstm\.donotinvoiceuntil_c > \'\d{4}\-\d{1,2}-\d{1,2} \d{2}:\d{2}:\d{2}\'/", $filter);
85 public function testQueryFilterNotEqualsStr()
87 $layout_def = array ('name' => 'donotinvoiceuntil_c', 'table_key' => 'self', 'qualifier_name' => 'not_equals', 'input_name0' => 'Today', 'input_name1' => '01:00am', 'input_name2' => 'on', 'table_alias' => 'pordr_purchaseorders_cstm', 'column_key' => 'self:donotinvoiceuntil_c', 'type' => 'datetimecombo');
88 $filter = $this->sugarWidgetField->queryFilterNot_Equals_str($layout_def);
89 $filter = preg_replace('/\s{2,}/', ' ', $filter);
90 $filter = str_replace("\n", '', $filter);
91 $filter = str_replace("\r", '', $filter);
92 if($GLOBALS['db']->getScriptName() == 'mysql')
94 $this->assertRegExp("/\(pordr_purchaseorders_cstm\.donotinvoiceuntil_c IS NULL OR pordr_purchaseorders_cstm\.donotinvoiceuntil_c < \'\d{4}\-\d{1,2}-\d{1,2} \d{2}:\d{2}:\d{2}\' OR pordr_purchaseorders_cstm\.donotinvoiceuntil_c > \'\d{4}\-\d{1,2}-\d{1,2} \d{2}:\d{2}:\d{2}\'\)/", $filter);
97 else if($GLOBALS['db']->getScriptName() == 'db2') {
98 $this->assertRegExp("/\(pordr_purchaseorders_cstm\.donotinvoiceuntil_c IS NULL OR pordr_purchaseorders_cstm\.donotinvoiceuntil_c < CONVERT\(datetime\,'\d{4}\-\d{1,2}-\d{1,2} \d{2}:\d{2}:\d{2}\',\d+?\) OR pordr_purchaseorders_cstm\.donotinvoiceuntil_c > CONVERT\(datetime\,'\d{4}\-\d{1,2}-\d{1,2} \d{2}:\d{2}:\d{2}\',120\)\)/", $filter);
106 class SugarWidgetFieldDateTime48616Mock extends SugarWidgetFieldDateTime
108 protected function queryDateOp($arg1, $arg2, $op, $type)
111 if($arg2 instanceof DateTime) {
112 $arg2 = $timedate->asDbType($arg2, $type);
114 return "$arg1 $op ".$GLOBALS['db']->convert($GLOBALS['db']->quoted($arg2), $type)."\n";