Skip to content

Commit

Permalink
Use ob_get_clean in field tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fjarrett-godaddy committed Apr 7, 2016
1 parent 1ae1d44 commit e8a68e7
Showing 1 changed file with 16 additions and 32 deletions.
48 changes: 16 additions & 32 deletions tests/test-class-gem-form-fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ public function test_dispatch_field() {
$field->display = 'text_a';
ob_start();
GEM_Form_Fields::dispatch_field( $field );
$actual_output = ob_get_contents();
ob_end_clean();
$actual_output = ob_get_clean();
$this->assertContains( '<input type="text" name="the_name_a" id="form_1_the_name_a" class="gem-field" />', $actual_output );

$field = new stdClass();
Expand All @@ -42,8 +41,7 @@ public function test_dispatch_field() {
$field->value = 1;
ob_start();
GEM_Form_Fields::dispatch_field( $field );
$actual_output = ob_get_contents();
ob_end_clean();
$actual_output = ob_get_clean();
$this->assertContains( '<input type="checkbox" value="1" name="the_name_a" id="form_1_the_name_a1" class="gem-checkbox" />', $actual_output );
}

Expand All @@ -55,17 +53,15 @@ public function test_string() {
$field->display = 'text_a';
ob_start();
GEM_Form_Fields::string( $field );
$actual_output = ob_get_contents();
ob_end_clean();
$actual_output = ob_get_clean();
$this->assertContains( '<label for="form_1_the_name_a">', $actual_output );
$this->assertContains( '<input type="text" name="the_name_a" id="form_1_the_name_a" class="gem-field a_sample_class" />', $actual_output );
remove_action( 'gem_required_field_class', array( $this, 'gem_required_field_class_callback' ) );

$field->required = true;
ob_start();
GEM_Form_Fields::string( $field );
$actual_output = ob_get_contents();
ob_end_clean();
$actual_output = ob_get_clean();
$this->assertContains( '<label for="form_1_the_name_a">', $actual_output );
$this->assertContains( '<span class="required">*</span>', $actual_output );
$this->assertContains( '<input type="text" name="the_name_a" id="form_1_the_name_a" class="gem-field gem-required" />', $actual_output );
Expand All @@ -80,8 +76,7 @@ public function test_checkbox() {
$field->value = 'the_value';
ob_start();
GEM_Form_Fields::checkbox( $field );
$actual_output = ob_get_contents();
ob_end_clean();
$actual_output = ob_get_clean();
$this->assertContains( '<label for="form_1_the_name_athe_value">', $actual_output );
$this->assertContains( '<input type="checkbox" value="the_value" name="the_name_a" id="form_1_the_name_athe_value" class="gem-checkbox a_sample_class" />', $actual_output );
$this->assertContains( 'text_a', $actual_output );
Expand All @@ -90,8 +85,7 @@ public function test_checkbox() {
$field->required = true;
ob_start();
GEM_Form_Fields::checkbox( $field );
$actual_output = ob_get_contents();
ob_end_clean();
$actual_output = ob_get_clean();
$this->assertContains( '<span class="required">*</span>', $actual_output );
$this->assertContains( '<label for="form_1_the_name_athe_value">', $actual_output );
$this->assertContains( '<input type="checkbox" value="the_value" name="the_name_a" id="form_1_the_name_athe_value" class="gem-checkbox gem-required" />', $actual_output );
Expand All @@ -108,8 +102,7 @@ public function test_checkboxes() {
$field->options = '["Option 1","Option 2"]';
ob_start();
GEM_Form_Fields::checkboxes( $field );
$actual_output = ob_get_contents();
ob_end_clean();
$actual_output = ob_get_clean();
$this->assertContains( '<label for="form_1_the_name_a">', $actual_output );
$this->assertContains( 'text_a', $actual_output );
$this->assertContains( '<input type="checkbox" id="form_1_the_name_a" name="the_name_a" value="Option 1"> Option 1<br>', $actual_output );
Expand All @@ -119,8 +112,7 @@ public function test_checkboxes() {
$field->required = true;
ob_start();
GEM_Form_Fields::checkboxes( $field );
$actual_output = ob_get_contents();
ob_end_clean();
$actual_output = ob_get_clean();
$this->assertContains( '<span class="required">*</span>', $actual_output );
$this->assertContains( '<label for="form_1_the_name_a">', $actual_output );
$this->assertContains( 'text_a', $actual_output );
Expand All @@ -138,8 +130,7 @@ public function test_dropdown() {
$field->options = '["Option 1","Option 2"]';
ob_start();
GEM_Form_Fields::dropdown( $field );
$actual_output = ob_get_contents();
ob_end_clean();
$actual_output = ob_get_clean();
$this->assertContains( '<label for="form_1_the_name_a">', $actual_output );
$this->assertContains( 'text_a', $actual_output );
$this->assertContains( '<select id="form_1_the_name_a" name="the_name_a">', $actual_output );
Expand All @@ -150,8 +141,7 @@ public function test_dropdown() {
$field->required = true;
ob_start();
GEM_Form_Fields::dropdown( $field );
$actual_output = ob_get_contents();
ob_end_clean();
$actual_output = ob_get_clean();
$this->assertContains( '<span class="required">*</span>', $actual_output );
$this->assertContains( '<label for="form_1_the_name_a">', $actual_output );
$this->assertContains( 'text_a', $actual_output );
Expand All @@ -170,8 +160,7 @@ public function test_radio_buttons() {
$field->options = '["Option 1","Option 2"]';
ob_start();
GEM_Form_Fields::radio_buttons( $field );
$actual_output = ob_get_contents();
ob_end_clean();
$actual_output = ob_get_clean();
$this->assertContains( '<label for="form_1_the_name_a">', $actual_output );
$this->assertContains( 'text_a', $actual_output );
$this->assertContains( '<input type="radio" id="form_1_the_name_a" name="the_name_a" value="Option 1"> Option 1<br>', $actual_output );
Expand All @@ -181,8 +170,7 @@ public function test_radio_buttons() {
$field->required = true;
ob_start();
GEM_Form_Fields::radio_buttons( $field );
$actual_output = ob_get_contents();
ob_end_clean();
$actual_output = ob_get_clean();
$this->assertContains( '<span class="required">*</span>', $actual_output );
$this->assertContains( '<label for="form_1_the_name_a">', $actual_output );
$this->assertContains( 'text_a', $actual_output );
Expand All @@ -199,8 +187,7 @@ public function test_date() {
$field->value = 'the_value';
ob_start();
GEM_Form_Fields::date( $field );
$actual_output = ob_get_contents();
ob_end_clean();
$actual_output = ob_get_clean();
$this->assertContains( '<label for="form_1_the_name_a">', $actual_output );
$this->assertContains( 'text_a', $actual_output );
$this->assertContains( '<select fingerprint="date" id="form_1_the_name_a" name="the_name_a">', $actual_output );
Expand All @@ -218,8 +205,7 @@ public function test_date() {
$field->required = true;
ob_start();
GEM_Form_Fields::date( $field );
$actual_output = ob_get_contents();
ob_end_clean();
$actual_output = ob_get_clean();
$this->assertContains( '<span class="required">*</span>', $actual_output );
}

Expand All @@ -232,8 +218,7 @@ public function test_text_field() {
$field->value = 'the_value';
ob_start();
GEM_Form_Fields::text_field( $field );
$actual_output = ob_get_contents();
ob_end_clean();
$actual_output = ob_get_clean();
$this->assertContains( '<label for="form_1_the_name_a">', $actual_output );
$this->assertContains( 'text_a', $actual_output );
$this->assertContains( '<input type="text" name="the_name_a" id="form_1_the_name_a" class="gem-field a_sample_class" />', $actual_output );
Expand All @@ -242,8 +227,7 @@ public function test_text_field() {
$field->required = true;
ob_start();
GEM_Form_Fields::text_field( $field );
$actual_output = ob_get_contents();
ob_end_clean();
$actual_output = ob_get_clean();
$this->assertContains( '<label for="form_1_the_name_a">', $actual_output );
$this->assertContains( 'text_a', $actual_output );
$this->assertContains( '<span class="required">*</span>', $actual_output );
Expand Down

0 comments on commit e8a68e7

Please sign in to comment.