@@ -372,6 +372,48 @@ public function test_track_settings_linker_allow_incoming_normalization() {
372372 $ this ->assertEquals ( 'no ' , $ data ['wc-google-analytics ' ]['linker_allow_incoming_enabled ' ] );
373373 }
374374
375+ /**
376+ * Test that $this->settings is fully populated when the database contains only the partial
377+ * defaults written by maybe_set_defaults() on a fresh activation.
378+ *
379+ * @return void
380+ */
381+ public function test_settings_are_complete_after_partial_activation_defaults () {
382+ // Simulate what maybe_set_defaults() writes on a fresh install.
383+ update_option ( 'woocommerce_google_analytics_settings ' , [ 'ga_product_identifier ' => 'product_id ' ] );
384+
385+ $ ga = new WC_Google_Analytics ();
386+
387+ $ reflection = new \ReflectionProperty ( WC_Google_Analytics::class, 'settings ' );
388+ $ reflection ->setAccessible ( true );
389+ $ settings = $ reflection ->getValue ( $ ga );
390+
391+ $ expected_keys = [
392+ 'ga_product_identifier ' ,
393+ 'ga_id ' ,
394+ 'ga_support_display_advertising ' ,
395+ 'ga_404_tracking_enabled ' ,
396+ 'ga_linker_allow_incoming_enabled ' ,
397+ 'ga_ecommerce_tracking_enabled ' ,
398+ 'ga_event_tracking_enabled ' ,
399+ 'ga_enhanced_remove_from_cart_enabled ' ,
400+ 'ga_enhanced_product_impression_enabled ' ,
401+ 'ga_enhanced_product_click_enabled ' ,
402+ 'ga_enhanced_product_detail_view_enabled ' ,
403+ 'ga_enhanced_checkout_process_enabled ' ,
404+ 'ga_linker_cross_domains ' ,
405+ ];
406+
407+ foreach ( $ expected_keys as $ key ) {
408+ $ this ->assertArrayHasKey ( $ key , $ settings , "Expected ' {$ key }' to be present in settings after construction with partial defaults. " );
409+ }
410+
411+ // The value set by maybe_set_defaults() should be preserved, not overwritten.
412+ $ this ->assertEquals ( 'product_id ' , $ settings ['ga_product_identifier ' ] );
413+
414+ delete_option ( 'woocommerce_google_analytics_settings ' );
415+ }
416+
375417 /**
376418 * Call a protected or private method via reflection.
377419 *
0 commit comments