More tests modifications for Product and ProductVariation code coverage.

This commit is contained in:
Geoff Taylor
2019-06-05 19:46:01 -04:00
parent c60814f649
commit e13ddce4b2
3 changed files with 46 additions and 20 deletions
@@ -1,6 +1,7 @@
<?php
use GraphQLRelay\Relay;
use WPGraphQL\Type\WPEnumType;
class ProductHelper extends WCG_Helper {
private $index;
@@ -320,6 +321,8 @@ class ProductHelper extends WCG_Helper {
: 'STANDARD',
'manageStock' => $data->get_manage_stock(),
'stockQuantity' => $data->get_stock_quantity(),
'stockStatus' => self::get_stock_status_enum( $data->get_stock_status() ),
'backorders' => WPEnumType::get_safe_name( $data->get_backorders() ),
'soldIndividually' => $data->get_sold_individually(),
'weight' => $data->get_weight(),
'length' => $data->get_length(),
@@ -416,11 +419,11 @@ class ProductHelper extends WCG_Helper {
);
}
public function field( $id, $field_name = 'id' ) {
public function field( $id, $field_name = 'id', $args = array() ) {
$get = 'get_' . $field_name;
$product = wc_get_product( $id );
if ( ! empty( $product ) ) {
return $product->{$get}();
return $product->{$get}( ...$args );
}
return null;
+2
View File
@@ -73,6 +73,8 @@ class ProductQueriesTest extends \Codeception\TestCase\WPTestCase {
taxClass
manageStock
stockQuantity
stockStatus
backorders
soldIndividually
weight
length
+39 -18
View File
@@ -105,7 +105,7 @@ class ProductVariationQueriesTest extends \Codeception\TestCase\WPTestCase {
}
public function testVariationsQueryAndWhereArgs() {
$id = Relay::toGlobalId( 'product', $this->products['product'] );
$id = $this->product_helper->to_relay_id( $this->products['product'] );
$variations = $this->products['variations'];
$query = '
@@ -117,6 +117,9 @@ class ProductVariationQueriesTest extends \Codeception\TestCase\WPTestCase {
$parentNotIn: [Int]
) {
product( id: $id ) {
price
regularPrice
salePrice
variations( where: {
minPrice: $minPrice,
parent: $parent,
@@ -138,13 +141,28 @@ class ProductVariationQueriesTest extends \Codeception\TestCase\WPTestCase {
*/
wp_set_current_user( $this->shop_manager );
$variables = array( 'id' => $id );
$actual = do_graphql_request( $query, 'variationsQuery', $variables );
$expected = array(
$actual = do_graphql_request( $query, 'variationsQuery', $variables );
$prices = $this->product_helper->field( $this->products['product'], 'variation_prices', array( true ) );
$product_fields = array(
'price' => \wc_graphql_price( current( $prices['price'] ) )
. ' - '
. \wc_graphql_price( end( $prices['price'] ) ),
'regularPrice' => \wc_graphql_price( current( $prices['regular_price'] ) )
. ' - '
. \wc_graphql_price( end( $prices['regular_price'] ) ),
'salePrice' => null,
);
$expected = array(
'data' => array(
'product' => array(
'variations' => array(
'nodes' => $this->helper->print_nodes( $variations ),
),
'product' => array_merge(
$product_fields,
array(
'variations' => array(
'nodes' => $this->helper->print_nodes( $variations ),
),
)
),
),
);
@@ -163,18 +181,21 @@ class ProductVariationQueriesTest extends \Codeception\TestCase\WPTestCase {
$actual = do_graphql_request( $query, 'variationsQuery', $variables );
$expected = array(
'data' => array(
'product' => array(
'variations' => array(
'nodes' => $this->helper->print_nodes(
$variations,
array(
'filter' => function( $id ) {
$variation = new WC_Product_Variation( $id );
return 15.00 <= floatval( $variation->get_price() );
}
)
'product' => array_merge(
$product_fields,
array(
'variations' => array(
'nodes' => $this->helper->print_nodes(
$variations,
array(
'filter' => function( $id ) {
$variation = new WC_Product_Variation( $id );
return 15.00 <= floatval( $variation->get_price() );
}
)
),
),
),
)
),
),
);