diff --git a/includes/Admin/Settings_Screens/Connection.php b/includes/Admin/Settings_Screens/Connection.php index ccadcc47..5555df2d 100644 --- a/includes/Admin/Settings_Screens/Connection.php +++ b/includes/Admin/Settings_Screens/Connection.php @@ -159,16 +159,23 @@ public function render() { ); // if the catalog ID is set, update the URL and try to get its name for display - if ( $catalog_id = $static_items['catalog']['value'] ) { - - $static_items['catalog']['url'] = "https://facebook.com/products/catalogs/{$catalog_id}"; - + $catalog_id = $static_items['catalog']['value']; + if ( !empty( $catalog_id ) ) { + $static_items['catalog']['url'] = "https://www.facebook.com/commerce/catalogs/{$catalog_id}/products/"; try { $response = facebook_for_woocommerce()->get_api()->get_catalog( $catalog_id ); if ( $name = $response->name ) { $static_items['catalog']['value'] = $name; } } catch ( ApiException $exception ) { + // Log the exception with additional information + facebook_for_woocommerce()->log( + sprintf( + 'Connection failed for catalog %s: %s ', + $catalog_id, + $exception->getMessage(), + ) + ); } } diff --git a/tests/Unit/Admin/Settings/ConnectionTest.php b/tests/Unit/Admin/Settings/ConnectionTest.php new file mode 100644 index 00000000..18a94e4d --- /dev/null +++ b/tests/Unit/Admin/Settings/ConnectionTest.php @@ -0,0 +1,51 @@ +connection = new Connection(); + } + + public function testEnqueueAssetsWhenNotOnPage(): void { + // Mock is_current_screen_page to return false + $connection = $this->getMockBuilder(Connection::class) + ->onlyMethods(['is_current_screen_page']) + ->getMock(); + + $connection->method('is_current_screen_page') + ->willReturn(false); + + // No styles should be enqueued + $connection->enqueue_assets(); + + $this->assertFalse(wp_style_is('wc-facebook-admin-connection-settings')); + } + + public function testGetSettings(): void { + $settings = $this->connection->get_settings(); + + $this->assertIsArray($settings); + $this->assertNotEmpty($settings); + + // Check that the settings array has the expected structure + $this->assertArrayHasKey('type', $settings[0]); + $this->assertEquals('title', $settings[0]['type']); + + // Check debug mode setting + $debug_setting = $settings[1]; + $this->assertEquals('checkbox', $debug_setting['type']); + $this->assertEquals('no', $debug_setting['default']); + + // Check feed generator setting + $feed_setting = $settings[2]; + $this->assertEquals('checkbox', $feed_setting['type']); + $this->assertEquals('no', $feed_setting['default']); + } +}