2019-03-13 12:31:37 -04:00
|
|
|
<?php
|
2020-10-22 15:59:11 -04:00
|
|
|
class ProductQueriesTest extends \Tests\WPGraphQL\WooCommerce\TestCase\WooGraphQLTestCase {
|
2020-07-28 20:18:30 -04:00
|
|
|
public function getExpectedProductData( $product_id ) {
|
|
|
|
|
$product = \wc_get_product( $product_id );
|
|
|
|
|
$is_shop_manager = false;
|
|
|
|
|
$user = wp_get_current_user();
|
2022-02-04 15:00:44 -05:00
|
|
|
if ( $user && in_array( 'shop_manager', (array) $user->roles, true ) ) {
|
2020-07-28 20:18:30 -04:00
|
|
|
$is_shop_manager = true;
|
|
|
|
|
}
|
2019-03-13 12:31:37 -04:00
|
|
|
|
2022-08-26 14:53:36 -04:00
|
|
|
return [
|
2024-08-06 16:54:18 -06:00
|
|
|
$this->expectedField( 'product.id', $this->toRelayId( 'post', $product_id ) ),
|
2021-07-05 13:51:52 -04:00
|
|
|
$this->expectedField( 'product.databaseId', $product->get_id() ),
|
|
|
|
|
$this->expectedField( 'product.name', $product->get_name() ),
|
|
|
|
|
$this->expectedField( 'product.slug', $product->get_slug() ),
|
|
|
|
|
$this->expectedField( 'product.date', $product->get_date_created()->__toString() ),
|
|
|
|
|
$this->expectedField( 'product.status', $product->get_status() ),
|
|
|
|
|
$this->expectedField( 'product.featured', $product->get_featured() ),
|
|
|
|
|
$this->expectedField(
|
2020-08-26 16:17:17 -04:00
|
|
|
'product.description',
|
|
|
|
|
$this->maybe(
|
2022-08-26 14:53:36 -04:00
|
|
|
[ $product->get_description(), apply_filters( 'the_content', $product->get_description() ) ],
|
2024-08-06 16:54:18 -06:00
|
|
|
static::IS_NULL
|
2020-07-28 20:18:30 -04:00
|
|
|
)
|
2020-08-26 16:17:17 -04:00
|
|
|
),
|
2021-07-05 13:51:52 -04:00
|
|
|
$this->expectedField(
|
2020-08-26 16:17:17 -04:00
|
|
|
'product.shortDescription',
|
|
|
|
|
$this->maybe(
|
2022-08-26 14:53:36 -04:00
|
|
|
[
|
2020-08-26 16:17:17 -04:00
|
|
|
$product->get_short_description(),
|
|
|
|
|
apply_filters(
|
|
|
|
|
'get_the_excerpt',
|
|
|
|
|
apply_filters( 'the_excerpt', $product->get_short_description() )
|
|
|
|
|
),
|
2022-08-26 14:53:36 -04:00
|
|
|
],
|
2024-08-06 16:54:18 -06:00
|
|
|
static::IS_NULL
|
2020-08-26 16:17:17 -04:00
|
|
|
)
|
|
|
|
|
),
|
2021-07-05 13:51:52 -04:00
|
|
|
$this->expectedField( 'product.sku', $product->get_sku() ),
|
|
|
|
|
$this->expectedField(
|
2020-08-26 16:17:17 -04:00
|
|
|
'product.price',
|
|
|
|
|
$this->maybe(
|
2022-08-26 14:53:36 -04:00
|
|
|
[ $product->get_price(), \wc_graphql_price( $product->get_price() ) ],
|
2024-08-06 16:54:18 -06:00
|
|
|
static::IS_NULL
|
2020-08-26 16:17:17 -04:00
|
|
|
)
|
|
|
|
|
),
|
2021-07-05 13:51:52 -04:00
|
|
|
$this->expectedField(
|
2020-08-26 16:17:17 -04:00
|
|
|
'product.regularPrice',
|
|
|
|
|
$this->maybe(
|
2022-08-26 14:53:36 -04:00
|
|
|
[ $product->get_regular_price(), \wc_graphql_price( $product->get_regular_price() ) ],
|
2024-08-06 16:54:18 -06:00
|
|
|
static::IS_NULL
|
2020-08-26 16:17:17 -04:00
|
|
|
)
|
|
|
|
|
),
|
2021-07-05 13:51:52 -04:00
|
|
|
$this->expectedField(
|
2020-08-26 16:17:17 -04:00
|
|
|
'product.salePrice',
|
|
|
|
|
$this->maybe(
|
2022-08-26 14:53:36 -04:00
|
|
|
[ $product->get_sale_price(), \wc_graphql_price( $product->get_sale_price() ) ],
|
2024-08-06 16:54:18 -06:00
|
|
|
static::IS_NULL
|
2020-08-26 16:17:17 -04:00
|
|
|
)
|
|
|
|
|
),
|
2021-07-05 13:51:52 -04:00
|
|
|
$this->expectedField(
|
2020-08-26 16:17:17 -04:00
|
|
|
'product.dateOnSaleFrom',
|
2024-08-06 16:54:18 -06:00
|
|
|
$this->maybe( $product->get_date_on_sale_from(), static::IS_NULL )
|
2020-08-26 16:17:17 -04:00
|
|
|
),
|
2021-07-05 13:51:52 -04:00
|
|
|
$this->expectedField(
|
2020-08-26 16:17:17 -04:00
|
|
|
'product.dateOnSaleTo',
|
2024-08-06 16:54:18 -06:00
|
|
|
$this->maybe( $product->get_date_on_sale_to(), static::IS_NULL )
|
2020-08-26 16:17:17 -04:00
|
|
|
),
|
2021-07-05 13:51:52 -04:00
|
|
|
$this->expectedField(
|
2020-08-26 16:17:17 -04:00
|
|
|
'product.taxStatus',
|
2024-08-06 16:54:18 -06:00
|
|
|
$this->maybe( strtoupper( $product->get_tax_status() ), static::IS_NULL )
|
2020-08-26 16:17:17 -04:00
|
|
|
),
|
2021-07-05 13:51:52 -04:00
|
|
|
$this->expectedField(
|
2020-08-26 16:17:17 -04:00
|
|
|
'product.taxClass',
|
|
|
|
|
$this->maybe( $product->get_tax_class(), 'STANDARD' )
|
|
|
|
|
),
|
2023-09-15 21:03:55 -04:00
|
|
|
$this->expectedField(
|
|
|
|
|
'product.manageStock',
|
|
|
|
|
! empty( $product->get_manage_stock() )
|
|
|
|
|
? \WPGraphQL\Type\WPEnumType::get_safe_name( $product->get_manage_stock() )
|
2024-08-06 16:54:18 -06:00
|
|
|
: static::IS_NULL
|
2023-09-15 21:03:55 -04:00
|
|
|
),
|
2021-07-05 13:51:52 -04:00
|
|
|
$this->expectedField(
|
2020-08-26 16:17:17 -04:00
|
|
|
'product.stockQuantity',
|
2024-08-06 16:54:18 -06:00
|
|
|
$this->maybe( $product->get_stock_quantity(), static::IS_NULL )
|
2020-08-26 16:17:17 -04:00
|
|
|
),
|
2021-07-05 13:51:52 -04:00
|
|
|
$this->expectedField(
|
2020-08-26 16:17:17 -04:00
|
|
|
'product.stockStatus',
|
|
|
|
|
$this->maybe(
|
|
|
|
|
$this->factory->product->getStockStatusEnum( $product->get_stock_status() ),
|
2024-08-06 16:54:18 -06:00
|
|
|
static::IS_NULL
|
2020-08-26 16:17:17 -04:00
|
|
|
)
|
|
|
|
|
),
|
2021-07-05 13:51:52 -04:00
|
|
|
$this->expectedField(
|
2020-08-26 16:17:17 -04:00
|
|
|
'product.backorders',
|
|
|
|
|
$this->maybe(
|
|
|
|
|
\WPGraphQL\Type\WPEnumType::get_safe_name( $product->get_backorders() ),
|
2024-08-06 16:54:18 -06:00
|
|
|
static::IS_NULL
|
2020-08-26 16:17:17 -04:00
|
|
|
)
|
|
|
|
|
),
|
2021-07-05 13:51:52 -04:00
|
|
|
$this->expectedField( 'product.soldIndividually', $product->get_sold_individually() ),
|
|
|
|
|
$this->expectedField(
|
2020-08-26 16:17:17 -04:00
|
|
|
'product.weight',
|
2024-08-06 16:54:18 -06:00
|
|
|
$this->maybe( $product->get_weight(), static::IS_NULL )
|
2020-08-26 16:17:17 -04:00
|
|
|
),
|
2021-07-05 13:51:52 -04:00
|
|
|
$this->expectedField(
|
2020-08-26 16:17:17 -04:00
|
|
|
'product.length',
|
2024-08-06 16:54:18 -06:00
|
|
|
$this->maybe( $product->get_length(), static::IS_NULL )
|
2020-08-26 16:17:17 -04:00
|
|
|
),
|
2021-07-05 13:51:52 -04:00
|
|
|
$this->expectedField(
|
2020-08-26 16:17:17 -04:00
|
|
|
'product.width',
|
2024-08-06 16:54:18 -06:00
|
|
|
$this->maybe( $product->get_width(), static::IS_NULL )
|
2020-08-26 16:17:17 -04:00
|
|
|
),
|
2021-07-05 13:51:52 -04:00
|
|
|
$this->expectedField(
|
2020-08-26 16:17:17 -04:00
|
|
|
'product.height',
|
2024-08-06 16:54:18 -06:00
|
|
|
$this->maybe( $product->get_height(), static::IS_NULL )
|
2020-08-26 16:17:17 -04:00
|
|
|
),
|
2021-07-05 13:51:52 -04:00
|
|
|
$this->expectedField(
|
2020-08-26 16:17:17 -04:00
|
|
|
'product.reviewsAllowed',
|
2024-08-06 16:54:18 -06:00
|
|
|
$this->maybe( $product->get_reviews_allowed(), static::IS_NULL )
|
2020-08-26 16:17:17 -04:00
|
|
|
),
|
2021-07-05 13:51:52 -04:00
|
|
|
$this->expectedField(
|
2020-08-26 16:17:17 -04:00
|
|
|
'product.purchaseNote',
|
2024-08-06 16:54:18 -06:00
|
|
|
$this->maybe( $product->get_purchase_note(), static::IS_NULL )
|
2020-08-26 16:17:17 -04:00
|
|
|
),
|
2021-07-05 13:51:52 -04:00
|
|
|
$this->expectedField( 'product.menuOrder', $product->get_menu_order() ),
|
|
|
|
|
$this->expectedField( 'product.virtual', $product->get_virtual() ),
|
2024-08-06 16:54:18 -06:00
|
|
|
$this->expectedField( 'product.downloadable', $product->get_downloadable(), static::IS_NULL ),
|
2021-07-05 13:51:52 -04:00
|
|
|
$this->expectedField(
|
2020-08-26 16:17:17 -04:00
|
|
|
'product.downloadLimit',
|
2024-08-06 16:54:18 -06:00
|
|
|
$this->maybe( $product->get_download_limit(), static::IS_NULL )
|
2020-08-26 16:17:17 -04:00
|
|
|
),
|
2021-07-05 13:51:52 -04:00
|
|
|
$this->expectedField(
|
2020-08-26 16:17:17 -04:00
|
|
|
'product.downloadExpiry',
|
2024-08-06 16:54:18 -06:00
|
|
|
$this->maybe( $product->get_download_expiry(), static::IS_NULL )
|
2020-08-26 16:17:17 -04:00
|
|
|
),
|
2022-02-04 15:00:44 -05:00
|
|
|
$this->expectedField( 'product.averageRating', (float) $product->get_average_rating() ),
|
2021-07-05 13:51:52 -04:00
|
|
|
$this->expectedField( 'product.reviewCount', (int) $product->get_review_count() ),
|
|
|
|
|
$this->expectedField(
|
2020-08-26 16:17:17 -04:00
|
|
|
'product.backordersAllowed',
|
2024-08-06 16:54:18 -06:00
|
|
|
$this->maybe( $product->backorders_allowed(), static::IS_FALSY )
|
2020-08-26 16:17:17 -04:00
|
|
|
),
|
2021-07-05 13:51:52 -04:00
|
|
|
$this->expectedField( 'product.onSale', $product->is_on_sale() ),
|
|
|
|
|
$this->expectedField( 'product.purchasable', $product->is_purchasable() ),
|
|
|
|
|
$this->expectedField( 'product.shippingRequired', $product->needs_shipping() ),
|
|
|
|
|
$this->expectedField( 'product.shippingTaxable', $product->is_shipping_taxable() ),
|
|
|
|
|
$this->expectedField(
|
2020-08-26 16:17:17 -04:00
|
|
|
'product.link',
|
2024-08-06 16:54:18 -06:00
|
|
|
$this->maybe( get_post_permalink( $product_id ), static::IS_NULL )
|
2020-08-26 16:17:17 -04:00
|
|
|
),
|
2021-07-05 13:51:52 -04:00
|
|
|
$this->expectedField(
|
2020-08-26 16:17:17 -04:00
|
|
|
'product.totalSales',
|
|
|
|
|
$this->maybe(
|
2022-08-26 14:53:36 -04:00
|
|
|
[
|
2020-08-26 16:17:17 -04:00
|
|
|
$is_shop_manager && $product->get_total_sales(),
|
|
|
|
|
$product->get_total_sales(),
|
2022-08-26 14:53:36 -04:00
|
|
|
],
|
2024-08-06 16:54:18 -06:00
|
|
|
static::IS_FALSY
|
2020-08-26 16:17:17 -04:00
|
|
|
)
|
|
|
|
|
),
|
2021-07-05 13:51:52 -04:00
|
|
|
$this->expectedField(
|
2020-08-26 16:17:17 -04:00
|
|
|
'product.catalogVisibility',
|
|
|
|
|
$this->maybe(
|
2022-08-26 14:53:36 -04:00
|
|
|
[
|
2020-08-26 16:17:17 -04:00
|
|
|
$is_shop_manager && ! empty( $product->get_catalog_visibility() ),
|
|
|
|
|
strtoupper( $product->get_catalog_visibility() ),
|
2022-08-26 14:53:36 -04:00
|
|
|
],
|
2024-08-06 16:54:18 -06:00
|
|
|
static::IS_NULL
|
2020-08-26 16:17:17 -04:00
|
|
|
)
|
|
|
|
|
),
|
2022-08-26 14:53:36 -04:00
|
|
|
];
|
2019-03-21 21:43:24 -04:00
|
|
|
}
|
2019-03-13 12:31:37 -04:00
|
|
|
|
2020-07-28 20:18:30 -04:00
|
|
|
public function getExpectedProductDownloadData( $product_id ) {
|
2022-02-04 15:00:44 -05:00
|
|
|
$product = wc_get_product( $product_id );
|
|
|
|
|
$downloads = (array) $product->get_downloads();
|
2020-07-28 20:18:30 -04:00
|
|
|
if ( empty( $downloads ) ) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2019-11-13 21:06:01 -05:00
|
|
|
|
2022-08-26 14:53:36 -04:00
|
|
|
$results = [];
|
2020-07-28 20:18:30 -04:00
|
|
|
foreach ( $downloads as $download ) {
|
2022-08-26 14:53:36 -04:00
|
|
|
$results[] = [
|
2020-07-28 20:18:30 -04:00
|
|
|
'name' => $download->get_name(),
|
|
|
|
|
'downloadId' => $download->get_id(),
|
|
|
|
|
'filePathType' => $download->get_type_of_file_path(),
|
|
|
|
|
'fileType' => $download->get_file_type(),
|
|
|
|
|
'fileExt' => $download->get_file_extension(),
|
|
|
|
|
'allowedFileType' => $download->is_allowed_filetype(),
|
|
|
|
|
'fileExists' => $download->file_exists(),
|
|
|
|
|
'file' => $download->get_file(),
|
2022-08-26 14:53:36 -04:00
|
|
|
];
|
2020-07-28 20:18:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $results;
|
2019-03-21 21:43:24 -04:00
|
|
|
}
|
2019-03-13 12:31:37 -04:00
|
|
|
|
2019-03-21 21:43:24 -04:00
|
|
|
// tests
|
2019-10-17 21:39:38 -04:00
|
|
|
public function testSimpleProductQuery() {
|
2020-07-28 20:18:30 -04:00
|
|
|
$product_id = $this->factory->product->createSimple();
|
|
|
|
|
$product = wc_get_product( $product_id );
|
|
|
|
|
|
2019-04-02 14:00:15 -04:00
|
|
|
$query = '
|
2019-09-03 15:36:48 -04:00
|
|
|
query ( $id: ID!, $format: PostObjectFieldFormatEnum ) {
|
2019-04-02 14:00:15 -04:00
|
|
|
product(id: $id) {
|
2019-10-17 21:39:38 -04:00
|
|
|
... on SimpleProduct {
|
|
|
|
|
id
|
2020-09-16 16:32:14 -04:00
|
|
|
databaseId
|
2019-10-17 21:39:38 -04:00
|
|
|
name
|
|
|
|
|
slug
|
|
|
|
|
date
|
|
|
|
|
modified
|
|
|
|
|
status
|
|
|
|
|
featured
|
|
|
|
|
catalogVisibility
|
|
|
|
|
description(format: $format)
|
|
|
|
|
shortDescription(format: $format)
|
|
|
|
|
sku
|
|
|
|
|
price
|
|
|
|
|
regularPrice
|
|
|
|
|
salePrice
|
|
|
|
|
dateOnSaleFrom
|
|
|
|
|
dateOnSaleTo
|
|
|
|
|
totalSales
|
|
|
|
|
taxStatus
|
|
|
|
|
taxClass
|
|
|
|
|
manageStock
|
|
|
|
|
stockQuantity
|
|
|
|
|
stockStatus
|
|
|
|
|
backorders
|
|
|
|
|
soldIndividually
|
|
|
|
|
weight
|
|
|
|
|
length
|
|
|
|
|
width
|
|
|
|
|
height
|
|
|
|
|
reviewsAllowed
|
|
|
|
|
purchaseNote
|
|
|
|
|
menuOrder
|
|
|
|
|
virtual
|
|
|
|
|
downloadable
|
|
|
|
|
downloadLimit
|
|
|
|
|
downloadExpiry
|
|
|
|
|
averageRating
|
|
|
|
|
reviewCount
|
|
|
|
|
backordersAllowed
|
|
|
|
|
onSale
|
|
|
|
|
purchasable
|
|
|
|
|
shippingRequired
|
|
|
|
|
shippingTaxable
|
2019-11-04 22:49:03 -05:00
|
|
|
link
|
2019-10-17 21:39:38 -04:00
|
|
|
}
|
2019-03-21 21:43:24 -04:00
|
|
|
}
|
|
|
|
|
}
|
2019-04-02 14:00:15 -04:00
|
|
|
';
|
2020-06-01 21:53:24 -04:00
|
|
|
|
2019-09-03 15:36:48 -04:00
|
|
|
/**
|
|
|
|
|
* Assertion One
|
2020-06-01 21:53:24 -04:00
|
|
|
*
|
2019-09-03 15:36:48 -04:00
|
|
|
* Test querying product.
|
|
|
|
|
*/
|
2024-08-06 16:54:18 -06:00
|
|
|
$variables = [ 'id' => $this->toRelayId( 'post', $product_id ) ];
|
2022-02-04 15:00:44 -05:00
|
|
|
$response = $this->graphql( compact( 'query', 'variables' ) );
|
|
|
|
|
$expected = $this->getExpectedProductData( $product_id );
|
2019-03-17 23:50:15 -04:00
|
|
|
|
2020-08-26 16:17:17 -04:00
|
|
|
$this->assertQuerySuccessful( $response, $expected );
|
2019-09-03 15:36:48 -04:00
|
|
|
|
|
|
|
|
// Clear cache
|
2023-08-22 17:14:39 -04:00
|
|
|
$this->clearLoaderCache( 'wc_post' );
|
2019-09-03 15:36:48 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Assertion Two
|
2020-06-01 21:53:24 -04:00
|
|
|
*
|
2019-09-03 15:36:48 -04:00
|
|
|
* Test querying product with unformatted content (edit-product cap required).
|
|
|
|
|
*/
|
2020-07-28 20:18:30 -04:00
|
|
|
$this->loginAsShopManager();
|
2022-08-26 14:53:36 -04:00
|
|
|
$variables = [
|
2024-08-06 16:54:18 -06:00
|
|
|
'id' => $this->toRelayId( 'post', $product_id ),
|
2020-07-28 20:18:30 -04:00
|
|
|
'format' => 'RAW',
|
2022-08-26 14:53:36 -04:00
|
|
|
];
|
2022-02-04 15:00:44 -05:00
|
|
|
$response = $this->graphql( compact( 'query', 'variables' ) );
|
2022-08-26 14:53:36 -04:00
|
|
|
$expected = [
|
2021-07-05 13:51:52 -04:00
|
|
|
$this->expectedField( 'product.description', $product->get_description() ),
|
|
|
|
|
$this->expectedField( 'product.shortDescription', $product->get_short_description() ),
|
|
|
|
|
$this->expectedField( 'product.totalSales', $product->get_total_sales() ),
|
|
|
|
|
$this->expectedField( 'product.catalogVisibility', strtoupper( $product->get_catalog_visibility() ) ),
|
2022-08-26 14:53:36 -04:00
|
|
|
];
|
2019-09-03 15:36:48 -04:00
|
|
|
|
2020-08-26 16:17:17 -04:00
|
|
|
$this->assertQuerySuccessful( $response, $expected );
|
2019-03-21 21:43:24 -04:00
|
|
|
}
|
2019-03-14 23:55:34 -04:00
|
|
|
|
2019-10-15 22:43:01 -04:00
|
|
|
public function testProductTaxonomies() {
|
2020-07-28 20:18:30 -04:00
|
|
|
// Create product and properties.
|
|
|
|
|
$category_5 = $this->factory->product->createProductCategory( 'category-five' );
|
|
|
|
|
$category_6 = $this->factory->product->createProductCategory( 'category-six', $category_5 );
|
|
|
|
|
$tag_2 = $this->factory->product->createProductTag( 'tag-two' );
|
|
|
|
|
$attachment_id = $this->factory->attachment->create(
|
2022-08-26 14:53:36 -04:00
|
|
|
[
|
2019-10-15 22:48:04 -04:00
|
|
|
'post_mime_type' => 'image/gif',
|
2022-02-04 15:00:44 -05:00
|
|
|
'post_author' => $this->admin,
|
2022-08-26 14:53:36 -04:00
|
|
|
]
|
2019-10-15 22:48:04 -04:00
|
|
|
);
|
2020-07-28 20:18:30 -04:00
|
|
|
$product_id = $this->factory->product->createSimple(
|
2022-08-26 14:53:36 -04:00
|
|
|
[
|
2019-10-15 22:43:01 -04:00
|
|
|
'price' => 10,
|
|
|
|
|
'regular_price' => 10,
|
2022-08-26 14:53:36 -04:00
|
|
|
'category_ids' => [ $category_5 ],
|
|
|
|
|
'tag_ids' => [ $tag_2 ],
|
2019-10-15 22:48:04 -04:00
|
|
|
'image_id' => $attachment_id,
|
2022-08-26 14:53:36 -04:00
|
|
|
]
|
2019-10-15 22:43:01 -04:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$query = '
|
2020-03-27 12:18:06 -04:00
|
|
|
query ( $id: ID!, $idType: ProductIdTypeEnum ) {
|
|
|
|
|
product( id: $id, idType: $idType ) {
|
2019-10-17 21:39:38 -04:00
|
|
|
... on SimpleProduct {
|
2019-10-15 22:48:04 -04:00
|
|
|
id
|
2019-10-17 21:39:38 -04:00
|
|
|
image {
|
|
|
|
|
id
|
|
|
|
|
}
|
2019-11-28 12:56:27 -05:00
|
|
|
productCategories {
|
2019-10-17 21:39:38 -04:00
|
|
|
nodes {
|
|
|
|
|
name
|
2020-08-06 16:25:50 -04:00
|
|
|
image { id }
|
|
|
|
|
display
|
|
|
|
|
menuOrder
|
2019-10-17 21:39:38 -04:00
|
|
|
children {
|
|
|
|
|
nodes {
|
|
|
|
|
name
|
|
|
|
|
}
|
2019-10-15 22:43:01 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-11-28 12:56:27 -05:00
|
|
|
productTags {
|
2019-10-17 21:39:38 -04:00
|
|
|
nodes {
|
|
|
|
|
name
|
|
|
|
|
}
|
2019-10-15 22:43:01 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Assertion One
|
2020-06-01 21:53:24 -04:00
|
|
|
*
|
2019-10-15 22:43:01 -04:00
|
|
|
* Test querying product with "productId" argument.
|
|
|
|
|
*/
|
2022-08-26 14:53:36 -04:00
|
|
|
$variables = [
|
2020-07-28 20:18:30 -04:00
|
|
|
'id' => $product_id,
|
2022-02-04 15:00:44 -05:00
|
|
|
'idType' => 'DATABASE_ID',
|
2022-08-26 14:53:36 -04:00
|
|
|
];
|
2020-07-28 20:18:30 -04:00
|
|
|
$response = $this->graphql( compact( 'query', 'variables' ) );
|
2022-08-26 14:53:36 -04:00
|
|
|
$expected = [
|
2024-08-06 16:54:18 -06:00
|
|
|
$this->expectedField( 'product.id', $this->toRelayId( 'post', $product_id ) ),
|
2021-07-05 13:51:52 -04:00
|
|
|
$this->expectedField( 'product.image.id', $this->toRelayId( 'post', $attachment_id ) ),
|
2020-07-28 20:18:30 -04:00
|
|
|
$this->expectedNode(
|
|
|
|
|
'product.productCategories.nodes',
|
2022-08-26 14:53:36 -04:00
|
|
|
[
|
2020-10-27 23:55:16 -04:00
|
|
|
'name' => 'category-five',
|
|
|
|
|
'image' => null,
|
|
|
|
|
'display' => 'DEFAULT',
|
|
|
|
|
'menuOrder' => 0,
|
2022-08-26 14:53:36 -04:00
|
|
|
'children' => [
|
|
|
|
|
'nodes' => [
|
|
|
|
|
[ 'name' => 'category-six' ],
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
]
|
2019-10-15 22:43:01 -04:00
|
|
|
),
|
2022-08-26 14:53:36 -04:00
|
|
|
$this->expectedNode( 'product.productTags.nodes', [ 'name' => 'tag-two' ] ),
|
|
|
|
|
];
|
2019-10-15 22:43:01 -04:00
|
|
|
|
2020-07-28 20:18:30 -04:00
|
|
|
$this->assertQuerySuccessful( $response, $expected );
|
2019-10-15 22:43:01 -04:00
|
|
|
}
|
|
|
|
|
|
2020-01-24 23:40:50 -05:00
|
|
|
public function testProductQueryAndIds() {
|
2020-07-28 20:18:30 -04:00
|
|
|
$product_id = $this->factory->product->createSimple();
|
|
|
|
|
$query = '
|
2020-01-24 23:40:50 -05:00
|
|
|
query ( $id: ID!, $idType: ProductIdTypeEnum ) {
|
|
|
|
|
product( id: $id, idType: $idType ) {
|
2019-10-17 21:39:38 -04:00
|
|
|
... on SimpleProduct {
|
|
|
|
|
id
|
|
|
|
|
}
|
2019-03-21 21:43:24 -04:00
|
|
|
}
|
|
|
|
|
}
|
2019-04-02 14:00:15 -04:00
|
|
|
';
|
2019-03-17 23:50:15 -04:00
|
|
|
|
2020-07-28 20:18:30 -04:00
|
|
|
// Define expected data for coming assertions.
|
2022-08-26 14:53:36 -04:00
|
|
|
$expected = [
|
2024-08-06 16:54:18 -06:00
|
|
|
$this->expectedField( 'product.id', $this->toRelayId( 'post', $product_id ) ),
|
2022-08-26 14:53:36 -04:00
|
|
|
];
|
2020-07-28 20:18:30 -04:00
|
|
|
|
2019-07-09 21:46:07 -04:00
|
|
|
/**
|
|
|
|
|
* Assertion One
|
2020-06-01 21:53:24 -04:00
|
|
|
*
|
2020-07-28 20:18:30 -04:00
|
|
|
* Test querying product with 'DATABASE_ID' set as the "idType".
|
2019-07-09 21:46:07 -04:00
|
|
|
*/
|
2022-08-26 14:53:36 -04:00
|
|
|
$variables = [
|
2020-07-28 20:18:30 -04:00
|
|
|
'id' => $product_id,
|
2020-01-24 23:40:50 -05:00
|
|
|
'idType' => 'DATABASE_ID',
|
2022-08-26 14:53:36 -04:00
|
|
|
];
|
2020-07-28 20:18:30 -04:00
|
|
|
$response = $this->graphql( compact( 'query', 'variables' ) );
|
|
|
|
|
$this->assertQuerySuccessful( $response, $expected );
|
2019-04-14 00:01:07 -04:00
|
|
|
|
2019-07-09 21:46:07 -04:00
|
|
|
/**
|
|
|
|
|
* Assertion Two
|
2020-06-01 21:53:24 -04:00
|
|
|
*
|
2020-07-28 20:18:30 -04:00
|
|
|
* Test querying product with "ID" set as the "idType".
|
2019-07-09 21:46:07 -04:00
|
|
|
*/
|
2022-08-26 14:53:36 -04:00
|
|
|
$variables = [
|
2024-08-06 16:54:18 -06:00
|
|
|
'id' => $this->toRelayId( 'post', $product_id ),
|
2020-01-24 23:40:50 -05:00
|
|
|
'idType' => 'ID',
|
2022-08-26 14:53:36 -04:00
|
|
|
];
|
2020-07-28 20:18:30 -04:00
|
|
|
$response = $this->graphql( compact( 'query', 'variables' ) );
|
|
|
|
|
$this->assertQuerySuccessful( $response, $expected );
|
2019-07-09 21:46:07 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Assertion Three
|
2020-06-01 21:53:24 -04:00
|
|
|
*
|
2020-07-28 20:18:30 -04:00
|
|
|
* Test querying product with "SLUG" set as the "idType".
|
2019-07-09 21:46:07 -04:00
|
|
|
*/
|
2022-08-26 14:53:36 -04:00
|
|
|
$variables = [
|
2020-07-28 20:18:30 -04:00
|
|
|
'id' => get_post_field( 'post_name', $product_id ),
|
2020-01-24 23:40:50 -05:00
|
|
|
'idType' => 'SLUG',
|
2022-08-26 14:53:36 -04:00
|
|
|
];
|
2020-07-28 20:18:30 -04:00
|
|
|
$response = $this->graphql( compact( 'query', 'variables' ) );
|
|
|
|
|
$this->assertQuerySuccessful( $response, $expected );
|
2019-07-09 21:46:07 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Assertion Four
|
2020-06-01 21:53:24 -04:00
|
|
|
*
|
2020-07-28 20:18:30 -04:00
|
|
|
* Test querying product with "SKU" set as the "idType".
|
2019-07-09 21:46:07 -04:00
|
|
|
*/
|
2022-08-26 14:53:36 -04:00
|
|
|
$variables = [
|
2020-07-28 20:18:30 -04:00
|
|
|
'id' => get_post_meta( $product_id, '_sku', true ),
|
2020-01-24 23:40:50 -05:00
|
|
|
'idType' => 'SKU',
|
2022-08-26 14:53:36 -04:00
|
|
|
];
|
2020-07-28 20:18:30 -04:00
|
|
|
$response = $this->graphql( compact( 'query', 'variables' ) );
|
|
|
|
|
$this->assertQuerySuccessful( $response, $expected );
|
2019-04-14 00:01:07 -04:00
|
|
|
}
|
|
|
|
|
|
2019-06-05 12:43:38 -04:00
|
|
|
public function testProductToTermConnection() {
|
2020-07-28 20:18:30 -04:00
|
|
|
$test_category = $this->factory->product->createProductCategory( 'test-product-category-1' );
|
|
|
|
|
$test_tag = $this->factory->product->createProductTag( 'test-product-tag-1' );
|
|
|
|
|
$product_id = $this->factory->product->createSimple(
|
2022-08-26 14:53:36 -04:00
|
|
|
[
|
|
|
|
|
'tag_ids' => [ $test_tag ],
|
|
|
|
|
'category_ids' => [ $test_category ],
|
|
|
|
|
]
|
2020-07-28 20:18:30 -04:00
|
|
|
);
|
2024-08-06 16:54:18 -06:00
|
|
|
$relay_id = $this->toRelayId( 'post', $product_id );
|
2020-07-28 20:18:30 -04:00
|
|
|
|
2019-06-05 12:43:38 -04:00
|
|
|
$query = '
|
2019-10-17 21:39:38 -04:00
|
|
|
query ($id: ID!) {
|
2019-06-05 12:43:38 -04:00
|
|
|
product(id: $id) {
|
2019-10-17 21:39:38 -04:00
|
|
|
... on SimpleProduct {
|
|
|
|
|
id
|
2019-11-28 12:56:27 -05:00
|
|
|
productTags {
|
2019-10-17 21:39:38 -04:00
|
|
|
nodes {
|
|
|
|
|
name
|
|
|
|
|
}
|
2019-06-05 12:43:38 -04:00
|
|
|
}
|
2019-11-28 12:56:27 -05:00
|
|
|
productCategories {
|
2019-10-17 21:39:38 -04:00
|
|
|
nodes {
|
|
|
|
|
name
|
|
|
|
|
}
|
2019-06-05 12:43:38 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
';
|
|
|
|
|
|
2022-08-26 14:53:36 -04:00
|
|
|
$variables = [ 'id' => $relay_id ];
|
2020-07-28 20:18:30 -04:00
|
|
|
$response = $this->graphql( compact( 'query', 'variables' ) );
|
2022-08-26 14:53:36 -04:00
|
|
|
$expected = [
|
2021-07-05 13:51:52 -04:00
|
|
|
$this->expectedField( 'product.id', $relay_id ),
|
2020-07-28 20:18:30 -04:00
|
|
|
$this->expectedNode(
|
|
|
|
|
'product.productTags.nodes',
|
2022-08-26 14:53:36 -04:00
|
|
|
[ 'name' => 'test-product-tag-1' ],
|
2020-07-28 20:18:30 -04:00
|
|
|
0
|
|
|
|
|
),
|
|
|
|
|
$this->expectedNode(
|
|
|
|
|
'product.productCategories.nodes',
|
2022-08-26 14:53:36 -04:00
|
|
|
[ 'name' => 'test-product-category-1' ],
|
2020-07-28 20:18:30 -04:00
|
|
|
0
|
|
|
|
|
),
|
2022-08-26 14:53:36 -04:00
|
|
|
];
|
2019-06-05 12:43:38 -04:00
|
|
|
|
2020-07-28 20:18:30 -04:00
|
|
|
$this->assertQuerySuccessful( $response, $expected );
|
2019-06-05 12:43:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testTermToProductConnection() {
|
2022-02-04 15:00:44 -05:00
|
|
|
$test_tag = $this->factory->product->createProductTag( 'test-product-tag-2' );
|
2020-07-28 20:18:30 -04:00
|
|
|
$image_id = $this->factory->post->create(
|
2022-08-26 14:53:36 -04:00
|
|
|
[
|
2022-02-04 15:00:44 -05:00
|
|
|
'post_author' => $this->shop_manager,
|
|
|
|
|
'post_status' => 'publish',
|
|
|
|
|
'post_title' => 'Product Image',
|
|
|
|
|
'post_type' => 'attachment',
|
2022-08-26 14:53:36 -04:00
|
|
|
]
|
2020-07-28 20:18:30 -04:00
|
|
|
);
|
|
|
|
|
$test_category = $this->factory->product->createProductCategory( 'test-product-category-2' );
|
|
|
|
|
update_term_meta( $test_category, 'thumbnail_id', $image_id );
|
|
|
|
|
|
2023-02-02 16:47:19 -05:00
|
|
|
$product_id = $this->factory->product->createSimple(
|
2022-08-26 14:53:36 -04:00
|
|
|
[
|
2023-02-02 16:47:19 -05:00
|
|
|
'tag_ids' => [ $test_tag ],
|
|
|
|
|
'category_ids' => [ $test_category ],
|
|
|
|
|
'price' => 10,
|
|
|
|
|
'regular_price' => 10,
|
|
|
|
|
]
|
|
|
|
|
);
|
|
|
|
|
$expensive_product_id = $this->factory->product->createSimple(
|
|
|
|
|
[
|
|
|
|
|
'tag_ids' => [ $test_tag ],
|
|
|
|
|
'category_ids' => [ $test_category ],
|
|
|
|
|
'price' => 100,
|
|
|
|
|
'regular_price' => 100,
|
2022-08-26 14:53:36 -04:00
|
|
|
]
|
2020-07-28 20:18:30 -04:00
|
|
|
);
|
|
|
|
|
|
2019-06-05 12:43:38 -04:00
|
|
|
$query = '
|
2023-02-02 16:47:19 -05:00
|
|
|
query($orderby: [ProductsOrderbyInput], $orderby2: [ProductsOrderbyInput]) {
|
2019-06-05 14:48:32 -04:00
|
|
|
productTags( where: { hideEmpty: true } ) {
|
2019-06-05 12:43:38 -04:00
|
|
|
nodes {
|
|
|
|
|
name
|
2023-02-02 16:47:19 -05:00
|
|
|
products(where: {orderby: $orderby}) {
|
2019-06-05 12:43:38 -04:00
|
|
|
nodes {
|
2019-10-17 21:39:38 -04:00
|
|
|
... on SimpleProduct {
|
|
|
|
|
id
|
2023-02-02 16:47:19 -05:00
|
|
|
price
|
2019-10-17 21:39:38 -04:00
|
|
|
}
|
2019-06-05 12:43:38 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-06-05 14:48:32 -04:00
|
|
|
productCategories( where: { hideEmpty: true } ) {
|
2019-06-05 12:43:38 -04:00
|
|
|
nodes {
|
|
|
|
|
name
|
2019-07-09 22:40:54 -04:00
|
|
|
image {
|
|
|
|
|
id
|
|
|
|
|
}
|
2023-02-02 16:47:19 -05:00
|
|
|
products(where: {orderby: $orderby2}) {
|
2019-06-05 12:43:38 -04:00
|
|
|
nodes {
|
2019-10-17 21:39:38 -04:00
|
|
|
... on SimpleProduct {
|
|
|
|
|
id
|
2023-02-02 16:47:19 -05:00
|
|
|
price
|
2019-10-17 21:39:38 -04:00
|
|
|
}
|
2019-06-05 12:43:38 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
';
|
|
|
|
|
|
2023-02-02 16:47:19 -05:00
|
|
|
$variables = [
|
|
|
|
|
'orderby' => [
|
|
|
|
|
[
|
|
|
|
|
'field' => 'PRICE',
|
|
|
|
|
'order' => 'ASC',
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
'orderby2' => [
|
|
|
|
|
[
|
|
|
|
|
'field' => 'PRICE',
|
|
|
|
|
'order' => 'DESC',
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
$response = $this->graphql( compact( 'query', 'variables' ) );
|
|
|
|
|
$expected = [
|
2020-07-28 20:18:30 -04:00
|
|
|
$this->expectedNode(
|
|
|
|
|
'productTags.nodes',
|
2022-08-26 14:53:36 -04:00
|
|
|
[
|
2023-02-02 16:47:19 -05:00
|
|
|
$this->expectedField( 'name', 'test-product-tag-2' ),
|
2024-08-06 16:54:18 -06:00
|
|
|
$this->expectedField( 'products.nodes.0.id', $this->toRelayId( 'post', $product_id ) ),
|
|
|
|
|
$this->expectedField( 'products.nodes.1.id', $this->toRelayId( 'post', $expensive_product_id ) ),
|
2022-08-26 14:53:36 -04:00
|
|
|
],
|
2020-07-28 20:18:30 -04:00
|
|
|
0
|
|
|
|
|
),
|
|
|
|
|
$this->expectedNode(
|
|
|
|
|
'productCategories.nodes',
|
2022-08-26 14:53:36 -04:00
|
|
|
[
|
2023-02-02 16:47:19 -05:00
|
|
|
$this->expectedField( 'name', 'test-product-category-2' ),
|
|
|
|
|
$this->expectedField( 'image.id', $this->toRelayId( 'post', $image_id ) ),
|
2024-08-06 16:54:18 -06:00
|
|
|
$this->expectedField( 'products.nodes.1.id', $this->toRelayId( 'post', $product_id ) ),
|
|
|
|
|
$this->expectedField( 'products.nodes.0.id', $this->toRelayId( 'post', $expensive_product_id ) ),
|
2022-08-26 14:53:36 -04:00
|
|
|
],
|
2020-07-28 20:18:30 -04:00
|
|
|
0
|
2019-06-05 12:43:38 -04:00
|
|
|
),
|
2022-08-26 14:53:36 -04:00
|
|
|
];
|
2019-06-05 12:43:38 -04:00
|
|
|
|
2020-07-28 20:18:30 -04:00
|
|
|
$this->assertQuerySuccessful( $response, $expected );
|
2019-06-05 12:43:38 -04:00
|
|
|
}
|
2019-06-05 14:48:32 -04:00
|
|
|
|
|
|
|
|
public function testProductToMediaItemConnections() {
|
2020-07-28 20:18:30 -04:00
|
|
|
$image_id = $this->factory->post->create(
|
2022-08-26 14:53:36 -04:00
|
|
|
[
|
2022-02-04 15:00:44 -05:00
|
|
|
'post_author' => $this->shop_manager,
|
|
|
|
|
'post_status' => 'publish',
|
|
|
|
|
'post_title' => 'Product Image',
|
|
|
|
|
'post_type' => 'attachment',
|
2022-08-26 14:53:36 -04:00
|
|
|
]
|
2020-07-28 20:18:30 -04:00
|
|
|
);
|
|
|
|
|
$product_id = $this->factory->product->createSimple(
|
2022-08-26 14:53:36 -04:00
|
|
|
[
|
2020-07-28 20:18:30 -04:00
|
|
|
'image_id' => $image_id,
|
2022-08-26 14:53:36 -04:00
|
|
|
'gallery_image_ids' => [ $image_id ],
|
|
|
|
|
]
|
2020-07-28 20:18:30 -04:00
|
|
|
);
|
|
|
|
|
|
2024-08-06 16:54:18 -06:00
|
|
|
$product_relay_id = $this->toRelayId( 'post', $product_id );
|
2022-02-04 15:00:44 -05:00
|
|
|
$image_relay_id = $this->toRelayId( 'post', $image_id );
|
2020-07-28 20:18:30 -04:00
|
|
|
|
|
|
|
|
$query = '
|
2019-10-17 21:39:38 -04:00
|
|
|
query ( $id: ID! ) {
|
2019-06-05 14:48:32 -04:00
|
|
|
product( id: $id ) {
|
2019-10-17 21:39:38 -04:00
|
|
|
... on SimpleProduct {
|
2019-06-05 14:48:32 -04:00
|
|
|
id
|
2019-10-17 21:39:38 -04:00
|
|
|
image {
|
2019-06-05 14:48:32 -04:00
|
|
|
id
|
|
|
|
|
}
|
2019-10-17 21:39:38 -04:00
|
|
|
galleryImages {
|
|
|
|
|
nodes {
|
|
|
|
|
id
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-06-05 14:48:32 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
';
|
|
|
|
|
|
2022-08-26 14:53:36 -04:00
|
|
|
$variables = [ 'id' => $product_relay_id ];
|
2022-02-04 15:00:44 -05:00
|
|
|
$response = graphql( compact( 'query', 'variables' ) );
|
2022-08-26 14:53:36 -04:00
|
|
|
$expected = [
|
2021-07-05 13:51:52 -04:00
|
|
|
$this->expectedField( 'product.id', $product_relay_id ),
|
|
|
|
|
$this->expectedField( 'product.image.id', $image_relay_id ),
|
2022-08-26 14:53:36 -04:00
|
|
|
$this->expectedNode( 'product.galleryImages.nodes', [ 'id' => $image_relay_id ] ),
|
|
|
|
|
];
|
2019-06-05 14:48:32 -04:00
|
|
|
|
2020-07-28 20:18:30 -04:00
|
|
|
$this->assertQuerySuccessful( $response, $expected );
|
2019-06-05 14:48:32 -04:00
|
|
|
}
|
2019-06-05 15:36:20 -04:00
|
|
|
|
|
|
|
|
public function testProductDownloads() {
|
2020-07-28 20:18:30 -04:00
|
|
|
$product_id = $this->factory->product->createSimple(
|
2022-08-26 14:53:36 -04:00
|
|
|
[
|
2022-02-04 15:00:44 -05:00
|
|
|
'downloadable' => true,
|
2022-08-26 14:53:36 -04:00
|
|
|
'downloads' => [ $this->factory->product->createDownload() ],
|
|
|
|
|
]
|
2020-07-28 20:18:30 -04:00
|
|
|
);
|
|
|
|
|
|
2024-08-06 16:54:18 -06:00
|
|
|
$relay_id = $this->toRelayId( 'post', $product_id );
|
2020-07-28 20:18:30 -04:00
|
|
|
|
2019-06-05 15:36:20 -04:00
|
|
|
$query = '
|
2019-10-17 21:39:38 -04:00
|
|
|
query ( $id: ID! ) {
|
2019-06-05 15:36:20 -04:00
|
|
|
product( id: $id ) {
|
2019-10-17 21:39:38 -04:00
|
|
|
... on SimpleProduct {
|
|
|
|
|
id
|
|
|
|
|
downloads {
|
|
|
|
|
name
|
|
|
|
|
downloadId
|
|
|
|
|
filePathType
|
|
|
|
|
fileType
|
|
|
|
|
fileExt
|
|
|
|
|
allowedFileType
|
|
|
|
|
fileExists
|
|
|
|
|
file
|
|
|
|
|
}
|
2019-06-05 15:36:20 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
';
|
|
|
|
|
|
2022-08-26 14:53:36 -04:00
|
|
|
$variables = [ 'id' => $relay_id ];
|
2020-07-28 20:18:30 -04:00
|
|
|
$response = $this->graphql( compact( 'query', 'variables' ) );
|
2022-08-26 14:53:36 -04:00
|
|
|
$expected = [
|
2021-07-05 13:51:52 -04:00
|
|
|
$this->expectedField( 'product.id', $relay_id ),
|
|
|
|
|
$this->expectedField( 'product.downloads', $this->getExpectedProductDownloadData( $product_id ) ),
|
2022-08-26 14:53:36 -04:00
|
|
|
];
|
2019-06-05 15:36:20 -04:00
|
|
|
|
2020-07-28 20:18:30 -04:00
|
|
|
$this->assertQuerySuccessful( $response, $expected );
|
2019-06-05 15:36:20 -04:00
|
|
|
}
|
2019-06-05 19:15:37 -04:00
|
|
|
|
|
|
|
|
public function testExternalProductQuery() {
|
2020-07-28 20:18:30 -04:00
|
|
|
$product_id = $this->factory->product->createExternal(
|
2022-08-26 14:53:36 -04:00
|
|
|
[
|
2020-07-28 20:18:30 -04:00
|
|
|
'product_url' => 'http://woographql.com',
|
|
|
|
|
'button_text' => 'Buy a external product',
|
2022-08-26 14:53:36 -04:00
|
|
|
]
|
2020-07-28 20:18:30 -04:00
|
|
|
);
|
2024-08-06 16:54:18 -06:00
|
|
|
$relay_id = $this->toRelayId( 'post', $product_id );
|
2020-07-28 20:18:30 -04:00
|
|
|
|
2022-02-04 15:00:44 -05:00
|
|
|
$query = '
|
2019-10-17 21:39:38 -04:00
|
|
|
query ( $id: ID! ) {
|
2019-06-05 19:15:37 -04:00
|
|
|
product(id: $id) {
|
2019-10-17 21:39:38 -04:00
|
|
|
... on ExternalProduct {
|
|
|
|
|
id
|
|
|
|
|
buttonText
|
|
|
|
|
externalUrl
|
|
|
|
|
}
|
2019-06-05 19:15:37 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
';
|
|
|
|
|
|
2022-08-26 14:53:36 -04:00
|
|
|
$variables = [ 'id' => $relay_id ];
|
2020-07-28 20:18:30 -04:00
|
|
|
$response = $this->graphql( compact( 'query', 'variables' ) );
|
2022-08-26 14:53:36 -04:00
|
|
|
$expected = [
|
2021-07-05 13:51:52 -04:00
|
|
|
$this->expectedField( 'product.id', $relay_id ),
|
|
|
|
|
$this->expectedField( 'product.buttonText', 'Buy a external product' ),
|
|
|
|
|
$this->expectedField( 'product.externalUrl', 'http://woographql.com' ),
|
2022-08-26 14:53:36 -04:00
|
|
|
];
|
2019-06-05 19:15:37 -04:00
|
|
|
|
2020-07-28 20:18:30 -04:00
|
|
|
$this->assertQuerySuccessful( $response, $expected );
|
2019-06-05 19:15:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testGroupProductConnections() {
|
2020-07-28 20:18:30 -04:00
|
|
|
$product_id = $this->factory->product->createGrouped(
|
2022-08-26 14:53:36 -04:00
|
|
|
[
|
2020-07-28 20:18:30 -04:00
|
|
|
'name' => 'Test Group',
|
2022-08-26 14:53:36 -04:00
|
|
|
'children' => [],
|
|
|
|
|
]
|
2020-07-28 20:18:30 -04:00
|
|
|
);
|
2022-08-26 14:53:36 -04:00
|
|
|
$grouped_product_ids = [
|
|
|
|
|
$this->factory->product->createSimple( [ 'regular_price' => '1.00' ] ),
|
|
|
|
|
$this->factory->product->createSimple( [ 'regular_price' => '5.00' ] ),
|
|
|
|
|
$this->factory->product->createSimple( [ 'regular_price' => '10.00' ] ),
|
|
|
|
|
];
|
2020-07-28 20:18:30 -04:00
|
|
|
|
|
|
|
|
$product = \wc_get_product( $product_id );
|
|
|
|
|
$this->factory->product->update_object(
|
|
|
|
|
$product,
|
2022-08-26 14:53:36 -04:00
|
|
|
[ 'children' => $grouped_product_ids ]
|
2020-07-28 20:18:30 -04:00
|
|
|
);
|
|
|
|
|
|
2024-08-06 16:54:18 -06:00
|
|
|
$relay_id = $this->toRelayId( 'post', $product_id );
|
2020-07-28 20:18:30 -04:00
|
|
|
|
|
|
|
|
$query = '
|
2019-10-17 21:39:38 -04:00
|
|
|
query ( $id: ID! ) {
|
2019-06-05 19:15:37 -04:00
|
|
|
product(id: $id) {
|
2020-07-28 20:18:30 -04:00
|
|
|
id
|
2019-10-17 21:39:38 -04:00
|
|
|
... on GroupProduct {
|
|
|
|
|
addToCartText
|
|
|
|
|
addToCartDescription
|
|
|
|
|
products {
|
2020-07-28 20:18:30 -04:00
|
|
|
nodes { id }
|
2019-06-05 19:15:37 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
';
|
|
|
|
|
|
2022-08-26 14:53:36 -04:00
|
|
|
$variables = [ 'id' => $relay_id ];
|
2020-07-28 20:18:30 -04:00
|
|
|
$response = $this->graphql( compact( 'query', 'variables' ) );
|
2022-08-26 14:53:36 -04:00
|
|
|
$expected = [
|
2021-07-05 13:51:52 -04:00
|
|
|
$this->expectedField( 'product.id', $relay_id ),
|
|
|
|
|
$this->expectedField( 'product.addToCartText', 'View products' ),
|
|
|
|
|
$this->expectedField(
|
2020-07-28 20:18:30 -04:00
|
|
|
'product.addToCartDescription',
|
2022-02-04 15:00:44 -05:00
|
|
|
/* translators: %s: Group name */
|
2026-06-30 10:16:21 -04:00
|
|
|
sprintf( __( 'View products in the “%s” group', 'graphql-for-ecommerce' ), 'Test Group' )
|
2019-06-05 19:15:37 -04:00
|
|
|
),
|
2022-08-26 14:53:36 -04:00
|
|
|
];
|
2019-06-05 19:15:37 -04:00
|
|
|
|
2022-02-04 15:00:44 -05:00
|
|
|
foreach ( $product->get_children() as $grouped_product_id ) {
|
2020-07-28 20:18:30 -04:00
|
|
|
$expected[] = $this->expectedNode(
|
|
|
|
|
'product.products.nodes',
|
2024-08-06 16:54:18 -06:00
|
|
|
[ 'id' => $this->toRelayId( 'post', $grouped_product_id ) ]
|
2020-07-28 20:18:30 -04:00
|
|
|
);
|
|
|
|
|
}
|
2019-06-05 19:15:37 -04:00
|
|
|
|
2020-07-28 20:18:30 -04:00
|
|
|
$this->assertQuerySuccessful( $response, $expected );
|
2021-02-26 09:29:19 -05:00
|
|
|
|
|
|
|
|
$query = '
|
|
|
|
|
query ( $id: ID! ) {
|
|
|
|
|
product( id: $id ) {
|
|
|
|
|
... on GroupProduct {
|
|
|
|
|
price
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
';
|
|
|
|
|
|
|
|
|
|
$response = $this->graphql( compact( 'query', 'variables' ) );
|
2022-08-26 14:53:36 -04:00
|
|
|
$expected = [ $this->expectedField( 'product.price', '$1.00 - $10.00' ) ];
|
2021-02-26 09:29:19 -05:00
|
|
|
|
|
|
|
|
$this->assertQuerySuccessful( $response, $expected );
|
2019-06-05 19:15:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testRelatedProductConnections() {
|
2020-07-28 20:18:30 -04:00
|
|
|
$products = $this->factory->product->createRelated();
|
2020-07-17 14:56:01 -04:00
|
|
|
|
|
|
|
|
$query = '
|
2019-10-17 21:39:38 -04:00
|
|
|
query ($id: ID!) {
|
2019-06-05 19:15:37 -04:00
|
|
|
product(id: $id) {
|
2019-10-17 21:39:38 -04:00
|
|
|
... on SimpleProduct {
|
2020-09-03 16:53:42 -04:00
|
|
|
related {
|
2019-10-17 21:39:38 -04:00
|
|
|
nodes {
|
|
|
|
|
... on SimpleProduct {
|
|
|
|
|
id
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-06-05 19:15:37 -04:00
|
|
|
}
|
2020-07-17 14:56:01 -04:00
|
|
|
crossSell{
|
2019-10-17 21:39:38 -04:00
|
|
|
nodes {
|
|
|
|
|
... on SimpleProduct {
|
|
|
|
|
id
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-06-05 19:15:37 -04:00
|
|
|
}
|
2019-10-17 21:39:38 -04:00
|
|
|
upsell {
|
|
|
|
|
nodes {
|
|
|
|
|
... on SimpleProduct {
|
|
|
|
|
id
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-06-05 19:15:37 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
';
|
|
|
|
|
|
2024-08-06 16:54:18 -06:00
|
|
|
$variables = [ 'id' => $this->toRelayId( 'post', $products['product'] ) ];
|
2020-07-28 20:18:30 -04:00
|
|
|
$response = $this->graphql( compact( 'query', 'variables' ) );
|
2022-08-26 14:53:36 -04:00
|
|
|
$expected = [];
|
2022-02-04 15:00:44 -05:00
|
|
|
foreach ( $products['related'] + $products['cross_sell'] + $products['upsell'] as $product_id ) {
|
2020-07-28 20:18:30 -04:00
|
|
|
$expected[] = $this->expectedNode(
|
|
|
|
|
'product.related.nodes',
|
2024-08-06 16:54:18 -06:00
|
|
|
[ 'id' => $this->toRelayId( 'post', $product_id ) ]
|
2020-07-28 20:18:30 -04:00
|
|
|
);
|
|
|
|
|
}
|
2022-02-04 15:00:44 -05:00
|
|
|
foreach ( $products['cross_sell'] as $product_id ) {
|
2020-07-28 20:18:30 -04:00
|
|
|
$expected[] = $this->expectedNode(
|
|
|
|
|
'product.crossSell.nodes',
|
2024-08-06 16:54:18 -06:00
|
|
|
[ 'id' => $this->toRelayId( 'post', $product_id ) ]
|
2020-07-28 20:18:30 -04:00
|
|
|
);
|
|
|
|
|
}
|
2022-02-04 15:00:44 -05:00
|
|
|
foreach ( $products['upsell'] as $product_id ) {
|
2020-07-28 20:18:30 -04:00
|
|
|
$expected[] = $this->expectedNode(
|
|
|
|
|
'product.upsell.nodes',
|
2024-08-06 16:54:18 -06:00
|
|
|
[ 'id' => $this->toRelayId( 'post', $product_id ) ]
|
2020-09-03 16:53:42 -04:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-28 20:18:30 -04:00
|
|
|
$this->assertQuerySuccessful( $response, $expected );
|
2019-06-05 19:15:37 -04:00
|
|
|
}
|
2019-12-18 15:11:59 -05:00
|
|
|
|
|
|
|
|
public function testProductToReviewConnections() {
|
2020-07-28 20:18:30 -04:00
|
|
|
$product_id = $this->factory->product->createSimple();
|
2022-08-26 14:53:36 -04:00
|
|
|
$reviews = [
|
2020-07-28 20:18:30 -04:00
|
|
|
$this->factory->product->createReview( $product_id ),
|
|
|
|
|
$this->factory->product->createReview( $product_id ),
|
|
|
|
|
$this->factory->product->createReview( $product_id ),
|
|
|
|
|
$this->factory->product->createReview( $product_id ),
|
|
|
|
|
$this->factory->product->createReview( $product_id ),
|
2022-08-26 14:53:36 -04:00
|
|
|
];
|
2024-08-06 16:54:18 -06:00
|
|
|
$relay_id = $this->toRelayId( 'post', $product_id );
|
2020-07-28 20:18:30 -04:00
|
|
|
$product = \wc_get_product( $product_id );
|
2019-12-18 15:11:59 -05:00
|
|
|
|
|
|
|
|
$query = '
|
|
|
|
|
query ($id: ID!) {
|
|
|
|
|
product(id: $id) {
|
|
|
|
|
id
|
2020-10-13 15:01:44 -04:00
|
|
|
reviews(last: 5) {
|
2019-12-18 15:11:59 -05:00
|
|
|
averageRating
|
|
|
|
|
edges {
|
|
|
|
|
rating
|
|
|
|
|
node {
|
|
|
|
|
id
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
';
|
|
|
|
|
|
2022-08-26 14:53:36 -04:00
|
|
|
$variables = [ 'id' => $relay_id ];
|
2020-07-28 20:18:30 -04:00
|
|
|
$response = $this->graphql( compact( 'query', 'variables' ) );
|
2022-08-26 14:53:36 -04:00
|
|
|
$expected = [
|
2021-07-05 13:51:52 -04:00
|
|
|
$this->expectedField( 'product.id', $relay_id ),
|
|
|
|
|
$this->expectedField( 'product.reviews.averageRating', floatval( $product->get_average_rating() ) ),
|
2022-08-26 14:53:36 -04:00
|
|
|
];
|
2019-12-18 15:11:59 -05:00
|
|
|
|
2022-02-04 15:00:44 -05:00
|
|
|
foreach ( $reviews as $review_id ) {
|
2020-07-28 20:18:30 -04:00
|
|
|
$expected[] = $this->expectedEdge(
|
|
|
|
|
'product.reviews.edges',
|
2022-08-26 14:53:36 -04:00
|
|
|
[
|
2020-07-28 20:18:30 -04:00
|
|
|
'rating' => floatval( get_comment_meta( $review_id, 'rating', true ) ),
|
2022-08-26 14:53:36 -04:00
|
|
|
'node' => [ 'id' => $this->toRelayId( 'comment', $review_id ) ],
|
|
|
|
|
]
|
2020-07-28 20:18:30 -04:00
|
|
|
);
|
|
|
|
|
}
|
2019-12-18 15:11:59 -05:00
|
|
|
|
2020-07-28 20:18:30 -04:00
|
|
|
$this->assertQuerySuccessful( $response, $expected );
|
2019-12-18 15:11:59 -05:00
|
|
|
}
|
2020-07-13 19:17:28 -04:00
|
|
|
|
|
|
|
|
public function testProductGalleryImagesConnection() {
|
|
|
|
|
$image_id = $this->factory->post->create(
|
2022-08-26 14:53:36 -04:00
|
|
|
[
|
2020-07-13 19:17:28 -04:00
|
|
|
'post_type' => 'attachment',
|
|
|
|
|
'post_content' => 'Lorem ipsum dolor...',
|
2022-08-26 14:53:36 -04:00
|
|
|
]
|
2020-07-13 19:17:28 -04:00
|
|
|
);
|
2020-10-27 23:55:16 -04:00
|
|
|
$product_id = $this->factory->product->createSimple(
|
2022-08-26 14:53:36 -04:00
|
|
|
[ 'gallery_image_ids' => [ $image_id ] ]
|
2020-07-13 19:17:28 -04:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$query = '
|
|
|
|
|
query( $id: ID! ) {
|
|
|
|
|
product( id: $id ) {
|
|
|
|
|
galleryImages {
|
|
|
|
|
nodes {
|
|
|
|
|
id
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
';
|
|
|
|
|
|
2024-08-06 16:54:18 -06:00
|
|
|
$variables = [ 'id' => $this->toRelayId( 'post', $product_id ) ];
|
2022-02-04 15:00:44 -05:00
|
|
|
$response = $this->graphql( compact( 'query', 'variables' ) );
|
2020-10-27 23:55:16 -04:00
|
|
|
$this->assertQuerySuccessful(
|
|
|
|
|
$response,
|
2022-08-26 14:53:36 -04:00
|
|
|
[
|
2020-10-27 23:55:16 -04:00
|
|
|
$this->expectedNode(
|
|
|
|
|
'product.galleryImages.nodes',
|
2022-08-26 14:53:36 -04:00
|
|
|
[ 'id' => $this->toRelayId( 'post', $image_id ) ]
|
2022-02-04 15:00:44 -05:00
|
|
|
),
|
2022-08-26 14:53:36 -04:00
|
|
|
]
|
2020-07-13 19:17:28 -04:00
|
|
|
);
|
|
|
|
|
}
|
2023-09-15 00:21:00 -04:00
|
|
|
|
|
|
|
|
// tests
|
|
|
|
|
public function testProductQueryWithInterfaces() {
|
|
|
|
|
$product_id = $this->factory->product->createSimple();
|
|
|
|
|
$product = wc_get_product( $product_id );
|
|
|
|
|
|
|
|
|
|
$query = '
|
|
|
|
|
query ( $id: ID!, $format: PostObjectFieldFormatEnum ) {
|
|
|
|
|
product(id: $id) {
|
|
|
|
|
id
|
|
|
|
|
databaseId
|
|
|
|
|
name
|
|
|
|
|
slug
|
|
|
|
|
date
|
|
|
|
|
modified
|
|
|
|
|
status
|
|
|
|
|
featured
|
|
|
|
|
catalogVisibility
|
|
|
|
|
description(format: $format)
|
|
|
|
|
shortDescription(format: $format)
|
|
|
|
|
sku
|
|
|
|
|
dateOnSaleFrom
|
|
|
|
|
dateOnSaleTo
|
|
|
|
|
totalSales
|
|
|
|
|
averageRating
|
|
|
|
|
reviewCount
|
|
|
|
|
onSale
|
|
|
|
|
purchasable
|
|
|
|
|
link
|
|
|
|
|
reviewsAllowed
|
|
|
|
|
purchaseNote
|
|
|
|
|
menuOrder
|
2025-05-01 14:46:55 -04:00
|
|
|
virtual
|
2023-09-15 21:03:55 -04:00
|
|
|
... on ProductWithPricing {
|
2023-09-15 00:21:00 -04:00
|
|
|
price
|
|
|
|
|
regularPrice
|
|
|
|
|
salePrice
|
|
|
|
|
taxStatus
|
|
|
|
|
taxClass
|
|
|
|
|
}
|
2023-09-15 21:03:55 -04:00
|
|
|
... on InventoriedProduct {
|
2023-09-15 00:21:00 -04:00
|
|
|
manageStock
|
|
|
|
|
stockQuantity
|
|
|
|
|
backorders
|
|
|
|
|
soldIndividually
|
|
|
|
|
backordersAllowed
|
|
|
|
|
stockStatus
|
|
|
|
|
}
|
2023-09-15 21:03:55 -04:00
|
|
|
... on ProductWithDimensions {
|
2023-09-15 00:21:00 -04:00
|
|
|
weight
|
|
|
|
|
length
|
|
|
|
|
width
|
|
|
|
|
height
|
|
|
|
|
shippingClassId
|
|
|
|
|
shippingRequired
|
|
|
|
|
shippingTaxable
|
|
|
|
|
}
|
2023-09-15 21:03:55 -04:00
|
|
|
... on DownloadableProduct {
|
2023-09-15 00:21:00 -04:00
|
|
|
downloadExpiry
|
|
|
|
|
downloadable
|
|
|
|
|
downloadLimit
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Assertion One
|
|
|
|
|
*
|
|
|
|
|
* Test querying product.
|
|
|
|
|
*/
|
2024-08-06 16:54:18 -06:00
|
|
|
$variables = [ 'id' => $this->toRelayId( 'post', $product_id ) ];
|
2023-09-15 00:21:00 -04:00
|
|
|
$response = $this->graphql( compact( 'query', 'variables' ) );
|
|
|
|
|
$expected = $this->getExpectedProductData( $product_id );
|
|
|
|
|
|
|
|
|
|
$this->assertQuerySuccessful( $response, $expected );
|
|
|
|
|
|
|
|
|
|
// Clear cache
|
|
|
|
|
$this->clearLoaderCache( 'wc_post' );
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Assertion Two
|
|
|
|
|
*
|
|
|
|
|
* Test querying product with unformatted content (edit-product cap required).
|
|
|
|
|
*/
|
|
|
|
|
$this->loginAsShopManager();
|
|
|
|
|
$variables = [
|
2024-08-06 16:54:18 -06:00
|
|
|
'id' => $this->toRelayId( 'post', $product_id ),
|
2023-09-15 00:21:00 -04:00
|
|
|
'format' => 'RAW',
|
|
|
|
|
];
|
|
|
|
|
$response = $this->graphql( compact( 'query', 'variables' ) );
|
|
|
|
|
$expected = [
|
|
|
|
|
$this->expectedField( 'product.description', $product->get_description() ),
|
|
|
|
|
$this->expectedField( 'product.shortDescription', $product->get_short_description() ),
|
|
|
|
|
$this->expectedField( 'product.totalSales', $product->get_total_sales() ),
|
|
|
|
|
$this->expectedField( 'product.catalogVisibility', strtoupper( $product->get_catalog_visibility() ) ),
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$this->assertQuerySuccessful( $response, $expected );
|
|
|
|
|
}
|
2024-05-16 21:27:54 -04:00
|
|
|
|
|
|
|
|
public function testProductsQueryWithAttributesFilter() {
|
|
|
|
|
// Create product attributes.
|
|
|
|
|
$kind_attribute = $this->factory->product->createAttribute( 'kind', [ 'special', 'normal' ], 'Product type' );
|
|
|
|
|
$normal_term_id = get_term_by( 'slug', 'normal', 'pa_kind' )->term_id;
|
|
|
|
|
$special_term_id = get_term_by( 'slug', 'special', 'pa_kind' )->term_id;
|
|
|
|
|
|
|
|
|
|
// Create attribute objects.
|
|
|
|
|
$kind_attribute_normal_only = $this->factory->product->createAttributeObject(
|
|
|
|
|
$kind_attribute['attribute_id'],
|
|
|
|
|
$kind_attribute['attribute_taxonomy'],
|
|
|
|
|
[ $normal_term_id ]
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$kind_attribute_special_only = $this->factory->product->createAttributeObject(
|
|
|
|
|
$kind_attribute['attribute_id'],
|
|
|
|
|
$kind_attribute['attribute_taxonomy'],
|
|
|
|
|
[ $special_term_id ]
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$kind_attribute_both = $this->factory->product->createAttributeObject(
|
|
|
|
|
$kind_attribute['attribute_id'],
|
|
|
|
|
$kind_attribute['attribute_taxonomy'],
|
|
|
|
|
[ $normal_term_id, $special_term_id ]
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Create products.
|
|
|
|
|
$normal_product_id = $this->factory->product->createSimple(
|
|
|
|
|
[
|
|
|
|
|
'attributes' => [ $kind_attribute_normal_only ],
|
|
|
|
|
'default_attributes' => [ 'pa_kind' => 'normal' ],
|
|
|
|
|
]
|
|
|
|
|
);
|
|
|
|
|
$special_product_id = $this->factory->product->createSimple(
|
|
|
|
|
[
|
|
|
|
|
'attributes' => [ $kind_attribute_special_only ],
|
|
|
|
|
'default_attributes' => [ 'pa_kind' => 'special' ],
|
|
|
|
|
]
|
|
|
|
|
);
|
|
|
|
|
$both_product_id = $this->factory->product->createSimple(
|
|
|
|
|
[
|
|
|
|
|
'attributes' => [ $kind_attribute_both ],
|
|
|
|
|
]
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Create query.
|
|
|
|
|
$query = '
|
2026-03-24 20:42:15 -04:00
|
|
|
query( $where: RootQueryToProductConnectionWhereArgs ) {
|
2024-05-16 21:27:54 -04:00
|
|
|
products( where: $where ) {
|
|
|
|
|
nodes {
|
|
|
|
|
... on SimpleProduct {
|
|
|
|
|
id
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
';
|
|
|
|
|
|
|
|
|
|
$variables = [
|
|
|
|
|
'where' => [
|
|
|
|
|
'attributes' => [
|
|
|
|
|
'queries' => [
|
|
|
|
|
[
|
|
|
|
|
'taxonomy' => 'PA_KIND',
|
|
|
|
|
'terms' => [ 'normal' ],
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
$response = $this->graphql( compact( 'query', 'variables' ) );
|
|
|
|
|
$expected = [
|
|
|
|
|
$this->expectedNode(
|
|
|
|
|
'products.nodes',
|
2024-08-06 16:54:18 -06:00
|
|
|
[ 'id' => $this->toRelayId( 'post', $normal_product_id ) ]
|
2024-05-16 21:27:54 -04:00
|
|
|
),
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$this->assertQuerySuccessful( $response, $expected );
|
|
|
|
|
|
|
|
|
|
$variables = [
|
|
|
|
|
'where' => [
|
|
|
|
|
'attributes' => [
|
|
|
|
|
'queries' => [
|
|
|
|
|
[
|
|
|
|
|
'taxonomy' => 'PA_KIND',
|
|
|
|
|
'terms' => [ 'special' ],
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
$response = $this->graphql( compact( 'query', 'variables' ) );
|
|
|
|
|
$expected = [
|
|
|
|
|
$this->expectedNode(
|
|
|
|
|
'products.nodes',
|
2024-08-06 16:54:18 -06:00
|
|
|
[ 'id' => $this->toRelayId( 'post', $special_product_id ) ]
|
2024-05-16 21:27:54 -04:00
|
|
|
),
|
|
|
|
|
];
|
|
|
|
|
$this->assertQuerySuccessful( $response, $expected );
|
|
|
|
|
|
|
|
|
|
$variables = [
|
|
|
|
|
'where' => [
|
|
|
|
|
'attributes' => [
|
|
|
|
|
'queries' => [
|
|
|
|
|
[
|
|
|
|
|
'taxonomy' => 'PA_KIND',
|
|
|
|
|
'terms' => [ 'normal', 'special' ],
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
$response = $this->graphql( compact( 'query', 'variables' ) );
|
|
|
|
|
$expected = [
|
|
|
|
|
$this->expectedNode(
|
|
|
|
|
'products.nodes',
|
2024-08-06 16:54:18 -06:00
|
|
|
[ 'id' => $this->toRelayId( 'post', $both_product_id ) ]
|
2024-05-16 21:27:54 -04:00
|
|
|
),
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$this->assertQuerySuccessful( $response, $expected );
|
|
|
|
|
|
|
|
|
|
$variables = [
|
|
|
|
|
'where' => [
|
|
|
|
|
'attributes' => [
|
|
|
|
|
'queries' => [
|
|
|
|
|
[
|
|
|
|
|
'taxonomy' => 'PA_KIND',
|
|
|
|
|
'terms' => [ 'normal', 'special' ],
|
|
|
|
|
'operator' => 'NOT_IN',
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
$response = $this->graphql( compact( 'query', 'variables' ) );
|
|
|
|
|
$expected = [
|
|
|
|
|
$this->expectedField(
|
|
|
|
|
'products.nodes',
|
2024-08-06 16:54:18 -06:00
|
|
|
static::IS_FALSY
|
2024-05-16 21:27:54 -04:00
|
|
|
),
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$this->assertQuerySuccessful( $response, $expected );
|
|
|
|
|
|
|
|
|
|
$variables = [
|
|
|
|
|
'where' => [
|
|
|
|
|
'attributes' => [
|
|
|
|
|
'queries' => [
|
|
|
|
|
[
|
|
|
|
|
'taxonomy' => 'PA_KIND',
|
|
|
|
|
'terms' => [ 'normal' ],
|
|
|
|
|
'operator' => 'NOT_IN',
|
|
|
|
|
],
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
$response = $this->graphql( compact( 'query', 'variables' ) );
|
|
|
|
|
$expected = [
|
|
|
|
|
$this->expectedNode(
|
|
|
|
|
'products.nodes',
|
2024-08-06 16:54:18 -06:00
|
|
|
[ 'id' => $this->toRelayId( 'post', $special_product_id ) ]
|
2024-05-16 21:27:54 -04:00
|
|
|
),
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$this->assertQuerySuccessful( $response, $expected );
|
|
|
|
|
|
|
|
|
|
$variables = [
|
|
|
|
|
'where' => [
|
|
|
|
|
'attributes' => [
|
|
|
|
|
'queries' => [
|
|
|
|
|
[
|
|
|
|
|
'taxonomy' => 'PA_KIND',
|
|
|
|
|
'terms' => [ 'normal' ],
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'taxonomy' => 'PA_KIND',
|
|
|
|
|
'terms' => [ 'special' ],
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
'relation' => 'AND',
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
$response = $this->graphql( compact( 'query', 'variables' ) );
|
|
|
|
|
$expected = [
|
|
|
|
|
$this->expectedNode(
|
|
|
|
|
'products.nodes',
|
2024-08-06 16:54:18 -06:00
|
|
|
[ 'id' => $this->toRelayId( 'post', $both_product_id ) ]
|
2024-05-16 21:27:54 -04:00
|
|
|
),
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$this->assertQuerySuccessful( $response, $expected );
|
|
|
|
|
}
|
2019-08-26 15:13:51 -04:00
|
|
|
}
|