Skip to content

Commit 82791a0

Browse files
authored
Merge pull request #12899 from google/infrastructure/11345-phpunit-assert-conversion
Add PHPUnit messages for conversion tracking test assertions.
2 parents 0d877bc + 0a6010c commit 82791a0

11 files changed

Lines changed: 106 additions & 136 deletions

tests/phpunit/integration/Core/Conversion_Tracking/Conversion_Event_Providers/Contact_Form_7Test.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
66
* @link https://sitekit.withgoogle.com
77
*/
8-
// phpcs:disable PHPCS.PHPUnit.RequireAssertionMessage.MissingAssertionMessage -- Ignoring assertion message rule, messages to be added in #10760
9-
10-
118
namespace Google\Tests\Core\Conversion_Tracking\Conversion_Event_Providers;
129

1310
use Google\Site_Kit\Context;
@@ -35,23 +32,23 @@ public function set_up() {
3532
* @runInSeparateProcess
3633
*/
3734
public function test_is_active() {
38-
$this->assertFalse( $this->contactform->is_active() );
35+
$this->assertFalse( $this->contactform->is_active(), 'Contact Form 7 provider should not be active before plugin constant.' );
3936
define( 'WPCF7_VERSION', 1 );
40-
$this->assertTrue( $this->contactform->is_active() );
37+
$this->assertTrue( $this->contactform->is_active(), 'Contact Form 7 provider should be active after plugin constant.' );
4138
}
4239

4340
public function test_get_event_names() {
4441
$events = $this->contactform->get_event_names();
45-
$this->assertCount( 1, $events );
46-
$this->assertEquals( 'contact', $events[0] );
42+
$this->assertCount( 1, $events, 'Contact Form 7 provider should expose one event.' );
43+
$this->assertEquals( 'contact', $events[0], 'Contact Form 7 event should be contact.' );
4744
}
4845

4946
public function test_register_script() {
5047
$handle = 'googlesitekit-events-provider-' . Contact_Form_7::CONVERSION_EVENT_PROVIDER_SLUG;
51-
$this->assertFalse( wp_script_is( $handle, 'registered' ) );
48+
$this->assertFalse( wp_script_is( $handle, 'registered' ), 'Contact Form 7 script should not be registered initially.' );
5249

5350
$script = $this->contactform->register_script();
54-
$this->assertInstanceOf( Script::class, $script );
55-
$this->assertTrue( wp_script_is( $handle, 'registered' ) );
51+
$this->assertInstanceOf( Script::class, $script, 'Contact Form 7 provider should return a script.' );
52+
$this->assertTrue( wp_script_is( $handle, 'registered' ), 'Contact Form 7 script should be registered.' );
5653
}
5754
}

tests/phpunit/integration/Core/Conversion_Tracking/Conversion_Event_Providers/Easy_Digital_DownloadsTest.php

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
66
* @link https://sitekit.withgoogle.com
77
*/
8-
// phpcs:disable PHPCS.PHPUnit.RequireAssertionMessage.MissingAssertionMessage -- Ignoring assertion message rule, messages to be added in #10760
9-
10-
118
namespace Google\Tests\Core\Conversion_Tracking\Conversion_Event_Providers;
129

