Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change CDN URL field type #704

Merged
merged 1 commit into from
Jul 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions lib/admin/WP_Auth0_Admin_Advanced.php
Original file line number Diff line number Diff line change
Expand Up @@ -579,16 +579,6 @@ public function basic_validation( $old_options, $input ) {
$input['auth0_implicit_workflow'] = ( isset( $input['auth0_implicit_workflow'] ) ? $input['auth0_implicit_workflow'] : 0 );
$input['force_https_callback'] = ( isset( $input['force_https_callback'] ) ? $input['force_https_callback'] : 0 );

$input['custom_cdn_url'] = empty( $input['custom_cdn_url'] ) ? 0 : 1;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to lib/admin/WP_Auth0_Admin_Appearance.php


$input['cdn_url'] = empty( $input['cdn_url'] ) ? WPA0_LOCK_CDN_URL : sanitize_text_field( $input['cdn_url'] );

// If an invalid URL is used, default to previously saved (if there is one) or default URL.
if ( ! filter_var( $input['cdn_url'], FILTER_VALIDATE_URL ) ) {
$input['cdn_url'] = isset( $old_options['cdn_url'] ) ? $old_options['cdn_url'] : WPA0_LOCK_CDN_URL;
self::add_validation_error( __( 'The Lock JS CDN URL used is not a valid URL.', 'wp-auth0' ) );
}

$input['migration_ips_filter'] = ( ! empty( $input['migration_ips_filter'] ) ? 1 : 0 );

$input['valid_proxy_ip'] = ( isset( $input['valid_proxy_ip'] ) ? $input['valid_proxy_ip'] : null );
Expand Down
13 changes: 12 additions & 1 deletion lib/admin/WP_Auth0_Admin_Appearance.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public function render_custom_cdn_url( $args = array() ) {
* @see add_settings_field()
*/
public function render_cdn_url( $args = array() ) {
$this->render_text_field( $args['label_for'], $args['opt_name'], 'url' );
$this->render_text_field( $args['label_for'], $args['opt_name'] );
$this->render_field_description(
__( 'This should point to the latest Lock JS available in the CDN and rarely needs to change', 'wp-auth0' )
);
Expand Down Expand Up @@ -482,6 +482,17 @@ public function basic_validation( $old_options, $input ) {
$input['language_dictionary'] = isset( $old_options['language_dictionary'] ) ? $old_options['language_dictionary'] : '';
}
}

$input['custom_cdn_url'] = empty( $input['custom_cdn_url'] ) ? 0 : 1;

$input['cdn_url'] = empty( $input['cdn_url'] ) ? WPA0_LOCK_CDN_URL : sanitize_text_field( $input['cdn_url'] );

// If an invalid URL is used, default to previously saved (if there is one) or default URL.
if ( ! filter_var( $input['cdn_url'], FILTER_VALIDATE_URL ) ) {
$input['cdn_url'] = isset( $old_options['cdn_url'] ) ? $old_options['cdn_url'] : WPA0_LOCK_CDN_URL;
self::add_validation_error( __( 'The Lock JS CDN URL used is not a valid URL.', 'wp-auth0' ) );
}

return $input;
}

Expand Down
4 changes: 2 additions & 2 deletions tests/testOptionLockCdn.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class TestOptionLockCdn extends WP_Auth0_Test_Case {
*/
public static function setUpBeforeClass() {
parent::setUpBeforeClass();
self::$admin = new WP_Auth0_Admin_Advanced( self::$opts, new WP_Auth0_Routes( self::$opts ) );
self::$admin = new WP_Auth0_Admin_Appearance( self::$opts, new WP_Auth0_Routes( self::$opts ) );
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was testing the wrong class (setting methods were moved and deprecated).

}

/**
Expand Down Expand Up @@ -122,7 +122,7 @@ public function testThatLockCdnUrlFieldDisplaysProperly() {
);

// Input should be a checkbox.
$this->assertEquals( 'url', $input->item( 0 )->getAttribute( 'type' ) );
$this->assertEquals( 'text', $input->item( 0 )->getAttribute( 'type' ) );

// Check that saving a custom domain appears in the field value.
self::$opts->set( $field_args['opt_name'], 'https://auth0.com' );
Expand Down