Skip to content

Commit

Permalink
Jetpack connector test completed.
Browse files Browse the repository at this point in the history
  • Loading branch information
kidunot89 committed Aug 21, 2020
1 parent c952c6f commit 7a7e12b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 9 deletions.
7 changes: 3 additions & 4 deletions connectors/class-connector-jetpack.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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';
Expand Down
39 changes: 34 additions & 5 deletions tests/tests/connectors/test-class-connector-jetpack.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ) );
Expand Down

0 comments on commit 7a7e12b

Please sign in to comment.