-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for connection profile steup step
- Loading branch information
1 parent
aa67eab
commit 8efa6b1
Showing
1 changed file
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
/** | ||
* Contains Class TestInitialSetupConnectionProfile. | ||
* | ||
* @package WP-Auth0 | ||
* | ||
* @since 4.0.0 | ||
*/ | ||
|
||
/** | ||
* Class TestInitialSetupConnectionProfile. | ||
*/ | ||
class TestInitialSetupConnectionProfile extends WP_Auth0_Test_Case { | ||
|
||
use RedirectHelpers; | ||
|
||
/** | ||
* Test that the create client call is made. | ||
*/ | ||
public function testThatConsentUrlIsBuiltProperly() { | ||
self::$opts->set( 'auth0_server_domain', '__test_auth0_domain__' ); | ||
$conn_profile = new WP_Auth0_InitialSetup_ConnectionProfile( self::$opts ); | ||
|
||
$consent_url = parse_url( $conn_profile->build_consent_url() ); | ||
|
||
$this->assertEquals( 'https', $consent_url['scheme'] ); | ||
$this->assertEquals( '__test_auth0_domain__', $consent_url['host'] ); | ||
$this->assertEquals( '/authorize', $consent_url['path'] ); | ||
|
||
$consent_url_query = explode( '&', $consent_url['query'] ); | ||
|
||
$this->assertContains( 'client_id=http%3A%2F%2Fexample.org', $consent_url_query ); | ||
$this->assertContains( 'response_type=code', $consent_url_query ); | ||
$this->assertContains( | ||
'redirect_uri=http%3A%2F%2Fexample.org%2Fwp-admin%2Fadmin.php%3Fpage%3Dwpa0-setup%26callback%3D1', | ||
$consent_url_query | ||
); | ||
$this->assertContains( | ||
'scope=create%3Aclients+create%3Aclient_grants+update%3Aconnections+create%3Aconnections+read%3Aconnections+read%3Ausers+update%3Ausers', | ||
$consent_url_query | ||
); | ||
} | ||
|
||
public function testThatNewConnectionIsCreatedWithExistingMigrationToken() { | ||
$this->startRedirectHalting(); | ||
$conn_profile = new WP_Auth0_InitialSetup_ConnectionProfile( self::$opts ); | ||
|
||
try { | ||
$conn_profile->callback(); | ||
$redirect_found = [ 'No redirect' ]; | ||
} catch ( Exception $e ) { | ||
$redirect_found = unserialize( $e->getMessage() ); | ||
} | ||
|
||
$this->assertEquals( 302, $redirect_found['status'] ); | ||
$this->assertStringStartsWith( 'https://auth0.auth0.com/authorize', $redirect_found['location'] ); | ||
} | ||
|
||
} |