Development

Changeset 8837

You must first sign up to be able to contribute.

Changeset 8837

Show
Ignore:
Timestamp:
05/07/08 18:51:41 (5 months ago)
Author:
FabianLange
Message:

fixed some issues with butto_to helper, query string is now appended correctly, short notation of attributes is parsed correctly, some internal refactoring and unit tests. fixes #3184

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.1/lib/helper/UrlHelper.php

    r8465 r8837  
    232232 * @see    url_for, link_to 
    233233 */ 
    234 function button_to($name, $internal_uri, $options = array()) 
    235 { 
    236   $html_options = _convert_options($options); 
     234function button_to($name, $internal_uri ='', $options = array()) 
     235{ 
     236  $html_options = _parse_attributes($options); 
    237237  $html_options['value'] = $name; 
    238238 
     
    249249    return form_tag($internal_uri, array('method' => 'post', 'class' => 'button_to')).content_tag('div', tag('input', $html_options)).'</form>'; 
    250250  } 
    251   else if (isset($html_options['popup'])) 
    252   { 
    253     $html_options['type'] = 'button'; 
    254     $html_options = _convert_options_to_javascript($html_options, $internal_uri); 
    255  
    256     return tag('input', $html_options); 
     251 
     252  $url = url_for($internal_uri); 
     253  if (isset($html_options['query_string'])) 
     254  { 
     255    $url = $url.'?'.$html_options['query_string']; 
     256    unset($html_options['query_string']); 
     257  } 
     258  $url = "'".$url."'"; 
     259  $html_options['type'] = 'button'; 
     260 
     261  if (isset($html_options['popup'])) 
     262  { 
     263    $html_options = _convert_options_to_javascript($html_options, $url); 
     264    unset($html_options['popup']); 
    257265  } 
    258266  else 
    259267  { 
    260     $html_options['type']    = 'button'; 
    261     $html_options['onclick'] = "document.location.href='".url_for($internal_uri)."';"; 
     268    $html_options['onclick'] = "document.location.href=".$url.";"; 
    262269    $html_options = _convert_options_to_javascript($html_options); 
    263  
    264     return tag('input', $html_options); 
    265   } 
     270  } 
     271 
     272  return tag('input', $html_options); 
    266273} 
    267274 
     
    326333} 
    327334 
    328 function _convert_options_to_javascript($html_options, $internal_uri = '') 
     335function _convert_options_to_javascript($html_options, $url = 'this.href') 
    329336{ 
    330337  // confirm 
     
    348355  else if ($confirm && $popup) 
    349356  { 
    350     $html_options['onclick'] = $onclick.'if ('._confirm_javascript_function($confirm).') { '._popup_javascript_function($popup, $internal_uri).' };return false;'; 
     357    $html_options['onclick'] = $onclick.'if ('._confirm_javascript_function($confirm).') { '._popup_javascript_function($popup, $url).' };return false;'; 
    351358  } 
    352359  else if ($confirm && $post) 
     
    371378  else if ($popup) 
    372379  { 
    373     $html_options['onclick'] = $onclick._popup_javascript_function($popup, $internal_uri).'return false;'; 
     380    $html_options['onclick'] = $onclick._popup_javascript_function($popup, $url).'return false;'; 
    374381  } 
    375382 
     
    382389} 
    383390 
    384 function _popup_javascript_function($popup, $internal_uri = '') 
    385 
    386   $url = $internal_uri == '' ? 'this.href' : "'".url_for($internal_uri)."'"; 
    387  
     391function _popup_javascript_function($popup, $url = '') 
     392
    388393  if (is_array($popup)) 
    389394  { 
  • branches/1.1/test/unit/helper/UrlHelperTest.php

    r7805 r8837  
    2020} 
    2121 
    22 $t = new lime_test(26, new lime_output_color()); 
     22$t = new lime_test(29, new lime_output_color()); 
    2323 
    2424$context = sfContext::getInstance(array('controller' => 'myController')); 
     
    4141$t->is(link_to('test', '', array('query_string' => 'foo=bar')), '<a href="module/action?foo=bar">test</a>', 'link_to() can take an "query_string" option'); 
    4242$t->is(link_to(''), '<a href="module/action">module/action</a>', 'link_to() takes the url as the link name if the first argument is empty'); 
     43 
     44//button_to() 
     45$t->diag('button_to()'); 
     46$t->is(button_to('test'), '<input value="test" type="button" onclick="document.location.href=\'module/action\';" />', 'button_to() returns an HTML "input" tag'); 
     47$t->is(button_to('test','', array('query_string' => 'foo=bar')), '<input value="test" type="button" onclick="document.location.href=\'module/action?foo=bar\';" />', 'button_to() returns an HTML "input" tag'); 
     48$t->is(button_to('test','', array('popup' => 'true', 'query_string' => 'foo=bar')), '<input value="test" type="button" onclick="var w=window.open(\'module/action?foo=bar\');w.focus();return false;" />', 'button_to() returns an HTML "input" tag'); 
     49 
    4350class testObject 
    4451{