From 0a6010c97a6f817b1d4286b93c134b4b0bc6043b Mon Sep 17 00:00:00 2001 From: Jacob Peattie Date: Mon, 15 Jun 2026 17:49:35 +1000 Subject: [PATCH] Add PHPUnit messages for conversion tracking test assertions. --- .../Contact_Form_7Test.php | 17 ++--- .../Easy_Digital_DownloadsTest.php | 23 +++--- .../MailchimpTest.php | 17 ++--- .../Ninja_FormsTest.php | 17 ++--- .../OptinMonsterTest.php | 17 ++--- .../PopupMakerTest.php | 17 ++--- .../WPFormsTest.php | 17 ++--- .../WooCommerceTest.php | 11 ++- .../Conversion_TrackingTest.php | 71 +++++++++---------- .../Conversion_Tracking_SettingsTest.php | 14 ++-- ...EST_Conversion_Tracking_ControllerTest.php | 21 +++--- 11 files changed, 106 insertions(+), 136 deletions(-) diff --git a/tests/phpunit/integration/Core/Conversion_Tracking/Conversion_Event_Providers/Contact_Form_7Test.php b/tests/phpunit/integration/Core/Conversion_Tracking/Conversion_Event_Providers/Contact_Form_7Test.php index f69c710c16d..1a353819e19 100644 --- a/tests/phpunit/integration/Core/Conversion_Tracking/Conversion_Event_Providers/Contact_Form_7Test.php +++ b/tests/phpunit/integration/Core/Conversion_Tracking/Conversion_Event_Providers/Contact_Form_7Test.php @@ -5,9 +5,6 @@ * @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0 * @link https://sitekit.withgoogle.com */ -// phpcs:disable PHPCS.PHPUnit.RequireAssertionMessage.MissingAssertionMessage -- Ignoring assertion message rule, messages to be added in #10760 - - namespace Google\Tests\Core\Conversion_Tracking\Conversion_Event_Providers; use Google\Site_Kit\Context; @@ -35,23 +32,23 @@ public function set_up() { * @runInSeparateProcess */ public function test_is_active() { - $this->assertFalse( $this->contactform->is_active() ); + $this->assertFalse( $this->contactform->is_active(), 'Contact Form 7 provider should not be active before plugin constant.' ); define( 'WPCF7_VERSION', 1 ); - $this->assertTrue( $this->contactform->is_active() ); + $this->assertTrue( $this->contactform->is_active(), 'Contact Form 7 provider should be active after plugin constant.' ); } public function test_get_event_names() { $events = $this->contactform->get_event_names(); - $this->assertCount( 1, $events ); - $this->assertEquals( 'contact', $events[0] ); + $this->assertCount( 1, $events, 'Contact Form 7 provider should expose one event.' ); + $this->assertEquals( 'contact', $events[0], 'Contact Form 7 event should be contact.' ); } public function test_register_script() { $handle = 'googlesitekit-events-provider-' . Contact_Form_7::CONVERSION_EVENT_PROVIDER_SLUG; - $this->assertFalse( wp_script_is( $handle, 'registered' ) ); + $this->assertFalse( wp_script_is( $handle, 'registered' ), 'Contact Form 7 script should not be registered initially.' ); $script = $this->contactform->register_script(); - $this->assertInstanceOf( Script::class, $script ); - $this->assertTrue( wp_script_is( $handle, 'registered' ) ); + $this->assertInstanceOf( Script::class, $script, 'Contact Form 7 provider should return a script.' ); + $this->assertTrue( wp_script_is( $handle, 'registered' ), 'Contact Form 7 script should be registered.' ); } } diff --git a/tests/phpunit/integration/Core/Conversion_Tracking/Conversion_Event_Providers/Easy_Digital_DownloadsTest.php b/tests/phpunit/integration/Core/Conversion_Tracking/Conversion_Event_Providers/Easy_Digital_DownloadsTest.php index cbc2e4fa93b..25c07489ea0 100644 --- a/tests/phpunit/integration/Core/Conversion_Tracking/Conversion_Event_Providers/Easy_Digital_DownloadsTest.php +++ b/tests/phpunit/integration/Core/Conversion_Tracking/Conversion_Event_Providers/Easy_Digital_DownloadsTest.php @@ -5,9 +5,6 @@ * @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0 * @link https://sitekit.withgoogle.com */ -// phpcs:disable PHPCS.PHPUnit.RequireAssertionMessage.MissingAssertionMessage -- Ignoring assertion message rule, messages to be added in #10760 - - namespace Google\Tests\Core\Conversion_Tracking\Conversion_Event_Providers; use Google\Site_Kit\Context; @@ -33,27 +30,27 @@ public function set_up() { * @runInSeparateProcess */ public function test_is_active() { - $this->assertFalse( $this->edd->is_active() ); + $this->assertFalse( $this->edd->is_active(), 'EDD provider should not be active before plugin constant.' ); define( 'EDD_VERSION', 1 ); - $this->assertTrue( $this->edd->is_active() ); + $this->assertTrue( $this->edd->is_active(), 'EDD provider should be active after plugin constant.' ); } public function test_get_event_names() { $events = $this->edd->get_event_names(); - $this->assertCount( 2, $events ); - $this->assertEquals( array( 'add_to_cart', 'purchase' ), $events ); + $this->assertCount( 2, $events, 'EDD provider should expose two events.' ); + $this->assertEquals( array( 'add_to_cart', 'purchase' ), $events, 'EDD events should include add to cart and purchase.' ); } public function test_register_script() { $handle = 'googlesitekit-events-provider-' . Easy_Digital_Downloads::CONVERSION_EVENT_PROVIDER_SLUG; - $this->assertFalse( wp_script_is( $handle, 'registered' ) ); + $this->assertFalse( wp_script_is( $handle, 'registered' ), 'EDD script should not be registered initially.' ); $script = $this->edd->register_script(); - $this->assertInstanceOf( Script::class, $script ); - $this->assertTrue( wp_script_is( $handle, 'registered' ) ); + $this->assertInstanceOf( Script::class, $script, 'EDD provider should return a script.' ); + $this->assertTrue( wp_script_is( $handle, 'registered' ), 'EDD script should be registered.' ); } public function test_register_hook() { @@ -74,12 +71,12 @@ public function test_get_enhanced_conversions_data_from_session_returns_expected $result = $method->invoke( $this->edd, $session_data ); $expected_without_user_data = $expected; unset( $expected_without_user_data['user_data'] ); - $this->assertEquals( $expected_without_user_data, $result ); + $this->assertEquals( $expected_without_user_data, $result, 'EDD session data should omit user data when feature disabled.' ); $this->enable_feature( 'gtagUserData' ); $result = $method->invoke( $this->edd, $session_data ); - $this->assertEquals( $expected, $result ); + $this->assertEquals( $expected, $result, 'EDD session data should include expected conversion data.' ); } /** @@ -91,7 +88,7 @@ public function test_extract_user_data_from_session_returns_expected_data( $sess $method->setAccessible( true ); $result = $method->invoke( $this->edd, $session_data ); - $this->assertSame( $expected, $result ); + $this->assertSame( $expected, $result, 'EDD session user data should match expected user data.' ); } public function enhanced_conversion_session_provider() { diff --git a/tests/phpunit/integration/Core/Conversion_Tracking/Conversion_Event_Providers/MailchimpTest.php b/tests/phpunit/integration/Core/Conversion_Tracking/Conversion_Event_Providers/MailchimpTest.php index 545e7fd29ec..5200fac7a28 100644 --- a/tests/phpunit/integration/Core/Conversion_Tracking/Conversion_Event_Providers/MailchimpTest.php +++ b/tests/phpunit/integration/Core/Conversion_Tracking/Conversion_Event_Providers/MailchimpTest.php @@ -5,9 +5,6 @@ * @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0 * @link https://sitekit.withgoogle.com */ -// phpcs:disable PHPCS.PHPUnit.RequireAssertionMessage.MissingAssertionMessage -- Ignoring assertion message rule, messages to be added in #10760 - - namespace Google\Tests\Core\Conversion_Tracking\Conversion_Event_Providers; use Google\Site_Kit\Context; @@ -35,23 +32,23 @@ public function set_up() { * @runInSeparateProcess */ public function test_is_active() { - $this->assertFalse( $this->mailchimp->is_active() ); + $this->assertFalse( $this->mailchimp->is_active(), 'Mailchimp provider should not be active before plugin constant.' ); define( 'MC4WP_VERSION', 1 ); - $this->assertTrue( $this->mailchimp->is_active() ); + $this->assertTrue( $this->mailchimp->is_active(), 'Mailchimp provider should be active after plugin constant.' ); } public function test_get_event_names() { $events = $this->mailchimp->get_event_names(); - $this->assertCount( 1, $events ); - $this->assertEquals( 'submit_lead_form', $events[0] ); + $this->assertCount( 1, $events, 'Mailchimp provider should expose one event.' ); + $this->assertEquals( 'submit_lead_form', $events[0], 'Mailchimp event should be submit_lead_form.' ); } public function test_register_script() { $handle = 'googlesitekit-events-provider-' . Mailchimp::CONVERSION_EVENT_PROVIDER_SLUG; - $this->assertFalse( wp_script_is( $handle, 'registered' ) ); + $this->assertFalse( wp_script_is( $handle, 'registered' ), 'Mailchimp script should not be registered initially.' ); $script = $this->mailchimp->register_script(); - $this->assertInstanceOf( Script::class, $script ); - $this->assertTrue( wp_script_is( $handle, 'registered' ) ); + $this->assertInstanceOf( Script::class, $script, 'Mailchimp provider should return a script.' ); + $this->assertTrue( wp_script_is( $handle, 'registered' ), 'Mailchimp script should be registered.' ); } } diff --git a/tests/phpunit/integration/Core/Conversion_Tracking/Conversion_Event_Providers/Ninja_FormsTest.php b/tests/phpunit/integration/Core/Conversion_Tracking/Conversion_Event_Providers/Ninja_FormsTest.php index 4c594851997..15abb20fcfd 100644 --- a/tests/phpunit/integration/Core/Conversion_Tracking/Conversion_Event_Providers/Ninja_FormsTest.php +++ b/tests/phpunit/integration/Core/Conversion_Tracking/Conversion_Event_Providers/Ninja_FormsTest.php @@ -5,9 +5,6 @@ * @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0 * @link https://sitekit.withgoogle.com */ -// phpcs:disable PHPCS.PHPUnit.RequireAssertionMessage.MissingAssertionMessage -- Ignoring assertion message rule, messages to be added in #10760 - - namespace Google\Tests\Core\Conversion_Tracking\Conversion_Event_Providers; use Google\Site_Kit\Context; @@ -35,23 +32,23 @@ public function set_up() { * @runInSeparateProcess */ public function test_is_active() { - $this->assertFalse( $this->ninjaform->is_active() ); + $this->assertFalse( $this->ninjaform->is_active(), 'Ninja Forms provider should not be active before plugin constant.' ); define( 'NF_PLUGIN_URL', 1 ); - $this->assertTrue( $this->ninjaform->is_active() ); + $this->assertTrue( $this->ninjaform->is_active(), 'Ninja Forms provider should be active after plugin constant.' ); } public function test_get_event_names() { $events = $this->ninjaform->get_event_names(); - $this->assertCount( 1, $events ); - $this->assertEquals( 'submit_lead_form', $events[0] ); + $this->assertCount( 1, $events, 'Ninja Forms provider should expose one event.' ); + $this->assertEquals( 'submit_lead_form', $events[0], 'Ninja Forms event should be submit_lead_form.' ); } public function test_register_script() { $handle = 'googlesitekit-events-provider-' . Ninja_Forms::CONVERSION_EVENT_PROVIDER_SLUG; - $this->assertFalse( wp_script_is( $handle, 'registered' ) ); + $this->assertFalse( wp_script_is( $handle, 'registered' ), 'Ninja Forms script should not be registered initially.' ); $script = $this->ninjaform->register_script(); - $this->assertInstanceOf( Script::class, $script ); - $this->assertTrue( wp_script_is( $handle, 'registered' ) ); + $this->assertInstanceOf( Script::class, $script, 'Ninja Forms provider should return a script.' ); + $this->assertTrue( wp_script_is( $handle, 'registered' ), 'Ninja Forms script should be registered.' ); } } diff --git a/tests/phpunit/integration/Core/Conversion_Tracking/Conversion_Event_Providers/OptinMonsterTest.php b/tests/phpunit/integration/Core/Conversion_Tracking/Conversion_Event_Providers/OptinMonsterTest.php index a6196efa7c0..e689beea7a9 100644 --- a/tests/phpunit/integration/Core/Conversion_Tracking/Conversion_Event_Providers/OptinMonsterTest.php +++ b/tests/phpunit/integration/Core/Conversion_Tracking/Conversion_Event_Providers/OptinMonsterTest.php @@ -5,9 +5,6 @@ * @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0 * @link https://sitekit.withgoogle.com */ -// phpcs:disable PHPCS.PHPUnit.RequireAssertionMessage.MissingAssertionMessage -- Ignoring assertion message rule, messages to be added in #10760 - - namespace Google\Tests\Core\Conversion_Tracking\Conversion_Event_Providers; use Google\Site_Kit\Context; @@ -35,23 +32,23 @@ public function set_up() { * @runInSeparateProcess */ public function test_is_active() { - $this->assertFalse( $this->optinmonster->is_active() ); + $this->assertFalse( $this->optinmonster->is_active(), 'OptinMonster provider should not be active before plugin constant.' ); define( 'OMAPI_FILE', 1 ); - $this->assertTrue( $this->optinmonster->is_active() ); + $this->assertTrue( $this->optinmonster->is_active(), 'OptinMonster provider should be active after plugin constant.' ); } public function test_get_event_names() { $events = $this->optinmonster->get_event_names(); - $this->assertCount( 1, $events ); - $this->assertEquals( 'submit_lead_form', $events[0] ); + $this->assertCount( 1, $events, 'OptinMonster provider should expose one event.' ); + $this->assertEquals( 'submit_lead_form', $events[0], 'OptinMonster event should be submit_lead_form.' ); } public function test_register_script() { $handle = 'googlesitekit-events-provider-' . OptinMonster::CONVERSION_EVENT_PROVIDER_SLUG; - $this->assertFalse( wp_script_is( $handle, 'registered' ) ); + $this->assertFalse( wp_script_is( $handle, 'registered' ), 'OptinMonster script should not be registered initially.' ); $script = $this->optinmonster->register_script(); - $this->assertInstanceOf( Script::class, $script ); - $this->assertTrue( wp_script_is( $handle, 'registered' ) ); + $this->assertInstanceOf( Script::class, $script, 'OptinMonster provider should return a script.' ); + $this->assertTrue( wp_script_is( $handle, 'registered' ), 'OptinMonster script should be registered.' ); } } diff --git a/tests/phpunit/integration/Core/Conversion_Tracking/Conversion_Event_Providers/PopupMakerTest.php b/tests/phpunit/integration/Core/Conversion_Tracking/Conversion_Event_Providers/PopupMakerTest.php index 37d5f961196..4091bee1a36 100644 --- a/tests/phpunit/integration/Core/Conversion_Tracking/Conversion_Event_Providers/PopupMakerTest.php +++ b/tests/phpunit/integration/Core/Conversion_Tracking/Conversion_Event_Providers/PopupMakerTest.php @@ -5,9 +5,6 @@ * @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0 * @link https://sitekit.withgoogle.com */ -// phpcs:disable PHPCS.PHPUnit.RequireAssertionMessage.MissingAssertionMessage -- Ignoring assertion message rule, messages to be added in #10760 - - namespace Google\Tests\Core\Conversion_Tracking\Conversion_Event_Providers; use Google\Site_Kit\Context; @@ -35,24 +32,24 @@ public function set_up() { * @runInSeparateProcess */ public function test_is_active() { - $this->assertFalse( $this->popupmaker->is_active() ); + $this->assertFalse( $this->popupmaker->is_active(), 'Popup Maker provider should not be active before plugin constant.' ); define( 'POPMAKE_VERSION', 1 ); - $this->assertTrue( $this->popupmaker->is_active() ); + $this->assertTrue( $this->popupmaker->is_active(), 'Popup Maker provider should be active after plugin constant.' ); } public function test_get_event_names() { $events = $this->popupmaker->get_event_names(); - $this->assertCount( 1, $events ); - $this->assertEquals( 'submit_lead_form', $events[0] ); + $this->assertCount( 1, $events, 'Popup Maker provider should expose one event.' ); + $this->assertEquals( 'submit_lead_form', $events[0], 'Popup Maker event should be submit_lead_form.' ); } public function test_register_script() { $handle = 'googlesitekit-events-provider-' . PopupMaker::CONVERSION_EVENT_PROVIDER_SLUG; - $this->assertFalse( wp_script_is( $handle, 'registered' ) ); + $this->assertFalse( wp_script_is( $handle, 'registered' ), 'Popup Maker script should not be registered initially.' ); $script = $this->popupmaker->register_script(); - $this->assertInstanceOf( Script::class, $script ); - $this->assertTrue( wp_script_is( $handle, 'registered' ) ); + $this->assertInstanceOf( Script::class, $script, 'Popup Maker provider should return a script.' ); + $this->assertTrue( wp_script_is( $handle, 'registered' ), 'Popup Maker script should be registered.' ); } } diff --git a/tests/phpunit/integration/Core/Conversion_Tracking/Conversion_Event_Providers/WPFormsTest.php b/tests/phpunit/integration/Core/Conversion_Tracking/Conversion_Event_Providers/WPFormsTest.php index a15b02403c8..d77c4dcb47a 100644 --- a/tests/phpunit/integration/Core/Conversion_Tracking/Conversion_Event_Providers/WPFormsTest.php +++ b/tests/phpunit/integration/Core/Conversion_Tracking/Conversion_Event_Providers/WPFormsTest.php @@ -5,9 +5,6 @@ * @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0 * @link https://sitekit.withgoogle.com */ -// phpcs:disable PHPCS.PHPUnit.RequireAssertionMessage.MissingAssertionMessage -- Ignoring assertion message rule, messages to be added in #10760 - - namespace Google\Tests\Core\Conversion_Tracking\Conversion_Event_Providers; use Google\Site_Kit\Context; @@ -35,23 +32,23 @@ public function set_up() { * @runInSeparateProcess */ public function test_is_active() { - $this->assertFalse( $this->wpforms->is_active() ); + $this->assertFalse( $this->wpforms->is_active(), 'WPForms provider should not be active before plugin constant.' ); define( 'WPFORMS_VERSION', 1 ); - $this->assertTrue( $this->wpforms->is_active() ); + $this->assertTrue( $this->wpforms->is_active(), 'WPForms provider should be active after plugin constant.' ); } public function test_get_event_names() { $events = $this->wpforms->get_event_names(); - $this->assertCount( 1, $events ); - $this->assertEquals( 'submit_lead_form', $events[0] ); + $this->assertCount( 1, $events, 'WPForms provider should expose one event.' ); + $this->assertEquals( 'submit_lead_form', $events[0], 'WPForms event should be submit_lead_form.' ); } public function test_register_script() { $handle = 'googlesitekit-events-provider-' . WPForms::CONVERSION_EVENT_PROVIDER_SLUG; - $this->assertFalse( wp_script_is( $handle, 'registered' ) ); + $this->assertFalse( wp_script_is( $handle, 'registered' ), 'WPForms script should not be registered initially.' ); $script = $this->wpforms->register_script(); - $this->assertInstanceOf( Script::class, $script ); - $this->assertTrue( wp_script_is( $handle, 'registered' ) ); + $this->assertInstanceOf( Script::class, $script, 'WPForms provider should return a script.' ); + $this->assertTrue( wp_script_is( $handle, 'registered' ), 'WPForms script should be registered.' ); } } diff --git a/tests/phpunit/integration/Core/Conversion_Tracking/Conversion_Event_Providers/WooCommerceTest.php b/tests/phpunit/integration/Core/Conversion_Tracking/Conversion_Event_Providers/WooCommerceTest.php index d921e1bbcf8..6318a33ca68 100644 --- a/tests/phpunit/integration/Core/Conversion_Tracking/Conversion_Event_Providers/WooCommerceTest.php +++ b/tests/phpunit/integration/Core/Conversion_Tracking/Conversion_Event_Providers/WooCommerceTest.php @@ -5,9 +5,6 @@ * @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0 * @link https://sitekit.withgoogle.com */ -// phpcs:disable PHPCS.PHPUnit.RequireAssertionMessage.MissingAssertionMessage -- Ignoring assertion message rule, messages to be added in #10760 - - namespace Google\Tests\Core\Conversion_Tracking\Conversion_Event_Providers; use Google\Site_Kit\Context; @@ -34,12 +31,12 @@ public function set_up() { * @runInSeparateProcess */ public function test_is_active() { - $this->assertFalse( $this->woocommerce->is_active() ); + $this->assertFalse( $this->woocommerce->is_active(), 'WooCommerce provider should not be active before class exists.' ); // Fake the existence of the `WooCommerce` class. class_alias( __CLASS__, 'WooCommerce' ); - $this->assertTrue( $this->woocommerce->is_active() ); + $this->assertTrue( $this->woocommerce->is_active(), 'WooCommerce provider should be active after class exists.' ); } public function test_events_to_track() { @@ -300,7 +297,7 @@ class_alias( 'Google\Site_Kit\Tests\WC_Countries_Fake', 'WC_Countries' ); $result = $method->invoke( $this->woocommerce, $phone, $country ); - $this->assertEquals( $expected, $result ); + $this->assertEquals( $expected, $result, 'Normalized WooCommerce phone should match expected value.' ); } public function phone_normalization_data_provider() { @@ -446,6 +443,6 @@ public function test_get_normalized_phone_fallback() { // Should fallback to Enhanced_Conversions::get_normalized_value(). // Enhanced_Conversions normalizes to lowercase and trims, but keeps other chars. - $this->assertEquals( '+94771770589', $result ); + $this->assertEquals( '+94771770589', $result, 'Normalized phone should fall back when country is empty.' ); } } diff --git a/tests/phpunit/integration/Core/Conversion_Tracking/Conversion_TrackingTest.php b/tests/phpunit/integration/Core/Conversion_Tracking/Conversion_TrackingTest.php index 7ecf818ef12..ee4059addfd 100644 --- a/tests/phpunit/integration/Core/Conversion_Tracking/Conversion_TrackingTest.php +++ b/tests/phpunit/integration/Core/Conversion_Tracking/Conversion_TrackingTest.php @@ -9,9 +9,6 @@ * * phpcs:disable PHPCS.Commenting.RequireDocTagDescription -- Pre-existing violations; tracked for follow-up cleanup. */ -// phpcs:disable PHPCS.PHPUnit.RequireAssertionMessage.MissingAssertionMessage -- Ignoring assertion message rule, messages to be added in #10760 - - namespace Google\Tests\Core\Conversion_Tracking; use Google\Site_Kit\Context; @@ -70,8 +67,8 @@ public function test_register__not_enqueued_when_no_snippet_inserted() { do_action( 'wp_enqueue_scripts' ); - $this->assertFalse( wp_script_is( 'gsk-cep-' . FakeConversionEventProvider_Active::CONVERSION_EVENT_PROVIDER_SLUG ) ); - $this->assertFalse( wp_script_is( 'gsk-cep-' . FakeConversionEventProvider::CONVERSION_EVENT_PROVIDER_SLUG ) ); + $this->assertFalse( wp_script_is( 'gsk-cep-' . FakeConversionEventProvider_Active::CONVERSION_EVENT_PROVIDER_SLUG ), 'Active provider script should not enqueue without snippet.' ); + $this->assertFalse( wp_script_is( 'gsk-cep-' . FakeConversionEventProvider::CONVERSION_EVENT_PROVIDER_SLUG ), 'Inactive provider script should not enqueue without snippet.' ); } public function test_register__not_enqueued_when_tracking_disabled() { @@ -82,7 +79,7 @@ public function test_register__not_enqueued_when_tracking_disabled() { do_action( 'googlesitekit_ads_init_tag' ); do_action( 'wp_enqueue_scripts' ); - $this->assertFalse( wp_script_is( 'gsk-cep-' . FakeConversionEventProvider_Active::CONVERSION_EVENT_PROVIDER_SLUG ) ); + $this->assertFalse( wp_script_is( 'gsk-cep-' . FakeConversionEventProvider_Active::CONVERSION_EVENT_PROVIDER_SLUG ), 'Provider script should not enqueue when tracking is disabled.' ); } public function test_register__feature_metrics() { @@ -99,17 +96,17 @@ public function test_register__feature_metrics() { * @dataProvider data_modules */ public function test_register__enqueued_when_snippet_inserted( $module_slug ) { - $this->assertFalse( has_action( 'fake_provider_action' ) ); + $this->assertFalse( has_action( 'fake_provider_action' ), 'Provider hook should not exist before registration.' ); $this->conversion_tracking->register(); do_action( "googlesitekit_{$module_slug}_init_tag" ); do_action( 'wp_enqueue_scripts' ); - $this->assertTrue( wp_script_is( 'gsk-cep-' . FakeConversionEventProvider_Active::CONVERSION_EVENT_PROVIDER_SLUG ) ); - $this->assertFalse( wp_script_is( 'gsk-cep-' . FakeConversionEventProvider::CONVERSION_EVENT_PROVIDER_SLUG ) ); + $this->assertTrue( wp_script_is( 'gsk-cep-' . FakeConversionEventProvider_Active::CONVERSION_EVENT_PROVIDER_SLUG ), 'Active provider script should enqueue after snippet.' ); + $this->assertFalse( wp_script_is( 'gsk-cep-' . FakeConversionEventProvider::CONVERSION_EVENT_PROVIDER_SLUG ), 'Inactive provider script should not enqueue after snippet.' ); - $this->assertTrue( has_action( 'fake_provider_action' ) ); + $this->assertTrue( has_action( 'fake_provider_action' ), 'Provider hook should be registered after snippet.' ); } public function data_modules() { @@ -122,15 +119,17 @@ public function data_modules() { public function test_get_active_conversion_event_providers() { $active_providers = $this->conversion_tracking->get_active_providers(); - $this->assertArrayHasKey( - FakeConversionEventProvider_Active::CONVERSION_EVENT_PROVIDER_SLUG, - $active_providers - ); - - $this->assertArrayNotHasKey( - FakeConversionEventProvider::CONVERSION_EVENT_PROVIDER_SLUG, - $active_providers - ); + $this->assertArrayHasKey( + FakeConversionEventProvider_Active::CONVERSION_EVENT_PROVIDER_SLUG, + $active_providers, + 'Active providers should include the active fake provider.' + ); + + $this->assertArrayNotHasKey( + FakeConversionEventProvider::CONVERSION_EVENT_PROVIDER_SLUG, + $active_providers, + 'Active providers should not include the inactive fake provider.' + ); } /** @@ -148,7 +147,7 @@ public function test_get_active_conversion_event_providers__classnames_exception if ( ! $expected_exception ) { $this->fail( 'No exception expected but a ' . get_class( $exception ) . ' was thrown' ); } - $this->assertEquals( $expected_exception, $exception->getMessage() ); + $this->assertEquals( $expected_exception, $exception->getMessage(), 'Provider exception message should match expected message.' ); } } @@ -199,7 +198,7 @@ public function test_get_supported_conversion_events__no_active_providers() { $this->assertEquals( array(), $events, - 'Supported conversion events should be an empty array when there are no active providers.' + 'Supported conversion events should be empty without active providers.' ); } @@ -231,12 +230,12 @@ public function test_inline_js_base_data__no_active_providers() { $data = apply_filters( 'googlesitekit_inline_base_data', array() ); - $this->assertArrayHasKey( 'hasActiveLeadEventProviders', $data ); - $this->assertArrayHasKey( 'hasActiveEcommerceEventProviders', $data ); - $this->assertArrayHasKey( 'hasMultipleActiveEcommerceEventProviders', $data ); - $this->assertFalse( $data['hasActiveLeadEventProviders'] ); - $this->assertFalse( $data['hasActiveEcommerceEventProviders'] ); - $this->assertFalse( $data['hasMultipleActiveEcommerceEventProviders'] ); + $this->assertArrayHasKey( 'hasActiveLeadEventProviders', $data, 'Inline base data should include active lead provider flag.' ); + $this->assertArrayHasKey( 'hasActiveEcommerceEventProviders', $data, 'Inline base data should include active ecommerce provider flag.' ); + $this->assertArrayHasKey( 'hasMultipleActiveEcommerceEventProviders', $data, 'Inline base data should include multiple ecommerce provider flag.' ); + $this->assertFalse( $data['hasActiveLeadEventProviders'], 'Lead provider flag should be false with no active providers.' ); + $this->assertFalse( $data['hasActiveEcommerceEventProviders'], 'Ecommerce provider flag should be false with no active providers.' ); + $this->assertFalse( $data['hasMultipleActiveEcommerceEventProviders'], 'Multiple ecommerce flag should be false with no active providers.' ); } public function test_inline_js_base_data__with_active_lead_provider() { @@ -248,8 +247,8 @@ public function test_inline_js_base_data__with_active_lead_provider() { $data = apply_filters( 'googlesitekit_inline_base_data', array() ); - $this->assertTrue( $data['hasActiveLeadEventProviders'] ); - $this->assertFalse( $data['hasActiveEcommerceEventProviders'] ); + $this->assertTrue( $data['hasActiveLeadEventProviders'], 'Lead provider flag should be true with active lead provider.' ); + $this->assertFalse( $data['hasActiveEcommerceEventProviders'], 'Ecommerce provider flag should be false with only lead provider.' ); } public function test_inline_js_base_data__with_active_ecommerce_provider() { @@ -261,10 +260,10 @@ public function test_inline_js_base_data__with_active_ecommerce_provider() { $data = apply_filters( 'googlesitekit_inline_base_data', array() ); - $this->assertFalse( $data['hasActiveLeadEventProviders'] ); - $this->assertTrue( $data['hasActiveEcommerceEventProviders'] ); + $this->assertFalse( $data['hasActiveLeadEventProviders'], 'Lead provider flag should be false with only ecommerce provider.' ); + $this->assertTrue( $data['hasActiveEcommerceEventProviders'], 'Ecommerce provider flag should be true with active provider.' ); // A single active ecommerce provider is not "multiple". - $this->assertFalse( $data['hasMultipleActiveEcommerceEventProviders'] ); + $this->assertFalse( $data['hasMultipleActiveEcommerceEventProviders'], 'Multiple ecommerce flag should be false with one provider.' ); } public function test_inline_js_base_data__with_multiple_active_ecommerce_providers() { @@ -277,8 +276,8 @@ public function test_inline_js_base_data__with_multiple_active_ecommerce_provide $data = apply_filters( 'googlesitekit_inline_base_data', array() ); - $this->assertTrue( $data['hasActiveEcommerceEventProviders'] ); - $this->assertTrue( $data['hasMultipleActiveEcommerceEventProviders'] ); + $this->assertTrue( $data['hasActiveEcommerceEventProviders'], 'Ecommerce provider flag should be true with active providers.' ); + $this->assertTrue( $data['hasMultipleActiveEcommerceEventProviders'], 'Multiple ecommerce flag should be true with multiple providers.' ); } public function test_inline_js_base_data__with_both_active_providers() { @@ -291,7 +290,7 @@ public function test_inline_js_base_data__with_both_active_providers() { $data = apply_filters( 'googlesitekit_inline_base_data', array() ); - $this->assertTrue( $data['hasActiveLeadEventProviders'] ); - $this->assertTrue( $data['hasActiveEcommerceEventProviders'] ); + $this->assertTrue( $data['hasActiveLeadEventProviders'], 'Lead provider flag should be true with both provider types.' ); + $this->assertTrue( $data['hasActiveEcommerceEventProviders'], 'Ecommerce provider flag should be true with both provider types.' ); } } diff --git a/tests/phpunit/integration/Core/Conversion_Tracking/Conversion_Tracking_SettingsTest.php b/tests/phpunit/integration/Core/Conversion_Tracking/Conversion_Tracking_SettingsTest.php index 1b1705dc9de..a1ab1c8c35a 100644 --- a/tests/phpunit/integration/Core/Conversion_Tracking/Conversion_Tracking_SettingsTest.php +++ b/tests/phpunit/integration/Core/Conversion_Tracking/Conversion_Tracking_SettingsTest.php @@ -7,9 +7,6 @@ * @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0 * @link https://sitekit.withgoogle.com */ -// phpcs:disable PHPCS.PHPUnit.RequireAssertionMessage.MissingAssertionMessage -- Ignoring assertion message rule, messages to be added in #10760 - - namespace Google\Site_Kit\Tests\Core\Conversion_Tracking; use Google\Site_Kit\Context; @@ -52,7 +49,8 @@ public function test_get_default() { array( 'enabled' => false, ), - $default_settings + $default_settings, + 'Default conversion tracking settings should include enabled false.' ); } @@ -99,16 +97,16 @@ public function data_conversion_tracking_settings() { */ public function test_get_sanitize_callback( $input, $expected ) { $this->settings->set( $input ); - $this->assertEqualSetsWithIndex( $expected, $this->settings->get() ); + $this->assertEqualSetsWithIndex( $expected, $this->settings->get(), 'Sanitized conversion tracking settings should match expected values.' ); } public function test_is_conversion_tracking_enabled() { - $this->assertFalse( $this->settings->is_conversion_tracking_enabled() ); + $this->assertFalse( $this->settings->is_conversion_tracking_enabled(), 'Conversion tracking should be disabled by default.' ); $this->settings->set( array( 'enabled' => true ) ); - $this->assertTrue( $this->settings->is_conversion_tracking_enabled() ); + $this->assertTrue( $this->settings->is_conversion_tracking_enabled(), 'Conversion tracking should be enabled after setting true.' ); $this->settings->set( array( 'enabled' => false ) ); - $this->assertFalse( $this->settings->is_conversion_tracking_enabled() ); + $this->assertFalse( $this->settings->is_conversion_tracking_enabled(), 'Conversion tracking should be disabled after setting false.' ); } } diff --git a/tests/phpunit/integration/Core/Conversion_Tracking/REST_Conversion_Tracking_ControllerTest.php b/tests/phpunit/integration/Core/Conversion_Tracking/REST_Conversion_Tracking_ControllerTest.php index b0ff33b9c32..083d36b920e 100644 --- a/tests/phpunit/integration/Core/Conversion_Tracking/REST_Conversion_Tracking_ControllerTest.php +++ b/tests/phpunit/integration/Core/Conversion_Tracking/REST_Conversion_Tracking_ControllerTest.php @@ -7,9 +7,6 @@ * @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0 * @link https://sitekit.withgoogle.com */ -// phpcs:disable PHPCS.PHPUnit.RequireAssertionMessage.MissingAssertionMessage -- Ignoring assertion message rule, messages to be added in #10760 - - namespace Google\Site_Kit\Tests\Core\Conversion_Tracking; use Google\Site_Kit\Context; @@ -75,8 +72,8 @@ public function test_register() { $this->controller->register(); - $this->assertTrue( has_filter( 'googlesitekit_rest_routes' ) ); - $this->assertTrue( has_filter( 'googlesitekit_apifetch_preload_paths' ) ); + $this->assertTrue( has_filter( 'googlesitekit_rest_routes' ), 'Conversion tracking REST routes should be registered.' ); + $this->assertTrue( has_filter( 'googlesitekit_apifetch_preload_paths' ), 'Conversion tracking preload paths should be registered.' ); } public function test_get_settings() { @@ -96,7 +93,7 @@ public function test_get_settings() { $request = new WP_REST_Request( 'GET', '/' . REST_Routes::REST_ROOT . '/core/site/data/conversion-tracking' ); $response = rest_get_server()->dispatch( $request ); - $this->assertEqualSetsWithIndex( $original_settings, $response->get_data() ); + $this->assertEqualSetsWithIndex( $original_settings, $response->get_data(), 'Conversion tracking response should contain stored settings.' ); } public function test_get_settings__requires_authenticated_admin() { @@ -116,7 +113,7 @@ public function test_get_settings__requires_authenticated_admin() { // This request is made by a user who is not authenticated with dashboard // view permissions and is therefore forbidden. - $this->assertEquals( 'rest_forbidden', $response->get_data()['code'] ); + $this->assertEquals( 'rest_forbidden', $response->get_data()['code'], 'Settings response should forbid unauthenticated admins.' ); } public function test_set_settings() { @@ -147,7 +144,7 @@ public function test_set_settings() { ); $response = rest_get_server()->dispatch( $request ); - $this->assertEqualSetsWithIndex( $changed_settings, $response->get_data() ); + $this->assertEqualSetsWithIndex( $changed_settings, $response->get_data(), 'Conversion tracking response should contain changed settings.' ); } public function test_set_settings__requires_authenticated_admin() { @@ -179,7 +176,7 @@ public function test_set_settings__requires_authenticated_admin() { // This request is made by a user who is not authenticated with dashboard // view permissions and is therefore forbidden. - $this->assertEquals( 'rest_forbidden', $response->get_data()['code'] ); + $this->assertEquals( 'rest_forbidden', $response->get_data()['code'], 'Settings update should forbid unauthenticated admins.' ); } /** @@ -213,8 +210,8 @@ function ( $caps, $cap ) { $response = rest_get_server()->dispatch( $request ); - $this->assertEquals( 400, $response->get_status() ); - $this->assertEquals( 'rest_invalid_param', $response->get_data()['code'] ); + $this->assertEquals( 400, $response->get_status(), 'Invalid settings response should use bad request status.' ); + $this->assertEquals( 'rest_invalid_param', $response->get_data()['code'], 'Invalid settings response should include invalid param code.' ); } public function provider_wrong_settings_data() { @@ -238,7 +235,7 @@ public function test_get_api_settings__requires_authenticated_admin() { // This request is made by a user who is not authenticated with dashboard // view permissions and is therefore forbidden. - $this->assertEquals( 'rest_forbidden', $response->get_data()['code'] ); + $this->assertEquals( 'rest_forbidden', $response->get_data()['code'], 'API settings response should forbid unauthenticated admins.' ); } private function grant_manage_options_permission() {