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

Update catalog link to navigate to correct tab in Commerce Manager #2848

Merged
merged 4 commits into from
Jan 21, 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
15 changes: 11 additions & 4 deletions includes/Admin/Settings_Screens/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] ) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed assignment within a conditional statement


$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(),
)
);
}
}

Expand Down
51 changes: 51 additions & 0 deletions tests/Unit/Admin/Settings/ConnectionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace WooCommerce\Facebook\Tests\Unit;

use WooCommerce\Facebook\Admin\Settings_Screens\Connection;

class ConnectionTest extends \WP_UnitTestCase {

private $connection;

protected function setUp(): void {
parent::setUp();
$this->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']);
}
}
Loading