|
| 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