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

Fixes undefined constant WC_Install::STORE_ID_OPTION error #10432

Merged
merged 3 commits into from
Feb 24, 2025
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
4 changes: 4 additions & 0 deletions changelog/fix-woopay-tracker-undefined-wc-store-id
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

Fixes incorrect defined statement for WC_Install::STORE_ID_OPTION constant.
2 changes: 1 addition & 1 deletion includes/class-woopay-tracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ private function tracks_build_event_obj( $user, $event_name, $properties = [] )
* @return string|null
*/
public function get_wc_store_id() {
if ( defined( \WC_Install::STORE_ID_OPTION ) ) {
if ( defined( '\WC_Install::STORE_ID_OPTION' ) ) {
return get_option( \WC_Install::STORE_ID_OPTION, null );
}
return null;
Expand Down
23 changes: 8 additions & 15 deletions tests/unit/test-class-woopay-tracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class WooPay_Tracker_Test extends WCPAY_UnitTestCase {
/**
* @var WooPay_Tracker
*/
private $mock_tracker;
private $tracker;

/**
* @var WC_Payments_Http
Expand Down Expand Up @@ -43,12 +43,7 @@ public function setUp(): void {
$this->http_client_stub->method( 'is_user_connected' )->willReturn( true );
$this->http_client_stub->method( 'get_connected_user_data' )->willReturn( [ 'ID' => 1234 ] );

$this->mock_tracker = $this->getMockBuilder( WooPay_Tracker::class )
->setConstructorArgs( [ $this->http_client_stub ] )
->onlyMethods( [ 'get_wc_store_id' ] )
->getMock();
$this->mock_tracker->method( 'get_wc_store_id' )
->willReturn( 'mock_store_id' );
$this->tracker = new WooPay_Tracker( $this->http_client_stub );

$this->cache = WC_Payments::get_database_cache();
$this->mock_cache = $this->createMock( WCPay\Database_Cache::class );
Expand All @@ -68,15 +63,15 @@ public function test_tracks_obeys_woopay_flag(): void {
$is_account_connected = true;

$this->setup_woopay_environment( $is_woopay_eligible, $is_account_connected );
$this->assertFalse( $this->mock_tracker->should_enable_tracking() );
$this->assertFalse( $this->tracker->should_enable_tracking() );
}

public function test_does_not_track_admin_pages(): void {
$is_woopay_eligible = true;
$is_account_connected = true;
$is_admin_page = true;
$this->setup_woopay_environment( $is_woopay_eligible, $is_account_connected, $is_admin_page );
$this->assertFalse( $this->mock_tracker->should_enable_tracking() );
$this->assertFalse( $this->tracker->should_enable_tracking() );
}

public function test_does_track_non_admins(): void {
Expand All @@ -89,26 +84,25 @@ public function test_does_track_non_admins(): void {

foreach ( $all_roles as $role ) {
wp_get_current_user()->set_role( $role );
$this->assertTrue( $this->mock_tracker->should_enable_tracking() );
$this->assertTrue( $this->tracker->should_enable_tracking() );
}
}

public function test_does_not_track_when_account_not_connected(): void {
$is_woopay_eligible = true;
$is_account_connected = false;
$this->setup_woopay_environment( $is_woopay_eligible, $is_account_connected );
$this->assertFalse( $this->mock_tracker->should_enable_tracking() );
$this->assertFalse( $this->tracker->should_enable_tracking() );
}

public function test_tracks_build_event_obj_for_admin_events(): void {
$this->set_account_connected( true );
$event_name = 'wcadmin_test_event';
$properties = [ 'test_property' => 'value' ];

$event_obj = $this->invoke_method( $this->mock_tracker, 'tracks_build_event_obj', [ wp_get_current_user(), $event_name, $properties ] );
$event_obj = $this->invoke_method( $this->tracker, 'tracks_build_event_obj', [ wp_get_current_user(), $event_name, $properties ] );
$this->assertEquals( 'value', $event_obj->test_property );
$this->assertEquals( 1234, $event_obj->_ui );
$this->assertEquals( 'mock_store_id', $event_obj->store_id );
$this->assertEquals( $event_name, $event_obj->_en );
}

Expand All @@ -117,12 +111,11 @@ public function test_tracks_build_event_obj_for_shopper_events() {
$event_name = 'wcpay_test_event';
$properties = [ 'test_property' => 'value' ];

$event_obj = $this->invoke_method( $this->mock_tracker, 'tracks_build_event_obj', [ wp_get_current_user(), $event_name, $properties ] );
$event_obj = $this->invoke_method( $this->tracker, 'tracks_build_event_obj', [ wp_get_current_user(), $event_name, $properties ] );

$this->assertInstanceOf( Jetpack_Tracks_Event::class, $event_obj );
$this->assertEquals( 'value', $event_obj->test_property );
$this->assertEquals( 1234, $event_obj->_ui );
$this->assertEquals( 'mock_store_id', $event_obj->store_id );
$this->assertEquals( $event_name, $event_obj->_en );
}

Expand Down
Loading