-
Notifications
You must be signed in to change notification settings - Fork 286
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8317 from google/enhancement/8274-como-set-consen…
…t-defaults
- Loading branch information
Showing
5 changed files
with
246 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
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
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,103 @@ | ||
/** | ||
* Consent Mode test. | ||
* | ||
* Site Kit by Google, Copyright 2024 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { activatePlugin, createURL } from '@wordpress/e2e-test-utils'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { | ||
setSiteVerification, | ||
setSearchConsoleProperty, | ||
enableFeature, | ||
wpApiFetch, | ||
} from '../../utils'; | ||
|
||
const eeaRegions = [ | ||
'AT', | ||
'BE', | ||
'BG', | ||
'CH', | ||
'CY', | ||
'CZ', | ||
'DE', | ||
'DK', | ||
'EE', | ||
'ES', | ||
'FI', | ||
'FR', | ||
'GR', | ||
'HR', | ||
'HU', | ||
'IE', | ||
'IS', | ||
'IT', | ||
'LI', | ||
'LT', | ||
'LU', | ||
'LV', | ||
'MT', | ||
'NL', | ||
'NO', | ||
'PL', | ||
'PT', | ||
'RO', | ||
'SE', | ||
'SI', | ||
'SK', | ||
'UK', | ||
]; | ||
|
||
describe( 'Consent Mode snippet', () => { | ||
beforeAll( async () => { | ||
await activatePlugin( 'e2e-tests-proxy-auth-plugin' ); | ||
await setSiteVerification(); | ||
await setSearchConsoleProperty(); | ||
await enableFeature( 'consentMode' ); | ||
await wpApiFetch( { | ||
path: 'google-site-kit/v1/core/site/data/consent-mode', | ||
method: 'post', | ||
data: { data: { settings: { enabled: true } } }, | ||
} ); | ||
} ); | ||
|
||
beforeEach( async () => { | ||
await page.goto( createURL( '/hello-world' ), { waitUntil: 'load' } ); | ||
} ); | ||
|
||
it( 'configures the Consent Mode defaults', async () => { | ||
const dataLayer = await page.evaluate( () => window.dataLayer ); | ||
|
||
expect( dataLayer ).toEqual( [ | ||
{ | ||
0: 'consent', | ||
1: 'default', | ||
2: { | ||
ad_personalization: 'denied', | ||
ad_storage: 'denied', | ||
ad_user_data: 'denied', | ||
analytics_storage: 'denied', | ||
regions: eeaRegions, | ||
}, | ||
}, | ||
] ); | ||
} ); | ||
} ); |
67 changes: 67 additions & 0 deletions
67
tests/phpunit/integration/Core/Consent_Mode/Consent_ModeTest.php
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,67 @@ | ||
<?php | ||
/** | ||
* Consent_ModeTest | ||
* | ||
* @package Google\Site_Kit\Tests\Core\Consent_Mode | ||
* @copyright 2024 Google LLC | ||
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0 | ||
* @link https://sitekit.withgoogle.com | ||
*/ | ||
|
||
namespace Google\Site_Kit\Tests\Core\Consent_Mode; | ||
|
||
use Google\Site_Kit\Context; | ||
use Google\Site_Kit\Core\Consent_Mode\Consent_Mode; | ||
use Google\Site_Kit\Core\Consent_Mode\Consent_Mode_Settings; | ||
use Google\Site_Kit\Core\Storage\Options; | ||
use Google\Site_Kit\Tests\TestCase; | ||
|
||
class Consent_ModeTest extends TestCase { | ||
|
||
/** | ||
* Context instance. | ||
* | ||
* @var Context | ||
*/ | ||
private $context; | ||
|
||
/** | ||
* Options instance. | ||
* | ||
* @var Options | ||
*/ | ||
private $options; | ||
|
||
public function set_up() { | ||
parent::set_up(); | ||
|
||
$this->enable_feature( 'consentMode' ); | ||
|
||
$this->context = new Context( GOOGLESITEKIT_PLUGIN_MAIN_FILE ); | ||
$this->options = new Options( $this->context ); | ||
} | ||
|
||
public function test_renders_consent_mode_snippet_when_enabled() { | ||
remove_all_actions( 'wp_head' ); | ||
|
||
( new Consent_Mode_Settings( $this->options ) )->set( array( 'enabled' => true ) ); | ||
|
||
$consent_mode = new Consent_Mode( $this->context, $this->options ); | ||
$consent_mode->register(); | ||
|
||
$output = $this->capture_action( 'wp_head' ); | ||
|
||
$this->assertStringContainsString( 'Google tag (gtag.js) Consent Mode snippet added by Site Kit', $output ); | ||
} | ||
|
||
public function test_does_not_render_consent_mode_snippet_when_disabled() { | ||
remove_all_actions( 'wp_head' ); | ||
|
||
$consent_mode = new Consent_Mode( $this->context, $this->options ); | ||
$consent_mode->register(); | ||
|
||
$output = $this->capture_action( 'wp_head' ); | ||
|
||
$this->assertStringNotContainsString( 'Google tag (gtag.js) Consent Mode snippet added by Site Kit', $output ); | ||
} | ||
} |
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