Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
154 changes: 84 additions & 70 deletions _inc/lib/debugger/class-jetpack-cxn-test-base.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,93 +244,105 @@ public function list_fails( $type = 'all', $group = 'all' ) {

/**
* Helper function to return consistent responses for a passing test.
*
* @param string $name Test name.
* @param string|bool $message Plain text message to show when test passed.
* @param string|bool $label Label to be used on Site Health card.
* @param string|bool $description HTML description to be used in Site Health card.
* Possible Args:
* - name: string The raw method name that runs the test. Default 'unnamed_test'.
* - label: bool|string If false, tests will be labeled with their `name`. You can pass a string to override this behavior. Default false.
* - pass: bool|string True if the test passed. Default true.
* - short_description: bool|string A brief, non-html description that will appear in CLI results. Default 'Test passed!'.
* - long_description: bool|string An html description that will appear in the site health page. Default false.
* - severity: bool|string 'critical', 'recommended', or 'good'. Default: false.
* - action: bool|string A URL for the recommended action. Default: false
* - action_label: bool|string The label for the recommended action. Default: false
* - show_in_site_health: bool True if the test should be shown on the Site Health page. Default: true
*
* @param array $args Arguments to override defaults.
*
* @return array Test results.
*/
public static function passing_test( $name = 'Unnamed', $message = false, $label = false, $description = false ) {
if ( ! $message ) {
$message = __( 'Test Passed!', 'jetpack' );
}
return array(
'name' => $name,
'pass' => true,
'message' => $message,
'description' => $description,
'resolution' => false,
'severity' => false,
'label' => $label,
public static function passing_test( $args ) {
return wp_parse_args(
$args,
array(
'name' => 'unnamed_test',
'label' => false,
'pass' => true,
'short_description' => __( 'Test passed!', 'jetpack' ),
'long_description' => false,
'severity' => false,
'action' => false,
'action_label' => false,
'show_in_site_health' => true,
)
);
}

/**
* Helper function to return consistent responses for a skipped test.
*
* @param string $name Test name.
* @param string $message Reason for skipping the test. Optional.
* Possible Args:
* - name: string The raw method name that runs the test. Default unnamed_test.
* - label: bool|string If false, tests will be labeled with their `name`. You can pass a string to override this behavior. Default false.
* - pass: bool|string True if the test passed. Default 'skipped'.
* - short_description: bool|string A brief, non-html description that will appear in CLI results, and as headings in admin UIs. Default false.
* - long_description: bool|string An html description that will appear in the site health page. Default false.
* - severity: bool|string 'critical', 'recommended', or 'good'. Default: false.
* - action: bool|string A URL for the recommended action. Default: false
* - action_label: bool|string The label for the recommended action. Default: false
* - show_in_site_health: bool True if the test should be shown on the Site Health page. Default: true
*
* @param array $args Arguments to override defaults.
*
* @return array Test results.
*/
public static function skipped_test( $name = 'Unnamed', $message = false ) {
return array(
'name' => $name,
'pass' => 'skipped',
'message' => $message,
'resolution' => false,
'severity' => false,
public static function skipped_test( $args = array() ) {
return wp_parse_args(
$args,
array(
'name' => 'unnamed_test',
'label' => false,
'pass' => 'skipped',
'short_description' => false,
'long_description' => false,
'severity' => false,
'action' => false,
'action_label' => false,
'show_in_site_health' => true,
)
);
}

/**
* Helper function to return consistent responses for a failing test.
* Possible Args:
* - name: string The raw method name that runs the test. Default unnamed_test.
* - label: bool|string If false, tests will be labeled with their `name`. You can pass a string to override this behavior. Default false.
* - pass: bool|string True if the test passed. Default false.
* - short_description: bool|string A brief, non-html description that will appear in CLI results, and as headings in admin UIs. Default 'Test failed!'.
* - long_description: bool|string An html description that will appear in the site health page. Default false.
* - severity: bool|string 'critical', 'recommended', or 'good'. Default: false.
* - action: bool|string A URL for the recommended action. Default: false.
* - action_label: bool|string The label for the recommended action. Default: false.
* - show_in_site_health: bool True if the test should be shown on the Site Health page. Default: true
*
* @since 7.1.0
* @since 7.3.0 Added $action for resolution action link, $severity for issue severity.
*
* @param string $name Test name.
* @param string $message Message detailing the failure.
* @param string $resolution Optional. Steps to resolve.
* @param string $action Optional. URL to direct users to self-resolve.
* @param string $severity Optional. "critical" or "recommended" for failure stats. "good" for passing.
* @param string $label Optional. The label to use instead of the test name.
* @param string|bool $action_label Optional. The label for the action url instead of default 'Resolve'.
* @param string|bool $description Optional. An HTML description to override resolution.
* @param array $args Arguments to override defaults.
*
* @return array Test results.
*/
public static function failing_test( $name, $message, $resolution = false, $action = false, $severity = 'critical', $label = false, $action_label = false, $description = false ) {
if ( ! $action_label ) {
/* translators: Resolve is used as a verb, a command that when invoked will lead to a problem's solution. */
$action_label = __( 'Resolve', 'jetpack' );
}
// Provide standard resolutions steps, but allow pass-through of non-standard ones.
switch ( $resolution ) {
case 'cycle_connection':
$resolution = __( 'Please disconnect and reconnect Jetpack.', 'jetpack' ); // @todo: Link.
break;
case 'outbound_requests':
$resolution = __( 'Please ask your hosting provider to confirm your server can make outbound requests to jetpack.com.', 'jetpack' );
break;
case 'support':
case false:
$resolution = __( 'Please contact Jetpack support.', 'jetpack' ); // @todo: Link to support.
break;
}

return array(
'name' => $name,
'pass' => false,
'message' => $message,
'resolution' => $resolution,
'action' => $action,
'severity' => $severity,
'label' => $label,
'action_label' => $action_label,
'description' => $description,
public static function failing_test( $args ) {
return wp_parse_args(
$args,
array(
'name' => 'unnamed_test',
'label' => false,
'pass' => false,
'short_description' => __( 'Test failed!', 'jetpack' ),
'long_description' => false,
'severity' => 'critical',
'action' => false,
'action_label' => false,
'show_in_site_health' => true,
)
);
}

Expand All @@ -355,12 +367,12 @@ public function output_results_for_cli( $type = 'all', $group = 'all' ) {
WP_CLI::log( WP_CLI::colorize( '%gPassed:%n ' . $test['name'] ) );
} elseif ( 'skipped' === $test['pass'] ) {
WP_CLI::log( WP_CLI::colorize( '%ySkipped:%n ' . $test['name'] ) );
if ( $test['message'] ) {
WP_CLI::log( ' ' . $test['message'] ); // Number of spaces to "tab indent" the reason.
if ( $test['short_description'] ) {
WP_CLI::log( ' ' . $test['short_description'] ); // Number of spaces to "tab indent" the reason.
}
} else { // Failed.
WP_CLI::log( WP_CLI::colorize( '%rFailed:%n ' . $test['name'] ) );
WP_CLI::log( ' ' . $test['message'] ); // Number of spaces to "tab indent" the reason.
WP_CLI::log( ' ' . $test['short_description'] ); // Number of spaces to "tab indent" the reason.
}
}
}
Expand Down Expand Up @@ -450,9 +462,11 @@ public function output_fails_as_wp_error( $type = 'all', $group = 'all' ) {

foreach ( $fails as $result ) {
$code = 'failed_' . $result['name'];
$message = $result['message'];
$message = $result['short_description'];
$data = array(
'resolution' => $result['resolution'],
'resolution' => $result['action'] ?
$result['action_label'] . ' :' . $result['action'] :
'',
);
if ( ! $error ) {
$error = new WP_Error( $code, $message, $data );
Expand Down
Loading