]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/include/generic/SugarWidgets/Bug48616Test.php
Release 6.4.0
[Github/sugarcrm.git] / tests / include / generic / SugarWidgets / Bug48616Test.php
1 <?php
2 /*********************************************************************************
3  * SugarCRM Community Edition is a customer relationship management program developed by
4  * SugarCRM, Inc. Copyright (C) 2004-2011 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 require_once "include/generic/LayoutManager.php";
39 require_once "include/generic/SugarWidgets/SugarWidgetFielddatetime.php";
40
41 class Bug48616Test extends PHPUnit_Framework_TestCase
42 {
43     var $sugarWidgetField;
44
45     public function setUp()
46     {
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;
52
53     }
54
55     public function tearDown()
56     {
57         SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
58     }
59
60     public function testQueryFilterBefore()
61     {
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')
65         {
66             $this->assertRegExp("/pordr_purchaseorders_cstm\.donotinvoiceuntil_c < \'\d{4}\-\d{1,2}-\d{1,2} \d{2}:\d{2}:\d{2}\'/", $filter);
67         }
68         /*
69         else if($GLOBALS['db']->getScriptName() == 'db2') {
70
71         }
72         */
73     }
74
75     public function testQueryFilterAfter()
76     {
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')
80         {
81             $this->assertRegExp("/pordr_purchaseorders_cstm\.donotinvoiceuntil_c > \'\d{4}\-\d{1,2}-\d{1,2} \d{2}:\d{2}:\d{2}\'/", $filter);
82         }
83     }
84
85     public function testQueryFilterNotEqualsStr()
86     {
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')
93         {
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);
95         }
96         /*
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);
99         }
100         */
101     }
102
103
104 }
105
106 class SugarWidgetFieldDateTime48616Mock extends SugarWidgetFieldDateTime
107 {
108     protected function queryDateOp($arg1, $arg2, $op, $type)
109     {
110         global $timedate;
111         if($arg2 instanceof DateTime) {
112             $arg2 = $timedate->asDbType($arg2, $type);
113         }
114         return "$arg1 $op ".$GLOBALS['db']->convert($GLOBALS['db']->quoted($arg2), $type)."\n";
115     }
116 }
117
118 ?>