Permalink
Browse files

consistently check 'checked' and 'selected' attributes

  • Loading branch information...
1 parent 39bdec7 commit 35e16a046b47c83e383b363ab1aacf3c5628072f @scribu committed Feb 21, 2013
Showing with 17 additions and 4 deletions.
  1. +17 −4 tests/test-forms.php
View
@@ -54,16 +54,25 @@ function testRadio() {
$this->assertEquals( ' ' . $choices[ $i ], $label->text() );
}
+
+ // should always have the first radio checked
+ $checked = $fd->find('//input[@checked]');
+
+ $this->assertCount( 1, $checked );
+
+ $this->assertEquals( $choices[0], $checked->attr('value') );
}
function testCheckbox() {
$choices = array( 'foo', 'bar' );
- $fd = self::domify( scbForms::input( array(
+ $args = array(
'name' => array( 'maxi', 'pads' ),
'type' => 'checkbox',
'choices' => $choices
- ) ) );
+ );
+
+ $fd = self::domify( scbForms::input( $args ) );
$labels = $fd->find('//label');
@@ -78,6 +87,8 @@ function testCheckbox() {
$this->assertEquals( $choices[ $i ], $el->attr('value') );
+ $this->assertEmpty( $el->attr( 'checked' ) );
+
$this->assertEquals( ' ' . $choices[ $i ], $label->text() );
}
}
@@ -95,10 +106,9 @@ function testSelect() {
'choices' => $choices,
);
+ // no pre-selected value
$fd = self::domify( scbForms::input( $args ) );
- $this->assertCount( 0, $fd->find('//select/option[@selected]') );
-
$options = $fd->find('//select/option');
$this->assertCount( count( $choices ), $options );
@@ -109,8 +119,11 @@ function testSelect() {
$this->assertEquals( $choices[ $i ], $el->attr('value') );
$this->assertEquals( $choices[ $i ], $el->text() );
+
+ $this->assertEmpty( $el->attr( 'selected' ) );
}
+ // pre-select a value
$fd = self::domify( scbForms::input( array_merge( $args, array( 'selected' => '1 1/3' ) ) ) );
$selected = $fd->find('//select/option[@selected]');

0 comments on commit 35e16a0

Please sign in to comment.