Skip to content

Commit

Permalink
Opt to output all status options even when empty to prevent de-select…
Browse files Browse the repository at this point in the history
…ion when changing selected error type
  • Loading branch information
westonruter committed Sep 5, 2018
1 parent 2882262 commit 3b87595
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 99 deletions.
173 changes: 82 additions & 91 deletions includes/validation/class-amp-validation-error-taxonomy.php
Original file line number Diff line number Diff line change
Expand Up @@ -888,103 +888,94 @@ public static function render_error_status_filter() {

$error_status_filter_value = isset( $_GET[ self::VALIDATION_ERROR_STATUS_QUERY_VAR ] ) ? intval( $_GET[ self::VALIDATION_ERROR_STATUS_QUERY_VAR ] ) : ''; // WPCS: CSRF OK.

if ( 0 === $new_term_count && 0 === $accepted_term_count && 0 === $rejected_term_count ) {
return;
}
?>
<label for="<?php echo esc_attr( self::VALIDATION_ERROR_STATUS_QUERY_VAR ); ?>" class="screen-reader-text"><?php esc_html_e( 'Filter by error status', 'amp' ); ?></label>
<select name="<?php echo esc_attr( self::VALIDATION_ERROR_STATUS_QUERY_VAR ); ?>" id="<?php echo esc_attr( self::VALIDATION_ERROR_STATUS_QUERY_VAR ); ?>">
<option value="<?php echo esc_attr( self::NO_FILTER_VALUE ); ?>"><?php esc_html_e( 'All Statuses', 'amp' ); ?></option>
<?php
if ( $new_term_count ) :
if ( 'edit' === $screen_base ) {
$new_term_text = sprintf(
/* translators: %s: the new term count. */
_nx(
'With New Error <span class="count">(%s)</span>',
'With New Errors <span class="count">(%s)</span>',
$new_term_count,
'terms',
'amp'
),
number_format_i18n( $new_term_count )
);
} else {
$new_term_text = sprintf(
/* translators: %s: the new term count. */
_nx(
'New Error <span class="count">(%s)</span>',
'New Errors <span class="count">(%s)</span>',
$new_term_count,
'terms',
'amp'
),
number_format_i18n( $new_term_count )
);
}
?>
<option value="<?php echo esc_attr( self::VALIDATION_ERROR_NEW_STATUS ); ?>" <?php selected( $error_status_filter_value, self::VALIDATION_ERROR_NEW_STATUS ); ?>><?php echo wp_kses_post( $new_term_text ); ?></option>
<?php endif; ?>
if ( 'edit' === $screen_base ) {
$new_term_text = sprintf(
/* translators: %s: the new term count. */
_nx(
'With New Error <span class="count">(%s)</span>',
'With New Errors <span class="count">(%s)</span>',
$new_term_count,
'terms',
'amp'
),
number_format_i18n( $new_term_count )
);
} else {
$new_term_text = sprintf(
/* translators: %s: the new term count. */
_nx(
'New Error <span class="count">(%s)</span>',
'New Errors <span class="count">(%s)</span>',
$new_term_count,
'terms',
'amp'
),
number_format_i18n( $new_term_count )
);
}
?>
<option value="<?php echo esc_attr( self::VALIDATION_ERROR_NEW_STATUS ); ?>" <?php selected( $error_status_filter_value, self::VALIDATION_ERROR_NEW_STATUS ); ?>><?php echo wp_kses_post( $new_term_text ); ?></option>
<?php
if ( $accepted_term_count ) :
if ( 'edit' === $screen_base ) {
$accepted_term_text = sprintf(
/* translators: %s: the accepted term count. */
_nx(
'With Accepted Error <span class="count">(%s)</span>',
'With Accepted Errors <span class="count">(%s)</span>',
$accepted_term_count,
'terms',
'amp'
),
number_format_i18n( $accepted_term_count )
);
} else {
$accepted_term_text = sprintf(
/* translators: %s: the accepted term count. */
_nx(
'Accepted Error <span class="count">(%s)</span>',
'Accepted Errors <span class="count">(%s)</span>',
$accepted_term_count,
'terms',
'amp'
),
number_format_i18n( $accepted_term_count )
);
}
?>
<option value="<?php echo esc_attr( self::VALIDATION_ERROR_ACCEPTED_STATUS ); ?>" <?php selected( $error_status_filter_value, self::VALIDATION_ERROR_ACCEPTED_STATUS ); ?>><?php echo wp_kses_post( $accepted_term_text ); ?></option>
<?php
endif;
if ( $rejected_term_count ) :
if ( 'edit' === $screen_base ) {
$rejected_term_text = sprintf(
/* translators: %s: the rejected term count. */
_nx(
'With Rejected Error <span class="count">(%s)</span>',
'With Rejected Errors <span class="count">(%s)</span>',
$rejected_term_count,
'terms',
'amp'
),
number_format_i18n( $rejected_term_count )
);
} else {
$rejected_term_text = sprintf(
/* translators: %s: the rejected term count. */
_nx(
'Rejected Error <span class="count">(%s)</span>',
'Rejected Errors <span class="count">(%s)</span>',
$rejected_term_count,
'terms',
'amp'
),
number_format_i18n( $rejected_term_count )
);
}
?>
<option value="<?php echo esc_attr( self::VALIDATION_ERROR_REJECTED_STATUS ); ?>" <?php selected( $error_status_filter_value, self::VALIDATION_ERROR_REJECTED_STATUS ); ?>><?php echo wp_kses_post( $rejected_term_text ); ?></option>
<?php endif; ?>
if ( 'edit' === $screen_base ) {
$accepted_term_text = sprintf(
/* translators: %s: the accepted term count. */
_nx(
'With Accepted Error <span class="count">(%s)</span>',
'With Accepted Errors <span class="count">(%s)</span>',
$accepted_term_count,
'terms',
'amp'
),
number_format_i18n( $accepted_term_count )
);
} else {
$accepted_term_text = sprintf(
/* translators: %s: the accepted term count. */
_nx(
'Accepted Error <span class="count">(%s)</span>',
'Accepted Errors <span class="count">(%s)</span>',
$accepted_term_count,
'terms',
'amp'
),
number_format_i18n( $accepted_term_count )
);
}
?>
<option value="<?php echo esc_attr( self::VALIDATION_ERROR_ACCEPTED_STATUS ); ?>" <?php selected( $error_status_filter_value, self::VALIDATION_ERROR_ACCEPTED_STATUS ); ?>><?php echo wp_kses_post( $accepted_term_text ); ?></option>
<?php
if ( 'edit' === $screen_base ) {
$rejected_term_text = sprintf(
/* translators: %s: the rejected term count. */
_nx(
'With Rejected Error <span class="count">(%s)</span>',
'With Rejected Errors <span class="count">(%s)</span>',
$rejected_term_count,
'terms',
'amp'
),
number_format_i18n( $rejected_term_count )
);
} else {
$rejected_term_text = sprintf(
/* translators: %s: the rejected term count. */
_nx(
'Rejected Error <span class="count">(%s)</span>',
'Rejected Errors <span class="count">(%s)</span>',
$rejected_term_count,
'terms',
'amp'
),
number_format_i18n( $rejected_term_count )
);
}
?>
<option value="<?php echo esc_attr( self::VALIDATION_ERROR_REJECTED_STATUS ); ?>" <?php selected( $error_status_filter_value, self::VALIDATION_ERROR_REJECTED_STATUS ); ?>><?php echo wp_kses_post( $rejected_term_text ); ?></option>
</select>
<?php
}
Expand Down
8 changes: 0 additions & 8 deletions tests/validation/test-class-amp-validation-error-taxonomy.php
Original file line number Diff line number Diff line change
Expand Up @@ -562,15 +562,7 @@ public function test_render_error_status_filter() {
AMP_Validation_Error_Taxonomy::render_error_status_filter();
$this->assertEmpty( ob_get_clean() );

/*
* This is now on the correct screen, so it shouldn't be empty anymore.
* When no validation error exists, there should not be an <option> for any specific error status, like 'New Error'.
*/
set_current_screen( 'edit.php' );
ob_start();
AMP_Validation_Error_Taxonomy::render_error_status_filter();
$this->assertNotContains( 'New Error', ob_get_clean() );

$number_of_errors = 10;
for ( $i = 0; $i < $number_of_errors; $i++ ) {
$invalid_url_post = $this->factory()->post->create( array( 'post_type' => AMP_Invalid_URL_Post_Type::POST_TYPE_SLUG ) );
Expand Down

0 comments on commit 3b87595

Please sign in to comment.