Skip to content

Commit

Permalink
consistently check 'checked' and 'selected' attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
scribu committed Feb 21, 2013
1 parent 39bdec7 commit 35e16a0
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions tests/test-forms.php
Expand Up @@ -54,16 +54,25 @@ function testRadio() {


$this->assertEquals( ' ' . $choices[ $i ], $label->text() ); $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() { function testCheckbox() {
$choices = array( 'foo', 'bar' ); $choices = array( 'foo', 'bar' );


$fd = self::domify( scbForms::input( array( $args = array(
'name' => array( 'maxi', 'pads' ), 'name' => array( 'maxi', 'pads' ),
'type' => 'checkbox', 'type' => 'checkbox',
'choices' => $choices 'choices' => $choices
) ) ); );

$fd = self::domify( scbForms::input( $args ) );


$labels = $fd->find('//label'); $labels = $fd->find('//label');


Expand All @@ -78,6 +87,8 @@ function testCheckbox() {


$this->assertEquals( $choices[ $i ], $el->attr('value') ); $this->assertEquals( $choices[ $i ], $el->attr('value') );


$this->assertEmpty( $el->attr( 'checked' ) );

$this->assertEquals( ' ' . $choices[ $i ], $label->text() ); $this->assertEquals( ' ' . $choices[ $i ], $label->text() );
} }
} }
Expand All @@ -95,10 +106,9 @@ function testSelect() {
'choices' => $choices, 'choices' => $choices,
); );


// no pre-selected value
$fd = self::domify( scbForms::input( $args ) ); $fd = self::domify( scbForms::input( $args ) );


$this->assertCount( 0, $fd->find('//select/option[@selected]') );

$options = $fd->find('//select/option'); $options = $fd->find('//select/option');


$this->assertCount( count( $choices ), $options ); $this->assertCount( count( $choices ), $options );
Expand All @@ -109,8 +119,11 @@ function testSelect() {
$this->assertEquals( $choices[ $i ], $el->attr('value') ); $this->assertEquals( $choices[ $i ], $el->attr('value') );


$this->assertEquals( $choices[ $i ], $el->text() ); $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' ) ) ) ); $fd = self::domify( scbForms::input( array_merge( $args, array( 'selected' => '1 1/3' ) ) ) );


$selected = $fd->find('//select/option[@selected]'); $selected = $fd->find('//select/option[@selected]');
Expand Down

0 comments on commit 35e16a0

Please sign in to comment.