Permalink
Browse files

add testCheckboxWithValues

  • Loading branch information...
1 parent b10a7dc commit fd0e0276f4f742c32f0ffcb352b203e6b63f2452 @scribu committed Feb 21, 2013
Showing with 38 additions and 0 deletions.
  1. +38 −0 tests/test-forms.php
View
@@ -113,6 +113,44 @@ function testCheckbox() {
}
}
+ function testCheckboxWithValues() {
+ $selected = array( 'a', 'c' );
+ $choices = array( 'a', 'b', 'c', 'd' );
+
+ $data = array(
+ __FUNCTION__ => $selected
+ );
+
+ $output = scbForms::input( array(
+ 'name' => __FUNCTION__,
+ 'type' => 'checkbox',
+ 'choices' => $choices
+ ), $data );
+
+ $labels = self::domify( $output )->find('//label');
+
+ $this->assertCount( count( $choices ), $labels );
+
+ foreach ( $labels as $i => $label ) {
+ $value = $choices[ $i ];
+
+ $label = FluentDOM( $label );
+
+ $el = $label->find('.//input[@type="checkbox"]');
+
+ $this->assertEquals( __FUNCTION__ . '[]', $el->attr('name') );
+
+ $this->assertEquals( $value, $el->attr('value') );
+
+ if ( in_array( $value, $selected ) )
+ $this->assertNotEmpty( $el->attr( 'checked' ) );
+ else
+ $this->assertEmpty( $el->attr( 'checked' ) );
+
+ $this->assertEquals( ' ' . $value, $label->text() );
+ }
+ }
+
function testSelect() {
$choices = array(
'1/2',

0 comments on commit fd0e027

Please sign in to comment.