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

Thank with Google PHP Foundation #5391

Merged
merged 6 commits into from
Jun 24, 2022
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
2 changes: 1 addition & 1 deletion feature-flags.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"dashboardSharing",
"ga4ActivationBanner",
"ideaHubModule",
"swgModule",
"twgModule",
"userInput",
"zeroDataStates"
]
10 changes: 5 additions & 5 deletions includes/Core/Authentication/Authentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
use Google\Site_Kit\Core\Modules\Modules;
use Google\Site_Kit\Core\Util\BC_Functions;
use Google\Site_Kit\Modules\Idea_Hub;
use Google\Site_Kit\Modules\Subscribe_With_Google;
use Google\Site_Kit\Modules\Thank_With_Google;

/**
* Authentication Class.
Expand Down Expand Up @@ -1360,12 +1360,12 @@ private function filter_features_via_proxy( $feature_enabled, $feature_name ) {
$features = $this->options->get( $remote_features_option );

if ( false === $features ) {
// The experimental features (ideaHubModule and swgModule) are checked within Modules::construct() which
// The experimental features (ideaHubModule and twgModule) are checked within Modules::construct() which
// runs before Modules::register() where the `googlesitekit_features_request_data` filter is registered.
// Without this filter, some necessary context data is not sent when a request to Google_Proxy::get_features() is
// made. So we avoid making this request and solely check the active modules in the database to see if these
// features are enabled.
if ( in_array( $feature_name, array( 'ideaHubModule', 'swgModule' ), true ) ) {
if ( in_array( $feature_name, array( 'ideaHubModule', 'twgModule' ), true ) ) {
$active_modules = $this->options->get( Modules::OPTION_ACTIVE_MODULES );

if ( ! is_array( $active_modules ) ) {
Expand All @@ -1376,8 +1376,8 @@ private function filter_features_via_proxy( $feature_enabled, $feature_name ) {
return in_array( Idea_Hub::MODULE_SLUG, $active_modules, true );
}

if ( 'swgModule' === $feature_name ) {
return in_array( Subscribe_With_Google::MODULE_SLUG, $active_modules, true );
if ( 'twgModule' === $feature_name ) {
return in_array( Thank_With_Google::MODULE_SLUG, $active_modules, true );
}
}

Expand Down
6 changes: 3 additions & 3 deletions includes/Core/Modules/Modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
use Google\Site_Kit\Modules\Search_Console;
use Google\Site_Kit\Modules\Site_Verification;
use Google\Site_Kit\Modules\Tag_Manager;
use Google\Site_Kit\Modules\Subscribe_With_Google;
use Google\Site_Kit\Modules\Thank_With_Google;
use WP_REST_Server;
use WP_REST_Request;
use WP_REST_Response;
Expand Down Expand Up @@ -188,8 +188,8 @@ public function __construct(
if ( Feature_Flags::enabled( 'ideaHubModule' ) ) {
$this->core_modules[ Idea_Hub::MODULE_SLUG ] = Idea_Hub::class;
}
if ( Feature_Flags::enabled( 'swgModule' ) ) {
$this->core_modules[ Subscribe_With_Google::MODULE_SLUG ] = Subscribe_With_Google::class;
if ( Feature_Flags::enabled( 'twgModule' ) ) {
$this->core_modules[ Thank_With_Google::MODULE_SLUG ] = Thank_With_Google::class;
}

if ( Feature_Flags::enabled( 'dashboardSharing' ) ) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Class Google\Site_Kit\Modules\Subscribe_With_Google
* Class Google\Site_Kit\Modules\Thank_With_Google
*
* @package Google\Site_Kit
* @copyright 2021 Google LLC
Expand All @@ -22,16 +22,16 @@
use Google\Site_Kit\Core\Modules\Module_With_Owner;
use Google\Site_Kit\Core\Modules\Module_With_Owner_Trait;
use Google\Site_Kit\Core\Util\Method_Proxy_Trait;
use Google\Site_Kit\Modules\Subscribe_With_Google\Settings;
use Google\Site_Kit\Modules\Thank_With_Google\Settings;

/**
* Class representing the Subscribe with Google module.
* Class representing the Thank with Google module.
*
* @since 1.41.0
* @since n.e.x.t
* @access private
* @ignore
*/
final class Subscribe_With_Google extends Module
final class Thank_With_Google extends Module
implements Module_With_Assets, Module_With_Deactivation, Module_With_Owner, Module_With_Settings {
use Method_Proxy_Trait;
use Module_With_Assets_Trait;
Expand All @@ -41,27 +41,25 @@ final class Subscribe_With_Google extends Module
/**
* Module slug name.
*/
const MODULE_SLUG = 'subscribe-with-google';
const MODULE_SLUG = 'thank-with-google';

/**
* Registers functionality through WordPress hooks.
*
* @since 1.41.0
* @since n.e.x.t
*/
public function register() {
if ( ! $this->is_connected() ) {
return;
}

// TODO: Bring back SwG functionality after #3120 is merged.
}

/**
* Checks whether the module is connected.
*
* A module being connected means that all steps required as part of its activation are completed.
*
* @since 1.41.0
* @since n.e.x.t
*
* @return bool True if module is connected, false otherwise.
*/
Expand Down Expand Up @@ -90,7 +88,7 @@ public function is_connected() {
/**
* Cleans up when the module is deactivated.
*
* @since 1.41.0
* @since n.e.x.t
*/
public function on_deactivation() {
$this->get_settings()->delete();
Expand All @@ -99,14 +97,14 @@ public function on_deactivation() {
/**
* Sets up information about the module.
*
* @since 1.41.0
* @since n.e.x.t
*
* @return array Associative array of module info.
*/
protected function setup_info() {
return array(
'slug' => 'subscribe-with-google',
'name' => _x( 'Subscribe with Google', 'Service name', 'google-site-kit' ),
'slug' => 'thank-with-google',
'name' => _x( 'Thank with Google', 'Service name', 'google-site-kit' ),
'description' => __( 'Generate revenue through your content by adding subscriptions or contributions to your publication', 'google-site-kit' ),
'order' => 7,
'homepage' => __( 'https://publishercenter.google.com/', 'google-site-kit' ),
Expand All @@ -116,7 +114,7 @@ protected function setup_info() {
/**
* Sets up the module's settings instance.
*
* @since 1.41.0
* @since n.e.x.t
*
* @return Module_Settings
*/
Expand All @@ -127,7 +125,7 @@ protected function setup_settings() {
/**
* Sets up the module's assets to register.
*
* @since 1.41.0
* @since n.e.x.t
*
* @return Asset[] List of Asset objects.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
<?php
/**
* Class Google\Site_Kit\Modules\Subscribe_With_Google\Settings
* Class Google\Site_Kit\Modules\Thank_With_Google\Settings
*
* @package Google\Site_Kit\Modules\Subscribe_With_Google
* @package Google\Site_Kit\Modules\Thank_With_Google
* @copyright 2021 Google LLC
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
* @link https://sitekit.withgoogle.com
*/

namespace Google\Site_Kit\Modules\Subscribe_With_Google;
namespace Google\Site_Kit\Modules\Thank_With_Google;

use Google\Site_Kit\Core\Modules\Module_Settings;
use Google\Site_Kit\Core\Storage\Setting_With_Owned_Keys_Interface;
use Google\Site_Kit\Core\Storage\Setting_With_Owned_Keys_Trait;

/**
* Class for Tag Manager settings.
* Class for Thank with Google settings.
*
* @since 1.41.0
* @since n.e.x.t
* @access private
* @ignore
*/
class Settings extends Module_Settings implements Setting_With_Owned_Keys_Interface {
use Setting_With_Owned_Keys_Trait;

const OPTION = 'googlesitekit_subscribe-with-google_settings';
const OPTION = 'googlesitekit_thank-with-google_settings';

/**
* Registers the setting in WordPress.
*
* @since 1.41.0
* @since n.e.x.t
*/
public function register() {
parent::register();
Expand All @@ -40,7 +40,7 @@ public function register() {
/**
* Returns keys for owned settings.
*
* @since 1.41.0
* @since n.e.x.t
*
* @return array An array of keys for owned settings.
*/
Expand All @@ -55,7 +55,7 @@ public function get_owned_keys() {
/**
* Gets the default value.
*
* @since 1.41.0
* @since n.e.x.t
*
* @return array
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -922,13 +922,13 @@ function ( $preempt, $args, $url ) use ( $google_proxy, &$proxy_server_requests

// Test experimental features are checked solely within the database via options.
$this->assertFalse( apply_filters( 'googlesitekit_is_feature_enabled', false, 'ideaHubModule' ) );
$this->assertFalse( apply_filters( 'googlesitekit_is_feature_enabled', false, 'swgModule' ) );
$this->assertFalse( apply_filters( 'googlesitekit_is_feature_enabled', false, 'twgModule' ) );
// Update the active modules and test if they are checked.
update_option( 'googlesitekit_active_modules', array( 'idea-hub' ) );
$this->assertTrue( apply_filters( 'googlesitekit_is_feature_enabled', false, 'ideaHubModule' ) );
$this->assertFalse( apply_filters( 'googlesitekit_is_feature_enabled', false, 'swgModule' ) );
update_option( 'googlesitekit_active_modules', array( 'idea-hub', 'subscribe-with-google' ) );
$this->assertTrue( apply_filters( 'googlesitekit_is_feature_enabled', false, 'swgModule' ) );
$this->assertFalse( apply_filters( 'googlesitekit_is_feature_enabled', false, 'twgModule' ) );
update_option( 'googlesitekit_active_modules', array( 'idea-hub', 'thank-with-google' ) );
$this->assertTrue( apply_filters( 'googlesitekit_is_feature_enabled', false, 'twgModule' ) );

// Till this point, no requests should have been made to the Google Proxy server.
$this->assertEmpty( $proxy_server_requests );
Expand Down
16 changes: 8 additions & 8 deletions tests/phpunit/integration/Core/Modules/ModulesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
use Google\Site_Kit\Modules\PageSpeed_Insights;
use Google\Site_Kit\Modules\Search_Console;
use Google\Site_Kit\Modules\Site_Verification;
use Google\Site_Kit\Modules\Subscribe_With_Google;
use Google\Site_Kit\Modules\Thank_With_Google;
use Google\Site_Kit\Modules\Tag_Manager;
use Google\Site_Kit\Tests\TestCase;
use Google\Site_Kit\Tests\FakeHttpClient;
Expand Down Expand Up @@ -501,22 +501,22 @@ public function provider_feature_flag_modules() {
$default_modules,
);

yield 'should include the `subscribe-with-google` module when enabled' => array(
yield 'should include the `thank-with-google` module when enabled' => array(
// Module feature flag.
'swgModule',
'twgModule',
// Module enabled or disabled
true,
Subscribe_With_Google::MODULE_SLUG,
Thank_With_Google::MODULE_SLUG,
// Expected
array_merge( $default_modules, array( Subscribe_With_Google::MODULE_SLUG ) ),
array_merge( $default_modules, array( Thank_With_Google::MODULE_SLUG ) ),
);

yield 'should not include the `subscribe-with-google` module when enabled' => array(
yield 'should not include the `thank-with-google` module when enabled' => array(
// Module feature flag.
'swgModule',
'twgModule',
// Module enabled or disabled
false,
Subscribe_With_Google::MODULE_SLUG,
Thank_With_Google::MODULE_SLUG,
// Expected
$default_modules,
);
Expand Down
70 changes: 0 additions & 70 deletions tests/phpunit/integration/Modules/Subscribe_With_GoogleTest.php

This file was deleted.

Loading