Skip to content

Commit

Permalink
Issue #842: Correct Travis issue and use constant.
Browse files Browse the repository at this point in the history
Correct an issue in improper vertical alignment.
And use constants in place of string literals.
  • Loading branch information
Ryan Kienstra committed Mar 1, 2018
1 parent 8684ad1 commit 0728a1e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 30 deletions.
8 changes: 4 additions & 4 deletions includes/utils/class-amp-validation-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -485,16 +485,16 @@ public static function display_error( $response ) {
echo '<div class="notice notice-warning">';
printf( '<p>%s</p>', esc_html__( 'Warning: There is content which fails AMP validation; it will be stripped when served as AMP.', 'amp' ) );
$removed_sets = array();
if ( ! empty( $response['removed_elements'] ) && is_array( $response['removed_elements'] ) ) {
if ( ! empty( $response[ self::REMOVED_ELEMENTS ] ) && is_array( $response[ self::REMOVED_ELEMENTS ] ) ) {
$removed_sets[] = array(
'label' => __( 'Invalid elements:', 'amp' ),
'names' => array_map( 'sanitize_key', $response['removed_elements'] ),
'names' => array_map( 'sanitize_key', $response[ self::REMOVED_ELEMENTS ] ),
);
}
if ( ! empty( $response['removed_attributes'] ) && is_array( $response['removed_attributes'] ) ) {
if ( ! empty( $response[ self::REMOVED_ATTRIBUTES ] ) && is_array( $response[ self::REMOVED_ATTRIBUTES ] ) ) {
$removed_sets[] = array(
'label' => __( 'Invalid attributes:', 'amp' ),
'names' => array_map( 'sanitize_key', $response['removed_attributes'] ),
'names' => array_map( 'sanitize_key', $response[ self::REMOVED_ATTRIBUTES ] ),
);
}
foreach ( $removed_sets as $removed_set ) {
Expand Down
52 changes: 26 additions & 26 deletions tests/test-class-amp-validation-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,13 +236,13 @@ public function test_validate_markup() {
) ) );
$response = AMP_Validation_Utils::validate_markup( $request );
$expected_response = array(
AMP_Validation_Utils::ERROR_KEY => true,
'removed_elements' => array(
AMP_Validation_Utils::ERROR_KEY => true,
AMP_Validation_Utils::REMOVED_ELEMENTS => array(
'script' => 1,
),
'removed_attributes' => array(),
'processed_markup' => $markup,
'sources_with_invalid_output' => array(),
AMP_Validation_Utils::REMOVED_ATTRIBUTES => array(),
'processed_markup' => $markup,
'sources_with_invalid_output' => array(),
);
$this->assertEquals( $expected_response, $response );

Expand All @@ -251,11 +251,11 @@ public function test_validate_markup() {
) ) );
$response = AMP_Validation_Utils::validate_markup( $request );
$expected_response = array(
AMP_Validation_Utils::ERROR_KEY => false,
'removed_elements' => array(),
'removed_attributes' => array(),
'processed_markup' => $this->valid_amp_img,
'sources_with_invalid_output' => array(),
AMP_Validation_Utils::ERROR_KEY => false,
AMP_Validation_Utils::REMOVED_ELEMENTS => array(),
AMP_Validation_Utils::REMOVED_ATTRIBUTES => array(),
'processed_markup' => $this->valid_amp_img,
'sources_with_invalid_output' => array(),
);
$this->assertEquals( $expected_response, $response );
}
Expand All @@ -271,13 +271,13 @@ public function test_get_response() {
$this->set_capability();
$response = AMP_Validation_Utils::get_response( $this->disallowed_tag );
$expected_response = array(
AMP_Validation_Utils::ERROR_KEY => true,
'removed_elements' => array(
AMP_Validation_Utils::ERROR_KEY => true,
AMP_Validation_Utils::REMOVED_ELEMENTS => array(
'script' => 1,
),
'removed_attributes' => array(),
'processed_markup' => $this->disallowed_tag,
'sources_with_invalid_output' => array(),
AMP_Validation_Utils::REMOVED_ATTRIBUTES => array(),
'processed_markup' => $this->disallowed_tag,
'sources_with_invalid_output' => array(),
);
$this->assertEquals( $expected_response, $response );
}
Expand Down Expand Up @@ -503,11 +503,11 @@ public function test_display_error() {
$removed_element = 'script';
$removed_attribute = 'onload';
$response = array(
AMP_Validation_Utils::ERROR_KEY => true,
'removed_elements' => array(
AMP_Validation_Utils::ERROR_KEY => true,
AMP_Validation_Utils::REMOVED_ELEMENTS => array(
$removed_element => 1,
),
'removed_attributes' => array(
AMP_Validation_Utils::REMOVED_ATTRIBUTES => array(
$removed_attribute => 1,
),
);
Expand Down Expand Up @@ -666,9 +666,9 @@ public function test_store_validation_errors() {

// This should create a new post for the errors.
$this->assertEquals( AMP_Validation_Utils::POST_TYPE_SLUG, $custom_post->post_type );
$this->assertEquals( $expected_removed_elements, $validation['removed_elements'] );
$this->assertEquals( $expected_removed_elements, $validation[ AMP_Validation_Utils::REMOVED_ELEMENTS ] );
$this->assertEquals( true, $validation[ AMP_Validation_Utils::ERROR_KEY ] );
$this->assertEquals( array(), $validation['removed_attributes'] );
$this->assertEquals( array(), $validation[ AMP_Validation_Utils::REMOVED_ATTRIBUTES ] );
$this->assertEquals( array( 'foo' ), $validation[ AMP_Validation_Utils::SOURCES_INVALID_OUTPUT ]['plugin'] );
$meta = get_post_meta( $post_id, AMP_Validation_Utils::AMP_URL_META, true );
$this->assertEquals( $url, $meta );
Expand Down Expand Up @@ -707,7 +707,7 @@ public function test_store_validation_errors() {
);

// A post already exists for this URL, so it should be updated.
$this->assertEquals( $expected_removed_elements, $validation['removed_elements'] );
$this->assertEquals( $expected_removed_elements, $validation[ AMP_Validation_Utils::REMOVED_ELEMENTS ] );
$this->assertTrue( $validation[ AMP_Validation_Utils::ERROR_KEY ] );
$this->assertEquals( array( 'foo' ), $validation[ AMP_Validation_Utils::SOURCES_INVALID_OUTPUT ]['plugin'] );
$this->assertEquals( $expected_url, $url );
Expand Down Expand Up @@ -821,7 +821,7 @@ public function get_custom_columns() {
'url',
get_home_url(),
),
'removed_elements' => array(
'removed_element' => array(
AMP_Validation_Utils::REMOVED_ELEMENTS,
$this->disallowed_tag_name,
),
Expand Down Expand Up @@ -861,7 +861,7 @@ public function test_add_recheck() {
* @return int|WP_Error $error_post The ID of new custom post, or an error.
*/
public function create_custom_post() {
$response = array(
$response = array(
AMP_Validation_Utils::ERROR_KEY => true,
AMP_Validation_Utils::REMOVED_ELEMENTS => array(
$this->disallowed_tag_name => 1,
Expand All @@ -873,9 +873,9 @@ public function create_custom_post() {
'plugin' => array( $this->plugin_name ),
),
);
$content = wp_json_encode( $response );
$encoded_errors = md5( $content );
$post_args = array(
$content = wp_json_encode( $response );
$encoded_errors = md5( $content );
$post_args = array(
'post_type' => AMP_Validation_Utils::POST_TYPE_SLUG,
'post_name' => $encoded_errors,
'post_content' => $content,
Expand Down

0 comments on commit 0728a1e

Please sign in to comment.