Skip to content

Commit 92939a0

Browse files
committed
Add optional license param to provide in auth url callback
1 parent b82d6f4 commit 92939a0

File tree

2 files changed

+68
-4
lines changed

2 files changed

+68
-4
lines changed

src/Uplink/Auth/Auth_Url_Builder.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,11 @@ public function __construct(
3535
*
3636
* @param string $slug The product/service slug.
3737
* @param string $domain An optional domain associated with a license key to pass along.
38+
* @param string $license An optional license key to pass along.
3839
*
3940
* @return string
4041
*/
41-
public function build( string $slug, string $domain = '' ): string {
42+
public function build( string $slug, string $domain = '', string $license = '' ): string {
4243
global $pagenow;
4344

4445
if ( empty( $pagenow ) ) {
@@ -53,8 +54,9 @@ public function build( string $slug, string $domain = '' ): string {
5354

5455
// Query arguments to combine with $_GET and add to the authorization URL.
5556
$args = [
56-
'uplink_domain' => $domain,
57-
'uplink_slug' => $slug,
57+
'uplink_domain' => $domain,
58+
'uplink_slug' => $slug,
59+
'uplink_license' => $license,
5860
];
5961

6062
$url = add_query_arg(
@@ -69,5 +71,4 @@ public function build( string $slug, string $domain = '' ): string {
6971
] )
7072
);
7173
}
72-
7374
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php declare( strict_types=1 );
2+
3+
namespace StellarWP\Uplink\Tests\Auth;
4+
5+
use StellarWP\Uplink\API\V3\Auth\Auth_Url;
6+
use StellarWP\Uplink\Auth\Auth_Url_Builder;
7+
use StellarWP\Uplink\Auth\Nonce;
8+
use StellarWP\Uplink\Config;
9+
use StellarWP\Uplink\Tests\Traits\With_Uopz;
10+
use StellarWP\Uplink\Tests\UplinkTestCase;
11+
use StellarWP\Uplink\Uplink;
12+
13+
final class AuthUrlBuilderTest extends UplinkTestCase {
14+
15+
use With_Uopz;
16+
17+
/**
18+
* @var Auth_Url_Builder
19+
*/
20+
private $auth_url_builder;
21+
22+
protected function setUp(): void {
23+
parent::setUp();
24+
25+
Config::set_token_auth_prefix( 'kadence_' );
26+
27+
// Run init again to reload all providers.
28+
Uplink::init();
29+
30+
$this->set_class_fn_return( Auth_Url::class, 'get', 'https://theeventscalendar.com/account-auth' );
31+
$this->set_class_fn_return( Nonce::class, 'create', 'abcd1234' );
32+
33+
$this->auth_url_builder = $this->container->get( Auth_Url_Builder::class );
34+
}
35+
36+
public function test_it_builds_url(): void {
37+
$url = $this->auth_url_builder->build( 'the-events-calendar', 'theeventscalendar.com' );
38+
39+
$callback = base64_encode( 'http://wordpress.test/wp-admin/index.php?uplink_domain=theeventscalendar.com&uplink_slug=the-events-calendar&_uplink_nonce=abcd1234' );
40+
$expected = 'https://theeventscalendar.com/account-auth?uplink_callback=' . rawurlencode( $callback );
41+
42+
$this->assertSame( $expected, $url );
43+
}
44+
45+
public function test_it_builds_url_with_license(): void {
46+
$url = $this->auth_url_builder->build( 'the-events-calendar', 'theeventscalendar.com', 'some-license-key' );
47+
48+
$callback = base64_encode( 'http://wordpress.test/wp-admin/index.php?uplink_domain=theeventscalendar.com&uplink_slug=the-events-calendar&uplink_license=some-license-key&_uplink_nonce=abcd1234' );
49+
$expected = 'https://theeventscalendar.com/account-auth?uplink_callback=' . rawurlencode( $callback );
50+
51+
$this->assertSame( $expected, $url );
52+
}
53+
54+
public function test_it_builds_url_with_empty_license(): void {
55+
$url = $this->auth_url_builder->build( 'the-events-calendar', 'theeventscalendar.com', '' );
56+
57+
$callback = base64_encode( 'http://wordpress.test/wp-admin/index.php?uplink_domain=theeventscalendar.com&uplink_slug=the-events-calendar&_uplink_nonce=abcd1234' );
58+
$expected = 'https://theeventscalendar.com/account-auth?uplink_callback=' . rawurlencode( $callback );
59+
60+
$this->assertSame( $expected, $url );
61+
}
62+
63+
}

0 commit comments

Comments
 (0)