]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/include/Smarty/plugins/FunctionSugarButtonTest.php
Release 6.5.10
[Github/sugarcrm.git] / tests / include / Smarty / plugins / FunctionSugarButtonTest.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 require_once 'include/Smarty/plugins/function.sugar_button.php';
39 require_once 'include/Smarty/plugins/function.sugar_menu.php';
40 require_once 'include/SugarHtml/SugarHtml.php';
41 require_once 'include/Sugar_Smarty.php';
42
43 class FunctionSugarButtonTest extends Sugar_PHPUnit_Framework_TestCase
44 {
45     public function setUp()
46     {
47         $this->_smarty = new Sugar_Smarty;
48
49     }
50
51     public function providerCustomCode() {
52         $onclick = 'this.form.module.value=\'Contacts\';';
53         $expected_onclick = 'var _form = document.getElementById(\'DetailView\');_form.module.value=\'Contacts\';_form.submit();';
54         $onclick2 = 'this.form.module.value=\'Projects\';';
55         $expected_onclick2 = 'var _form = document.getElementById(\'DetailView\');_form.module.value=\'Projects\';_form.submit();';
56         $onclick3 = 'this.form.module.value=\'Meeting\';';
57         $expected_onclick3 = 'var _form = document.getElementById(\'DetailView\');_form.module.value=\'Meeting\';_form.submit();';
58         $onclick4 = 'this.form.module.value=\'Notes\';';
59         $expected_onclick4 = 'var _form = document.getElementById(\'DetailView\');_form.module.value=\'Notes\';_form.submit();';
60         return array(
61
62             //set #0: simple input code
63             array(
64                 '<input type="submit" value="{$APP.BUTTON_LABEL}" onclick="'.$onclick.'">',
65                 array(
66                     'tag' => 'input',
67                     'type' => 'submit',
68                     'self_closing' => true,
69                     'onclick' => $onclick,
70                     'value' => '{$APP.BUTTON_LABEL}'
71                 ),
72                 '<input type="button" value="{$APP.BUTTON_LABEL}" onclick="'.$expected_onclick.'"/>',
73             ),
74             //set #1:
75             array(
76                 '<input type="submit" disabled value="{$APP.BUTTON_LABEL}" onclick="'.$onclick.'">',
77                 array(
78                     'tag' => 'input',
79                     'type' => 'submit',
80                     'self_closing' => true,
81                     'onclick' => $onclick,
82                     'value' => '{$APP.BUTTON_LABEL}',
83                     'disabled' => '',
84                 ),
85                 '<input type="button" disabled value="{$APP.BUTTON_LABEL}" onclick="'.$expected_onclick.'"/>',
86             ),
87
88             //set #2: custom code contains smarty conditional statement
89             array(
90                 '<input type="submit" value="{$APP.BUTTON_LABEL}" onclick="{if $bean->access(\'edit\')}'.$onclick.'{/if}">',
91                 array(
92                     'tag' => 'input',
93                     'type' => 'submit',
94                     'self_closing' => true,
95                     'onclick' => '{if $bean->access(\'edit\')}'.$onclick.'{/if}',
96                     'value' => '{$APP.BUTTON_LABEL}'
97                 ),
98                 '<input type="button" value="{$APP.BUTTON_LABEL}" onclick="var _form = document.getElementById(\'DetailView\');{if $bean->access(\'edit\')}_form.module.value=\'Contacts\';{/if};_form.submit();"/>',
99             ),
100             //set #3: attributes wrapped with smarty
101             array(
102                 //custom code
103                 '<input {if $bean->access(\'edit\')}type="submit"{else}type="hidden"{/if} value="{$APP.BUTTON_LABEL}" {if $bean->access(\'edit\')}onclick="'.$onclick.'"{else}onclick="alert(\'nope\');"{/if} id="button_submit">',
104                 //parsed array
105                 array(
106                     'id' => 'button_submit',
107                     'tag' => 'input',
108                     'self_closing' => true,
109                     'smarty' => array(
110                         array(
111                             'template' => '{if $bean->access(\'edit\')}[CONTENT0]{else}[CONTENT1]{/if}',
112                             '[CONTENT0]' => array(
113                                 'type' => 'submit'
114                             ),
115                             '[CONTENT1]' => array(
116                                 'type' => 'hidden'
117                             )
118                         ),
119                         array(
120                             'template' => '{if $bean->access(\'edit\')}[CONTENT0]{else}[CONTENT1]{/if}',
121                             '[CONTENT0]' => array(
122                                 'onclick' => $onclick
123                             ),
124                             '[CONTENT1]' => array(
125                                 'onclick' => 'alert(\'nope\');'
126                             )
127                         )
128                     ),
129
130                     'value' => '{$APP.BUTTON_LABEL}'
131                 ),
132                 '<input {if $bean->access(\'edit\')}type="submit"{else}type="hidden"{/if} {if $bean->access(\'edit\')}onclick="'.$expected_onclick.'"{else}onclick="alert(\'nope\');"{/if} value="{$APP.BUTTON_LABEL}" id="button_submit"/>',
133             ),
134
135             //set #4: attributes wrapped with smarty
136             array(
137                 //custom code
138                 '<input type="submit"{if $bean->access(\'edit\')}onclick="'.$onclick.'"{else}onclick="this.form.module.value=\'{$APP.MODULE}\';this.form.action.value=\'{$APP.ACTION}\';"{/if} value="{$APP.BUTTON_LABEL}" id="button_submit">',
139                 //parsed array
140                 array(
141                     'id' => 'button_submit',
142                     'tag' => 'input',
143                     'type' => 'submit',
144                     'self_closing' => true,
145                     'smarty' => array(
146                         array(
147                             'template' => '{if $bean->access(\'edit\')}[CONTENT0]{else}[CONTENT1]{/if}',
148                             '[CONTENT0]' => array(
149                                 'onclick' => $onclick
150                             ),
151                             '[CONTENT1]' => array(
152                                 'onclick' => 'this.form.module.value=\'{$APP.MODULE}\';this.form.action.value=\'{$APP.ACTION}\';'
153                             )
154                         )
155                     ),
156
157                     'value' => '{$APP.BUTTON_LABEL}'
158                 ),
159                 '<input {if $bean->access(\'edit\')}onclick="'.$expected_onclick.'"{else}onclick="var _form = document.getElementById(\'DetailView\');_form.module.value=\'{$APP.MODULE}\';_form.action.value=\'{$APP.ACTION}\';_form.submit();"{/if} type="button" value="{$APP.BUTTON_LABEL}" id="button_submit"/>',
160             ),
161
162             //set #5: recursive smarty wrapper within the attributes
163             array(
164                 '<input type="submit" value="{$APP.BUTTON_LABEL}" {$APP.DISABLED} {if $bean->access(\'edit\')}{if $APP.CONTAINER = true}onclick="'.$onclick.'"{/if}{else if $bean->access(\'delete\') }onclick="del();"{else}onclick="alert(\'nope\');"{/if} id="button_submit">',
165                 array(
166                     'id' => 'button_submit',
167                     'tag' => 'input',
168                     'type' => 'submit',
169                     'self_closing' => true,
170                     'value' => '{$APP.BUTTON_LABEL}',
171                     'smarty' => array(
172                         array(
173                             'template' => '{$APP.DISABLED}'
174                         ),
175                         array(
176                             'template' => '{if $bean->access(\'edit\')}[CONTENT0]{else if $bean->access(\'delete\') }[CONTENT1]{else}[CONTENT2]{/if}',
177                             '[CONTENT0]' => array(
178                                 'smarty' => array(
179                                     array(
180                                         'template' => '{if $APP.CONTAINER = true}[CONTENT0]{/if}',
181                                         '[CONTENT0]' => array(
182                                             'onclick' => $onclick
183                                         ),
184                                     )
185                                 ),
186                             ),
187                             '[CONTENT1]' => array(
188                                 'onclick' => 'del();'
189                             ),
190                             '[CONTENT2]' => array(
191                                 'onclick' => 'alert(\'nope\');'
192                             ),
193                         ),
194                     ),
195                 ),
196                 '<input {$APP.DISABLED} {if $bean->access(\'edit\')}{if $APP.CONTAINER = true}onclick="'.$expected_onclick.'"{/if}{else if $bean->access(\'delete\') }onclick="del();"{else}onclick="alert(\'nope\');"{/if} type="button" value="{$APP.BUTTON_LABEL}" id="button_submit"/>',
197             ),
198             //set #6: Begins with smarty conditional statement
199             array(
200                 '{if $fields.status.value != "Held"} <input title="{$APP.LBL_CLOSE_AND_CREATE_BUTTON_TITLE}" class="button" onclick="'.$onclick.'" value="{$APP.LBL_CLOSE_AND_CREATE_BUTTON_TITLE}"  type="submit">{/if}',
201                 array(
202                     'smarty' => array(
203                         array(
204                             'template' => '{if $fields.status.value != "Held"}[CONTENT0]{/if}',
205                             '[CONTENT0]' => array(
206                                 'tag' => 'input',
207                                 'type' => 'submit',
208                                 'self_closing' => true,
209                                 'title' => '{$APP.LBL_CLOSE_AND_CREATE_BUTTON_TITLE}',
210                                 'class' => 'button',
211                                 'onclick' => $onclick,
212                                 'value' => '{$APP.LBL_CLOSE_AND_CREATE_BUTTON_TITLE}'
213                             ),
214                         )
215                     ),
216                 ),
217                 '{if $fields.status.value != "Held"}<input title="{$APP.LBL_CLOSE_AND_CREATE_BUTTON_TITLE}" class="button" onclick="'.$expected_onclick.'" value="{$APP.LBL_CLOSE_AND_CREATE_BUTTON_TITLE}" type="button"/>{/if}'
218             ),
219             //set #7: Begins with smarty conditional statement and contains recursive conditional statement inside the context
220             array(
221                 '{ if($fields.status.value != "Held") } <input title="{$APP.LBL_CLOSE_AND_CREATE_BUTTON_TITLE}" {if $bean->access(\'edit\')}{if $APP.CONTAINER = true}onclick="'.$onclick.'"{/if}{else if $bean->access(\'delete\') }onclick="del();"{else}onclick="alert(\'nope\');"{/if}  class="button" onclick="'.$onclick.'" value="{$APP.LBL_CLOSE_AND_CREATE_BUTTON_TITLE}"  type="submit">{/if}',
222                 array(
223                     'smarty' => array(
224                         array(
225                             'template' => '{ if($fields.status.value != "Held") }[CONTENT0]{/if}',
226                             '[CONTENT0]' => array(
227                                 'tag' => 'input',
228                                 'type' => 'submit',
229                                 'class' => 'button',
230                                 'value' => '{$APP.LBL_CLOSE_AND_CREATE_BUTTON_TITLE}',
231                                 'onclick' => $onclick,
232                                 'self_closing' => true,
233                                 'title' => '{$APP.LBL_CLOSE_AND_CREATE_BUTTON_TITLE}',
234                                 'smarty' => array(
235                                     array(
236                                         'template' => '{if $bean->access(\'edit\')}[CONTENT0]{else if $bean->access(\'delete\') }[CONTENT1]{else}[CONTENT2]{/if}',
237                                         '[CONTENT0]' => array(
238                                             'smarty' => array(
239                                                 array(
240                                                     'template' => '{if $APP.CONTAINER = true}[CONTENT0]{/if}',
241                                                     '[CONTENT0]' => array(
242                                                         'onclick' => $onclick
243                                                     ),
244                                                 )
245                                             ),
246                                         ),
247                                         '[CONTENT1]' => array(
248                                             'onclick' => 'del();'
249                                         ),
250                                         '[CONTENT2]' => array(
251                                             'onclick' => 'alert(\'nope\');'
252                                         ),
253                                     )
254                                 ),
255
256                             ),
257                         )
258                     ),
259                 ),
260                 '{ if($fields.status.value != "Held") }<input {if $bean->access(\'edit\')}{if $APP.CONTAINER = true}onclick="'.$expected_onclick.'"{/if}{else if $bean->access(\'delete\') }onclick="del();"{else}onclick="alert(\'nope\');"{/if} title="{$APP.LBL_CLOSE_AND_CREATE_BUTTON_TITLE}" class="button" onclick="'.$expected_onclick.'" value="{$APP.LBL_CLOSE_AND_CREATE_BUTTON_TITLE}" type="button"/>{/if}'
261             ),
262             //set #8: The submit button is encapsulated with another form
263             array(
264                 '<form name="blah">   <input type="hidden" name="id1">    <input type="hidden" name="id2">     <input type="submit" onclick="'.$onclick.'"></form>',
265                 array(
266                     'tag' => 'form',
267                     'name' => 'blah',
268                     'self_closing' => false,
269                     'container' => array(
270                         array(
271                             'tag' => 'input',
272                             'type' => 'hidden',
273                             'name' => 'id1',
274                             'self_closing' => true,
275                         ),
276                         array(
277                             'tag' => 'input',
278                             'type' => 'hidden',
279                             'name' => 'id2',
280                             'self_closing' => true,
281                         ),
282                         array(
283                             'tag' => 'input',
284                             'type' => 'submit',
285                             'onclick' => $onclick,
286                             'self_closing' => true,
287                         ),
288                     ),
289                 ),
290                 '<form name="blah"><input type="hidden" name="id1"/><input type="hidden" name="id2"/><input type="submit" onclick="'.$onclick.'"/></form>',
291             ),
292
293             //set #9: custom code encapsulated smarty conditional statement, and contains additional hidden fields
294             array(
295                 '{if $fields.status.value != "Held"} <input type="hidden" name="id1" value="true">    <input type="hidden" name="id2">     <input type="submit" {if $APP.CONTAINER = true}onclick="'.$onclick.'"{else}onclick="stop();"{/if} value="{$APP.LBL_CLOSE_AND_CREATE_BUTTON_TITLE}">{/if}',
296                 array(
297                     'smarty' => array(
298                         array(
299                             'template' => '{if $fields.status.value != "Held"}[CONTENT0]{/if}',
300                             '[CONTENT0]' => array(
301                                 array(
302                                     'tag' => 'input',
303                                     'type' => 'hidden',
304                                     'name' => 'id1',
305                                     'self_closing' => true,
306                                     'value' => "true"
307                                 ),
308                                 array(
309                                     'tag' => 'input',
310                                     'type' => 'hidden',
311                                     'name' => 'id2',
312                                     'self_closing' => true,
313                                 ),
314                                 array(
315                                     'tag' => 'input',
316                                     'type' => 'submit',
317                                     'value' => '{$APP.LBL_CLOSE_AND_CREATE_BUTTON_TITLE}',
318                                     'self_closing' => true,
319                                     'smarty' => array(
320                                         array(
321                                             'template' => '{if $APP.CONTAINER = true}[CONTENT0]{else}[CONTENT1]{/if}',
322                                             '[CONTENT0]' => array(
323                                                 'onclick' => $onclick
324                                             ),
325                                             '[CONTENT1]' => array(
326                                                 'onclick' => 'stop();'
327                                             ),
328                                         )
329                                     ),
330                                 ),
331                             ),
332                         )
333                     ),
334                 ),
335                 '{if $fields.status.value != "Held"}<input type="hidden" name="id1" value="true"/><input type="hidden" name="id2"/><input {if $APP.CONTAINER = true}onclick="'.$expected_onclick.'"{else}onclick="stop();"{/if} type="button" value="{$APP.LBL_CLOSE_AND_CREATE_BUTTON_TITLE}"/>{/if}'
336             ),
337             //set #10: empty spaces after the equal sign
338             array (
339                 '<input title="{$APP.LBL_SAVE_BUTTON_TITLE}" id= "SAVE" disabled onclick="SUGAR.meetings.fill_invitees();document.EditView.action.value=\'Save\'; document.EditView.return_action.value=\'DetailView\'; {if isset($smarty.request.isDuplicate) && $smarty.request.isDuplicate eq "true"}document.EditView.return_id.value=\'\'; {/if} formSubmitCheck();"type="button" name="button" value="{$APP.LBL_SAVE_BUTTON_LABEL}">',
340                 array(
341                     'tag' => 'input',
342                     'title' => '{$APP.LBL_SAVE_BUTTON_TITLE}',
343                     'id' => 'SAVE',
344                     'disabled' => '',
345                     'onclick' => 'SUGAR.meetings.fill_invitees();document.EditView.action.value=\'Save\'; document.EditView.return_action.value=\'DetailView\'; {if isset($smarty.request.isDuplicate) && $smarty.request.isDuplicate eq "true"}document.EditView.return_id.value=\'\'; {/if} formSubmitCheck();',
346                     'type' => 'button',
347                     'name' => "button",
348                     'value' => '{$APP.LBL_SAVE_BUTTON_LABEL}',
349                     'self_closing' => true,
350                 ),
351                 '<input title="{$APP.LBL_SAVE_BUTTON_TITLE}" id="SAVE" disabled onclick="SUGAR.meetings.fill_invitees();document.EditView.action.value=\'Save\'; document.EditView.return_action.value=\'DetailView\'; {if isset($smarty.request.isDuplicate) && $smarty.request.isDuplicate eq "true"}document.EditView.return_id.value=\'\'; {/if} formSubmitCheck();" type="button" name="button" value="{$APP.LBL_SAVE_BUTTON_LABEL}"/>',
352             ),
353             //set #11: empty spaces before the equal sign
354             array (
355                 '<input title="{$APP.LBL_SAVE_BUTTON_TITLE}" id    = "SAVE" disabled onclick="SUGAR.meetings.fill_invitees();document.EditView.action.value=\'Save\'; document.EditView.return_action.value=\'DetailView\'; {if isset($smarty.request.isDuplicate) && $smarty.request.isDuplicate eq "true"}document.EditView.return_id.value=\'\'; {/if} formSubmitCheck();"type="button" name="button" value="{$APP.LBL_SAVE_BUTTON_LABEL}">',
356                 array(
357                     'tag' => 'input',
358                     'title' => '{$APP.LBL_SAVE_BUTTON_TITLE}',
359                     'id' => 'SAVE',
360                     'disabled' => '',
361                     'onclick' => 'SUGAR.meetings.fill_invitees();document.EditView.action.value=\'Save\'; document.EditView.return_action.value=\'DetailView\'; {if isset($smarty.request.isDuplicate) && $smarty.request.isDuplicate eq "true"}document.EditView.return_id.value=\'\'; {/if} formSubmitCheck();',
362                     'type' => 'button',
363                     'name' => "button",
364                     'value' => '{$APP.LBL_SAVE_BUTTON_LABEL}',
365                     'self_closing' => true,
366                 ),
367                 '<input title="{$APP.LBL_SAVE_BUTTON_TITLE}" id="SAVE" disabled onclick="SUGAR.meetings.fill_invitees();document.EditView.action.value=\'Save\'; document.EditView.return_action.value=\'DetailView\'; {if isset($smarty.request.isDuplicate) && $smarty.request.isDuplicate eq "true"}document.EditView.return_id.value=\'\'; {/if} formSubmitCheck();" type="button" name="button" value="{$APP.LBL_SAVE_BUTTON_LABEL}"/>',
368             ),
369             //set #12: Contains smarty syntax "ldelim, rdelim"
370             array(
371                 '{if $bean->aclAccess("delete") && !empty($smarty.request.record)}<input title="{$APP.LBL_DELETE_BUTTON_TITLE}" accessKey="{$APP.LBL_DELETE_BUTTON_KEY}" class="button" onclick="this.form.return_module.value=\'Users\'; this.form.return_action.value=\'EditView\'; this.form.action.value=\'Delete\'; this.form.return_id.value=\'{$return_id}\'; if (confirm(\'{$APP.NTC_DELETE_CONFIRMATION}\')){ldelim}disableOnUnloadEditView(); return true;{rdelim}else{ldelim}return false;{rdelim};" type="submit" name="Delete" value="{$APP.LBL_DELETE_BUTTON_LABEL}">{/if} ',
372                 array(
373                     'smarty' => array(
374                         array(
375                             'template' => '{if $bean->aclAccess("delete") && !empty($smarty.request.record)}[CONTENT0]{/if}',
376                             '[CONTENT0]' => array(
377                                 'tag' => 'input',
378                                 'self_closing' => true,
379                                 'title' => '{$APP.LBL_DELETE_BUTTON_TITLE}',
380                                 'accessKey' => '{$APP.LBL_DELETE_BUTTON_KEY}',
381                                 'class' => 'button',
382                                 'onclick' => 'this.form.return_module.value=\'Users\'; this.form.return_action.value=\'EditView\'; this.form.action.value=\'Delete\'; this.form.return_id.value=\'{$return_id}\'; if (confirm(\'{$APP.NTC_DELETE_CONFIRMATION}\')){ldelim}disableOnUnloadEditView(); return true;{rdelim}else{ldelim}return false;{rdelim};',
383                                 'type' => 'submit',
384                                 'name' => 'Delete',
385                                 'value' => '{$APP.LBL_DELETE_BUTTON_LABEL}',
386                             ),
387                         )
388                     )
389                 ),
390                 '{if $bean->aclAccess("delete") && !empty($smarty.request.record)}<input title="{$APP.LBL_DELETE_BUTTON_TITLE}" accessKey="{$APP.LBL_DELETE_BUTTON_KEY}" class="button" onclick="var _form = document.getElementById(\'DetailView\'); var _onclick=(function(){ldelim}_form.return_module.value=\'Users\'; _form.return_action.value=\'EditView\'; _form.action.value=\'Delete\'; _form.return_id.value=\'{$return_id}\'; if (confirm(\'{$APP.NTC_DELETE_CONFIRMATION}\')){ldelim}disableOnUnloadEditView(); return true;{rdelim}else{ldelim}return false;{rdelim};{rdelim}()); if(_onclick!==false) _form.submit();" type="button" name="Delete" value="{$APP.LBL_DELETE_BUTTON_LABEL}"/>{/if}'
391             ),
392
393             //set #13: Contains smarty syntax "literal"
394             array(
395                 '{if $bean->aclAccess("delete") && !empty($smarty.request.record)}<input title="{$APP.LBL_DELETE_BUTTON_TITLE}" accessKey="{$APP.LBL_DELETE_BUTTON_KEY}" class="button" onclick="this.form.return_module.value=\'Users\'; this.form.return_action.value=\'EditView\'; this.form.action.value=\'Delete\'; this.form.return_id.value=\'{$return_id}\'; {literal}if (confirm(\'{$APP.NTC_DELETE_CONFIRMATION}\')){disableOnUnloadEditView(); return true;}else{return false;};{/literal}" type="submit" name="Delete" value="{$APP.LBL_DELETE_BUTTON_LABEL}">{/if} ',
396                 array(
397                     'smarty' => array(
398                         array(
399                             'template' => '{if $bean->aclAccess("delete") && !empty($smarty.request.record)}[CONTENT0]{/if}',
400                             '[CONTENT0]' => array(
401                                 'tag' => 'input',
402                                 'self_closing' => true,
403                                 'title' => '{$APP.LBL_DELETE_BUTTON_TITLE}',
404                                 'accessKey' => '{$APP.LBL_DELETE_BUTTON_KEY}',
405                                 'class' => 'button',
406                                 'onclick' => 'this.form.return_module.value=\'Users\'; this.form.return_action.value=\'EditView\'; this.form.action.value=\'Delete\'; this.form.return_id.value=\'{$return_id}\'; {literal}if (confirm(\'{$APP.NTC_DELETE_CONFIRMATION}\')){disableOnUnloadEditView(); return true;}else{return false;};{/literal}',
407                                 'type' => 'submit',
408                                 'name' => 'Delete',
409                                 'value' => '{$APP.LBL_DELETE_BUTTON_LABEL}',
410                             ),
411                         )
412                     )
413                 ),
414                 '{if $bean->aclAccess("delete") && !empty($smarty.request.record)}<input title="{$APP.LBL_DELETE_BUTTON_TITLE}" accessKey="{$APP.LBL_DELETE_BUTTON_KEY}" class="button" onclick="var _form = document.getElementById(\'DetailView\'); var _onclick=(function(){ldelim}_form.return_module.value=\'Users\'; _form.return_action.value=\'EditView\'; _form.action.value=\'Delete\'; _form.return_id.value=\'{$return_id}\'; {literal}if (confirm(\'{$APP.NTC_DELETE_CONFIRMATION}\')){disableOnUnloadEditView(); return true;}else{return false;};{/literal};{rdelim}()); if(_onclick!==false) _form.submit();" type="button" name="Delete" value="{$APP.LBL_DELETE_BUTTON_LABEL}"/>{/if}'
415             ),
416
417             //set #14: Multiple conditional statement
418             array(
419                 '{if !empty($smarty.request.return_action) && $smarty.request.return_action == "ProjectTemplatesDetailView" && (!empty($fields.id.value) || !empty($smarty.request.return_id)) }'.
420                     '<input title="{$APP.LBL_CANCEL_BUTTON_TITLE}" accessKey="{$APP.LBL_CANCEL_BUTTON_KEY}" class="button" onclick="'.$onclick.'" type="submit" name="button" value="{$APP.LBL_CANCEL_BUTTON_LABEL}" id="Cancel"> '.
421                     '{elseif !empty($smarty.request.return_action) && $smarty.request.return_action == "DetailView" && (!empty($fields.id.value) || !empty($smarty.request.return_id)) }'.
422                     '<input title="{$APP.LBL_CANCEL_BUTTON_TITLE}" accessKey="{$APP.LBL_CANCEL_BUTTON_KEY}" class="button" onclick="'.$onclick2.'" type="submit" name="button" value="{$APP.LBL_CANCEL_BUTTON_LABEL}" id="Cancel"> '.
423                     '{elseif $is_template}'.
424                     '<input title="{$APP.LBL_CANCEL_BUTTON_TITLE}" accessKey="{$APP.LBL_CANCEL_BUTTON_KEY}" class="button" onclick="'.$onclick3.'" type="submit" name="button" value="{$APP.LBL_CANCEL_BUTTON_LABEL}" id="Cancel"> '.
425                     '{else}'.
426                     '<input title="{$APP.LBL_CANCEL_BUTTON_TITLE}" accessKey="{$APP.LBL_CANCEL_BUTTON_KEY}" class="button" onclick="'.$onclick4.'" type="submit" name="button" value="{$APP.LBL_CANCEL_BUTTON_LABEL}" id="Cancel"> '.
427                     '{/if}',
428                 array(
429                     'smarty' => array(
430                         array(
431                             'template' => '{if !empty($smarty.request.return_action) && $smarty.request.return_action == "ProjectTemplatesDetailView" && (!empty($fields.id.value) || !empty($smarty.request.return_id)) }[CONTENT0]{elseif !empty($smarty.request.return_action) && $smarty.request.return_action == "DetailView" && (!empty($fields.id.value) || !empty($smarty.request.return_id)) }[CONTENT1]{elseif $is_template}[CONTENT2]{else}[CONTENT3]{/if}',
432                             '[CONTENT0]' => array(
433                                 'tag' => 'input',
434                                 'title' => '{$APP.LBL_CANCEL_BUTTON_TITLE}',
435                                 'accessKey' => '{$APP.LBL_CANCEL_BUTTON_KEY}',
436                                 'class' => "button",
437                                 'type' => "submit",
438                                 'name' => "button",
439                                 'value' => '{$APP.LBL_CANCEL_BUTTON_LABEL}',
440                                 'id' => "Cancel",
441                                 'onclick' => $onclick,
442                                 'self_closing' => true
443                             ),
444                             '[CONTENT1]' => array(
445                                 'tag' => 'input',
446                                 'title' => '{$APP.LBL_CANCEL_BUTTON_TITLE}',
447                                 'accessKey' => '{$APP.LBL_CANCEL_BUTTON_KEY}',
448                                 'class' => "button",
449                                 'type' => "submit",
450                                 'name' => "button",
451                                 'value' => '{$APP.LBL_CANCEL_BUTTON_LABEL}',
452                                 'id' => "Cancel",
453                                 'onclick' => $onclick2,
454                                 'self_closing' => true
455                             ),
456                             '[CONTENT2]' => array(
457                                 'tag' => 'input',
458                                 'title' => '{$APP.LBL_CANCEL_BUTTON_TITLE}',
459                                 'accessKey' => '{$APP.LBL_CANCEL_BUTTON_KEY}',
460                                 'class' => "button",
461                                 'type' => "submit",
462                                 'name' => "button",
463                                 'value' => '{$APP.LBL_CANCEL_BUTTON_LABEL}',
464                                 'id' => "Cancel",
465                                 'onclick' => $onclick3,
466                                 'self_closing' => true
467                             ),
468                             '[CONTENT3]' => array(
469                                 'tag' => 'input',
470                                 'title' => '{$APP.LBL_CANCEL_BUTTON_TITLE}',
471                                 'accessKey' => '{$APP.LBL_CANCEL_BUTTON_KEY}',
472                                 'class' => "button",
473                                 'type' => "submit",
474                                 'name' => "button",
475                                 'value' => '{$APP.LBL_CANCEL_BUTTON_LABEL}',
476                                 'id' => "Cancel",
477                                 'onclick' => $onclick4,
478                                 'self_closing' => true
479                             ),
480                         )
481                     )
482                 ),
483                 '{if !empty($smarty.request.return_action) && $smarty.request.return_action == "ProjectTemplatesDetailView" && (!empty($fields.id.value) || !empty($smarty.request.return_id)) }'.
484                     '<input title="{$APP.LBL_CANCEL_BUTTON_TITLE}" accessKey="{$APP.LBL_CANCEL_BUTTON_KEY}" class="button" onclick="'.$expected_onclick.'" type="button" name="button" value="{$APP.LBL_CANCEL_BUTTON_LABEL}" id="Cancel"/>'.
485                     '{elseif !empty($smarty.request.return_action) && $smarty.request.return_action == "DetailView" && (!empty($fields.id.value) || !empty($smarty.request.return_id)) }'.
486                     '<input title="{$APP.LBL_CANCEL_BUTTON_TITLE}" accessKey="{$APP.LBL_CANCEL_BUTTON_KEY}" class="button" onclick="'.$expected_onclick2.'" type="button" name="button" value="{$APP.LBL_CANCEL_BUTTON_LABEL}" id="Cancel"/>'.
487                     '{elseif $is_template}'.
488                     '<input title="{$APP.LBL_CANCEL_BUTTON_TITLE}" accessKey="{$APP.LBL_CANCEL_BUTTON_KEY}" class="button" onclick="'.$expected_onclick3.'" type="button" name="button" value="{$APP.LBL_CANCEL_BUTTON_LABEL}" id="Cancel"/>'.
489                     '{else}'.
490                     '<input title="{$APP.LBL_CANCEL_BUTTON_TITLE}" accessKey="{$APP.LBL_CANCEL_BUTTON_KEY}" class="button" onclick="'.$expected_onclick4.'" type="button" name="button" value="{$APP.LBL_CANCEL_BUTTON_LABEL}" id="Cancel"/>'.
491                     '{/if}'
492             ),
493
494             //set #15: Parallel smarty strings
495             array(
496                 '{$APP.VALUE1} {$HIDDEN_FIELD} <input type="submit" value="{$APP.BUTTON_LABEL}" onclick="'.$onclick.'">',
497                 array(
498                     array(
499                         'smarty' => array(
500                             array(
501                                 'template' => '{$APP.VALUE1}',
502                             )
503                         ),
504                     ),
505                     array(
506                         'smarty' => array(
507                             array(
508                                 'template' => '{$HIDDEN_FIELD}',
509                             )
510                         ),
511                     ),
512                     array(
513                         'tag' => 'input',
514                         'type' => 'submit',
515                         'self_closing' => true,
516                         'onclick' => $onclick,
517                         'value' => '{$APP.BUTTON_LABEL}'
518                     )
519                 ),
520                 '{$APP.VALUE1}{$HIDDEN_FIELD}<input type="button" value="{$APP.BUTTON_LABEL}" onclick="'.$expected_onclick.'"/>',
521             ),
522             //set #16: Contains smarty syntax "nocache"
523             array(
524                 '<form action="index.php" method="{$PDFMETHOD}" name="ViewPDF" id="form" onsubmit="this.sugarpdf.value =(document.getElementById(\'sugarpdf\'))? document.getElementById(\'sugarpdf\').value: \'\';"><input type="hidden" name="module" value="Quotes">'
525                     .'{nocache}'
526                     .'{sugar_email_btn}'
527                     .'{/nocache}'
528                     .'</form>',
529                 array(
530                     'tag' => 'form',
531                     'action' => 'index.php',
532                     'method' => '{$PDFMETHOD}',
533                     'name' => 'ViewPDF',
534                     'id' => 'form',
535                     'onsubmit' => 'this.sugarpdf.value =(document.getElementById(\'sugarpdf\'))? document.getElementById(\'sugarpdf\').value: \'\';',
536                     'container' => array(
537                         array(
538                             'tag' => 'input',
539                             'type' => "hidden",
540                             'name' => "module",
541                             'value' => "Quotes",
542                             'self_closing' => true,
543                         ),
544                         array(
545                             'smarty' => array(
546                                 array(
547                                     'template' => '{nocache}{sugar_email_btn}{/nocache}',
548                                 ),
549                             )
550                         )
551                     ),
552                     'self_closing' => false,
553                 ),
554                 '<form action="index.php" method="{$PDFMETHOD}" name="ViewPDF" id="form" onsubmit="this.sugarpdf.value =(document.getElementById(\'sugarpdf\'))? document.getElementById(\'sugarpdf\').value: \'\';"><input type="hidden" name="module" value="Quotes"/>'
555                     .'{nocache}'
556                     .'{sugar_email_btn}'
557                     .'{/nocache}'
558                     .'</form>',
559             ),
560
561
562         );
563     }
564     /**
565      * @dataProvider providerCustomCode
566      */
567     public function testCustomCode($customCode, $expected_parsed_array, $expected_customCode)
568     {
569         //Test for parseHtmlTag
570         $this->assertEquals($expected_parsed_array, SugarHtml::parseHtmlTag($customCode));
571         $params = array(
572             'module' => 'Accounts',
573             'view' => 'DetailView',
574             'id' => array(
575                 'customCode' => $customCode
576             ),
577             'form_id' => 'DetailView'
578         );
579
580
581         //Test for smarty_function_sugar_button for customCode
582         $this->assertEquals($expected_customCode, smarty_function_sugar_button($params, $this->_smarty));
583
584     }
585
586     public function providerCustomCodeWithHidden() {
587
588         $onclick = 'this.form.module.value=\'Contacts\';this.form.action.value=\'DetailView\';';
589         $expected_onclick = 'var _form = document.getElementById(\'DetailView\');_form.module.value=\'Contacts\';_form.action.value=\'DetailView\';_form.submit();';
590
591         return array(
592             //set #0: Button with hidden field
593             array(
594                 '<input type="hidden" name="id2" value="2">     <input type="submit"onclick="'.$onclick.'"value="{$APP.LBL_CLOSE_AND_CREATE_BUTTON_TITLE}">',
595                 '<input type="hidden" name="id2" value="2"/><input type="button" onclick="'.$expected_onclick.'" value="{$APP.LBL_CLOSE_AND_CREATE_BUTTON_TITLE}"/>',
596                 array(
597                     '<input type="hidden" name="id2" value="2"/>'
598                 ),
599             ),
600             //set #1: Button with hidden field wrapping with conditional smarty statement
601             array(
602                 '{if $fields.status.value != "Held"} <input type="hidden" name="id1" value="true">    <input type="hidden" name="id2">     <input type="submit" {if $APP.CONTAINER = true}onclick="'.$onclick.'"{else}onclick="stop();"{/if} value="{$APP.LBL_CLOSE_AND_CREATE_BUTTON_TITLE}">{/if}',
603                 '{if $fields.status.value != "Held"}<input type="hidden" name="id1" value="true"/><input type="hidden" name="id2"/><input {if $APP.CONTAINER = true}onclick="'.$expected_onclick.'"{else}onclick="stop();"{/if} type="button" value="{$APP.LBL_CLOSE_AND_CREATE_BUTTON_TITLE}"/>{/if}',
604                 array(
605                     '{if $fields.status.value != "Held"}<input type="hidden" name="id1" value="true"/><input type="hidden" name="id2"/>{/if}',
606                 ),
607             ),
608             //set #2: wrapping with conditional smarty statement great equal than two phases
609             array(
610                 '{if $fields.status.value != "Held"}<input type="hidden" name="id1" value="true"><input type="hidden" name="id2"><input type="submit" onclick="'.$onclick.'">{else}<input type="hidden" name="id3" value="true"><input type="submit" onclick="'.$onclick.'">{/if}',
611                 '{if $fields.status.value != "Held"}<input type="hidden" name="id1" value="true"/><input type="hidden" name="id2"/><input type="button" onclick="'.$expected_onclick.'"/>{else}<input type="hidden" name="id3" value="true"/><input type="button" onclick="'.$expected_onclick.'"/>{/if}',
612                 array(
613                     '{if $fields.status.value != "Held"}<input type="hidden" name="id1" value="true"/><input type="hidden" name="id2"/>{else}<input type="hidden" name="id3" value="true"/>{/if}',
614                 ),
615             ),
616
617             //set #3: hidden fields wrapped with the additional form element
618             array(
619                 '<form name="blah">   <input type="hidden" name="id1">    <input type="hidden" name="id2">     <input type="submit" onclick="'.$onclick.'"></form>',
620                 '<form name="blah"><input type="hidden" name="id1"/><input type="hidden" name="id2"/><input type="submit" onclick="'.$onclick.'"/></form>',
621                 null
622             ),
623         );
624     }
625     /**
626      * @dataProvider providerCustomCodeWithHidden
627      */
628     public function testCustomCodeWithHidden($customCode, $expected_customCode, $expected_hidden_array) {
629
630         $params = array(
631             'module' => 'Accounts',
632             'view' => 'DetailView',
633             'id' => array(
634                 'customCode' => $customCode
635             ),
636             'form_id' => 'DetailView'
637         );
638         $this->assertEquals($expected_customCode, smarty_function_sugar_button($params, $this->_smarty));
639         $form = $this->_smarty->get_template_vars('form');
640
641         $this->assertEquals($expected_hidden_array, $form['hidden']);
642
643     }
644
645     public function testBuildSugarHtml() {
646
647         $sugar_html = array(
648             'type' => 'submit',
649             'value' => '{$APP.LBL_CLOSE_AND_CREATE_BUTTON_TITLE}',
650             'htmlOptions' => array(
651                 'title' => '{$APP.LBL_CLOSE_AND_CREATE_BUTTON_TITLE}',
652                 'name' => 'button',
653                 'class' => 'button',
654                 'onclick' => 'this.form.isSaveFromDetailView.value=true; this.form.status.value=\'Held\'; this.form.action.value=\'Save\';this.form.return_module.value=\'Meetings\';this.form.isDuplicate.value=true;this.form.isSaveAndNew.value=true;this.form.return_action.value=\'EditView\'; this.form.isDuplicate.value=true;this.form.return_id.value=\'{$fields.id.value}\';',
655
656             ),
657             'template' => '{if $fields.status.value != "Held"}[CONTENT]{/if}',
658         );
659         $expected_html = '{if $fields.status.value != "Held"}<input title="{$APP.LBL_CLOSE_AND_CREATE_BUTTON_TITLE}" name="button" class="button" onclick="var _form = document.getElementById(\'DetailView\');_form.isSaveFromDetailView.value=true; _form.status.value=\'Held\'; _form.action.value=\'Save\';_form.return_module.value=\'Meetings\';_form.isDuplicate.value=true;_form.isSaveAndNew.value=true;_form.return_action.value=\'EditView\'; _form.isDuplicate.value=true;_form.return_id.value=\'{$fields.id.value}\';_form.submit();" type="button" value="{$APP.LBL_CLOSE_AND_CREATE_BUTTON_TITLE}"/>{/if}';
660
661         $params = array(
662             'module' => 'Accounts',
663             'view' => 'DetailView',
664             'id' => array(
665                 'sugar_html' => $sugar_html
666             ),
667             'form_id' => 'DetailView'
668         );
669         //Test for smarty_function_sugar_button for sugar_html
670         $this->assertEquals($expected_html, smarty_function_sugar_button($params, $this->_smarty));
671
672     }
673 }