Skip to content

Instantly share code, notes, and snippets.

@westonruter
Created November 25, 2020 21:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save westonruter/47fff71b68cfdb087c19ee96df7101f1 to your computer and use it in GitHub Desktop.
Save westonruter/47fff71b68cfdb087c19ee96df7101f1 to your computer and use it in GitHub Desktop.
Gathering all validation errors generated during AMP plugin unit tests
diff --git a/includes/sanitizers/class-amp-base-sanitizer.php b/includes/sanitizers/class-amp-base-sanitizer.php
index 32badf460..312fc2431 100644
--- a/includes/sanitizers/class-amp-base-sanitizer.php
+++ b/includes/sanitizers/class-amp-base-sanitizer.php
@@ -542,10 +542,12 @@ abstract class AMP_Base_Sanitizer {
* @return bool Whether to sanitize.
*/
public function should_sanitize_validation_error( $validation_error, $data = [] ) {
+ $validation_error = $this->prepare_validation_error( $validation_error, $data );
+ file_put_contents( AMP__DIR__ . '/error-key-dump.txt', json_encode( $validation_error ) . PHP_EOL, FILE_APPEND );
+
if ( empty( $this->args['validation_error_callback'] ) || ! is_callable( $this->args['validation_error_callback'] ) ) {
return true;
}
- $validation_error = $this->prepare_validation_error( $validation_error, $data );
return false !== call_user_func( $this->args['validation_error_callback'], $validation_error, $data );
}
<?php
$errors = [];
$all_keys = [];
foreach ( file( __DIR__ . '/error-key-dump.txt' ) as $line ) {
$line = trim( $line );
if ( empty( $line ) ) {
continue;
}
$data = json_decode( $line, true );
$errors[] = $data;
foreach ( $data as $key => $value ) {
if ( ! isset( $all_keys[ $key ] ) ) {
$all_keys[ $key ] = 0;
}
$all_keys[ $key ] += 1;
}
}
arsort( $all_keys );
foreach ( $all_keys as $property => $frequency ) {
echo "$frequency\t$property\n";
}
file_put_contents( __DIR__ . '/all-unit-test-validation-errors.json', json_encode( $errors, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT ) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment