Skip to content

Commit

Permalink
Fixing bad merge.
Browse files Browse the repository at this point in the history
  • Loading branch information
redscar committed Dec 19, 2024
1 parent d858c21 commit d17172c
Showing 1 changed file with 0 additions and 125 deletions.
125 changes: 0 additions & 125 deletions tests/integration/Tribe/PUE/Checker_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -601,129 +601,4 @@ function () {
'A transient marked invalid should return false.',
];
}

/**
* Mock we're inside the wp-admin dashboard and fire off the admin_init hook.
*
* @param bool $network Whether we're in the network dashboard.
*
* @return void
*/
protected function admin_init( bool $network = false ): void {
$screen = WP_Screen::get( $network ? 'dashboard-network' : 'dashboard' );
$GLOBALS['current_screen'] = $screen;

if ( $network ) {
$this->assertTrue( $screen->in_admin( 'network' ) );
}

$this->assertTrue( $screen->in_admin() );

// Fire off admin_init to run any of our events hooked into this action.
do_action( 'admin_init' );
}

/**
* Helper to register a new plugin for Uplink testing.
*
* @param string $slug The slug of the plugin.
* @param string $name The name of the plugin.
* @param string $version The version of the plugin.
*
* @return Resource
*/
private function register_new_uplink_plugin( string $slug, string $name = 'Sample Plugin', string $version = '1.0.10' ): Resource {
return Register::plugin(
$slug,
$name,
$version,
__DIR__,
tribe( Tribe__Main::class )
);
}

/**
* Creates a valid Uplink license for testing.
*
* @param string $slug The slug of the plugin to create a license for.
*
* @return string The generated token for the Uplink license.
*/
private function create_valid_uplink_license( string $slug ): string {
$plugin = $this->register_new_uplink_plugin( $slug );

// Set the current user to an admin.
wp_set_current_user( 1 );

// Initialize the token manager.
$this->token_manager = tribe( Token_Manager::class );

// Ensure no token exists for the plugin initially.
$this->assertNull( $this->token_manager->get( $plugin ) );

// Generate a nonce and a token.
$nonce = ( tribe( Nonce::class ) )->create();
$token = '53ca40ab-c6c7-4482-a1eb-14c56da31015';

// Mock these were passed via the query string.
global $_GET;
$_GET[ Connect_Controller::TOKEN ] = $token;
$_GET[ Connect_Controller::NONCE ] = $nonce;
$_GET[ Connect_Controller::SLUG ] = $slug;

// Mock we're an admin inside the dashboard.
$this->admin_init();

// Fire off the specification action tied to this slug.
do_action( tribe( Action_Manager::class )->get_hook_name( $slug ) );

// Verify that the token was assigned correctly.
$this->assertSame( $token, $this->token_manager->get( $plugin ) );

// Verify that the general 'connected' action fires.
$this->assertEquals( 1, did_action( 'stellarwp/uplink/' . Config::get_hook_prefix() . '/connected' ) ,'Hook should only run once');

return $token;
}

/**
* Helper to disconnect an Uplink plugin.
*
* @param string $slug The slug of the plugin to disconnect.
*/
private function disconnect_uplink_plugin( string $slug ): void {
$plugin = get_resource( $slug );
if ( empty( $plugin ) ) {
return;
}

if ( empty( $this->token_manager ) ) {
return;
}

global $_GET;
wp_set_current_user( 1 );

$token = $this->token_manager->get( $plugin );
$this->assertNotNull( $token );

// Mock these were passed via the query string.
$_GET[ Disconnect_Controller::ARG ] = 1;
$_GET[ Disconnect_Controller::CACHE_KEY ] = 'nada';
$_GET[ Disconnect_Controller::SLUG ] = $slug;
$_GET['_wpnonce'] = wp_create_nonce( Disconnect_Controller::ARG );

// Mock we're an admin inside the dashboard.
$this->admin_init();

// Fire off the specification action tied to this slug.
do_action( tribe( Action_Manager::class )->get_hook_name( $slug ) );

// Assert that the token is removed.
$this->assertNull( $this->token_manager->get( $plugin ) );

// Verify that the disconnected action fires.
$this->assertEquals( 1, did_action( 'stellarwp/uplink/' . Config::get_hook_prefix() . '/disconnected' ) );
}

}

0 comments on commit d17172c

Please sign in to comment.