Changeset 11019
- Timestamp:
- 08/21/08 17:22:03 (11 months ago)
- Files:
-
- branches/1.2/UPGRADE_TO_1_2 (modified) (2 diffs)
- branches/1.2/lib/util/sfBrowser.class.php (modified) (4 diffs)
- branches/1.2/test/unit/util/sfBrowserTest.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.2/UPGRADE_TO_1_2
r10835 r11019 67 67 Tests 68 68 ----- 69 70 Cookies 71 ~~~~~~~ 69 72 70 73 Cookies are now extensively supported in the `sfBrowser` and `sfTestBrowser` … … 106 109 The browser class also automatically expires cookies as per the `expire` value 107 110 of each cookie. 111 112 Links 113 ~~~~~ 114 115 When you simulate a click on a button or on a link, you give the name to the `click()` 116 method. But you don't have the possibility to differentiate two different links or buttons 117 with the same name. 118 119 As of symfony 1.2, the `click()` method takes a third argument to tell the position of 120 the link you want to click on the page: 121 122 [php] 123 $b-> 124 click('/', array(), 1)-> 125 // ... 126 ; 127 128 By default, symfony clicks on the first link it finds in the page. 108 129 109 130 YAML branches/1.2/lib/util/sfBrowser.class.php
r10950 r11019 575 575 * Simulates a click on a link or button. 576 576 * 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) 583 584 { 584 585 $dom = $this->getResponseDom(); … … 592 593 593 594 // text link 594 if ($link = $xpath->query(sprintf('//a[.="%s"]', $name))->item( 0))595 if ($link = $xpath->query(sprintf('//a[.="%s"]', $name))->item($position)) 595 596 { 596 597 return $this->get($link->getAttribute('href')); … … 598 599 599 600 // 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)) 601 602 { 602 603 return $this->get($link->getAttribute('href')); … … 604 605 605 606 // 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)) 609 610 { 610 611 throw new sfException(sprintf('Cannot find the "%s" link or button.', $name)); branches/1.2/test/unit/util/sfBrowserTest.php
r10950 r11019 11 11 require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 12 12 13 $t = new lime_test(5 1, new lime_output_color());13 $t = new lime_test(52, new lime_output_color()); 14 14 15 15 // ->click() … … 110 110 </form> 111 111 112 <a href="/myotherlink">test link</a> 113 112 114 </body> 113 115 </html> … … 139 141 list($method, $uri, $parameters) = $b->click('test link'); 140 142 $t->is($uri, '/mylink', '->click() clicks on links'); 143 144 list($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'); 141 146 142 147 list($method, $uri, $parameters) = $b->click('image link'); … … 253 258 $t->is($files['myfile']['error'], UPLOAD_ERR_OK, 'existent file exists (UPLOAD_ERR_OK)'); 254 259 $t->is($files['myfile']['name'], basename($existentFilename), 'name key ok'); 255

