Changeset 13023
- Timestamp:
- 11/16/08 01:25:26 (8 months ago)
- Files:
-
- branches/1.2/lib/test/sfTestFunctionalBase.class.php (modified) (1 diff)
- branches/1.2/lib/util/sfBrowserBase.class.php (modified) (1 diff)
- branches/1.2/test/unit/util/sfBrowserTest.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.2/lib/test/sfTestFunctionalBase.class.php
r12996 r13023 244 244 245 245 $this->browser->call($uri, $method, $parameters, $changeStack); 246 247 return $this; 248 } 249 250 /** 251 * Simulates deselecting a checkbox or radiobutton. 252 * 253 * @param string $name The checkbox or radiobutton id, name or text 254 * 255 * @return sfBrowser 256 */ 257 public function deselect($name) 258 { 259 $this->browser->doSelect($name, false); 260 261 return $this; 262 } 263 264 /** 265 * Simulates selecting a checkbox or radiobutton. 266 * 267 * @param string $name The checkbox or radiobutton id, name or text 268 * 269 * @return sfBrowser 270 */ 271 public function select($name) 272 { 273 $this->browser->doSelect($name, true); 246 274 247 275 return $this; branches/1.2/lib/util/sfBrowserBase.class.php
r12853 r13023 540 540 541 541 /** 542 * Simulates deselecting a checkbox or radiobutton. 543 * 544 * @param string $name The checkbox or radiobutton id, name or text 545 * 546 * @return sfBrowser 547 * 548 * @see doSelect() 549 */ 550 public function deselect($name) 551 { 552 $this->doSelect($name, false); 553 554 return $this; 555 } 556 557 /** 558 * Simulates selecting a checkbox or radiobutton. 559 * 560 * @param string $name The checkbox or radiobutton id, name or text 561 * 562 * @return sfBrowser 563 * 564 * @see doSelect() 565 */ 566 public function select($name) 567 { 568 $this->doSelect($name, true); 569 570 return $this; 571 } 572 573 /** 574 * Simulates selecting a checkbox or radiobutton. 575 * 576 * This method is called internally by the select() and deselect() methods. 577 * 578 * @param string $name The checkbox or radiobutton id, name or text 579 * @param boolean $selected If true the item will be selected 580 * 581 */ 582 public function doSelect($name, $selected) 583 { 584 $position = 0; 585 $dom = $this->getResponseDom(); 586 587 if (!$dom) 588 { 589 throw new LogicException('Cannot select because there is no current page in the browser.'); 590 } 591 592 $xpath = new DomXpath($dom); 593 594 if ($element = $xpath->query(sprintf('//input[(@type="radio" or @type="checkbox") and (.="%s" or @id="%s" or @name="%s")]', $name, $name, $name))->item($position)) 595 { 596 if ($selected) 597 { 598 if ($element->getAttribute('type') == 'radio') 599 { 600 //we need to deselect all other radio buttons with the same name 601 foreach ($xpath->query(sprintf('//input[@type="radio" and @name="%s"]', $element->getAttribute('name'))) as $radio) 602 { 603 $radio->removeAttribute('checked'); 604 } 605 } 606 $element->setAttribute('checked', 'checked'); 607 } 608 else 609 { 610 if ($element->getAttribute('type') == 'radio') 611 { 612 throw new InvalidArgumentException('Radiobutton cannot be deselected - Select another radiobutton to deselect the current.'); 613 } 614 $element->removeAttribute('checked'); 615 } 616 } 617 else 618 { 619 throw new InvalidArgumentException(sprintf('Cannot find the "%s" checkbox or radiobutton.', $name)); 620 } 621 } 622 623 /** 542 624 * Simulates a click on a link or button. 543 625 * branches/1.2/test/unit/util/sfBrowserTest.php
r11497 r13023 11 11 require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 12 12 13 $t = new lime_test(5 4, new lime_output_color());13 $t = new lime_test(59, new lime_output_color()); 14 14 15 15 // ->click() … … 79 79 <input type="checkbox" name="checkbox1" value="checkboxvalue" checked="checked" /> 80 80 <input type="checkbox" name="checkbox2" checked="checked" /> 81 <input type="checkbox" name="checkbox3" /> 82 <input type="radio" name="radio1" value="a" id="a-radio" /> 83 <input type="radio" name="radio1" value="b" id="b-radio" /> 81 84 <input type="button" name="mybutton" value="mybuttonvalue" /> 82 85 <input type="submit" name="submit" value="submit" /> … … 234 237 $t->is($parameters['text'], 'yourothervalue', '->setField() is overriden by parameters from click call'); 235 238 239 // ->deselect()/select() 240 $t->diag('->deselect()/select()'); 241 list($method, $uri, $parameters) = $b-> 242 deselect('checkbox1')-> 243 select('checkbox3')-> 244 select('b-radio')-> 245 click('submit') 246 ; 247 $t->is(isset($parameters['checkbox1']), false, '->deselect() unckecks a checkbox'); 248 $t->is(isset($parameters['checkbox3']), true, '->select() ckecks a checkbox'); 249 $t->is($parameters['radio1'], 'b', '->select() selects a radiobutton'); 250 list($method, $uri, $parameters) = $b-> 251 select('a-radio')-> 252 click('submit') 253 ; 254 $t->is($parameters['radio1'], 'a', '->select() toggles radiobuttons'); 255 256 try 257 { 258 $b->deselect('b-radio'); 259 $t->fail('->deselect() cannot deselect radiobuttons'); 260 } 261 catch(Exception $e) 262 { 263 $t->pass('->deselect() cannot deselect radiobuttons'); 264 } 265 236 266 // ->call() 237 267 $t->diag('->call()');

