-
Notifications
You must be signed in to change notification settings - Fork 295
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
Add get help link to authentication request failed message #5635
Add get help link to authentication request failed message #5635
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @nfmohit, this is looking good. I have left a handful of minor comments around testing for you to take a look at.
* | ||
* @return string The get help link. | ||
*/ | ||
public function get_oauth_proxy_failed_help_link() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This helper method is only used within this class (when looking at the production code), and it's not apparent that it'll be needed outside of the class. Therefore I'd suggest it should not be public
- I'd go for private
instead.
I know it's used in the unit tests, but it's generally not good practice to allow unit tests to dictate the public API of the code they are testing. Within the tests themselves I think testing for the string literal is fine in this case - and indeed, that will have the added benefit of actually verifying the result of get_oauth_proxy_failed_help_link()
.
public function get_oauth_proxy_failed_help_link() { | |
private function get_oauth_proxy_failed_help_link() { |
$setup = new Setup( $context, new User_Options( $context ), new Authentication( $context ) ); | ||
$context = new Context( GOOGLESITEKIT_PLUGIN_MAIN_FILE, new MutableInput() ); | ||
$setup = new Setup( $context, new User_Options( $context ), new Authentication( $context ) ); | ||
$oauth_proxy_failed_help_link = $setup->get_oauth_proxy_failed_help_link(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned above, I don't think this test should be referencing get_oauth_proxy_failed_help_link()
...
$oauth_proxy_failed_help_link = $setup->get_oauth_proxy_failed_help_link(); |
sprintf( | ||
'The request to the authentication proxy has failed with an error: %1$s %2$s.', | ||
$error, | ||
$oauth_proxy_failed_help_link | ||
), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead, just include the expected string directly - this is a more robust test, and clearer as to what the expectation is.
sprintf( | |
'The request to the authentication proxy has failed with an error: %1$s %2$s.', | |
$error, | |
$oauth_proxy_failed_help_link | |
), | |
sprintf( | |
'The request to the authentication proxy has failed with an error: %1$s <a href="https://sitekit.withgoogle.com/support/?error_id=request_to_auth_proxy_failed" target="_blank">Get Help</a>.', | |
$error | |
), |
|
||
$context = new Context( GOOGLESITEKIT_PLUGIN_MAIN_FILE, new MutableInput() ); | ||
$setup = new Setup( $context, new User_Options( $context ), new Authentication( $context ) ); | ||
$oauth_proxy_failed_help_link = $setup->get_oauth_proxy_failed_help_link(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same applies here
$oauth_proxy_failed_help_link = $setup->get_oauth_proxy_failed_help_link(); |
sprintf( | ||
'The request to the authentication proxy has failed. Please, try again later. %s.', | ||
$oauth_proxy_failed_help_link | ||
), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And again, test for the literal string here...
sprintf( | |
'The request to the authentication proxy has failed. Please, try again later. %s.', | |
$oauth_proxy_failed_help_link | |
), | |
'The request to the authentication proxy has failed. Please, try again later. <a href="https://sitekit.withgoogle.com/support/?error_id=request_to_auth_proxy_failed" target="_blank">Get Help</a>.', |
|
||
add_filter( | ||
'pre_http_request', | ||
function( $preempt, $args, $url ) use ( $context, &$proxy_server_requests, $has_credentials ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$has_credentials
is unused within the function
function( $preempt, $args, $url ) use ( $context, &$proxy_server_requests, $has_credentials ) { | |
function( $preempt, $args, $url ) use ( $context, &$proxy_server_requests ) { |
Very valid suggestions! I've addressed them. Thank you @techanvil! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice one @nfmohit! LGTM 🎉
return sprintf( | ||
/* translators: 1: Support link URL. 2: Get help string. */ | ||
__( '<a href="%1$s" target="_blank">%2$s</a>', 'google-site-kit' ), | ||
esc_url( $this->proxy_support_link_url . '/?error_id=request_to_auth_proxy_failed' ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use add_query_arg()
to add query parameters instead of manually concatenating pieces of a URL.
Not only is that a best practice in WordPress, it is also more error proof: Right now, the code here only works as long as we know or can assume that $this->proxy_support_link_url
does not end in a trailing slash. With add_query_arg
, we don't have that problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duly noted and very valid concern. Thank you for noticing and pointing it out @felixarntz!
Summary
Addresses issue:
Relevant technical choices
This PR simply adds "Get Help" links to the authentication request failed message. It also updates test cases to address this change.
PR Author Checklist
Do not alter or remove anything below. The following sections will be managed by moderators only.
Code Reviewer Checklist
Merge Reviewer Checklist