Changeset 11452
- Timestamp:
- 09/11/08 20:38:31 (5 years ago)
- Files:
-
- branches/1.2/UPGRADE_TO_1_2 (modified) (1 diff)
- branches/1.2/lib/util/sfBrowserBase.class.php (modified) (5 diffs)
- branches/1.2/test/unit/util/sfBrowserTest.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.2/UPGRADE_TO_1_2
r11444 r11452 538 538 with the same name. 539 539 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: 540 As of symfony 1.2, the `click()` method takes a third argument to pass some options. 541 542 You can pass a `position` option to change the link you want to click on: 542 543 543 544 [php] 544 545 $b-> 545 click('/', array(), 1)->546 click('/', array(), array('position' => 1))-> 546 547 // ... 547 548 ; 548 549 549 550 By default, symfony clicks on the first link it finds in the page. 551 552 You can also pass a `method` option to change the method of the link or the form 553 you are clicking on: 554 555 [php] 556 $b-> 557 click('/delete', array(), array('method' => 'delete'))-> 558 // ... 559 ; 560 561 This is very useful when a link is converted to a dynamic form generated 562 with JavaScript. 550 563 551 564 YAML branches/1.2/lib/util/sfBrowserBase.class.php
r11212 r11452 536 536 * Simulates a click on a link or button. 537 537 * 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 * 538 544 * @param string $name The link or button text 539 545 * @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 546 554 $dom = $this->getResponseDom(); 547 555 … … 552 560 553 561 $xpath = new DomXpath($dom); 562 563 $method = strtolower(isset($options['method']) ? $options['method'] : 'get'); 554 564 555 565 // text link 556 566 if ($link = $xpath->query(sprintf('//a[.="%s"]', $name))->item($position)) 557 567 { 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 } 559 576 } 560 577 … … 562 579 if ($link = $xpath->query(sprintf('//a/img[@alt="%s"]/ancestor::a', $name))->item($position)) 563 580 { 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 } 565 589 } 566 590 … … 576 600 // form attributes 577 601 $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')); 579 603 580 604 // merge form default values and arguments … … 677 701 // create request parameters 678 702 $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); 682 706 } 683 707 else branches/1.2/test/unit/util/sfBrowserTest.php
r11020 r11452 144 144 $t->is($uri, '/mylink', '->click() clicks on links'); 145 145 146 list($method, $uri, $parameters) = $b->click('test link', array(), 1);146 list($method, $uri, $parameters) = $b->click('test link', array(), array('position' => 1)); 147 147 $t->is($uri, '/myotherlink', '->click() can take a third argument to tell the position of the link to click on'); 148 148