Development

Changeset 11019

You must first sign up to be able to contribute.

Changeset 11019

Show
Ignore:
Timestamp:
08/21/08 17:22:03 (11 months ago)
Author:
fabien
Message:

[1.2] added the possibility for sfBrowser to click on a link or button when several links or buttons exist with the same name (closes #4240)

Files:

Legend:

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

    r10835 r11019  
    6767Tests 
    6868----- 
     69 
     70Cookies 
     71~~~~~~~ 
    6972 
    7073Cookies are now extensively supported in the `sfBrowser` and `sfTestBrowser` 
     
    106109The browser class also automatically expires cookies as per the `expire` value 
    107110of each cookie. 
     111 
     112Links 
     113~~~~~ 
     114 
     115When you simulate a click on a button or on a link, you give the name to the `click()` 
     116method. But you don't have the possibility to differentiate two different links or buttons 
     117with the same name. 
     118 
     119As of symfony 1.2, the `click()` method takes a third argument to tell the position of 
     120the link you want to click on the page: 
     121 
     122    [php] 
     123    $b-> 
     124      click('/', array(), 1)-> 
     125      // ... 
     126    ; 
     127 
     128By default, symfony clicks on the first link it finds in the page. 
    108129 
    109130YAML 
  • branches/1.2/lib/util/sfBrowser.class.php

    r10950 r11019  
    575575   * Simulates a click on a link or button. 
    576576   * 
    577    * @param string $name       The link or button text 
    578    * @param array  $arguments 
    579    * 
    580    * @return sfBrowser 
    581    */ 
    582   public function click($name, $arguments = array()) 
     577   * @param string  $name       The link or button text 
     578   * @param array   $arguments  The arguments to pass to the link 
     579   * @param integer $position   The position of the linked to link if several ones have the same name 
     580   * 
     581   * @return sfBrowser 
     582   */ 
     583  public function click($name, $arguments = array(), $position = 0) 
    583584  { 
    584585    $dom = $this->getResponseDom(); 
     
    592593 
    593594    // text link 
    594     if ($link = $xpath->query(sprintf('//a[.="%s"]', $name))->item(0)) 
     595    if ($link = $xpath->query(sprintf('//a[.="%s"]', $name))->item($position)) 
    595596    { 
    596597      return $this->get($link->getAttribute('href')); 
     
    598599 
    599600    // image link 
    600     if ($link = $xpath->query(sprintf('//a/img[@alt="%s"]/ancestor::a', $name))->item(0)) 
     601    if ($link = $xpath->query(sprintf('//a/img[@alt="%s"]/ancestor::a', $name))->item($position)) 
    601602    { 
    602603      return $this->get($link->getAttribute('href')); 
     
    604605 
    605606    // form 
    606     if (!$form = $xpath->query(sprintf('//input[((@type="submit" or @type="button") and @value="%s") or (@type="image" and @alt="%s")]/ancestor::form', $name, $name))->item(0)) 
    607     { 
    608       if (!$form = $xpath->query(sprintf('//button[.="%s" or @id="%s" or @name="%s"]/ancestor::form', $name, $name, $name))->item(0)) 
     607    if (!$form = $xpath->query(sprintf('//input[((@type="submit" or @type="button") and @value="%s") or (@type="image" and @alt="%s")]/ancestor::form', $name, $name))->item($position)) 
     608    { 
     609      if (!$form = $xpath->query(sprintf('//button[.="%s" or @id="%s" or @name="%s"]/ancestor::form', $name, $name, $name))->item($position)) 
    609610      { 
    610611        throw new sfException(sprintf('Cannot find the "%s" link or button.', $name)); 
  • branches/1.2/test/unit/util/sfBrowserTest.php

    r10950 r11019  
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    1212 
    13 $t = new lime_test(51, new lime_output_color()); 
     13$t = new lime_test(52, new lime_output_color()); 
    1414 
    1515// ->click() 
     
    110110    </form> 
    111111 
     112    <a href="/myotherlink">test link</a> 
     113 
    112114  </body> 
    113115</html> 
     
    139141list($method, $uri, $parameters) = $b->click('test link'); 
    140142$t->is($uri, '/mylink', '->click() clicks on links'); 
     143 
     144list($method, $uri, $parameters) = $b->click('test link', array(), 1); 
     145$t->is($uri, '/myotherlink', '->click() can take a third argument to tell the position of the link to click on'); 
    141146 
    142147list($method, $uri, $parameters) = $b->click('image link'); 
     
    253258$t->is($files['myfile']['error'], UPLOAD_ERR_OK, 'existent file exists (UPLOAD_ERR_OK)'); 
    254259$t->is($files['myfile']['name'], basename($existentFilename), 'name key ok'); 
    255  

The Sensio Labs Network

Since 1998, Sensio Labs has been promoting the Open-Source software movement by providing quality web application development, training, consulting, and supporting several large Open-Source projects.