Skip to content

Commit

Permalink
Add unit tests for different verification token variants.
Browse files Browse the repository at this point in the history
  • Loading branch information
felixarntz committed Nov 2, 2019
1 parent 6523950 commit 8b863d3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
4 changes: 2 additions & 2 deletions includes/Core/Authentication/Clients/OAuth_Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -632,10 +632,10 @@ public function get_proxy_setup_url( $access_code = '', $error_code = '' ) {
'nonce' => $nonce,
'name' => rawurlencode( wp_specialchars_decode( get_bloginfo( 'name' ) ) ),
'url' => rawurlencode( $home_url ),
'version' => GOOGLESITEKIT_VERSION,
'rest_root' => rawurlencode( $rest_root ),
'admin_root' => rawurlencode( $admin_root ),
'scope' => rawurlencode( $scope ),
'version' => GOOGLESITEKIT_VERSION,
),
$url
);
Expand All @@ -644,8 +644,8 @@ public function get_proxy_setup_url( $access_code = '', $error_code = '' ) {
$query_args = array(
'site_id' => $credentials->web->client_id,
'code' => $access_code,
'scope' => rawurlencode( $scope ),
'version' => GOOGLESITEKIT_VERSION,
'scope' => rawurlencode( $scope ),
);
if ( 'missing_verification' === $error_code ) {
$query_args['verification_nonce'] = wp_create_nonce( 'googlesitekit_verification' );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,26 +95,42 @@ protected function assertSetupDataExtended() {
);
}

public function test_register_head_verification_tags() {
/**
* @dataProvider data_register_head_verification_tags
*/
public function test_register_head_verification_tags( $saved_tag, $expected_output ) {
remove_all_actions( 'wp_head' );
remove_all_actions( 'login_head' );
$auth = new Authentication( new Context( GOOGLESITEKIT_PLUGIN_MAIN_FILE ) );
$auth->register();

$tag_html = '<meta name="google-site-verification" content="test-verification-content">';
set_transient( 'googlesitekit_verification_meta_tags', array( $tag_html ) );
set_transient( 'googlesitekit_verification_meta_tags', array( $saved_tag ) );

$this->assertContains(
$tag_html,
$expected_output,
$this->capture_action( 'wp_head' )
);

$this->assertContains(
$tag_html,
$expected_output,
$this->capture_action( 'login_head' )
);
}

public function data_register_head_verification_tags() {
return array(
array( // Full meta tag stored.
'<meta name="google-site-verification" content="test-verification-content">',
'<meta name="google-site-verification" content="test-verification-content">',
),
array(
// Only verification token stored.
'test-verification-content-2',
'<meta name="google-site-verification" content="test-verification-content-2">',
),
);
}

public function test_register_allowed_redirect_hosts() {
remove_all_filters( 'allowed_redirect_hosts' );
$auth = new Authentication( new Context( GOOGLESITEKIT_PLUGIN_MAIN_FILE ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ public function test_get_proxy_setup_url() {
$url = $client->get_proxy_setup_url();
$this->assertContains( 'name=', $url );
$this->assertContains( 'url=', $url );
$this->assertContains( 'version=', $url );
$this->assertContains( 'rest_root=', $url );
$this->assertContains( 'admin_root=', $url );
$this->assertContains( 'scope=', $url );
Expand All @@ -285,6 +286,7 @@ public function test_get_proxy_setup_url() {
$url = $client->get_proxy_setup_url( 'temp-code' );
$this->assertContains( 'site_id=' . self::SITE_ID, $url );
$this->assertContains( 'code=temp-code', $url );
$this->assertContains( 'version=', $url );
$this->assertContains( 'scope=', $url );
$this->assertNotContains( 'name=', $url );
$this->assertNotContains( 'url=', $url );
Expand Down

0 comments on commit 8b863d3

Please sign in to comment.