Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
15.79% covered (danger)
15.79%
6 / 38
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
Jetpack_Cxn_Tests
13.89% covered (danger)
13.89%
5 / 36
50.00% covered (danger)
50.00%
1 / 2
38.29
0.00% covered (danger)
0.00%
0 / 1
 register_tests_on
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
3
 test__sync_health
0.00% covered (danger)
0.00%
0 / 31
0.00% covered (danger)
0.00%
0 / 1
20
1<?php
2/**
3 * Jetpack-specific connection tests.
4 *
5 * Extends the connection package's Connection_Health_Test_Base with Jetpack-specific
6 * tests (sync health) and Jetpack-specific helper overrides.
7 *
8 * @package automattic/jetpack
9 */
10
11use Automattic\Jetpack\Connection\Connection_Health_Test_Base;
12use Automattic\Jetpack\Redirect;
13use Automattic\Jetpack\Sync\Health as Sync_Health;
14use Automattic\Jetpack\Sync\Settings as Sync_Settings;
15
16if ( ! defined( 'ABSPATH' ) ) {
17    exit( 0 );
18}
19
20/**
21 * Class Jetpack_Cxn_Tests contains the Jetpack-specific connection tests.
22 *
23 * Extends the connection package's framework and provides Jetpack-specific
24 * tests (sync health), encryption, and Jetpack-specific helper overrides.
25 *
26 * Jetpack-specific tests are also registered with the connection package's
27 * Site Health integration via the jetpack_connection_tests_loaded action.
28 */
29class Jetpack_Cxn_Tests extends Connection_Health_Test_Base {
30
31    /**
32     * Register Jetpack-specific tests on an external test suite instance.
33     *
34     * Used to add Jetpack tests to the connection package's Site Health integration
35     * via the jetpack_connection_tests_loaded action.
36     *
37     * @param Connection_Health_Test_Base $target The test suite to register tests on.
38     */
39    public function register_tests_on( $target ) {
40        $methods = get_class_methods( static::class );
41        foreach ( $methods as $method ) {
42            if ( ! str_contains( $method, 'test__' ) ) {
43                continue;
44            }
45            $target->add_test( array( $this, $method ), $method, 'direct' );
46        }
47    }
48
49    /**
50     * Sync Health Tests.
51     *
52     * @return array Test results.
53     */
54    protected function test__sync_health() {
55        $name = 'test__sync_health';
56
57        if ( ! $this->helper_is_connected() ) {
58            return self::skipped_test(
59                array(
60                    'name'                => $name,
61                    'show_in_site_health' => false,
62                )
63            );
64        }
65
66        if ( ! Sync_Settings::is_sync_enabled() ) {
67            return self::failing_test(
68                array(
69                    'name'              => $name,
70                    'label'             => __( 'Jetpack Sync has been disabled on your site.', 'jetpack' ),
71                    'severity'          => 'recommended',
72                    'action'            => 'https://github.com/Automattic/jetpack/blob/trunk/projects/packages/sync/src/class-settings.php',
73                    'action_label'      => __( 'See GitHub for more on Sync Settings', 'jetpack' ),
74                    'short_description' => __( 'Jetpack Sync has been disabled on your site. This could be impacting some of your site\'s Jetpack-powered features. Developers may enable / disable syncing using the Sync Settings API.', 'jetpack' ),
75                )
76            );
77        }
78
79        if ( Sync_Health::get_status() === Sync_Health::STATUS_OUT_OF_SYNC ) {
80            return self::failing_test(
81                array(
82                    'name'              => $name,
83                    'label'             => __( 'Jetpack has detected a problem with the communication between your site and WordPress.com', 'jetpack' ),
84                    'severity'          => 'critical',
85                    'action'            => Redirect::get_url( 'jetpack-contact-support' ),
86                    'action_label'      => __( 'Contact Jetpack Support', 'jetpack' ),
87                    'short_description' => __( 'There is a problem with the communication between your site and WordPress.com. This could be impacting some of your site\'s Jetpack-powered features. If you continue to see this error, please contact support for assistance.', 'jetpack' ),
88                )
89            );
90        }
91
92        return self::passing_test( array( 'name' => $name ) );
93    }
94}