diff --git a/connectors/class-connector-jetpack.php b/connectors/class-connector-jetpack.php index a425ee16c..ee75ff504 100644 --- a/connectors/class-connector-jetpack.php +++ b/connectors/class-connector-jetpack.php @@ -327,7 +327,7 @@ public function register() { } /** - * Track Jetpack log entries + * Tracks logs add to Jetpack logging. * Includes: * - Activation/Deactivation of modules * - Registration/Disconnection of blogs @@ -380,10 +380,9 @@ public function callback_jetpack_log_entry( array $entry ) { $meta = compact( 'user_id', 'user_email', 'user_login' ); $message = sprintf( /* translators: %1$s: a user display name, %2$s: a status, %3$s: the connection either "from" or "to" (e.g. "Jane Doe", "unlinked", "from") */ - __( '%1$s\'s account %2$s %3$s Jetpack', 'stream' ), + __( '%1$s\'s account %2$s Jetpack', 'stream' ), $user->display_name, - ( 'unlink' === $action ) ? esc_html__( 'unlinked', 'stream' ) : esc_html__( 'linked', 'stream' ), - ( 'unlink' === $action ) ? esc_html__( 'from', 'stream' ) : esc_html__( 'to', 'stream' ) + ( 'unlink' === $action ) ? esc_html__( 'unlinked from', 'stream' ) : esc_html__( 'linked to', 'stream' ), ); } elseif ( in_array( $method, array( 'register', 'disconnect', 'subsiteregister', 'subsitedisconnect' ), true ) ) { $context = 'blogs'; diff --git a/tests/tests/connectors/test-class-connector-jetpack.php b/tests/tests/connectors/test-class-connector-jetpack.php index b7ca775c8..64795aa82 100644 --- a/tests/tests/connectors/test-class-connector-jetpack.php +++ b/tests/tests/connectors/test-class-connector-jetpack.php @@ -38,16 +38,45 @@ public function test_jetpack_installed_and_activated() { } public function test_callback_jetpack_log_entry() { - // Prepare scenario + // Get blog details and create user for later use. + $user_id = self::factory()->user->create( array( 'display_name' => 'testuser' ) ); + $user = new \WP_User( $user_id ); // Expected log calls. - $this->mock->expects( $this->once() ) + $this->mock->expects( $this->exactly( 3 ) ) ->method( 'log' ) - ->with( - + ->withConsecutive( + array( + 'Comments module activated', + array( 'module_slug' => 'comments'), + null, + 'modules', + 'activated', + ), + array( + 'testuser\'s account linked to Jetpack', + array( + 'user_id' => $user_id, + 'user_email' => $user->user_email, + 'user_login' => $user->user_login, + ), + null, + 'users', + 'authorize', + ), + array( + 'Site connected to Jetpack', + array(), + null, + 'blogs', + 'register' + ) ); - // Do stuff. + // Run Jetpack log function to trigger callback. + \Jetpack::log( 'activate', 'comments' ); + \Jetpack::log( 'authorize', $user_id ); + \Jetpack::log( 'register' ); // Check callback test action. $this->assertFalse( 0 === did_action( 'wp_stream_test_callback_jetpack_log_entry' ) );