Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.' );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() {
Expand All @@ -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.' );
}

/**
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.' );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.' );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.' );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.' );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.' );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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.' );
}
}
Loading