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

Add site health checks for Ads module. #8379

Merged
merged 8 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
27 changes: 24 additions & 3 deletions includes/Modules/Ads.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@
use Google\Site_Kit\Core\Modules\Module_Settings;
use Google\Site_Kit\Core\Modules\Module_With_Assets;
use Google\Site_Kit\Core\Modules\Module_With_Assets_Trait;
use Google\Site_Kit\Core\Modules\Module_With_Debug_Fields;
use Google\Site_Kit\Core\Modules\Module_With_Settings;
use Google\Site_Kit\Core\Modules\Module_With_Settings_Trait;
use Google\Site_Kit\Core\Modules\Module_With_Tag;
use Google\Site_Kit\Core\Modules\Module_With_Tag_Trait;
use Google\Site_Kit\Core\Tags\Guards\Tag_Environment_Type_Guard;
use Google\Site_Kit\Core\Tags\Guards\Tag_Verify_Guard;
use Google\Site_Kit\Core\Modules\Tags\Module_Tag_Matchers;
use Google\Site_Kit\Modules\Ads\Settings;
use Google\Site_Kit\Modules\Ads\Tag_Guard;
use Google\Site_Kit\Modules\Ads\Tag_Matchers;
use Google\Site_Kit\Modules\Ads\Web_Tag;
use Google\Site_Kit\Core\Tags\Guards\Tag_Environment_Type_Guard;
use Google\Site_Kit\Core\Tags\Guards\Tag_Verify_Guard;

/**
* Class representing the Ads module.
Expand All @@ -33,8 +35,9 @@
* @access private
* @ignore
*/
final class Ads extends Module implements Module_With_Assets, Module_With_Settings, Module_With_Tag {
final class Ads extends Module implements Module_With_Assets, Module_With_Debug_Fields, Module_With_Settings, Module_With_Tag {
use Module_With_Assets_Trait;
use Module_With_Tag_Trait;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is not needed because it is already added to the class.

use Module_With_Settings_Trait;
use Module_With_Tag_Trait;

Expand Down Expand Up @@ -159,6 +162,24 @@ public function register_tag() {
$tag->register();
}

/**
* Gets an array of debug field definitions.
*
* @since n.e.x.t
*
* @return array
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's add a description for what is returned from this function to make it consistent with other method phpdocs.

*/
public function get_debug_fields() {
$settings = $this->get_settings()->get();

return array(
'ads_conversion_id' => array(
'label' => __( 'Ads Conversion ID', 'google-site-kit' ),
'value' => $settings['adsConversionID'],
),
);
}

/**
* Returns the Module_Tag_Matchers instance.
*
Expand Down
14 changes: 14 additions & 0 deletions tests/phpunit/integration/Modules/AdsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

/**
* @group Modules
* @group Ads
*/
class AdsTest extends TestCase {

Expand Down Expand Up @@ -50,6 +51,19 @@ public function test_settings_reset_on_deactivation() {
$this->assertFalse( $ads_settings );
}

public function test_get_debug_fields() {
$ads = new Ads( new Context( GOOGLESITEKIT_PLUGIN_MAIN_FILE ) );

$ads->get_settings()->set( array( 'adsConversionID' => 'AW-123456789' ) );

$this->assertEqualSets(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's also verify that the value is the same as we set in the settings.

array(
'ads_conversion_id',
),
array_keys( $ads->get_debug_fields() )
);
}

/**
* @dataProvider template_redirect_data_provider
*
Expand Down
Loading