1310
use Google\Site_Kit\Context;
@@ -33,27 +30,27 @@ public function set_up() {
3330
* @runInSeparateProcess
3431
*/
3532
public function test_is_active() {
36-
$this->assertFalse( $this->edd->is_active() );
33+
$this->assertFalse( $this->edd->is_active(), 'EDD provider should not be active before plugin constant.' );
3734
define( 'EDD_VERSION', 1 );
38-
$this->assertTrue( $this->edd->is_active() );
35+
$this->assertTrue( $this->edd->is_active(), 'EDD provider should be active after plugin constant.' );
3936
}
4037

4138

4239

4340
public function test_get_event_names() {
4441
$events = $this->edd->get_event_names();
45-
$this->assertCount( 2, $events );
46-
$this->assertEquals( array( 'add_to_cart', 'purchase' ), $events );
42+
$this->assertCount( 2, $events, 'EDD provider should expose two events.' );
43+
$this->assertEquals( array( 'add_to_cart', 'purchase' ), $events, 'EDD events should include add to cart and purchase.' );
4744
}
4845

4946

5047
public function test_register_script() {
5148
$handle = 'googlesitekit-events-provider-' . Easy_Digital_Downloads::CONVERSION_EVENT_PROVIDER_SLUG;
52-
$this->assertFalse( wp_script_is( $handle, 'registered' ) );
49+
$this->assertFalse( wp_script_is( $handle, 'registered' ), 'EDD script should not be registered initially.' );
5350

5451
$script = $this->edd->register_script();
55-
$this->assertInstanceOf( Script::class, $script );
56-
$this->assertTrue( wp_script_is( $handle, 'registered' ) );
52+
$this->assertInstanceOf( Script::class, $script, 'EDD provider should return a script.' );
53+
$this->assertTrue( wp_script_is( $handle, 'registered' ), 'EDD script should be registered.' );
5754
}
5855

5956
public function test_register_hook() {
@@ -74,12 +71,12 @@ public function test_get_enhanced_conversions_data_from_session_returns_expected
7471
$result = $method->invoke( $this->edd, $session_data );
7572
$expected_without_user_data = $expected;
7673
unset( $expected_without_user_data['user_data'] );
77-
$this->assertEquals( $expected_without_user_data, $result );
74+
$this->assertEquals( $expected_without_user_data, $result, 'EDD session data should omit user data when feature disabled.' );
7875

7976
$this->enable_feature( 'gtagUserData' );
8077

8178
$result = $method->invoke( $this->edd, $session_data );
82-
$this->assertEquals( $expected, $result );
79+
$this->assertEquals( $expected, $result, 'EDD session data should include expected conversion data.' );
8380
}
8481

8582
/**
@@ -91,7 +88,7 @@ public function test_extract_user_data_from_session_returns_expected_data( $sess
9188
$method->setAccessible( true );
9289

9390
$result = $method->invoke( $this->edd, $session_data );
94-
$this->assertSame( $expected, $result );
91+
$this->assertSame( $expected, $result, 'EDD session user data should match expected user data.' );
9592
}
9693

9794
public function enhanced_conversion_session_provider() {

tests/phpunit/integration/Core/Conversion_Tracking/Conversion_Event_Providers/MailchimpTest.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
66
* @link https://sitekit.withgoogle.com
77
*/
8-
// phpcs:disable PHPCS.PHPUnit.RequireAssertionMessage.MissingAssertionMessage -- Ignoring assertion message rule, messages to be added in #10760
9-
10-
118
namespace Google\Tests\Core\Conversion_Tracking\Conversion_Event_Providers;
129

1310
use Google\Site_Kit\Context;
@@ -35,23 +32,23 @@ public function set_up() {
3532
* @runInSeparateProcess
3633
*/
3734
public function test_is_active() {
38-
$this->assertFalse( $this->mailchimp->is_active() );
35+
$this->assertFalse( $this->mailchimp->is_active(), 'Mailchimp provider should not be active before plugin constant.' );
3936
define( 'MC4WP_VERSION', 1 );
40-
$this->assertTrue( $this->mailchimp->is_active() );
37+
$this->assertTrue( $this->mailchimp->is_active(), 'Mailchimp provider should be active after plugin constant.' );
4138
}
4239

4340
public function test_get_event_names() {
4441
$events = $this->mailchimp->get_event_names();
45-
$this->assertCount( 1, $events );
46-
$this->assertEquals( 'submit_lead_form', $events[0] );
42+
$this->assertCount( 1, $events, 'Mailchimp provider should expose one event.' );
43+
$this->assertEquals( 'submit_lead_form', $events[0], 'Mailchimp event should be submit_lead_form.' );
4744
}
4845

4946
public function test_register_script() {
5047
$handle = 'googlesitekit-events-provider-' . Mailchimp::CONVERSION_EVENT_PROVIDER_SLUG;
51-
$this->assertFalse( wp_script_is( $handle, 'registered' ) );
48+
$this->assertFalse( wp_script_is( $handle, 'registered' ), 'Mailchimp script should not be registered initially.' );
5249

5350
$script = $this->mailchimp->register_script();
54-
$this->assertInstanceOf( Script::class, $script );
55-
$this->assertTrue( wp_script_is( $handle, 'registered' ) );
51+
$this->assertInstanceOf( Script::class, $script, 'Mailchimp provider should return a script.' );
52+
$this->assertTrue( wp_script_is( $handle, 'registered' ), 'Mailchimp script should be registered.' );
5653
}
5754
}

tests/phpunit/integration/Core/Conversion_Tracking/Conversion_Event_Providers/Ninja_FormsTest.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
66
* @link https://sitekit.withgoogle.com
77
*/
8-
// phpcs:disable PHPCS.PHPUnit.RequireAssertionMessage.MissingAssertionMessage -- Ignoring assertion message rule, messages to be added in #10760
9-
10-
118
namespace Google\Tests\Core\Conversion_Tracking\Conversion_Event_Providers;
129

1310
use Google\Site_Kit\Context;
@@ -35,23 +32,23 @@ public function set_up() {
3532
* @runInSeparateProcess
3633
*/
3734
public function test_is_active() {
38-
$this->assertFalse( $this->ninjaform->is_active() );
35+
$this->assertFalse( $this->ninjaform->is_active(), 'Ninja Forms provider should not be active before plugin constant.' );
3936
define( 'NF_PLUGIN_URL', 1 );
40-
$this->assertTrue( $this->ninjaform->is_active() );
37+
$this->assertTrue( $this->ninjaform->is_active(), 'Ninja Forms provider should be active after plugin constant.' );
4138
}
4239

4340
public function test_get_event_names() {
4441
$events = $this->ninjaform->get_event_names();
45-
$this->assertCount( 1, $events );
46-
$this->assertEquals( 'submit_lead_form', $events[0] );
42+
$this->assertCount( 1, $events, 'Ninja Forms provider should expose one event.' );
43+
$this->assertEquals( 'submit_lead_form', $events[0], 'Ninja Forms event should be submit_lead_form.' );
4744
}
4845

4946
public function test_register_script() {
5047
$handle = 'googlesitekit-events-provider-' . Ninja_Forms::CONVERSION_EVENT_PROVIDER_SLUG;
51-
$this->assertFalse( wp_script_is( $handle, 'registered' ) );
48+
$this->assertFalse( wp_script_is( $handle, 'registered' ), 'Ninja Forms script should not be registered initially.' );
5249

5350
$script = $this->ninjaform->register_script();
54-
$this->assertInstanceOf( Script::class, $script );
55-
$this->assertTrue( wp_script_is( $handle, 'registered' ) );
51+
$this->assertInstanceOf( Script::class, $script, 'Ninja Forms provider should return a script.' );
52+
$this->assertTrue( wp_script_is( $handle, 'registered' ), 'Ninja Forms script should be registered.' );
5653
}
5754
}

tests/phpunit/integration/Core/Conversion_Tracking/Conversion_Event_Providers/OptinMonsterTest.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
66
* @link https://sitekit.withgoogle.com
77
*/
8-
// phpcs:disable PHPCS.PHPUnit.RequireAssertionMessage.MissingAssertionMessage -- Ignoring assertion message rule, messages to be added in #10760
9-
10-
118
namespace Google\Tests\Core\Conversion_Tracking\Conversion_Event_Providers;
129

1310
use Google\Site_Kit\Context;
@@ -35,23 +32,23 @@ public function set_up() {
3532
* @runInSeparateProcess
3633
*/
3734
public function test_is_active() {
38-
$this->assertFalse( $this->optinmonster->is_active() );
35+
$this->assertFalse( $this->optinmonster->is_active(), 'OptinMonster provider should not be active before plugin constant.' );
3936
define( 'OMAPI_FILE', 1 );
40-
$this->assertTrue( $this->optinmonster->is_active() );
37+
$this->assertTrue( $this->optinmonster->is_active(), 'OptinMonster provider should be active after plugin constant.' );
4138
}
4239

4340
public function test_get_event_names() {
4441
$events = $this->optinmonster->get_event_names();
45-
$this->assertCount( 1, $events );
46-
$this->assertEquals( 'submit_lead_form', $events[0] );
42+
$this->assertCount( 1, $events, 'OptinMonster provider should expose one event.' );
43+
$this->assertEquals( 'submit_lead_form', $events[0], 'OptinMonster event should be submit_lead_form.' );
4744
}
4845

4946
public function test_register_script() {
5047
$handle = 'googlesitekit-events-provider-' . OptinMonster::CONVERSION_EVENT_PROVIDER_SLUG;
51-
$this->assertFalse( wp_script_is( $handle, 'registered' ) );
48+
$this->assertFalse( wp_script_is( $handle, 'registered' ), 'OptinMonster script should not be registered initially.' );
5249

5350
$script = $this->optinmonster->register_script();
54-
$this->assertInstanceOf( Script::class, $script );
55-
$this->assertTrue( wp_script_is( $handle, 'registered' ) );
51+
$this->assertInstanceOf( Script::class, $script, 'OptinMonster provider should return a script.' );
52+
$this->assertTrue( wp_script_is( $handle, 'registered' ), 'OptinMonster script should be registered.' );
5653
}
5754
}

tests/phpunit/integration/Core/Conversion_Tracking/Conversion_Event_Providers/PopupMakerTest.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
66
* @link https://sitekit.withgoogle.com
77
*/
8-
// phpcs:disable PHPCS.PHPUnit.RequireAssertionMessage.MissingAssertionMessage -- Ignoring assertion message rule, messages to be added in #10760
9-
10-
118
namespace Google\Tests\Core\Conversion_Tracking\Conversion_Event_Providers;
129

1310
use Google\Site_Kit\Context;
@@ -35,24 +32,24 @@ public function set_up() {
3532
* @runInSeparateProcess
3633
*/
3734
public function test_is_active() {
38-
$this->assertFalse( $this->popupmaker->is_active() );
35+
$this->assertFalse( $this->popupmaker->is_active(), 'Popup Maker provider should not be active before plugin constant.' );
3936
define( 'POPMAKE_VERSION', 1 );
40-
$this->assertTrue( $this->popupmaker->is_active() );
37+
$this->assertTrue( $this->popupmaker->is_active(), 'Popup Maker provider should be active after plugin constant.' );
4138
}
4239

4340
public function test_get_event_names() {
4441
$events = $this->popupmaker->get_event_names();
45-
$this->assertCount( 1, $events );
46-
$this->assertEquals( 'submit_lead_form', $events[0] );
42+
$this->assertCount( 1, $events, 'Popup Maker provider should expose one event.' );
43+
$this->assertEquals( 'submit_lead_form', $events[0], 'Popup Maker event should be submit_lead_form.' );
4744
}
4845

4946
public function test_register_script() {
5047
$handle = 'googlesitekit-events-provider-' . PopupMaker::CONVERSION_EVENT_PROVIDER_SLUG;
51-
$this->assertFalse( wp_script_is( $handle, 'registered' ) );
48+
$this->assertFalse( wp_script_is( $handle, 'registered' ), 'Popup Maker script should not be registered initially.' );
5249

5350
$script = $this->popupmaker->register_script();
5451

55-
$this->assertInstanceOf( Script::class, $script );
56-
$this->assertTrue( wp_script_is( $handle, 'registered' ) );
52+
$this->assertInstanceOf( Script::class, $script, 'Popup Maker provider should return a script.' );
53+
$this->assertTrue( wp_script_is( $handle, 'registered' ), 'Popup Maker script should be registered.' );
5754
}
5855
}

tests/phpunit/integration/Core/Conversion_Tracking/Conversion_Event_Providers/WPFormsTest.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
66
* @link https://sitekit.withgoogle.com
77
*/
8-
// phpcs:disable PHPCS.PHPUnit.RequireAssertionMessage.MissingAssertionMessage -- Ignoring assertion message rule, messages to be added in #10760
9-
10-
118
namespace Google\Tests\Core\Conversion_Tracking\Conversion_Event_Providers;
129

1310
use Google\Site_Kit\Context;
@@ -35,23 +32,23 @@ public function set_up() {
3532
* @runInSeparateProcess
3633
*/
3734
public function test_is_active() {
38-
$this->assertFalse( $this->wpforms->is_active() );
35+
$this->assertFalse( $this->wpforms->is_active(), 'WPForms provider should not be active before plugin constant.' );
3936
define( 'WPFORMS_VERSION', 1 );
40-
$this->assertTrue( $this->wpforms->is_active() );
37+
$this->assertTrue( $this->wpforms->is_active(), 'WPForms provider should be active after plugin constant.' );
4138
}
4239

4340
public function test_get_event_names() {
4441
$events = $this->wpforms->get_event_names();
45-
$this->assertCount( 1, $events );
46-
$this->assertEquals( 'submit_lead_form', $events[0] );
42+
$this->assertCount( 1, $events, 'WPForms provider should expose one event.' );
43+
$this->assertEquals( 'submit_lead_form', $events[0], 'WPForms event should be submit_lead_form.' );
4744
}
4845

4946
public function test_register_script() {
5047
$handle = 'googlesitekit-events-provider-' . WPForms::CONVERSION_EVENT_PROVIDER_SLUG;
51-
$this->assertFalse( wp_script_is( $handle, 'registered' ) );
48+
$this->assertFalse( wp_script_is( $handle, 'registered' ), 'WPForms script should not be registered initially.' );
5249

5350
$script = $this->wpforms->register_script();
54-
$this->assertInstanceOf( Script::class, $script );
55-
$this->assertTrue( wp_script_is( $handle, 'registered' ) );
51+
$this->assertInstanceOf( Script::class, $script, 'WPForms provider should return a script.' );
52+
$this->assertTrue( wp_script_is( $handle, 'registered' ), 'WPForms script should be registered.' );
5653
}
5754
}

tests/phpunit/integration/Core/Conversion_Tracking/Conversion_Event_Providers/WooCommerceTest.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
66
* @link https://sitekit.withgoogle.com
77
*/
8-
// phpcs:disable PHPCS.PHPUnit.RequireAssertionMessage.MissingAssertionMessage -- Ignoring assertion message rule, messages to be added in #10760
9-
10-
118
namespace Google\Tests\Core\Conversion_Tracking\Conversion_Event_Providers;
129

1310
use Google\Site_Kit\Context;
@@ -34,12 +31,12 @@ public function set_up() {
3431
* @runInSeparateProcess
3532
*/
3633
public function test_is_active() {
37-
$this->assertFalse( $this->woocommerce->is_active() );
34+
$this->assertFalse( $this->woocommerce->is_active(), 'WooCommerce provider should not be active before class exists.' );
3835

3936
// Fake the existence of the `WooCommerce` class.
4037
class_alias( __CLASS__, 'WooCommerce' );
4138

42-
$this->assertTrue( $this->woocommerce->is_active() );
39+
$this->assertTrue( $this->woocommerce->is_active(), 'WooCommerce provider should be active after class exists.' );
4340
}
4441

4542
public function test_events_to_track() {
@@ -300,7 +297,7 @@ class_alias( 'Google\Site_Kit\Tests\WC_Countries_Fake', 'WC_Countries' );
300297

301298
$result = $method->invoke( $this->woocommerce, $phone, $country );
302299

303-
$this->assertEquals( $expected, $result );
300+
$this->assertEquals( $expected, $result, 'Normalized WooCommerce phone should match expected value.' );
304301
}
305302

306303
public function phone_normalization_data_provider() {
@@ -446,6 +443,6 @@ public function test_get_normalized_phone_fallback() {
446443

447444
// Should fallback to Enhanced_Conversions::get_normalized_value().
448445
// Enhanced_Conversions normalizes to lowercase and trims, but keeps other chars.
449-
$this->assertEquals( '+94771770589', $result );
446+
$this->assertEquals( '+94771770589', $result, 'Normalized phone should fall back when country is empty.' );
450447
}
451448
}

0 commit comments

Comments
 (0)