From 192794ea0f2a125bd20bc2012c29b851bb86fbbe Mon Sep 17 00:00:00 2001 From: Dimitrios Pantazis Date: Tue, 1 Oct 2024 01:19:38 +0300 Subject: [PATCH] Provides a connected hook --- src/Uplink/Auth/Admin/Connect_Controller.php | 9 +++++++++ tests/wpunit/Auth/Admin/ConnectControllerTest.php | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/src/Uplink/Auth/Admin/Connect_Controller.php b/src/Uplink/Auth/Admin/Connect_Controller.php index b826eb84..7eed335c 100644 --- a/src/Uplink/Auth/Admin/Connect_Controller.php +++ b/src/Uplink/Auth/Admin/Connect_Controller.php @@ -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 ); } } diff --git a/tests/wpunit/Auth/Admin/ConnectControllerTest.php b/tests/wpunit/Auth/Admin/ConnectControllerTest.php index 4e76ce60..7712437c 100644 --- a/tests/wpunit/Auth/Admin/ConnectControllerTest.php +++ b/tests/wpunit/Auth/Admin/ConnectControllerTest.php @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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' ) ); } /** @@ -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' ) ); } /** @@ -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' ) ); } }