Development

Changeset 11452

You must first sign up to be able to contribute.

Changeset 11452

Show
Ignore:
Timestamp:
09/11/08 20:38:31 (5 years ago)
Author:
fabien
Message:

[1.2] added support for PUT and DELETE to the browser class

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.2/UPGRADE_TO_1_2

    r11444 r11452  
    538538with the same name. 
    539539 
    540 As of symfony 1.2, the `click()` method takes a third argument to tell the position of 
    541 the link you want to click on the page: 
     540As of symfony 1.2, the `click()` method takes a third argument to pass some options. 
     541 
     542You can pass a `position` option to change the link you want to click on: 
    542543 
    543544    [php] 
    544545    $b-> 
    545       click('/', array(), 1)-> 
     546      click('/', array(), array('position' => 1))-> 
    546547      // ... 
    547548    ; 
    548549 
    549550By default, symfony clicks on the first link it finds in the page. 
     551 
     552You can also pass a `method` option to change the method of the link or the form 
     553you are clicking on: 
     554 
     555    [php] 
     556    $b-> 
     557      click('/delete', array(), array('method' => 'delete'))-> 
     558      // ... 
     559    ; 
     560 
     561This is very useful when a link is converted to a dynamic form generated 
     562with JavaScript. 
    550563 
    551564YAML 
  • branches/1.2/lib/util/sfBrowserBase.class.php

    r11212 r11452  
    536536   * Simulates a click on a link or button. 
    537537   * 
     538   * Available options: 
     539   * 
     540   *  * position: The position of the linked to link if several ones have the same name 
     541   *  * method:   The method to used instead of the form ones 
     542   *              (useful when you need to click on a link that is converted to a form with JavaScript code) 
     543   * 
    538544   * @param string  $name       The link or button text 
    539545   * @param array   $arguments  The arguments to pass to the link 
    540    * @param integer $position   The position of the linked to link if several ones have the same name 
    541    * 
    542    * @return sfBrowser 
    543    */ 
    544   public function click($name, $arguments = array(), $position = 0) 
    545   { 
     546   * @param array   $options    An array of options 
     547   * 
     548   * @return sfBrowser 
     549   */ 
     550  public function click($name, $arguments = array(), $options = array()) 
     551  { 
     552    $position = isset($options['position']) ? $options['position'] : 0; 
     553 
    546554    $dom = $this->getResponseDom(); 
    547555 
     
    552560 
    553561    $xpath = new DomXpath($dom); 
     562 
     563    $method = strtolower(isset($options['method']) ? $options['method'] : 'get'); 
    554564 
    555565    // text link 
    556566    if ($link = $xpath->query(sprintf('//a[.="%s"]', $name))->item($position)) 
    557567    { 
    558       return $this->get($link->getAttribute('href')); 
     568      if (in_array($method, array('post', 'put', 'delete'))) 
     569      { 
     570        return $this->call($link->getAttribute('href'), $method, $arguments); 
     571      } 
     572      else 
     573      { 
     574        return $this->get($link->getAttribute('href')); 
     575      } 
    559576    } 
    560577 
     
    562579    if ($link = $xpath->query(sprintf('//a/img[@alt="%s"]/ancestor::a', $name))->item($position)) 
    563580    { 
    564       return $this->get($link->getAttribute('href')); 
     581      if (in_array($method, array('post', 'put', 'delete'))) 
     582      { 
     583        return $this->call($link->getAttribute('href'), $method, $arguments); 
     584      } 
     585      else 
     586      { 
     587        return $this->get($link->getAttribute('href')); 
     588      } 
    565589    } 
    566590 
     
    576600    // form attributes 
    577601    $url = $form->getAttribute('action'); 
    578     $method = $form->getAttribute('method') ? strtolower($form->getAttribute('method')) : 'get'
     602    $method = strtolower(isset($options['method']) ? $options['method'] : ($form->getAttribute('method') ? $form->getAttribute('method') : 'get'))
    579603 
    580604    // merge form default values and arguments 
     
    677701    // create request parameters 
    678702    $arguments = sfToolkit::arrayDeepMerge($defaults, $arguments); 
    679     if ('post' == $method
    680     { 
    681       return $this->post($url, $arguments); 
     703    if (in_array($method, array('post', 'put', 'delete'))
     704    { 
     705      return $this->call($url, $method, $arguments); 
    682706    } 
    683707    else 
  • branches/1.2/test/unit/util/sfBrowserTest.php

    r11020 r11452  
    144144$t->is($uri, '/mylink', '->click() clicks on links'); 
    145145 
    146 list($method, $uri, $parameters) = $b->click('test link', array(), 1); 
     146list($method, $uri, $parameters) = $b->click('test link', array(), array('position' => 1)); 
    147147$t->is($uri, '/myotherlink', '->click() can take a third argument to tell the position of the link to click on'); 
    148148