From f2e422f9a95c31ca0b380adcadd05eb0fc7a2bd7 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Thu, 26 Apr 2018 10:46:02 -0700 Subject: [PATCH] Fix OutputNotEscaped errors in tests; restore output of debug information via assertion message --- ...ribute-sanitizer-private-methods-tests.php | 68 +++---------------- 1 file changed, 11 insertions(+), 57 deletions(-) diff --git a/tests/amp-tag-and-attribute-sanitizer-private-methods-tests.php b/tests/amp-tag-and-attribute-sanitizer-private-methods-tests.php index a4286604307..eb2bd5404f5 100644 --- a/tests/amp-tag-and-attribute-sanitizer-private-methods-tests.php +++ b/tests/amp-tag-and-attribute-sanitizer-private-methods-tests.php @@ -409,11 +409,7 @@ public function test_validate_attr_spec_rules( $data, $expected ) { $got = $this->invoke_method( $sanitizer, $data['func_name'], array( $node, $data['attribute_name'], $attr_spec_rule ) ); - if ( $expected != $got ) { - printf( 'using source: %s' . PHP_EOL, $source ); - } - - $this->assertEquals( $expected, $got ); + $this->assertEquals( $expected, $got, sprintf( "using source: %s\n%s", $source, wp_json_encode( $data ) ) ); } public function get_is_allowed_attribute_data() { @@ -565,11 +561,7 @@ public function test_is_allowed_attribute( $data, $expected ) { $got = $this->invoke_method( $sanitizer, $data['func_name'], array( $data['attribute_name'], $attr_spec_list ) ); - if ( $expected != $got ) { - printf( 'using source: %s' . PHP_EOL, $source ); - } - - $this->assertEquals( $expected, $got ); + $this->assertEquals( $expected, $got, sprintf( "using source: %s\n%s", $source, wp_json_encode( $data ) ) ); } public function get_remove_node_data() { @@ -660,12 +652,7 @@ public function test_remove_node( $data, $expected ) { $got = AMP_DOM_Utils::get_content_from_dom( $dom ); - if ( $expected != $got ) { - printf( 'using source: %s' . PHP_EOL, $data['source'] ); - printf( 'got = %s' .PHP_EOL, $got ); - } - - $this->assertEquals( $expected, $got ); + $this->assertEquals( $expected, $got, sprintf( "using source: %s\n%s", $data['source'], wp_json_encode( $data ) ) ); } @@ -800,12 +787,7 @@ public function test_replace_node_with_children( $data, $expected ) { $got = AMP_DOM_Utils::get_content_from_dom( $dom ); $got = preg_replace( '/(?<=>)\s+(?=<)/', '', $got ); - if ( $expected != $got ) { - printf( 'using source: %s' . PHP_EOL, $data['source'] ); - printf( 'got = %s' .PHP_EOL, $got ); - } - - $this->assertEquals( $expected, $got ); + $this->assertEquals( $expected, $got, sprintf( "using source: %s\n%s", $data['source'], wp_json_encode( $data ) ) ); } public function get_ancestor_with_tag_name_data() { @@ -861,11 +843,7 @@ public function test_get_ancestor_with_tag_name( $data, $expected ) { $got = $this->invoke_method( $sanitizer, 'get_ancestor_with_tag_name', array( $node, $data['ancestor_tag_name'] ) ); - if ( $ancestor_node != $got ) { - printf( 'using source: %s' . PHP_EOL, $data['source'] ); - } - - $this->assertEquals( $ancestor_node, $got ); + $this->assertEquals( $ancestor_node, $got, sprintf( "using source: %s\n%s", $data['source'], wp_json_encode( $data ) ) ); } public function get_validate_attr_spec_list_for_node_data() { @@ -1066,11 +1044,7 @@ public function test_validate_attr_spec_list_for_node( $data, $expected ) { $got = $this->invoke_method( $sanitizer, 'validate_attr_spec_list_for_node', array( $node, $data['attr_spec_list'] ) ); - if ( $expected != $got ) { - printf( 'using source: %s' . PHP_EOL, $data['source'] ); - } - - $this->assertEquals( $expected, $got ); + $this->assertEquals( $expected, $got, sprintf( "using source: %s\n%s", $data['source'], wp_json_encode( $data ) ) ); } public function get_check_attr_spec_rule_value_data() { @@ -1192,11 +1166,7 @@ public function test_check_attr_spec_rule_value( $data, $expected ) { $got = $this->invoke_method( $sanitizer, 'check_attr_spec_rule_value', array( $node, $data['attr_name'], $data['attr_spec_rule'] ) ); - if ( $expected != $got ) { - printf( 'using source: %s' . PHP_EOL, $data['source'] ); - } - - $this->assertEquals( $expected, $got ); + $this->assertEquals( $expected, $got, sprintf( "using source: %s\n%s", $data['source'], wp_json_encode( $data ) ) ); } public function get_check_attr_spec_rule_value_casei_data() { @@ -1343,11 +1313,7 @@ public function test_check_attr_spec_rule_value_casei( $data, $expected ) { $got = $this->invoke_method( $sanitizer, 'check_attr_spec_rule_value_casei', array( $node, $data['attr_name'], $data['attr_spec_rule'] ) ); - if ( $expected != $got ) { - printf( 'using source: %s' . PHP_EOL, $data['source'] ); - } - - $this->assertEquals( $expected, $got ); + $this->assertEquals( $expected, $got, sprintf( "using source: %s\n%s", $data['source'], wp_json_encode( $data ) ) ); } public function get_check_attr_spec_rule_blacklisted_value_regex() { @@ -1436,11 +1402,7 @@ public function test_check_attr_spec_rule_blacklisted_value_regex( $data, $expec $got = $this->invoke_method( $sanitizer, 'check_attr_spec_rule_blacklisted_value_regex', array( $node, $data['attr_name'], $data['attr_spec_rule'] ) ); - if ( $expected != $got ) { - printf( 'using source: %s' . PHP_EOL, $data['source'] ); - } - - $this->assertEquals( $expected, $got ); + $this->assertEquals( $expected, $got, sprintf( "using source: %s\n%s", $data['source'], wp_json_encode( $data ) ) ); } public function get_check_attr_spec_rule_allowed_protocol() { @@ -1570,11 +1532,7 @@ public function test_check_attr_spec_rule_allowed_protocol( $data, $expected ) { $got = $this->invoke_method( $sanitizer, 'check_attr_spec_rule_allowed_protocol', array( $node, $data['attr_name'], $data['attr_spec_rule'] ) ); - if ( $expected != $got ) { - printf( 'using source: %s' . PHP_EOL, $data['source'] ); - } - - $this->assertEquals( $expected, $got ); + $this->assertEquals( $expected, $got, sprintf( "using source: %s\n%s", $data['source'], wp_json_encode( $data ) ) ); } public function get_check_attr_spec_rule_disallowed_relative() { @@ -1718,11 +1676,7 @@ public function test_check_attr_spec_rule_disallowed_relative( $data, $expected $got = $this->invoke_method( $sanitizer, 'check_attr_spec_rule_disallowed_relative', array( $node, $data['attr_name'], $data['attr_spec_rule'] ) ); - if ( $expected != $got ) { - printf( 'using source: %s' . PHP_EOL, $data['source'] ); - } - - $this->assertEquals( $expected, $got ); + $this->assertEquals( $expected, $got, sprintf( "using source: %s\n%s", $data['source'], wp_json_encode( $data ) ) ); } /**