]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/modules/ModuleBuilder/parsers/SearchViewMetaDataParserTest.php
Release 6.4.1
[Github/sugarcrm.git] / tests / modules / ModuleBuilder / parsers / SearchViewMetaDataParserTest.php
1 <?php
2 /*********************************************************************************
3  * SugarCRM Community Edition is a customer relationship management program developed by
4  * SugarCRM, Inc. Copyright (C) 2004-2012 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("modules/ModuleBuilder/parsers/views/SearchViewMetaDataParser.php");
39 require_once("modules/ModuleBuilder/parsers/views/DeployedMetaDataImplementation.php");
40
41 class SearchViewMetaDataParserTest extends Sugar_PHPUnit_Framework_TestCase
42 {
43
44
45     public function setUp()
46     {
47         //echo "Setup";
48     }
49
50     public function tearDown()
51     {
52         //echo "TearDown";
53     }
54
55     /**
56      * Bug 40530 returned faulty search results when a assigned_to relate field was used on the basic search
57      * The fix is making the widgets consistent between Basic and Advanced search when there is no definition
58      * for basic search. This was implemented in getOriginalViewDefs and that is what is being tested here.
59      */
60     public function test_Bug40530_getOriginalViewDefs()
61     {
62         //echo "begin test";
63         // NOTE This is sample data from the live application used for test verification purposes
64         $orgViewDefs = array(
65             'templateMeta' =>
66             array(
67                 'maxColumns' => '3',
68                 'widths' =>
69                 array(
70                     'label' => '10',
71                     'field' => '30',
72                 ),
73             ),
74             'layout' =>
75             array(
76                 'basic_search' =>
77                 array(
78                     'name' =>
79                     array(
80                         'name' => 'name',
81                         'default' => true,
82                         'width' => '10%',
83                     ),
84                     'current_user_only' =>
85                     array(
86                         'name' => 'current_user_only',
87                         'label' => 'LBL_CURRENT_USER_FILTER',
88                         'type' => 'bool',
89                         'default' => true,
90                         'width' => '10%',
91                     ),
92                     0 =>
93                     array(
94                         'name' => 'favorites_only',
95                         'label' => 'LBL_FAVORITES_FILTER',
96                         'type' => 'bool',
97                     ),
98                 ),
99                 'advanced_search' =>
100                 array(
101                     'name' =>
102                     array(
103                         'name' => 'name',
104                         'default' => true,
105                         'width' => '10%',
106                     ),
107                     'website' =>
108                     array(
109                         'name' => 'website',
110                         'default' => true,
111                         'width' => '10%',
112                     ),
113                     'phone' =>
114                     array(
115                         'name' => 'phone',
116                         'label' => 'LBL_ANY_PHONE',
117                         'type' => 'name',
118                         'default' => true,
119                         'width' => '10%',
120                     ),
121                     'email' =>
122                     array(
123                         'name' => 'email',
124                         'label' => 'LBL_ANY_EMAIL',
125                         'type' => 'name',
126                         'default' => true,
127                         'width' => '10%',
128                     ),
129                     'address_street' =>
130                     array(
131                         'name' => 'address_street',
132                         'label' => 'LBL_ANY_ADDRESS',
133                         'type' => 'name',
134                         'default' => true,
135                         'width' => '10%',
136                     ),
137                     'address_city' =>
138                     array(
139                         'name' => 'address_city',
140                         'label' => 'LBL_CITY',
141                         'type' => 'name',
142                         'default' => true,
143                         'width' => '10%',
144                     ),
145                     'address_state' =>
146                     array(
147                         'name' => 'address_state',
148                         'label' => 'LBL_STATE',
149                         'type' => 'name',
150                         'default' => true,
151                         'width' => '10%',
152                     ),
153                     'address_postalcode' =>
154                     array(
155                         'name' => 'address_postalcode',
156                         'label' => 'LBL_POSTAL_CODE',
157                         'type' => 'name',
158                         'default' => true,
159                         'width' => '10%',
160                     ),
161                     'billing_address_country' =>
162                     array(
163                         'name' => 'billing_address_country',
164                         'label' => 'LBL_COUNTRY',
165                         'type' => 'name',
166                         'options' => 'countries_dom',
167                         'default' => true,
168                         'width' => '10%',
169                     ),
170                     'account_type' =>
171                     array(
172                         'name' => 'account_type',
173                         'default' => true,
174                         'width' => '10%',
175                     ),
176                     'industry' =>
177                     array(
178                         'name' => 'industry',
179                         'default' => true,
180                         'width' => '10%',
181                     ),
182                     'assigned_user_id' =>
183                     array(
184                         'name' => 'assigned_user_id',
185                         'type' => 'enum',
186                         'label' => 'LBL_ASSIGNED_TO',
187                         'function' =>
188                         array(
189                             'name' => 'get_user_array',
190                             'params' =>
191                             array(
192                                 0 => false,
193                             ),
194                         ),
195                         'default' => true,
196                         'width' => '10%',
197                     ),
198                     0 =>
199                     array(
200                         'name' => 'favorites_only',
201                         'label' => 'LBL_FAVORITES_FILTER',
202                         'type' => 'bool',
203                     ),
204                 ),
205             ),
206         );
207
208         $expectedResult = array(
209             'name' =>
210             array(
211                 'name' => 'name',
212                 'default' => true,
213                 'width' => '10%',
214             ),
215             'website' =>
216             array(
217                 'name' => 'website',
218                 'default' => true,
219                 'width' => '10%',
220             ),
221             'phone' =>
222             array(
223                 'name' => 'phone',
224                 'label' => 'LBL_ANY_PHONE',
225                 'type' => 'name',
226                 'default' => true,
227                 'width' => '10%',
228             ),
229             'email' =>
230             array(
231                 'name' => 'email',
232                 'label' => 'LBL_ANY_EMAIL',
233                 'type' => 'name',
234                 'default' => true,
235                 'width' => '10%',
236             ),
237             'address_street' =>
238             array(
239                 'name' => 'address_street',
240                 'label' => 'LBL_ANY_ADDRESS',
241                 'type' => 'name',
242                 'default' => true,
243                 'width' => '10%',
244             ),
245             'address_city' =>
246             array(
247                 'name' => 'address_city',
248                 'label' => 'LBL_CITY',
249                 'type' => 'name',
250                 'default' => true,
251                 'width' => '10%',
252             ),
253             'address_state' =>
254             array(
255                 'name' => 'address_state',
256                 'label' => 'LBL_STATE',
257                 'type' => 'name',
258                 'default' => true,
259                 'width' => '10%',
260             ),
261             'address_postalcode' =>
262             array(
263                 'name' => 'address_postalcode',
264                 'label' => 'LBL_POSTAL_CODE',
265                 'type' => 'name',
266                 'default' => true,
267                 'width' => '10%',
268             ),
269             'billing_address_country' =>
270             array(
271                 'name' => 'billing_address_country',
272                 'label' => 'LBL_COUNTRY',
273                 'type' => 'name',
274                 'options' => 'countries_dom',
275                 'default' => true,
276                 'width' => '10%',
277             ),
278             'account_type' =>
279             array(
280                 'name' => 'account_type',
281                 'default' => true,
282                 'width' => '10%',
283             ),
284             'industry' =>
285             array(
286                 'name' => 'industry',
287                 'default' => true,
288                 'width' => '10%',
289             ),
290             'assigned_user_id' =>
291             array(
292                 'name' => 'assigned_user_id',
293                 'type' => 'enum',
294                 'label' => 'LBL_ASSIGNED_TO',
295                 'function' =>
296                 array(
297                     'name' => 'get_user_array',
298                     'params' =>
299                     array(
300                         0 => false,
301                     ),
302                 ),
303                 'default' => true,
304                 'width' => '10%',
305             ),
306             'favorites_only' =>
307             array(
308                 'name' => 'favorites_only',
309                 'label' => 'LBL_FAVORITES_FILTER',
310                 'type' => 'bool',
311             ),
312             'current_user_only' =>
313             array(
314                 'name' => 'current_user_only',
315                 'label' => 'LBL_CURRENT_USER_FILTER',
316                 'type' => 'bool',
317                 'default' => true,
318                 'width' => '10%',
319             ),
320         );
321
322         // We use a derived class to aid in stubbing out test properties and functions
323         $parser = new SearchViewMetaDataParserTestDerivative("basic_search");
324
325         // Creating a mock object for the DeployedMetaDataImplementation
326
327         $impl = $this->getMock('DeployedMetaDataImplementation',
328                                array('getOriginalViewdefs'),
329                                array(),
330                                'DeployedMetaDataImplementation_Mock',
331                                FALSE);
332
333         // Making the getOriginalViewdefs function return the test viewdefs and verify that it is being called once
334         $impl->expects($this->once())
335                 ->method('getOriginalViewdefs')
336                 ->will($this->returnValue($orgViewDefs));
337
338         // Replace the protected implementation with our Mock object
339         $parser->setImpl($impl);
340
341         // Execute the method under test
342         $result = $parser->getOriginalViewDefs();
343
344         // Verify that the returned result matches our expectations
345         $this->assertEquals($result, $expectedResult);
346
347         //echo "Done";
348     }
349
350 }
351
352 /**
353  * Using derived helper class from SearchViewMetaDataParser to avoid having to fully
354  * initialize the whole class and to give us the flexibility to replace the
355  * Deploy/Undeploy MetaDataImplementation
356  */
357 class SearchViewMetaDataParserTestDerivative extends SearchViewMetaDataParser
358 {
359     function __construct ($layout){
360         $this->_searchLayout = $layout;
361     }
362
363     function setImpl($impl) {
364         $this->implementation = $impl;
365     }
366 }