Skip to content

Commit

Permalink
Provides a connected hook
Browse files Browse the repository at this point in the history
  • Loading branch information
dpanta94 committed Sep 30, 2024
1 parent de339bf commit 192794e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
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' ) );
}

}

0 comments on commit 192794e

Please sign in to comment.