2 /*********************************************************************************
3 * SugarCRM Community Edition is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2013 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/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';
43 class FunctionSugarButtonTest extends Sugar_PHPUnit_Framework_TestCase
45 public function setUp()
47 $this->_smarty = new Sugar_Smarty;
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();';
62 //set #0: simple input code
64 '<input type="submit" value="{$APP.BUTTON_LABEL}" onclick="'.$onclick.'">',
68 'self_closing' => true,
69 'onclick' => $onclick,
70 'value' => '{$APP.BUTTON_LABEL}'
72 '<input type="button" value="{$APP.BUTTON_LABEL}" onclick="'.$expected_onclick.'"/>',
76 '<input type="submit" disabled value="{$APP.BUTTON_LABEL}" onclick="'.$onclick.'">',
80 'self_closing' => true,
81 'onclick' => $onclick,
82 'value' => '{$APP.BUTTON_LABEL}',
85 '<input type="button" disabled value="{$APP.BUTTON_LABEL}" onclick="'.$expected_onclick.'"/>',
88 //set #2: custom code contains smarty conditional statement
90 '<input type="submit" value="{$APP.BUTTON_LABEL}" onclick="{if $bean->access(\'edit\')}'.$onclick.'{/if}">',
94 'self_closing' => true,
95 'onclick' => '{if $bean->access(\'edit\')}'.$onclick.'{/if}',
96 'value' => '{$APP.BUTTON_LABEL}'
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();"/>',
100 //set #3: attributes wrapped with smarty
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">',
106 'id' => 'button_submit',
108 'self_closing' => true,
111 'template' => '{if $bean->access(\'edit\')}[CONTENT0]{else}[CONTENT1]{/if}',
112 '[CONTENT0]' => array(
115 '[CONTENT1]' => array(
120 'template' => '{if $bean->access(\'edit\')}[CONTENT0]{else}[CONTENT1]{/if}',
121 '[CONTENT0]' => array(
122 'onclick' => $onclick
124 '[CONTENT1]' => array(
125 'onclick' => 'alert(\'nope\');'
130 'value' => '{$APP.BUTTON_LABEL}'
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"/>',
135 //set #4: attributes wrapped with smarty
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">',
141 'id' => 'button_submit',
144 'self_closing' => true,
147 'template' => '{if $bean->access(\'edit\')}[CONTENT0]{else}[CONTENT1]{/if}',
148 '[CONTENT0]' => array(
149 'onclick' => $onclick
151 '[CONTENT1]' => array(
152 'onclick' => 'this.form.module.value=\'{$APP.MODULE}\';this.form.action.value=\'{$APP.ACTION}\';'
157 'value' => '{$APP.BUTTON_LABEL}'
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"/>',
162 //set #5: recursive smarty wrapper within the attributes
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">',
166 'id' => 'button_submit',
169 'self_closing' => true,
170 'value' => '{$APP.BUTTON_LABEL}',
173 'template' => '{$APP.DISABLED}'
176 'template' => '{if $bean->access(\'edit\')}[CONTENT0]{else if $bean->access(\'delete\') }[CONTENT1]{else}[CONTENT2]{/if}',
177 '[CONTENT0]' => array(
180 'template' => '{if $APP.CONTAINER = true}[CONTENT0]{/if}',
181 '[CONTENT0]' => array(
182 'onclick' => $onclick
187 '[CONTENT1]' => array(
188 'onclick' => 'del();'
190 '[CONTENT2]' => array(
191 'onclick' => 'alert(\'nope\');'
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"/>',
198 //set #6: Begins with smarty conditional statement
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}',
204 'template' => '{if $fields.status.value != "Held"}[CONTENT0]{/if}',
205 '[CONTENT0]' => array(
208 'self_closing' => true,
209 'title' => '{$APP.LBL_CLOSE_AND_CREATE_BUTTON_TITLE}',
211 'onclick' => $onclick,
212 'value' => '{$APP.LBL_CLOSE_AND_CREATE_BUTTON_TITLE}'
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}'
219 //set #7: Begins with smarty conditional statement and contains recursive conditional statement inside the context
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}',
225 'template' => '{ if($fields.status.value != "Held") }[CONTENT0]{/if}',
226 '[CONTENT0]' => array(
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}',
236 'template' => '{if $bean->access(\'edit\')}[CONTENT0]{else if $bean->access(\'delete\') }[CONTENT1]{else}[CONTENT2]{/if}',
237 '[CONTENT0]' => array(
240 'template' => '{if $APP.CONTAINER = true}[CONTENT0]{/if}',
241 '[CONTENT0]' => array(
242 'onclick' => $onclick
247 '[CONTENT1]' => array(
248 'onclick' => 'del();'
250 '[CONTENT2]' => array(
251 'onclick' => 'alert(\'nope\');'
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}'
262 //set #8: The submit button is encapsulated with another form
264 '<form name="blah"> <input type="hidden" name="id1"> <input type="hidden" name="id2"> <input type="submit" onclick="'.$onclick.'"></form>',
268 'self_closing' => false,
269 'container' => array(
274 'self_closing' => true,
280 'self_closing' => true,
285 'onclick' => $onclick,
286 'self_closing' => true,
290 '<form name="blah"><input type="hidden" name="id1"/><input type="hidden" name="id2"/><input type="submit" onclick="'.$onclick.'"/></form>',
293 //set #9: custom code encapsulated smarty conditional statement, and contains additional hidden fields
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}',
299 'template' => '{if $fields.status.value != "Held"}[CONTENT0]{/if}',
300 '[CONTENT0]' => array(
305 'self_closing' => true,
312 'self_closing' => true,
317 'value' => '{$APP.LBL_CLOSE_AND_CREATE_BUTTON_TITLE}',
318 'self_closing' => true,
321 'template' => '{if $APP.CONTAINER = true}[CONTENT0]{else}[CONTENT1]{/if}',
322 '[CONTENT0]' => array(
323 'onclick' => $onclick
325 '[CONTENT1]' => array(
326 'onclick' => 'stop();'
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}'
337 //set #10: empty spaces after the equal sign
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}">',
342 'title' => '{$APP.LBL_SAVE_BUTTON_TITLE}',
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();',
348 'value' => '{$APP.LBL_SAVE_BUTTON_LABEL}',
349 'self_closing' => true,
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}"/>',
353 //set #11: empty spaces before the equal sign
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}">',
358 'title' => '{$APP.LBL_SAVE_BUTTON_TITLE}',
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();',
364 'value' => '{$APP.LBL_SAVE_BUTTON_LABEL}',
365 'self_closing' => true,
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}"/>',
369 //set #12: Contains smarty syntax "ldelim, rdelim"
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} ',
375 'template' => '{if $bean->aclAccess("delete") && !empty($smarty.request.record)}[CONTENT0]{/if}',
376 '[CONTENT0]' => array(
378 'self_closing' => true,
379 'title' => '{$APP.LBL_DELETE_BUTTON_TITLE}',
380 'accessKey' => '{$APP.LBL_DELETE_BUTTON_KEY}',
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};',
385 'value' => '{$APP.LBL_DELETE_BUTTON_LABEL}',
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}'
393 //set #13: Contains smarty syntax "literal"
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} ',
399 'template' => '{if $bean->aclAccess("delete") && !empty($smarty.request.record)}[CONTENT0]{/if}',
400 '[CONTENT0]' => array(
402 'self_closing' => true,
403 'title' => '{$APP.LBL_DELETE_BUTTON_TITLE}',
404 'accessKey' => '{$APP.LBL_DELETE_BUTTON_KEY}',
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}',
409 'value' => '{$APP.LBL_DELETE_BUTTON_LABEL}',
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}'
417 //set #14: Multiple conditional statement
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"> '.
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"> '.
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(
434 'title' => '{$APP.LBL_CANCEL_BUTTON_TITLE}',
435 'accessKey' => '{$APP.LBL_CANCEL_BUTTON_KEY}',
439 'value' => '{$APP.LBL_CANCEL_BUTTON_LABEL}',
441 'onclick' => $onclick,
442 'self_closing' => true
444 '[CONTENT1]' => array(
446 'title' => '{$APP.LBL_CANCEL_BUTTON_TITLE}',
447 'accessKey' => '{$APP.LBL_CANCEL_BUTTON_KEY}',
451 'value' => '{$APP.LBL_CANCEL_BUTTON_LABEL}',
453 'onclick' => $onclick2,
454 'self_closing' => true
456 '[CONTENT2]' => array(
458 'title' => '{$APP.LBL_CANCEL_BUTTON_TITLE}',
459 'accessKey' => '{$APP.LBL_CANCEL_BUTTON_KEY}',
463 'value' => '{$APP.LBL_CANCEL_BUTTON_LABEL}',
465 'onclick' => $onclick3,
466 'self_closing' => true
468 '[CONTENT3]' => array(
470 'title' => '{$APP.LBL_CANCEL_BUTTON_TITLE}',
471 'accessKey' => '{$APP.LBL_CANCEL_BUTTON_KEY}',
475 'value' => '{$APP.LBL_CANCEL_BUTTON_LABEL}',
477 'onclick' => $onclick4,
478 'self_closing' => true
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"/>'.
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"/>'.
494 //set #15: Parallel smarty strings
496 '{$APP.VALUE1} {$HIDDEN_FIELD} <input type="submit" value="{$APP.BUTTON_LABEL}" onclick="'.$onclick.'">',
501 'template' => '{$APP.VALUE1}',
508 'template' => '{$HIDDEN_FIELD}',
515 'self_closing' => true,
516 'onclick' => $onclick,
517 'value' => '{$APP.BUTTON_LABEL}'
520 '{$APP.VALUE1}{$HIDDEN_FIELD}<input type="button" value="{$APP.BUTTON_LABEL}" onclick="'.$expected_onclick.'"/>',
522 //set #16: Contains smarty syntax "nocache"
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">'
531 'action' => 'index.php',
532 'method' => '{$PDFMETHOD}',
535 'onsubmit' => 'this.sugarpdf.value =(document.getElementById(\'sugarpdf\'))? document.getElementById(\'sugarpdf\').value: \'\';',
536 'container' => array(
542 'self_closing' => true,
547 'template' => '{nocache}{sugar_email_btn}{/nocache}',
552 'self_closing' => false,
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"/>'
565 * @dataProvider providerCustomCode
567 public function testCustomCode($customCode, $expected_parsed_array, $expected_customCode)
569 //Test for parseHtmlTag
570 $this->assertEquals($expected_parsed_array, SugarHtml::parseHtmlTag($customCode));
572 'module' => 'Accounts',
573 'view' => 'DetailView',
575 'customCode' => $customCode
577 'form_id' => 'DetailView'
581 //Test for smarty_function_sugar_button for customCode
582 $this->assertEquals($expected_customCode, smarty_function_sugar_button($params, $this->_smarty));
586 public function providerCustomCodeWithHidden() {
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();';
592 //set #0: Button with hidden field
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}"/>',
597 '<input type="hidden" name="id2" value="2"/>'
600 //set #1: Button with hidden field wrapping with conditional smarty statement
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}',
605 '{if $fields.status.value != "Held"}<input type="hidden" name="id1" value="true"/><input type="hidden" name="id2"/>{/if}',
608 //set #2: wrapping with conditional smarty statement great equal than two phases
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}',
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}',
617 //set #3: hidden fields wrapped with the additional form element
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>',
626 * @dataProvider providerCustomCodeWithHidden
628 public function testCustomCodeWithHidden($customCode, $expected_customCode, $expected_hidden_array) {
631 'module' => 'Accounts',
632 'view' => 'DetailView',
634 'customCode' => $customCode
636 'form_id' => 'DetailView'
638 $this->assertEquals($expected_customCode, smarty_function_sugar_button($params, $this->_smarty));
639 $form = $this->_smarty->get_template_vars('form');
641 $this->assertEquals($expected_hidden_array, $form['hidden']);
645 public function testBuildSugarHtml() {
649 'value' => '{$APP.LBL_CLOSE_AND_CREATE_BUTTON_TITLE}',
650 'htmlOptions' => array(
651 'title' => '{$APP.LBL_CLOSE_AND_CREATE_BUTTON_TITLE}',
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}\';',
657 'template' => '{if $fields.status.value != "Held"}[CONTENT]{/if}',
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}';
662 'module' => 'Accounts',
663 'view' => 'DetailView',
665 'sugar_html' => $sugar_html
667 'form_id' => 'DetailView'
669 //Test for smarty_function_sugar_button for sugar_html
670 $this->assertEquals($expected_html, smarty_function_sugar_button($params, $this->_smarty));