mirror of
https://github.com/wp-graphql/wp-graphql-woocommerce.git
synced 2026-08-14 12:53:44 +02:00
* feat: WC Settings API, compatibility refactor, HPOS fix, CI improvements WC Settings GraphQL API: - Add WCSetting interface with common fields and type-safe resolveType - Add concrete types: WCStringSetting, WCArraySetting, WCRelativeDateSetting, WCImageWidthSetting with typed value/default fields - Add WCSettingGroup type with nested settings field - Add wcSettingGroups and wcSettings root query fields (admin only) - Add updateWCSetting and updateWCSettings mutations - Dynamic WCSettingTypeEnum collected from registered WC settings - Filters: graphql_woocommerce_setting_type_map, graphql_woocommerce_setting_types - Register WC admin settings for GraphQL requests via Compatibility class Compatibility refactor: - Consolidate ACF, JWT Auth, and QL Search filters into Compatibility class - Remove class-acf-schema-filters.php, class-jwt-auth-schema-filters.php, functions.php HPOS compatibility fix: - Replace hardcoded directory name check with dirname(__DIR__) === WP_PLUGIN_DIR - Works with any plugin folder name while still skipping nested vendor installs CI improvements: - Remove STRIPE_API_PUBLISHABLE_KEY restriction from coverage job - Add HPOS to coverage matrix entries - Sort type registry and includes alphabetically Other fixes: - Fix Settings_Mutation::validate_setting_checkbox_field to be static - Update ShippingZone settings field type to WCStringSetting Closes #864, closes #969 * refactor: Rename and split core classes, add order cursor pagination tests Class renames: - WooCommerce_Filters → WooCommerce (class-woocommerce.php), setup() → init() - Core_Schema_Filters → Post_Types (class-post-types.php) Class split: - Extract taxonomy registration from Core_Schema_Filters into Taxonomies (class-taxonomies.php) Access functions: - Add wc_graphql_resolve_product_type() for interface resolveType callbacks - Add wc_graphql_is_session_handler_disabled() - Add wc_graphql_enabled_authorizing_url_fields() - Add wc_graphql_get_authorizing_url_nonce_param_name() - Replace direct class references with global functions in type-registry, compatibility, protected-router, and all product interface files Stripe gateway compatibility: - Move woographql_stripe_gateway_args from WooCommerce to Compatibility class - Rename to woocommerce_gateway_stripe_args Tests: - Add OrderCursorPaginationTest (6 tests) covering COT cursor-based pagination: forward/backward, date ordering ASC/DESC, cursor integrity * fix: Use proper expectedField/expectedNode assertions in cursor pagination tests Replace empty assertQuerySuccessful([]) calls and manual lodashGet assertions with expectedField, expectedNode, and not()->expectedNode() for proper GraphQL response validation.
137 lines
3.0 KiB
PHP
137 lines
3.0 KiB
PHP
<?php
|
|
|
|
class WCSettingsQueriesTest extends \Tests\WPGraphQL\WooCommerce\TestCase\WooGraphQLTestCase {
|
|
public function testWcSettingGroupsQueryAsAdmin() {
|
|
$this->loginAsShopManager();
|
|
|
|
$query = '
|
|
query {
|
|
wcSettingGroups {
|
|
id
|
|
label
|
|
description
|
|
parentId
|
|
subGroups
|
|
}
|
|
}
|
|
';
|
|
|
|
$response = $this->graphql( compact( 'query' ) );
|
|
|
|
$this->assertQuerySuccessful( $response, [] );
|
|
|
|
$groups = $this->lodashGet( $response, 'data.wcSettingGroups' );
|
|
$this->assertNotEmpty( $groups, 'Should return at least one setting group.' );
|
|
|
|
$group_ids = array_column( $groups, 'id' );
|
|
$this->assertContains( 'general', $group_ids, 'Should contain the "general" settings group.' );
|
|
}
|
|
|
|
public function testWcSettingGroupsQueryAsCustomerFails() {
|
|
$customer_id = $this->factory->customer->create();
|
|
$this->loginAs( $customer_id );
|
|
|
|
$query = '
|
|
query {
|
|
wcSettingGroups {
|
|
id
|
|
}
|
|
}
|
|
';
|
|
|
|
$response = $this->graphql( compact( 'query' ) );
|
|
|
|
$this->assertQueryError(
|
|
$response,
|
|
[ $this->expectedErrorMessage( 'Sorry, you cannot view settings.', self::MESSAGE_EQUALS ) ]
|
|
);
|
|
}
|
|
|
|
public function testWcSettingsQueryReturnsGroupSettings() {
|
|
$this->loginAsShopManager();
|
|
|
|
$query = '
|
|
query ($group: String!) {
|
|
wcSettings(group: $group) {
|
|
id
|
|
label
|
|
description
|
|
type
|
|
tip
|
|
placeholder
|
|
groupId
|
|
options
|
|
... on WCStringSetting {
|
|
value
|
|
default
|
|
}
|
|
}
|
|
}
|
|
';
|
|
|
|
$variables = [ 'group' => 'general' ];
|
|
$response = $this->graphql( compact( 'query', 'variables' ) );
|
|
|
|
$this->assertQuerySuccessful( $response, [] );
|
|
|
|
$settings = $this->lodashGet( $response, 'data.wcSettings' );
|
|
$this->assertNotEmpty( $settings, 'Should return settings for the "general" group.' );
|
|
|
|
$setting_ids = array_column( $settings, 'id' );
|
|
$this->assertContains( 'woocommerce_store_address', $setting_ids, 'Should contain the store address setting.' );
|
|
}
|
|
|
|
public function testWcSettingsQueryInvalidGroupFails() {
|
|
$this->loginAsShopManager();
|
|
|
|
$query = '
|
|
query ($group: String!) {
|
|
wcSettings(group: $group) {
|
|
id
|
|
}
|
|
}
|
|
';
|
|
|
|
$variables = [ 'group' => 'nonexistent_group' ];
|
|
$response = $this->graphql( compact( 'query', 'variables' ) );
|
|
|
|
$this->assertQueryError( $response );
|
|
}
|
|
|
|
public function testWcSettingGroupSettingsField() {
|
|
$this->loginAsShopManager();
|
|
|
|
$query = '
|
|
query {
|
|
wcSettingGroups {
|
|
id
|
|
settings {
|
|
id
|
|
label
|
|
type
|
|
... on WCStringSetting {
|
|
value
|
|
}
|
|
}
|
|
}
|
|
}
|
|
';
|
|
|
|
$response = $this->graphql( compact( 'query' ) );
|
|
|
|
$this->assertQuerySuccessful( $response, [] );
|
|
|
|
$groups = $this->lodashGet( $response, 'data.wcSettingGroups' );
|
|
$general = null;
|
|
foreach ( $groups as $group ) {
|
|
if ( 'general' === $group['id'] ) {
|
|
$general = $group;
|
|
break;
|
|
}
|
|
}
|
|
|
|
$this->assertNotNull( $general, 'Should find the "general" group.' );
|
|
$this->assertNotEmpty( $general['settings'], 'General group should have settings.' );
|
|
}
|
|
}
|