Skip to content

Commit 738ce6a

Browse files
Fixes undefined constant WC_Install::STORE_ID_OPTION error (#10432)
1 parent d7f79a9 commit 738ce6a

File tree

3 files changed

+13
-16
lines changed

3 files changed

+13
-16
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: fix
3+
4+
Fixes incorrect defined statement for WC_Install::STORE_ID_OPTION constant.

includes/class-woopay-tracker.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ private function tracks_build_event_obj( $user, $event_name, $properties = [] )
387387
* @return string|null
388388
*/
389389
public function get_wc_store_id() {
390-
if ( defined( \WC_Install::STORE_ID_OPTION ) ) {
390+
if ( defined( '\WC_Install::STORE_ID_OPTION' ) ) {
391391
return get_option( \WC_Install::STORE_ID_OPTION, null );
392392
}
393393
return null;

tests/unit/test-class-woopay-tracker.php

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class WooPay_Tracker_Test extends WCPAY_UnitTestCase {
1414
/**
1515
* @var WooPay_Tracker
1616
*/
17-
private $mock_tracker;
17+
private $tracker;
1818

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

46-
$this->mock_tracker = $this->getMockBuilder( WooPay_Tracker::class )
47-
->setConstructorArgs( [ $this->http_client_stub ] )
48-
->onlyMethods( [ 'get_wc_store_id' ] )
49-
->getMock();
50-
$this->mock_tracker->method( 'get_wc_store_id' )
51-
->willReturn( 'mock_store_id' );
46+
$this->tracker = new WooPay_Tracker( $this->http_client_stub );
5247

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

7065
$this->setup_woopay_environment( $is_woopay_eligible, $is_account_connected );
71-
$this->assertFalse( $this->mock_tracker->should_enable_tracking() );
66+
$this->assertFalse( $this->tracker->should_enable_tracking() );
7267
}
7368

7469
public function test_does_not_track_admin_pages(): void {
7570
$is_woopay_eligible = true;
7671
$is_account_connected = true;
7772
$is_admin_page = true;
7873
$this->setup_woopay_environment( $is_woopay_eligible, $is_account_connected, $is_admin_page );
79-
$this->assertFalse( $this->mock_tracker->should_enable_tracking() );
74+
$this->assertFalse( $this->tracker->should_enable_tracking() );
8075
}
8176

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

9085
foreach ( $all_roles as $role ) {
9186
wp_get_current_user()->set_role( $role );
92-
$this->assertTrue( $this->mock_tracker->should_enable_tracking() );
87+
$this->assertTrue( $this->tracker->should_enable_tracking() );
9388
}
9489
}
9590

9691
public function test_does_not_track_when_account_not_connected(): void {
9792
$is_woopay_eligible = true;
9893
$is_account_connected = false;
9994
$this->setup_woopay_environment( $is_woopay_eligible, $is_account_connected );
100-
$this->assertFalse( $this->mock_tracker->should_enable_tracking() );
95+
$this->assertFalse( $this->tracker->should_enable_tracking() );
10196
}
10297

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

108-
$event_obj = $this->invoke_method( $this->mock_tracker, 'tracks_build_event_obj', [ wp_get_current_user(), $event_name, $properties ] );
103+
$event_obj = $this->invoke_method( $this->tracker, 'tracks_build_event_obj', [ wp_get_current_user(), $event_name, $properties ] );
109104
$this->assertEquals( 'value', $event_obj->test_property );
110105
$this->assertEquals( 1234, $event_obj->_ui );
111-
$this->assertEquals( 'mock_store_id', $event_obj->store_id );
112106
$this->assertEquals( $event_name, $event_obj->_en );
113107
}
114108

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

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

122116
$this->assertInstanceOf( Jetpack_Tracks_Event::class, $event_obj );
123117
$this->assertEquals( 'value', $event_obj->test_property );
124118
$this->assertEquals( 1234, $event_obj->_ui );
125-
$this->assertEquals( 'mock_store_id', $event_obj->store_id );
126119
$this->assertEquals( $event_name, $event_obj->_en );
127120
}
128121

0 commit comments

Comments
 (0)