Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provides a connected hook #87

Merged
merged 1 commit into from
Sep 30, 2024
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
9 changes: 9 additions & 0 deletions src/Uplink/Auth/Admin/Connect_Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,5 +170,14 @@ public function maybe_store_token_data(): void {
true
)
);

/**
* Fires after a plugin has been connected.
*
* @since 2.2.1
*
* @param \StellarWP\Uplink\Resources\Resource $plugin The plugin that was connected.
*/
do_action( 'stellarwp/uplink/' . Config::get_hook_prefix() . '/' . $slug . '/connected', $plugin );
}
}
8 changes: 8 additions & 0 deletions tests/wpunit/Auth/Admin/ConnectControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public function test_it_stores_basic_token_data(): void {
do_action( $this->container->get( Action_Manager::class )->get_hook_name( $this->slug ) );

$this->assertSame( $token, $this->token_manager->get( $this->plugin ) );
$this->assertEquals( 1, did_action( 'stellarwp/uplink/' . Config::get_hook_prefix() . '/' . $this->slug . '/connected' ) );
}

public function test_it_sets_additional_license_key(): void {
Expand Down Expand Up @@ -111,6 +112,7 @@ public function test_it_sets_additional_license_key(): void {

$this->assertSame( $token, $this->token_manager->get( $this->plugin ) );
$this->assertSame( $this->plugin->get_license_key(), $license );
$this->assertEquals( 1, did_action( 'stellarwp/uplink/' . Config::get_hook_prefix() . '/' . $this->slug . '/connected' ) );
}

public function test_it_does_not_store_with_an_invalid_nonce(): void {
Expand All @@ -131,6 +133,7 @@ public function test_it_does_not_store_with_an_invalid_nonce(): void {
$this->admin_init();

$this->assertNull( $this->token_manager->get( $this->plugin ) );
$this->assertEmpty( did_action( 'stellarwp/uplink/' . Config::get_hook_prefix() . '/' . $this->slug . '/connected' ) );
}

public function test_it_does_not_store_an_invalid_token(): void {
Expand All @@ -155,6 +158,7 @@ public function test_it_does_not_store_an_invalid_token(): void {
do_action( $this->container->get( Action_Manager::class )->get_hook_name( $this->slug ) );

$this->assertNull( $this->token_manager->get( $this->plugin ) );
$this->assertEmpty( did_action( 'stellarwp/uplink/' . Config::get_hook_prefix() . '/' . $this->slug . '/connected' ) );
}

public function test_it_does_not_stores_token_or_license_with_a_slug_that_does_not_exist(): void {
Expand Down Expand Up @@ -184,6 +188,7 @@ public function test_it_does_not_stores_token_or_license_with_a_slug_that_does_n

$this->assertNull( $this->token_manager->get( $this->plugin ) );
$this->assertEmpty( $this->plugin->get_license_key() );
$this->assertEmpty( did_action( 'stellarwp/uplink/' . Config::get_hook_prefix() . '/a-plugin-slug-that-does-not-exist/connected' ) );
}

public function test_it_stores_token_but_not_license_without_a_license(): void {
Expand Down Expand Up @@ -218,6 +223,7 @@ public function test_it_stores_token_but_not_license_without_a_license(): void {

$this->assertSame( $token, $this->token_manager->get( $this->plugin ) );
$this->assertEmpty( $this->plugin->get_license_key() );
$this->assertEquals( 1, did_action( 'stellarwp/uplink/' . Config::get_hook_prefix() . '/' . $this->slug . '/connected' ) );
}

/**
Expand Down Expand Up @@ -259,6 +265,7 @@ public function test_it_sets_token_and_additional_license_key_on_multisite_netwo

$this->assertSame( $token, $this->token_manager->get( $this->plugin ) );
$this->assertSame( $this->plugin->get_license_key( 'network' ), $license );
$this->assertEquals( 1, did_action( 'stellarwp/uplink/' . Config::get_hook_prefix() . '/' . $this->slug . '/connected' ) );
}

/**
Expand Down Expand Up @@ -302,6 +309,7 @@ public function test_it_stores_token_data_on_subfolder_subsite(): void {

$this->assertSame( $token, $this->token_manager->get( $this->plugin ) );
$this->assertSame( $this->plugin->get_license_key( 'network' ), $license );
$this->assertEquals( 1, did_action( 'stellarwp/uplink/' . Config::get_hook_prefix() . '/' . $this->slug . '/connected' ) );
}

}
Loading