@@ -836,28 +836,28 @@ public function getCatalog() {
';
// Create cart page.
- $wpdb = $this->getModule( 'WPDb' );
-
+ $wpdb = $this->getModule( 'WPDb' );
+
$cart_page_id = $wpdb->havePostInDatabase(
- [
+ array(
'post_type' => 'page',
'post_title' => 'Cart',
'post_name' => 'cart',
'post_author' => 1,
'post_content' => $cart_page_content,
'post_status' => 'publish',
- ]
+ )
);
$wpdb->haveOptionInDatabase( 'woocommerce_cart_page_id', $cart_page_id );
$checkout_page_id = $wpdb->havePostInDatabase(
- [
+ array(
'post_type' => 'page',
'post_title' => 'Checkout',
'post_name' => 'checkout',
'post_author' => 1,
'post_content' => $checkout_page_content,
'post_status' => 'publish',
- ]
+ )
);
$wpdb->haveOptionInDatabase( 'woocommerce_checkout_page_id', $checkout_page_id );
@@ -883,19 +883,19 @@ public function _setupStore() {
// Enable payment gateway.
$wpdb->haveOptionInDatabase(
'woocommerce_bacs_settings',
- [
+ array(
'enabled' => 'yes',
'title' => 'Direct bank transfer',
'description' => 'Make your payment directly into our bank account. Please use your Order ID as the payment reference. Your order will not be shipped until the funds have cleared in our account.',
'instructions' => 'Instructions that will be added to the thank you page and emails.',
'account' => '',
- ]
+ )
);
// forcing has_block_template to be false
add_filter( 'woocommerce_has_block_template', '__return_false', 10, 2 );
- //Additional cart fees.
+ // Additional cart fees.
add_action(
'woocommerce_cart_calculate_fees',
static function () {
@@ -939,15 +939,15 @@ static function () {
$zone->add_shipping_method( 'flat_rate' );
$zone->add_shipping_method( 'free_shipping' );
- global $wp_rewrite;
+ global $wp_rewrite;
- //Write the rule
- $wp_rewrite->set_permalink_structure('/%postname%/');
+ // Write the rule
+ $wp_rewrite->set_permalink_structure( '/%postname%/' );
- //Set the option
- update_option( "rewrite_rules", FALSE );
+ // Set the option
+ update_option( 'rewrite_rules', false );
- //Flush the rules and tell it to write htaccess
+ // Flush the rules and tell it to write htaccess
$wp_rewrite->flush_rules( true );
}
@@ -967,10 +967,10 @@ public function haveAProductInTheDatabase( $args, &$product_id, $term = 'simple'
// Create Product
$product_id = $wpdb->havePostInDatabase(
array_replace_recursive(
- [
+ array(
'post_type' => 'product',
'post_title' => 't-shirt',
- 'meta_input' => [
+ 'meta_input' => array(
'_visibility' => 'visible',
'_sku' => '',
'_price' => '100',
@@ -991,38 +991,38 @@ public function haveAProductInTheDatabase( $args, &$product_id, $term = 'simple'
'_length' => '',
'_width' => '',
'_height' => '',
- '_upsell_ids' => [],
- '_cross_sell_ids' => [],
+ '_upsell_ids' => array(),
+ '_cross_sell_ids' => array(),
'_purchase_note' => '',
- '_default_attributes' => [],
- '_product_attributes' => [],
+ '_default_attributes' => array(),
+ '_product_attributes' => array(),
'_virtual' => false,
'_downloadable' => false,
'_download_limit' => -1,
'_download_expiry' => -1,
'_featured' => false,
- '_wc_rating_counts' => [],
+ '_wc_rating_counts' => array(),
'_wc_average_rating' => 0,
'_wc_review_count' => 0,
- ],
- ],
+ ),
+ ),
$args
)
);
if ( ! $term_id ) {
$term_id = $wpdb->grabTermIdFromDatabase(
- [
+ array(
'name' => $term,
'slug' => $term,
- ]
+ )
);
}
$term_taxonomy_id = $wpdb->grabTermTaxonomyIdFromDatabase(
- [
+ array(
'term_id' => $term_id,
'taxonomy' => 'product_type',
- ]
+ )
);
$wpdb->haveTermRelationshipInDatabase( $product_id, $term_id );
}
@@ -1034,10 +1034,10 @@ public function setupStoreAndUsers() {
$userId = $wpdb->haveUserInDatabase(
'jimbo1234',
'customer',
- [
+ array(
'user_pass' => 'password',
'user_email' => 'jimbo1234@example.com',
- ]
+ )
);
}
diff --git a/tests/_support/Helper/Wpunit.php b/tests/_support/Helper/Wpunit.php
index b0307f53e..b84493d48 100644
--- a/tests/_support/Helper/Wpunit.php
+++ b/tests/_support/Helper/Wpunit.php
@@ -30,10 +30,10 @@ public function _initialize() {
*/
public function _beforeSuite( $settings = null ) {
$helper = $this->product();
- $helper->create_attribute( 'size', [ 'small', 'medium', 'large' ], 'Product size' );
- $helper->create_attribute( 'color', [ 'red', 'blue', 'green' ], 'Product color' );
+ $helper->create_attribute( 'size', array( 'small', 'medium', 'large' ), 'Product size' );
+ $helper->create_attribute( 'color', array( 'red', 'blue', 'green' ), 'Product color' );
codecept_debug( 'ATTRIBUTES_LOADED' );
- add_action( 'init_graphql_request', [ self::class, 'shortcode_test_init' ] );
+ add_action( 'init_graphql_request', array( self::class, 'shortcode_test_init' ) );
codecept_debug( 'SHORTCODE_INITIALIZED' );
\Stripe\Stripe::setApiKey(
defined( 'STRIPE_API_SECRET_KEY' ) ? STRIPE_API_SECRET_KEY : getenv( 'STRIPE_API_SECRET_KEY' )
@@ -81,12 +81,12 @@ public function tax_rate() {
}
public function get_nodes( $ids, $crud ) {
- $nodes = [];
+ $nodes = array();
foreach ( $ids as $id ) {
$nodes[] = $crud->get_query_data( $id );
}
- return [ 'nodes' => $nodes ];
+ return array( 'nodes' => $nodes );
}
public function clear_loader_cache( $loader_name ) {
@@ -95,7 +95,7 @@ public function clear_loader_cache( $loader_name ) {
}
public static function shortcode_test_init() {
- add_shortcode( 'shortcode_test', [ self::class, 'shortcode_test_handler' ] );
+ add_shortcode( 'shortcode_test', array( self::class, 'shortcode_test_handler' ) );
}
public static function shortcode_test_handler( $atts ) {
diff --git a/tests/_support/Helper/crud-helpers/cart.php b/tests/_support/Helper/crud-helpers/cart.php
index 004f2779f..4bd0b3f05 100644
--- a/tests/_support/Helper/crud-helpers/cart.php
+++ b/tests/_support/Helper/crud-helpers/cart.php
@@ -10,7 +10,7 @@ public function to_relay_id( $id ) {
public function add( ...$products ) {
$keys = array();
- foreach( $products as $product ) {
+ foreach ( $products as $product ) {
if ( gettype( $product ) === 'array' ) {
if ( empty( $product['product_id'] ) ) {
codecept_debug( $product );
@@ -51,9 +51,9 @@ public function print_query( $id = 0 ) {
'isEmpty' => $cart->is_empty(),
'displayPricesIncludeTax' => $cart->display_prices_including_tax(),
'needsShippingAddress' => $cart->needs_shipping_address(),
- 'totalTaxes' => ! empty( $cart->get_tax_totals() )
+ 'totalTaxes' => ! empty( $cart->get_tax_totals() )
? array_map(
- function( $tax_data ) {
+ function ( $tax_data ) {
return array(
'id' => $tax_data->tax_rate_id,
'label' => $tax_data->label,
@@ -79,8 +79,8 @@ public function print_item_query( $key ) {
if ( ! empty( $variation ) ) {
$variation = \wc_get_product( $variation );
foreach ( $variation->get_attributes() as $name => $default_value ) {
- if ( isset( $variation_data["attribute_{$name}"] ) ) {
- $value = $variation_data["attribute_{$name}"];
+ if ( isset( $variation_data[ "attribute_{$name}" ] ) ) {
+ $value = $variation_data[ "attribute_{$name}" ];
} else {
$value = $default_value;
}
@@ -145,7 +145,7 @@ public function print_fee_query( $id ) {
$fees = $cart->get_fees();
$fee = ! empty( $fees[ $id ] ) ? $fees[ $id ] : null;
- return !empty( $fee )
+ return ! empty( $fee )
? array(
'id' => $fee->id,
'name' => $fee->name,
@@ -158,15 +158,15 @@ public function print_fee_query( $id ) {
}
public function print_nodes( $processors = array(), $_ = null ) {
- $cart = WC()->cart;
- $ids = array_keys( $cart->get_cart() );
+ $cart = WC()->cart;
+ $ids = array_keys( $cart->get_cart() );
$default_processors = array(
- 'mapper' => function( $key ) {
+ 'mapper' => function ( $key ) {
return array( 'key' => $key );
},
- 'filter' => function( $key ) {
+ 'filter' => function ( $key ) {
return true;
- }
+ },
);
$processors = array_merge( $default_processors, $processors );
@@ -177,24 +177,24 @@ public function print_nodes( $processors = array(), $_ = null ) {
}
public function print_fee_nodes( $processors = array(), $_ = null ) {
- $cart = WC()->cart;
- $ids = array_keys( $cart->get_fees() );
+ $cart = WC()->cart;
+ $ids = array_keys( $cart->get_fees() );
$default_processors = array(
- 'mapper' => function( $id ) {
+ 'mapper' => function ( $id ) {
return array( 'id' => $id );
},
- 'sorter' => function( $id_a, $id_b ) {
+ 'sorter' => function ( $id_a, $id_b ) {
return 0;
},
- 'filter' => function( $id ) {
+ 'filter' => function ( $id ) {
return true;
- }
+ },
);
$processors = array_merge( $default_processors, $processors );
$results = array_filter( $ids, $processors['filter'] );
- if( ! empty( $results ) ) {
+ if ( ! empty( $results ) ) {
usort( $results, $processors['sorter'] );
}
diff --git a/tests/_support/Helper/crud-helpers/coupon.php b/tests/_support/Helper/crud-helpers/coupon.php
index b9e57cd48..015386ff0 100644
--- a/tests/_support/Helper/crud-helpers/coupon.php
+++ b/tests/_support/Helper/crud-helpers/coupon.php
@@ -22,11 +22,11 @@ public function create( $args = array(), $save = true ) {
$coupon->set_props(
array_merge(
array(
- 'code' => $amount . 'off',
- 'amount' => floatval( $amount ),
- 'date_expires' => null,
- 'discount_type' => 'percent',
- 'description' => 'Test coupon',
+ 'code' => $amount . 'off',
+ 'amount' => floatval( $amount ),
+ 'date_expires' => null,
+ 'discount_type' => 'percent',
+ 'description' => 'Test coupon',
),
$args
)
@@ -38,7 +38,7 @@ public function create( $args = array(), $save = true ) {
}
// Return instance in not saving.
- if( ! $save ) {
+ if ( ! $save ) {
return $coupon;
}
@@ -79,46 +79,46 @@ public function print_query( $id ) {
'emailRestrictions' => ! empty( $data->get_email_restrictions() )
? $data->get_email_restrictions()
: null,
- 'products' => [
+ 'products' => array(
'nodes' => array_map(
- function( $id ) {
+ function ( $id ) {
return array( 'databaseId' => $id );
},
$data->get_product_ids()
),
- ],
- 'excludedProducts' => [
+ ),
+ 'excludedProducts' => array(
'nodes' => array_map(
- function( $id ) {
+ function ( $id ) {
return array( 'databaseId' => $id );
},
$data->get_excluded_product_ids()
),
- ],
- 'productCategories' => [
+ ),
+ 'productCategories' => array(
'nodes' => array_map(
- function( $id ) {
+ function ( $id ) {
return array( 'productCategoryId' => $id );
},
$data->get_product_categories()
),
- ],
- 'excludedProductCategories' => [
+ ),
+ 'excludedProductCategories' => array(
'nodes' => array_map(
- function( $id ) {
+ function ( $id ) {
return array( 'productCategoryId' => $id );
},
$data->get_excluded_product_categories()
),
- ],
- 'usedBy' => [
+ ),
+ 'usedBy' => array(
'nodes' => array_map(
- function( $id ) {
+ function ( $id ) {
return array( 'databaseId' => $id );
},
$data->get_used_by()
),
- ],
+ ),
);
}
diff --git a/tests/_support/Helper/crud-helpers/customer.php b/tests/_support/Helper/crud-helpers/customer.php
index ae8f05b74..fc6b6e138 100644
--- a/tests/_support/Helper/crud-helpers/customer.php
+++ b/tests/_support/Helper/crud-helpers/customer.php
@@ -39,28 +39,28 @@ public function create( $args = array() ) {
'role' => 'customer',
'username' => $username,
'billing' => array(
- 'first_name' => $first_name,
- 'last_name' => $last_name,
- 'company' => '',
- 'address_1' => $street,
- 'address_2' => '',
- 'city' => $city,
- 'state' => $state,
- 'postcode' => $postcode,
- 'country' => $country,
- 'email' => $email,
- 'phone' => $phone,
+ 'first_name' => $first_name,
+ 'last_name' => $last_name,
+ 'company' => '',
+ 'address_1' => $street,
+ 'address_2' => '',
+ 'city' => $city,
+ 'state' => $state,
+ 'postcode' => $postcode,
+ 'country' => $country,
+ 'email' => $email,
+ 'phone' => $phone,
),
'shipping' => array(
- 'first_name' => $first_name,
- 'last_name' => $last_name,
- 'company' => '',
- 'address_1' => $street,
- 'address_2' => '',
- 'city' => $city,
- 'state' => $state,
- 'postcode' => $postcode,
- 'country' => $country,
+ 'first_name' => $first_name,
+ 'last_name' => $last_name,
+ 'company' => '',
+ 'address_1' => $street,
+ 'address_2' => '',
+ 'city' => $city,
+ 'state' => $state,
+ 'postcode' => $postcode,
+ 'country' => $country,
),
'is_paying_customer' => false,
),
@@ -77,7 +77,7 @@ public function create( $args = array() ) {
}
public function print_query( $id, $session = false ) {
- $data = new WC_Customer( $id, $session );
+ $data = new WC_Customer( $id, $session );
$wp_user = get_user_by( 'ID', $data->get_id() );
return array(
diff --git a/tests/_support/Helper/crud-helpers/includes/class-dummy.php b/tests/_support/Helper/crud-helpers/includes/class-dummy.php
index b950ae368..5231fd9dd 100644
--- a/tests/_support/Helper/crud-helpers/includes/class-dummy.php
+++ b/tests/_support/Helper/crud-helpers/includes/class-dummy.php
@@ -1,8 +1,7 @@
username();
- $fn = $this->firstname();
- $ln = $this->lastname();
-
- $dump = array(
- "primaryText" => $this->words(6),
- "secondaryText" => $this->sentence(),
- "userid" => $this->number(),
- "rid" => $this->number(),
-
- "link" => "http://www.google.com",
- "date" => $this->mdy(),
- "time" => $this->hm(),
- "text" => $this->text(40,140),
- "body" => $this->text(140,600),
- "number" => $this->number(),
- "background" => $this->image(640,480),
- "image" => $this->image(),
- "thumbnail" => $this->placeholder(150,150),
- "price" => $this->price(),
- "product" => $this->product(),
- "firstname" => $fn,
- "lastname" => $ln,
- "name" => $fn." ".$ln,
- "username" => $un,
- "email" => $this->email($un),
- "street" => $this->street(),
- "city" => $this->city(),
- "state" => $this->state(),
- "zipcode" => $this->zipcode(),
- "telephone" => $this->telephone()
- );
-
- return($dump);
- }
-
- public function dump( $qty = 5 ) {
- $a = array();
-
- for($b=0;$b<$qty;$b++) {
- $a[] = $this->all();
- }
-
- return($a);
- }
-
- public function yesno( $w = 5 ) {
- if (rand(0,10) > $w) {
- return(true);
- } else {
- return(false);
- }
- }
-
- public function mdy() {
- return(rand(1,12)."/".rand(1,30)."/".rand(1943,2010));
- }
-
- public function hm( $s = false ) {
- $t = rand(1,12).":".rand(10,59);
-
- if ($s) { $t = $t.":".rand(10,59); }
-
- if ($this->yesno()) { $t .= " AM"; } else { $t .= " PM"; }
-
- return($t);
- }
-
- public function text( $min = 30, $max = 120, $nospaces = false ) {
- $s = "Aliquam lectus nulla, eleifend ut tellus in, euismod porttitor arcu. Aliquam erat volutpat. Morbi massa sapien, condimentum ultrices pretium porta, semper ac lacus. Nulla pharetra, urna a lacinia facilisis, neque libero placerat turpis, vel tincidunt massa nunc ac nunc. In nec volutpat ligula. Sed hendrerit ligula vel felis venenatis egestas. Duis sit amet pharetra erat. Interdum et malesuada fames ac ante ipsum primis in faucibus. Morbi rutrum vel magna et tincidunt. Curabitur mattis, sem eget suscipit porta, nibh enim auctor mi, eu lacinia magna velit eu quam. Donec commodo ultrices lorem vel ultrices. Aliquam erat volutpat. Praesent in libero bibendum, euismod dui quis, volutpat purus. Fusce non est egestas, volutpat ipsum ut, cursus augue. In hac habitasse platea dictumst. Mum volutpat.";
- $s = explode(" ",$s);
- shuffle($s);
- $s = implode(" ", $s);
- $s = ucfirst(substr($s, 0, rand($min,$max)));
-
- if ($nospaces) {
- $s = str_replace(" ","",$s);
- }
-
- return($s);
- }
-
- public function words( $max = 5, $cmin = 2, $cmax = 6) {
- $t = array();
-
- for ($a=0; $a <= ($max-1); $a++) {
- $t[] = str_replace(array(",","."), array("",""), $this->text($cmin, ($cmax+2), true));
- }
-
- return(implode(" ",$t));
- }
-
- public function sentence( $min = 3, $max = 10 ) {
- $l = rand($min,$max);
-
- $w = ucfirst(strtolower($this->words($l))).".";
- return($w);
- }
-
- function number($min=10, $max=1000) {
- return(round(rand($min,$max)));
- }
-
- public function image( $w = 300, $h = 300 ) {
- $c = array("city","people","animals","food","business","cats","technics","sports");
- shuffle($c);
- $u = "http://lorempixel.com/".$w."/".$h."/".current($c);
-
- return($u);
- }
-
- public function placeholder( $w = 300, $h = 300 ) {
- return("http://placehold.it/".$w."x".$h);
- }
-
- public function price( $min = 2, $max = 500 ) {
- $c = array("00","99","49","00","50","29"); shuffle($c);
- $p = rand($min,$max).".".current($c);
- return($p);
- }
-
- public function product() {
- $items = "book,exam,hub cap,paperclip,model train,phaser,socks,light saber,lamp,piano,salad,lunch,violin,pony,deoderant,powder,radio,purse,mp3 player,eyeliner,laptop,wheel,glove,boot,pen,slippers,bed,dog,wall,paper,cellular phone,clock,tree,guitar,mullet,dog,cushion,table,ginger,roundabout,cake,teapot,dreadlocks,lampshade,piggy bank,church,eagle,butterfly,keyboard,laptop";
- $adj1 = "original,brand new,mint,new-in-box,trendy,vintage,retro,old,new,gently used,big,small,tarnished,broken,refurbished";
- $adj2 = "hipster,red,blue,green,orange,muddy,waterproof,purple,stainless steel,24k gold,handmade,custom";
-
- $a = explode(",",$adj1);
- $a2 = explode(",",$adj2);
- $i = explode(",",$items);
- shuffle($a);
- shuffle($a2);
- shuffle($i);
-
- //$t = ucfirst($a[0]." ".$a2[3]." ".$i[1]);
- $t = ucfirst($a2[3]." ".$i[1]);
- return($t);
- }
-
- public function firstname( $gender = "any" ) {
- $m = explode(",","James,John,Robert,Michael,William,David,Richard,Charles,Joseph,Thomas,Christopher,Daniel,Paul,Mark,Donald,George,Kenneth,Steven,Edward,Brian,Ronald,Anthony,Kevin,Jason,Matthew,Gary,Timothy,Jose,Larry,Jeffrey,Frank,Scott,Eric,Stephen,Andrew,Raymond,Gregory,Joshua,Jerry,Dennis,Walter,Patrick,Peter,Harold,Douglas,Henry,Carl,Arthur,Ryan,Roger");
- $fm = explode(",","Mary,Patricia,Linda,Barbara,Elizabeth,Jennifer,Maria,Susan,Margaret,Dorothy,Lisa,Nancy,Karen,Betty,Helen,Sandra,Donna,Carol,Ruth,Sharon,Michelle,Laura,Sarah,Kimberly,Deborah,Jessica,Shirley,Cynthia,Angela,Melissa,Brenda,Amy,Anna,Rebecca,Virginia,Kathleen,Pamela,Martha,Debra,Amanda,Stephanie,Carolyn,Christine,Marie,Janet,Catherine,Frances,Ann,Joyce,Diane");
- $all = array_merge($m, $fm);
-
- shuffle($m);
- shuffle($fm);
- shuffle($all);
-
- switch ($gender) {
- default:
- return(current($all));
- break;
- case "m":
- return(current($m));
- break;
- case "fm":
- return(current($fm));
- break;
- }
- }
-
- public function lastname() {
- $list = explode(",","Smith,Johnson,Williams,Jones,Brown,Davis,Miller,Wilson,Moore,Taylor,Anderson,Thomas,Jackson,White,Harris,Martin,Thompson,Garcia,Martinez,Robinson,Clark,Rodriguez,Lewis,Lee,Walker,Hall,Allen,Young,Hernandez,King,Wright,Lopez,Hill,Scott,Green,Adams,Baker,Gonzalez,Nelson,Carter,Mitchell,Perez,Roberts,Turner,Phillips,Campbell,Parker,Evans,Edwards,Collins,Dexter,Dennis,Menace,Jesus,Bart,Homer,Dan,Bub,Sparkster,Yanni");
- shuffle($list);
- return(current($list));
- }
-
- public function name() {
- $f = $this->firstname();
- $l = $this->lastname();
- return($f." ".$l);
- }
-
- public function username() {
- $n = rand(1,300);
- $f = substr($this->firstname(),0,1);
- $l = $this->lastname() .$n;
-
- return(strtolower($f.$l));
-
- }
-
- public function email( $u = false ) {
- if (!$u) { $u = $this->username(); }
- $m = array("@gmail.com","@hotmail.com","@yahoo.com","@aol.com","@redlinederby.com");
- shuffle($m);
- $m = current($m);
-
-
- return(strtolower($u.$m));
- }
-
- public function street() {
- $list = explode(",","Second,Third,First,Fourth,Park,Fifth,Main,Sixth,Oak,Seventh,Pine,Maple,Cedar,Eighth,Elm,Washington,Ninth,Lake,Hill");
- $n = rand(700,5500);
- shuffle($list);
- return($n." ".current($list)." St.");
- }
-
- public function city() {
- $list = explode(",","Gotham City,Metropolis,Oz,Smallville,Mos Eisley,Mayberry,Bedrock,Springfield,Vice City,Atlantis,Hill Valley,New New York,Cloud City,Bikini Bottom");
- shuffle($list);
- return(current($list));
- }
-
- public function state( $full = false ) {
- $list = array('AL'=>"Alabama",'AK'=>"Alaska", 'AZ'=>"Arizona", 'AR'=>"Arkansas", 'CA'=>"California", 'CO'=>"Colorado", 'CT'=>"Connecticut", 'DE'=>"Delaware", 'DC'=>"District Of Columbia", 'FL'=>"Florida", 'GA'=>"Georgia", 'HI'=>"Hawaii", 'ID'=>"Idaho", 'IL'=>"Illinois", 'IN'=>"Indiana", 'IA'=>"Iowa", 'KS'=>"Kansas", 'KY'=>"Kentucky", 'LA'=>"Louisiana", 'ME'=>"Maine", 'MD'=>"Maryland", 'MA'=>"Massachusetts", 'MI'=>"Michigan", 'MN'=>"Minnesota", 'MS'=>"Mississippi", 'MO'=>"Missouri", 'MT'=>"Montana", 'NE'=>"Nebraska", 'NV'=>"Nevada", 'NH'=>"New Hampshire", 'NJ'=>"New Jersey", 'NM'=>"New Mexico", 'NY'=>"New York", 'NC'=>"North Carolina", 'ND'=>"North Dakota", 'OH'=>"Ohio", 'OK'=>"Oklahoma", 'OR'=>"Oregon", 'PA'=>"Pennsylvania", 'RI'=>"Rhode Island", 'SC'=>"South Carolina", 'SD'=>"South Dakota", 'TN'=>"Tennessee", 'TX'=>"Texas", 'UT'=>"Utah", 'VT'=>"Vermont", 'VA'=>"Virginia", 'WA'=>"Washington", 'WV'=>"West Virginia", 'WI'=>"Wisconsin", 'WY'=>"Wyoming");
- $abbv = array_rand($list, 1);
-
- if ($full) {
- return($list[$abbv]);
- } else {
- return($abbv);
- }
- }
-
- public function zipcode() {
- return(rand(12345,98765));
- }
-
- public function address() {
- $a = $this->street()."
".$this->city().", ".$this->state()." ".$this->zipcode();
- return($a);
- }
-
- public function telephone() {
- return(rand(123,876)."-".rand(123,987)."-".rand(1234,9876));
- }
-}
\ No newline at end of file
+ public function __construct() {
+ }
+
+ public function all() {
+ $un = $this->username();
+ $fn = $this->firstname();
+ $ln = $this->lastname();
+
+ $dump = array(
+ 'primaryText' => $this->words( 6 ),
+ 'secondaryText' => $this->sentence(),
+ 'userid' => $this->number(),
+ 'rid' => $this->number(),
+ 'link' => 'http://www.google.com',
+ 'date' => $this->mdy(),
+ 'time' => $this->hm(),
+ 'text' => $this->text( 40, 140 ),
+ 'body' => $this->text( 140, 600 ),
+ 'number' => $this->number(),
+ 'background' => $this->image( 640, 480 ),
+ 'image' => $this->image(),
+ 'thumbnail' => $this->placeholder( 150, 150 ),
+ 'price' => $this->price(),
+ 'product' => $this->product(),
+ 'firstname' => $fn,
+ 'lastname' => $ln,
+ 'name' => $fn . ' ' . $ln,
+ 'username' => $un,
+ 'email' => $this->email( $un ),
+ 'street' => $this->street(),
+ 'city' => $this->city(),
+ 'state' => $this->state(),
+ 'zipcode' => $this->zipcode(),
+ 'telephone' => $this->telephone(),
+ );
+
+ return( $dump );
+ }
+
+ public function dump( $qty = 5 ) {
+ $a = array();
+
+ for ( $b = 0;$b < $qty;$b++ ) {
+ $a[] = $this->all();
+ }
+
+ return( $a );
+ }
+
+ public function yesno( $w = 5 ) {
+ if ( rand( 0, 10 ) > $w ) {
+ return( true );
+ } else {
+ return( false );
+ }
+ }
+
+ public function mdy() {
+ return( rand( 1, 12 ) . '/' . rand( 1, 30 ) . '/' . rand( 1943, 2010 ) );
+ }
+
+ public function hm( $s = false ) {
+ $t = rand( 1, 12 ) . ':' . rand( 10, 59 );
+
+ if ( $s ) {
+ $t = $t . ':' . rand( 10, 59 ); }
+
+ if ( $this->yesno() ) {
+ $t .= ' AM';
+ } else {
+ $t .= ' PM'; }
+
+ return( $t );
+ }
+
+ public function text( $min = 30, $max = 120, $nospaces = false ) {
+ $s = 'Aliquam lectus nulla, eleifend ut tellus in, euismod porttitor arcu. Aliquam erat volutpat. Morbi massa sapien, condimentum ultrices pretium porta, semper ac lacus. Nulla pharetra, urna a lacinia facilisis, neque libero placerat turpis, vel tincidunt massa nunc ac nunc. In nec volutpat ligula. Sed hendrerit ligula vel felis venenatis egestas. Duis sit amet pharetra erat. Interdum et malesuada fames ac ante ipsum primis in faucibus. Morbi rutrum vel magna et tincidunt. Curabitur mattis, sem eget suscipit porta, nibh enim auctor mi, eu lacinia magna velit eu quam. Donec commodo ultrices lorem vel ultrices. Aliquam erat volutpat. Praesent in libero bibendum, euismod dui quis, volutpat purus. Fusce non est egestas, volutpat ipsum ut, cursus augue. In hac habitasse platea dictumst. Mum volutpat.';
+ $s = explode( ' ', $s );
+ shuffle( $s );
+ $s = implode( ' ', $s );
+ $s = ucfirst( substr( $s, 0, rand( $min, $max ) ) );
+
+ if ( $nospaces ) {
+ $s = str_replace( ' ', '', $s );
+ }
+
+ return( $s );
+ }
+
+ public function words( $max = 5, $cmin = 2, $cmax = 6 ) {
+ $t = array();
+
+ for ( $a = 0; $a <= ( $max - 1 ); $a++ ) {
+ $t[] = str_replace( array( ',', '.' ), array( '', '' ), $this->text( $cmin, ( $cmax + 2 ), true ) );
+ }
+
+ return( implode( ' ', $t ) );
+ }
+
+ public function sentence( $min = 3, $max = 10 ) {
+ $l = rand( $min, $max );
+
+ $w = ucfirst( strtolower( $this->words( $l ) ) ) . '.';
+ return( $w );
+ }
+
+ function number( $min = 10, $max = 1000 ) {
+ return( round( rand( $min, $max ) ) );
+ }
+
+ public function image( $w = 300, $h = 300 ) {
+ $c = array( 'city', 'people', 'animals', 'food', 'business', 'cats', 'technics', 'sports' );
+ shuffle( $c );
+ $u = 'http://lorempixel.com/' . $w . '/' . $h . '/' . current( $c );
+
+ return( $u );
+ }
+
+ public function placeholder( $w = 300, $h = 300 ) {
+ return( 'http://placehold.it/' . $w . 'x' . $h );
+ }
+
+ public function price( $min = 2, $max = 500 ) {
+ $c = array( '00', '99', '49', '00', '50', '29' );
+ shuffle( $c );
+ $p = rand( $min, $max ) . '.' . current( $c );
+ return( $p );
+ }
+
+ public function product() {
+ $items = 'book,exam,hub cap,paperclip,model train,phaser,socks,light saber,lamp,piano,salad,lunch,violin,pony,deoderant,powder,radio,purse,mp3 player,eyeliner,laptop,wheel,glove,boot,pen,slippers,bed,dog,wall,paper,cellular phone,clock,tree,guitar,mullet,dog,cushion,table,ginger,roundabout,cake,teapot,dreadlocks,lampshade,piggy bank,church,eagle,butterfly,keyboard,laptop';
+ $adj1 = 'original,brand new,mint,new-in-box,trendy,vintage,retro,old,new,gently used,big,small,tarnished,broken,refurbished';
+ $adj2 = 'hipster,red,blue,green,orange,muddy,waterproof,purple,stainless steel,24k gold,handmade,custom';
+
+ $a = explode( ',', $adj1 );
+ $a2 = explode( ',', $adj2 );
+ $i = explode( ',', $items );
+ shuffle( $a );
+ shuffle( $a2 );
+ shuffle( $i );
+
+ // $t = ucfirst($a[0]." ".$a2[3]." ".$i[1]);
+ $t = ucfirst( $a2[3] . ' ' . $i[1] );
+ return( $t );
+ }
+
+ public function firstname( $gender = 'any' ) {
+ $m = explode( ',', 'James,John,Robert,Michael,William,David,Richard,Charles,Joseph,Thomas,Christopher,Daniel,Paul,Mark,Donald,George,Kenneth,Steven,Edward,Brian,Ronald,Anthony,Kevin,Jason,Matthew,Gary,Timothy,Jose,Larry,Jeffrey,Frank,Scott,Eric,Stephen,Andrew,Raymond,Gregory,Joshua,Jerry,Dennis,Walter,Patrick,Peter,Harold,Douglas,Henry,Carl,Arthur,Ryan,Roger' );
+ $fm = explode( ',', 'Mary,Patricia,Linda,Barbara,Elizabeth,Jennifer,Maria,Susan,Margaret,Dorothy,Lisa,Nancy,Karen,Betty,Helen,Sandra,Donna,Carol,Ruth,Sharon,Michelle,Laura,Sarah,Kimberly,Deborah,Jessica,Shirley,Cynthia,Angela,Melissa,Brenda,Amy,Anna,Rebecca,Virginia,Kathleen,Pamela,Martha,Debra,Amanda,Stephanie,Carolyn,Christine,Marie,Janet,Catherine,Frances,Ann,Joyce,Diane' );
+ $all = array_merge( $m, $fm );
+
+ shuffle( $m );
+ shuffle( $fm );
+ shuffle( $all );
+
+ switch ( $gender ) {
+ default:
+ return( current( $all ) );
+ break;
+ case 'm':
+ return( current( $m ) );
+ break;
+ case 'fm':
+ return( current( $fm ) );
+ break;
+ }
+ }
+
+ public function lastname() {
+ $list = explode( ',', 'Smith,Johnson,Williams,Jones,Brown,Davis,Miller,Wilson,Moore,Taylor,Anderson,Thomas,Jackson,White,Harris,Martin,Thompson,Garcia,Martinez,Robinson,Clark,Rodriguez,Lewis,Lee,Walker,Hall,Allen,Young,Hernandez,King,Wright,Lopez,Hill,Scott,Green,Adams,Baker,Gonzalez,Nelson,Carter,Mitchell,Perez,Roberts,Turner,Phillips,Campbell,Parker,Evans,Edwards,Collins,Dexter,Dennis,Menace,Jesus,Bart,Homer,Dan,Bub,Sparkster,Yanni' );
+ shuffle( $list );
+ return( current( $list ) );
+ }
+
+ public function name() {
+ $f = $this->firstname();
+ $l = $this->lastname();
+ return( $f . ' ' . $l );
+ }
+
+ public function username() {
+ $n = rand( 1, 300 );
+ $f = substr( $this->firstname(), 0, 1 );
+ $l = $this->lastname() . $n;
+
+ return( strtolower( $f . $l ) );
+ }
+
+ public function email( $u = false ) {
+ if ( ! $u ) {
+ $u = $this->username(); }
+ $m = array( '@gmail.com', '@hotmail.com', '@yahoo.com', '@aol.com', '@redlinederby.com' );
+ shuffle( $m );
+ $m = current( $m );
+
+ return( strtolower( $u . $m ) );
+ }
+
+ public function street() {
+ $list = explode( ',', 'Second,Third,First,Fourth,Park,Fifth,Main,Sixth,Oak,Seventh,Pine,Maple,Cedar,Eighth,Elm,Washington,Ninth,Lake,Hill' );
+ $n = rand( 700, 5500 );
+ shuffle( $list );
+ return( $n . ' ' . current( $list ) . ' St.' );
+ }
+
+ public function city() {
+ $list = explode( ',', 'Gotham City,Metropolis,Oz,Smallville,Mos Eisley,Mayberry,Bedrock,Springfield,Vice City,Atlantis,Hill Valley,New New York,Cloud City,Bikini Bottom' );
+ shuffle( $list );
+ return( current( $list ) );
+ }
+
+ public function state( $full = false ) {
+ $list = array(
+ 'AL' => 'Alabama',
+ 'AK' => 'Alaska',
+ 'AZ' => 'Arizona',
+ 'AR' => 'Arkansas',
+ 'CA' => 'California',
+ 'CO' => 'Colorado',
+ 'CT' => 'Connecticut',
+ 'DE' => 'Delaware',
+ 'DC' => 'District Of Columbia',
+ 'FL' => 'Florida',
+ 'GA' => 'Georgia',
+ 'HI' => 'Hawaii',
+ 'ID' => 'Idaho',
+ 'IL' => 'Illinois',
+ 'IN' => 'Indiana',
+ 'IA' => 'Iowa',
+ 'KS' => 'Kansas',
+ 'KY' => 'Kentucky',
+ 'LA' => 'Louisiana',
+ 'ME' => 'Maine',
+ 'MD' => 'Maryland',
+ 'MA' => 'Massachusetts',
+ 'MI' => 'Michigan',
+ 'MN' => 'Minnesota',
+ 'MS' => 'Mississippi',
+ 'MO' => 'Missouri',
+ 'MT' => 'Montana',
+ 'NE' => 'Nebraska',
+ 'NV' => 'Nevada',
+ 'NH' => 'New Hampshire',
+ 'NJ' => 'New Jersey',
+ 'NM' => 'New Mexico',
+ 'NY' => 'New York',
+ 'NC' => 'North Carolina',
+ 'ND' => 'North Dakota',
+ 'OH' => 'Ohio',
+ 'OK' => 'Oklahoma',
+ 'OR' => 'Oregon',
+ 'PA' => 'Pennsylvania',
+ 'RI' => 'Rhode Island',
+ 'SC' => 'South Carolina',
+ 'SD' => 'South Dakota',
+ 'TN' => 'Tennessee',
+ 'TX' => 'Texas',
+ 'UT' => 'Utah',
+ 'VT' => 'Vermont',
+ 'VA' => 'Virginia',
+ 'WA' => 'Washington',
+ 'WV' => 'West Virginia',
+ 'WI' => 'Wisconsin',
+ 'WY' => 'Wyoming',
+ );
+ $abbv = array_rand( $list, 1 );
+
+ if ( $full ) {
+ return( $list[ $abbv ] );
+ } else {
+ return( $abbv );
+ }
+ }
+
+ public function zipcode() {
+ return( rand( 12345, 98765 ) );
+ }
+
+ public function address() {
+ $a = $this->street() . '
' . $this->city() . ', ' . $this->state() . ' ' . $this->zipcode();
+ return( $a );
+ }
+
+ public function telephone() {
+ return( rand( 123, 876 ) . '-' . rand( 123, 987 ) . '-' . rand( 1234, 9876 ) );
+ }
+}
diff --git a/tests/_support/Helper/crud-helpers/order-item.php b/tests/_support/Helper/crud-helpers/order-item.php
index 41a5a5805..26a3343a7 100644
--- a/tests/_support/Helper/crud-helpers/order-item.php
+++ b/tests/_support/Helper/crud-helpers/order-item.php
@@ -21,7 +21,7 @@ public function add_coupon( $order, $coupon_id = 0, $save = true ) {
if ( empty( $coupon_id ) ) {
// Get order product IDs
$product_ids = array();
- foreach( $order->get_items() as $item ) {
+ foreach ( $order->get_items() as $item ) {
if ( ! in_array( $item->get_product_id(), $product_ids ) ) {
$product_ids[] = $item->get_product_id();
}
@@ -31,7 +31,7 @@ public function add_coupon( $order, $coupon_id = 0, $save = true ) {
CouponHelper::instance()->create( array( 'product_ids' => $product_ids ) )
);
} else {
- $coupon = new WC_Coupon( $coupon_id );
+ $coupon = new WC_Coupon( $coupon_id );
}
// Apply coupon to order.
@@ -55,17 +55,17 @@ public function add_fee( $order, $args = array(), $save = true ) {
// Set the array for tax calculations.
$calculate_tax_for = array(
- 'country' => $country_code,
- 'state' => '',
- 'postcode' => '',
- 'city' => ''
+ 'country' => $country_code,
+ 'state' => '',
+ 'postcode' => '',
+ 'city' => '',
);
$imported_total_fee = 8.4342;
// Create and add fee to order.
$item = new WC_Order_Item_Fee();
- $item->set_name( "Fee" ); // Generic fee name
+ $item->set_name( 'Fee' ); // Generic fee name
$item->set_amount( $imported_total_fee ); // Fee amount
$item->set_tax_class( '' ); // default for ''
$item->set_tax_status( 'taxable' ); // or 'none'
@@ -225,4 +225,4 @@ public function print_query( $id ) {
public function print_nodes( $ids = 0, $processors = array() ) {
return array();
}
-}
\ No newline at end of file
+}
diff --git a/tests/_support/Helper/crud-helpers/order.php b/tests/_support/Helper/crud-helpers/order.php
index 01b0fd9ce..7eb8a8eb9 100644
--- a/tests/_support/Helper/crud-helpers/order.php
+++ b/tests/_support/Helper/crud-helpers/order.php
@@ -14,15 +14,15 @@ public function to_relay_id( $id ) {
return Relay::toGlobalId( 'order', $id );
}
- public function set_to_customer_billing_address( $order, $customer, $save = true ) {
- if ( ! is_a( $order, WC_Order::class ) ) {
- $order = new WC_Order( absint( $order ) );
- }
- if ( ! is_a( $customer, WC_Customer::class ) ) {
- $customer = new WC_Customer( $customer );
- }
-
- // Set billing address
+ public function set_to_customer_billing_address( $order, $customer, $save = true ) {
+ if ( ! is_a( $order, WC_Order::class ) ) {
+ $order = new WC_Order( absint( $order ) );
+ }
+ if ( ! is_a( $customer, WC_Customer::class ) ) {
+ $customer = new WC_Customer( $customer );
+ }
+
+ // Set billing address
$order->set_billing_first_name( $customer->get_first_name() );
$order->set_billing_last_name( $customer->get_last_name() );
$order->set_billing_company( $customer->get_billing_company() );
@@ -33,24 +33,24 @@ public function set_to_customer_billing_address( $order, $customer, $save = true
$order->set_billing_postcode( $customer->get_billing_postcode() );
$order->set_billing_country( $customer->get_billing_country() );
$order->set_billing_email( $customer->get_billing_email() );
- $order->set_billing_phone( $customer->get_billing_phone() );
+ $order->set_billing_phone( $customer->get_billing_phone() );
- if ( $save ) {
- return $order->save();
+ if ( $save ) {
+ return $order->save();
}
return $order;
- }
+ }
- public function set_to_customer_shipping_address( $order, $customer, $save = true ) {
- if ( ! is_a( $order, WC_Order::class ) ) {
- $order = new WC_Order( absint( $order ) );
- }
- if ( ! is_a( $customer, WC_Customer::class ) ) {
- $customer = new WC_Customer( $customer );
- }
+ public function set_to_customer_shipping_address( $order, $customer, $save = true ) {
+ if ( ! is_a( $order, WC_Order::class ) ) {
+ $order = new WC_Order( absint( $order ) );
+ }
+ if ( ! is_a( $customer, WC_Customer::class ) ) {
+ $customer = new WC_Customer( $customer );
+ }
- // Set shipping address
+ // Set shipping address
$order->set_shipping_first_name( $customer->get_first_name() );
$order->set_shipping_last_name( $customer->get_last_name() );
$order->set_shipping_company( $customer->get_shipping_company() );
@@ -59,46 +59,46 @@ public function set_to_customer_shipping_address( $order, $customer, $save = tru
$order->set_shipping_city( $customer->get_shipping_city() );
$order->set_shipping_state( $customer->get_shipping_state() );
$order->set_shipping_postcode( $customer->get_shipping_postcode() );
- $order->set_shipping_country( $customer->get_shipping_country() );
+ $order->set_shipping_country( $customer->get_shipping_country() );
- if ( $save ) {
- return $order->save();
+ if ( $save ) {
+ return $order->save();
}
return $order;
- }
+ }
public function create( $args = array(), $items = array() ) {
if ( empty( $args['customer_id'] ) ) {
- $customer = new WC_Customer( CustomerHelper::instance()->create() );
+ $customer = new WC_Customer( CustomerHelper::instance()->create() );
$customer_id = $customer->get_id();
} else {
$customer_id = $args['customer_id'];
}
$shipping_method_helper = ShippingMethodHelper::instance();
- $shipping_method_helper->create_legacy_flat_rate_instance();
-
- // Create order
- $order_data = array_merge(
- array(
- 'status' => 'pending',
- 'customer_id' => $customer_id,
- 'customer_note' => '',
- 'total' => '',
- ),
- $args
+ $shipping_method_helper->create_legacy_flat_rate_instance();
+
+ // Create order
+ $order_data = array_merge(
+ array(
+ 'status' => 'pending',
+ 'customer_id' => $customer_id,
+ 'customer_note' => '',
+ 'total' => '',
+ ),
+ $args
);
$_SERVER['REMOTE_ADDR'] = '127.0.0.1'; // Required, else wc_create_order throws an exception
- $order = wc_create_order( $order_data );
+ $order = wc_create_order( $order_data );
// Add line items
if ( ! empty( $items['line_items'] ) ) {
- foreach( $items['line_items'] as $item ) {
+ foreach ( $items['line_items'] as $item ) {
$order = OrderItemHelper::instance()->add_line_item( $order, $item, false );
}
} else {
- for ( $i = 0; $i < rand( 1, 3 ); $i++ ) {
+ for ( $i = 0; $i < rand( 1, 3 ); $i++ ) {
$order = OrderItemHelper::instance()->add_line_item(
$order,
array(
@@ -107,33 +107,34 @@ public function create( $args = array(), $items = array() ) {
),
false
);
- }
+ }
}
$order->save();
-
- // Add billing / shipping address
- $order = $this->set_to_customer_billing_address( $order, $customer_id, false );
- $order = $this->set_to_customer_shipping_address( $order, $customer_id, false );
+ // Add billing / shipping address
+ $order = $this->set_to_customer_billing_address( $order, $customer_id, false );
+ $order = $this->set_to_customer_shipping_address( $order, $customer_id, false );
// Add shipping costs
$shipping_taxes = WC_Tax::calc_shipping_tax( '10', WC_Tax::get_shipping_tax_rates() );
$rate = new WC_Shipping_Rate( 'flat_rate_shipping', 'Flat rate shipping', '10', $shipping_taxes, 'flat_rate' );
$item = new WC_Order_Item_Shipping();
- $item->set_props( array(
- 'method_title' => $rate->label,
- 'method_id' => $rate->id,
- 'total' => wc_format_decimal( $rate->cost ),
- 'taxes' => $rate->taxes,
- ) );
+ $item->set_props(
+ array(
+ 'method_title' => $rate->label,
+ 'method_id' => $rate->id,
+ 'total' => wc_format_decimal( $rate->cost ),
+ 'taxes' => $rate->taxes,
+ )
+ );
foreach ( $rate->get_meta_data() as $key => $value ) {
$item->add_meta_data( $key, $value, true );
}
- $order->add_item( $item );
+ $order->add_item( $item );
// Set payment gateway
$payment_gateways = WC()->payment_gateways->payment_gateways();
- $order->set_payment_method( $payment_gateways['bacs'] );
+ $order->set_payment_method( $payment_gateways['bacs'] );
// Set totals
$order->set_shipping_total( 10 );
@@ -141,14 +142,14 @@ public function create( $args = array(), $items = array() ) {
$order->set_discount_tax( 0 );
$order->set_cart_tax( 0 );
$order->set_shipping_tax( 0 );
- $order->set_total( 50 ); // 4 x $10 simple helper product
+ $order->set_total( 50 ); // 4 x $10 simple helper product
// Set meta data.
if ( ! empty( $args['meta_data'] ) ) {
$order->set_meta_data( $args['meta_data'] );
}
- // Save and return ID.
+ // Save and return ID.
return $order->save();
}
@@ -157,24 +158,24 @@ public function get_order_key( $id ) {
}
public function has_product( $id, $product_id ) {
- $order = new WC_Order( $id );
+ $order = new WC_Order( $id );
$line_items = $order->get_items();
- foreach ( $line_items as $item ) {
- if ( $item['product_id'] == $product_id ) {
- return true;
- }
+ foreach ( $line_items as $item ) {
+ if ( $item['product_id'] == $product_id ) {
+ return true;
+ }
}
return false;
}
- public function print_query( $id ) {
+ public function print_query( $id ) {
$data = new WC_Order( $id );
if ( ! $data->get_id() ) {
return null;
}
// Get unformatted country before it's cached.
- $billing_country = ! empty( $data->get_billing_country( 'edit' ) )
+ $billing_country = ! empty( $data->get_billing_country( 'edit' ) )
? 'US'
: null;
$shipping_country = ! empty( $data->get_address( 'shipping' )['country'] )
@@ -186,10 +187,10 @@ public function print_query( $id ) {
'databaseId' => $data->get_id(),
'currency' => ! empty( $data->get_currency() ) ? $data->get_currency() : null,
'orderVersion' => ! empty( $data->get_version() ) ? $data->get_version() : null,
- 'date' => $data->get_date_created()->__toString(),
- 'modified' => $data->get_date_modified()->__toString(),
+ 'date' => $data->get_date_created()->__toString(),
+ 'modified' => $data->get_date_modified()->__toString(),
'status' => WPEnumType::get_safe_name( $data->get_status() ),
- 'discountTotal' => \wc_graphql_price( $data->get_discount_total(), array( 'currency' => $data->get_currency() ) ),
+ 'discountTotal' => \wc_graphql_price( $data->get_discount_total(), array( 'currency' => $data->get_currency() ) ),
'discountTax' => \wc_graphql_price( $data->get_discount_tax(), array( 'currency' => $data->get_currency() ) ),
'shippingTotal' => \wc_graphql_price( $data->get_shipping_total(), array( 'currency' => $data->get_currency() ) ),
'shippingTax' => \wc_graphql_price( $data->get_shipping_tax(), array( 'currency' => $data->get_currency() ) ),
@@ -328,8 +329,8 @@ public function print_restricted_query( $id ) {
'databaseId' => $id,
'currency' => null,
'orderVersion' => null,
- 'date' => $data->get_date_created()->__toString(),
- 'modified' => $data->get_date_modified()->__toString(),
+ 'date' => $data->get_date_created()->__toString(),
+ 'modified' => $data->get_date_modified()->__toString(),
'status' => WPEnumType::get_safe_name( $data->get_status() ),
'discountTotal' => \wc_graphql_price( $data->get_discount_total(), array( 'currency' => $data->get_currency() ) ),
'discountTax' => \wc_graphql_price( $data->get_discount_tax(), array( 'currency' => $data->get_currency() ) ),
@@ -424,7 +425,8 @@ public function print_restricted_query( $id ) {
: null,
'datePaid' => ! empty( $data->get_date_paid() )
? $data->get_date_paid()->__toString()
- : null,'cartHash' => null,
+ : null,
+ 'cartHash' => null,
'shippingAddressMapUrl' => ! empty( $data->get_shipping_address_map_url() )
? $data->get_shipping_address_map_url()
: null,
diff --git a/tests/_support/Helper/crud-helpers/product-variation.php b/tests/_support/Helper/crud-helpers/product-variation.php
index 8dd805f4a..de9299b16 100644
--- a/tests/_support/Helper/crud-helpers/product-variation.php
+++ b/tests/_support/Helper/crud-helpers/product-variation.php
@@ -22,7 +22,7 @@ public function reset_indexes() {
}
private function next_slug() {
- $slug = 'test-variation-' . absint( $this->index );
+ $slug = 'test-variation-' . absint( $this->index );
$this->index += 1;
return $slug;
}
@@ -45,7 +45,7 @@ public function create( $product_id, $args = array() ) {
}
// Create medium size variation with image
- $image_id = \wp_insert_post(
+ $image_id = \wp_insert_post(
array(
'post_author' => 1,
'post_content' => '',
@@ -99,7 +99,7 @@ public function create( $product_id, $args = array() ) {
public function print_query( $id ) {
$data = new WC_Product_Variation( $id );
- if( empty( $data ) ) {
+ if ( empty( $data ) ) {
return null;
}
@@ -154,7 +154,7 @@ public function print_query( $id ) {
: null,
'hasAttributes' => ! empty( $data->has_attributes() ) ? $data->has_attributes() : null,
'type' => WPEnumType::get_safe_name( $data->get_type() ),
- 'parent' => array (
+ 'parent' => array(
'node' => array(
'id' => Relay::toGlobalId( 'product', $data->get_parent_id() ),
),
@@ -173,8 +173,8 @@ public function print_attributes( $id, $from = 'VARIATION' ) {
$results = array();
- foreach( $attributes as $name => $value ) {
- $term = get_term_by( 'slug', $value, $name );
+ foreach ( $attributes as $name => $value ) {
+ $term = get_term_by( 'slug', $value, $name );
$results[] = array(
'id' => base64_encode( $product->get_id() . '||' . $name . '||' . $value ),
'attributeId' => ! empty( $term ) ? $term->term_id : 0,
@@ -183,11 +183,11 @@ public function print_attributes( $id, $from = 'VARIATION' ) {
);
}
- return ! empty ( $results ) ? array( 'nodes' => $results ) : null;
+ return ! empty( $results ) ? array( 'nodes' => $results ) : null;
}
public function field( $id, $field_name = 'id' ) {
- $get = 'get_' . $field_name;
+ $get = 'get_' . $field_name;
$variation = new WC_Product_Variation( $id );
if ( ! empty( $variation ) ) {
return $variation->{$get}();
diff --git a/tests/_support/Helper/crud-helpers/product.php b/tests/_support/Helper/crud-helpers/product.php
index 2ec343215..efd503a16 100644
--- a/tests/_support/Helper/crud-helpers/product.php
+++ b/tests/_support/Helper/crud-helpers/product.php
@@ -22,7 +22,7 @@ public function reset_indexes() {
}
private function next_slug() {
- $slug = 'test-product-' . absint( $this->index );
+ $slug = 'test-product-' . absint( $this->index );
$this->index += 1;
return $slug;
}
@@ -35,7 +35,7 @@ public static function get_stock_status_enum( $status ) {
);
if ( in_array( $status, array_keys( $statuses ) ) ) {
- return $statuses[$status];
+ return $statuses[ $status ];
}
return null;
@@ -55,7 +55,7 @@ public function create_product_category( $term, $parent_id = 0 ) {
if ( term_exists( $term, 'product_cat' ) ) {
$term = get_term( $term, 'product_cat', ARRAY_A );
} else {
- $args = [];
+ $args = array();
if ( $parent_id ) {
$args['parent'] = $parent_id;
}
@@ -100,9 +100,9 @@ public function create_simple( $args = array() ) {
}
public function create_external( $args = array() ) {
- $product = new WC_Product_External();
- $name = $this->dummy->product();
- $price = $this->dummy->price( 15, 200 );
+ $product = new WC_Product_External();
+ $name = $this->dummy->product();
+ $price = $this->dummy->price( 15, 200 );
$product->set_props(
array_merge(
array(
@@ -124,7 +124,7 @@ public function create_grouped( $args = array(), $children = array() ) {
$children = array( $this->create_simple() );
}
- $product = new WC_Product_Grouped();
+ $product = new WC_Product_Grouped();
$product->set_props(
array_merge(
array(
@@ -136,12 +136,15 @@ public function create_grouped( $args = array(), $children = array() ) {
)
);
$product->set_children( $children );
- return array( 'parent' => $product->save(), 'children' => $children );
+ return array(
+ 'parent' => $product->save(),
+ 'children' => $children,
+ );
}
public function create_variable( $args = array() ) {
$product = new WC_Product_Variable();
- $props = array_merge(
+ $props = array_merge(
array(
'name' => $this->dummy->product(),
'slug' => $this->next_slug(),
@@ -204,7 +207,7 @@ public function create_related( $args = array() ) {
'upsell_ids' => $upsell_ids,
)
),
- 'related' => array( $related_product_id ),
+ 'related' => array( $related_product_id ),
'cross_sell' => $cross_sell_ids,
'upsell' => $upsell_ids,
);
@@ -278,7 +281,7 @@ public function create_attribute( $raw_name = 'size', $terms = array( 'small' ),
$result = term_exists( $term, $attribute->slug );
if ( ! $result ) {
- $result = wp_insert_term( $term, $attribute->slug );
+ $result = wp_insert_term( $term, $attribute->slug );
$return['term_ids'][] = absint( $result['term_id'] );
} else {
$return['term_ids'][] = absint( $result['term_id'] );
@@ -300,7 +303,7 @@ public static function createDownload( $id = 0 ) {
if ( $id ) {
$product = \wc_get_product( $id );
- $product->set_downloads( array($download) );
+ $product->set_downloads( array( $download ) );
$product->save();
}
@@ -308,9 +311,9 @@ public static function createDownload( $id = 0 ) {
}
public function print_query( $id, $raw = false ) {
- $data = wc_get_product( $id );
+ $data = wc_get_product( $id );
$is_shop_manager = false;
- $user = wp_get_current_user();
+ $user = wp_get_current_user();
if ( $user && in_array( 'shop_manager', (array) $user->roles ) ) {
$is_shop_manager = true;
}
@@ -380,7 +383,7 @@ public function print_query( $id, $raw = false ) {
'shippingTaxable' => $data->is_shipping_taxable(),
'link' => get_post_permalink( $id ),
'totalSales' => $is_shop_manager ? $data->get_total_sales() : null,
- 'catalogVisibility' => $is_shop_manager ? strtoupper( $data->get_catalog_visibility() ) :null,
+ 'catalogVisibility' => $is_shop_manager ? strtoupper( $data->get_catalog_visibility() ) : null,
);
}
@@ -390,7 +393,7 @@ public function print_attributes( $id ) {
$results = array();
- foreach( $attributes as $attribute_name => $attribute ) {
+ foreach ( $attributes as $attribute_name => $attribute ) {
$results[] = array(
'id' => base64_encode( $attribute_name . ':' . $id . ':' . $attribute->get_name() ),
'attributeId' => $attribute->get_id(),
@@ -405,12 +408,12 @@ public function print_attributes( $id ) {
);
}
- return ! empty ( $results ) ? array( 'nodes' => $results ) : null;
+ return ! empty( $results ) ? array( 'nodes' => $results ) : null;
}
public function print_downloads( $id ) {
- $product = wc_get_product( $id );
- $downloads = (array) $product->get_downloads();
+ $product = wc_get_product( $id );
+ $downloads = (array) $product->get_downloads();
if ( empty( $downloads ) ) {
return null;
}
@@ -433,10 +436,10 @@ public function print_downloads( $id ) {
}
public function print_grouped( $id ) {
- $data = wc_get_product( $id );
+ $data = wc_get_product( $id );
$children = array( 'nodes' => array() );
foreach ( $data->get_children() as $child ) {
- $parent_id = $this->field( $child, 'parent_id' );
+ $parent_id = $this->field( $child, 'parent_id' );
$children['nodes'][] = array(
'id' => $this->to_relay_id( $child ),
'parent' => ! empty( $parent_id ) ? array( 'id' => $this->to_relay_id( $parent_id ) ) : null,
@@ -461,7 +464,7 @@ public function print_external( $id ) {
}
public function field( $id, $field_name = 'id', $args = array() ) {
- $get = 'get_' . $field_name;
+ $get = 'get_' . $field_name;
$product = wc_get_product( $id );
if ( ! empty( $product ) ) {
return $product->{$get}( ...$args );
@@ -472,7 +475,7 @@ public function field( $id, $field_name = 'id', $args = array() ) {
public function create_review( $product_id, $args = array() ) {
$firstName = $this->dummy->firstname();
- $data = array_merge(
+ $data = array_merge(
array(
'comment_post_ID' => $product_id,
'comment_author' => $firstName,
@@ -503,7 +506,7 @@ public function print_review_edges( $ids ) {
$reviews[] = array(
'rating' => floatval( get_comment_meta( $review_id, 'rating', true ) ),
'node' => array(
- 'id' => Relay::toGlobalId( 'comment', $review_id )
+ 'id' => Relay::toGlobalId( 'comment', $review_id ),
),
);
}
diff --git a/tests/_support/Helper/crud-helpers/refund.php b/tests/_support/Helper/crud-helpers/refund.php
index c5fee8a40..12125572d 100644
--- a/tests/_support/Helper/crud-helpers/refund.php
+++ b/tests/_support/Helper/crud-helpers/refund.php
@@ -53,7 +53,7 @@ public function print_query( $id ) {
'reason' => $data->get_reason(),
'amount' => $data->get_amount(),
'refundedBy' => array(
- 'id' => Relay::toGlobalId( 'user', $data->get_refunded_by() )
+ 'id' => Relay::toGlobalId( 'user', $data->get_refunded_by() ),
),
'date' => $data->get_date_modified(),
);
diff --git a/tests/_support/Helper/crud-helpers/tax-rate.php b/tests/_support/Helper/crud-helpers/tax-rate.php
index ae8b38c79..539796c6e 100644
--- a/tests/_support/Helper/crud-helpers/tax-rate.php
+++ b/tests/_support/Helper/crud-helpers/tax-rate.php
@@ -22,7 +22,7 @@ public function get_index() {
public function create( $args = array() ) {
$rate_args = array();
- $fields = array(
+ $fields = array(
'country' => 'tax_rate_country',
'state' => 'tax_rate_state',
'rate' => 'tax_rate',
@@ -33,7 +33,7 @@ public function create( $args = array() ) {
'order' => 'tax_rate_order',
'class' => 'tax_rate_class',
);
- foreach( $args as $key => $value ) {
+ foreach ( $args as $key => $value ) {
if ( in_array( $key, array_keys( $fields ) ) ) {
$rate_args[ $fields[ $key ] ] = $value;
}
@@ -44,7 +44,7 @@ public function create( $args = array() ) {
'tax_rate_country' => 'US',
'tax_rate_state' => '*',
'tax_rate' => 20.0000,
- 'tax_rate_name' => "VAT",
+ 'tax_rate_name' => 'VAT',
'tax_rate_priority' => 1,
'tax_rate_compound' => 1,
'tax_rate_shipping' => 1,
@@ -96,8 +96,8 @@ public function print_query( $id ) {
'databaseId' => absint( $rate->tax_rate_id ),
'country' => ! empty( $rate->tax_rate_country ) ? $rate->tax_rate_country : null,
'state' => ! empty( $rate->tax_rate_state ) ? $rate->tax_rate_state : null,
- 'postcode' => ! empty( $rate->tax_rate_postcode ) ? $rate->tax_rate_postcode : array( "*" ),
- 'city' => ! empty( $rate->tax_rate_city ) ? $rate->tax_rate_city : array( "*" ),
+ 'postcode' => ! empty( $rate->tax_rate_postcode ) ? $rate->tax_rate_postcode : array( '*' ),
+ 'city' => ! empty( $rate->tax_rate_city ) ? $rate->tax_rate_city : array( '*' ),
'rate' => ! empty( $rate->tax_rate ) ? $rate->tax_rate : null,
'name' => ! empty( $rate->tax_rate_name ) ? $rate->tax_rate_name : null,
'priority' => absint( $rate->tax_rate_priority ),
diff --git a/tests/_support/Helper/crud-helpers/wcg-helper.php b/tests/_support/Helper/crud-helpers/wcg-helper.php
index 4248802b3..107201737 100644
--- a/tests/_support/Helper/crud-helpers/wcg-helper.php
+++ b/tests/_support/Helper/crud-helpers/wcg-helper.php
@@ -15,38 +15,38 @@ protected function __construct() {
$this->dummy = new Dummy();
}
- public static function instance(){
+ public static function instance() {
return new static();
}
- public abstract function to_relay_id( $id );
+ abstract public function to_relay_id( $id );
- public abstract function print_query( $id );
+ abstract public function print_query( $id );
public function print_nodes( $ids, $processors = array() ) {
$default_processors = array(
- 'mapper' => function( $id ) {
- return array( 'id' => Relay::toGlobalId( $this->node_type, $id ) );
+ 'mapper' => function ( $id ) {
+ return array( 'id' => Relay::toGlobalId( $this->node_type, $id ) );
},
- 'sorter' => function( $id_a, $id_b ) {
+ 'sorter' => function ( $id_a, $id_b ) {
if ( $id_a == $id_b ) {
return 0;
}
return ( $id_a > $id_b ) ? -1 : 1;
},
- 'filter' => function( $id ) {
+ 'filter' => function ( $id ) {
return true;
- }
+ },
);
$processors = array_merge( $default_processors, $processors );
$results = array_filter( $ids, $processors['filter'] );
- if( ! empty( $results ) ) {
+ if ( ! empty( $results ) ) {
usort( $results, $processors['sorter'] );
}
return array_values( array_map( $processors['mapper'], $results ) );
}
-}
\ No newline at end of file
+}
diff --git a/tests/_support/TestCase/WooGraphQLTestCase.php b/tests/_support/TestCase/WooGraphQLTestCase.php
index d03c2c71c..9365f553c 100644
--- a/tests/_support/TestCase/WooGraphQLTestCase.php
+++ b/tests/_support/TestCase/WooGraphQLTestCase.php
@@ -35,7 +35,7 @@ public function setUp(): void {
parent::setUp();
// Load factories.
- $factories = [
+ $factories = array(
'Product',
'ProductVariation',
'Cart',
@@ -47,7 +47,7 @@ public function setUp(): void {
'Order',
'Refund',
'PaymentToken',
- ];
+ );
foreach ( $factories as $factory ) {
$factory_name = strtolower( preg_replace( '/\B([A-Z])/', '_$1', $factory ) );
@@ -58,7 +58,7 @@ public function setUp(): void {
$this->factory->shipping_zone->createLegacyFlatRate();
// Create test users.
- $this->shop_manager = $this->factory->user->create( [ 'role' => 'shop_manager' ] );
+ $this->shop_manager = $this->factory->user->create( array( 'role' => 'shop_manager' ) );
$this->customer = $this->factory->customer->create();
// For these tests, we are not concerned with Approved Download Directory functionality.
diff --git a/tests/_support/Utils/Dummy.php b/tests/_support/Utils/Dummy.php
index 930e67547..a89bfd02e 100644
--- a/tests/_support/Utils/Dummy.php
+++ b/tests/_support/Utils/Dummy.php
@@ -39,7 +39,7 @@ public function all() {
$fn = $this->firstname();
$ln = $this->lastname();
- $dump = [
+ $dump = array(
'primaryText' => $this->words( 6 ),
'secondaryText' => $this->sentence(),
'userid' => $this->number(),
@@ -66,13 +66,13 @@ public function all() {
'state' => $this->state(),
'zipcode' => $this->zipcode(),
'telephone' => $this->telephone(),
- ];
+ );
return( $dump );
}
public function dump( $qty = 5 ) {
- $a = [];
+ $a = array();
for ( $b = 0;$b < $qty;$b++ ) {
$a[] = $this->all();
@@ -122,10 +122,10 @@ public function text( $min = 30, $max = 120, $nospaces = false ) {
}
public function words( $max = 5, $cmin = 2, $cmax = 6 ) {
- $t = [];
+ $t = array();
for ( $a = 0; $a <= ( $max - 1 ); $a++ ) {
- $t[] = str_replace( [ ',', '.' ], [ '', '' ], $this->text( $cmin, ( $cmax + 2 ), true ) );
+ $t[] = str_replace( array( ',', '.' ), array( '', '' ), $this->text( $cmin, ( $cmax + 2 ), true ) );
}
return( implode( ' ', $t ) );
@@ -143,7 +143,7 @@ public function number( $min = 10, $max = 1000 ) {
}
public function image( $w = 300, $h = 300 ) {
- $c = [ 'city', 'people', 'animals', 'food', 'business', 'cats', 'technics', 'sports' ];
+ $c = array( 'city', 'people', 'animals', 'food', 'business', 'cats', 'technics', 'sports' );
shuffle( $c );
$u = 'http://lorempixel.com/' . $w . '/' . $h . '/' . current( $c );
@@ -155,7 +155,7 @@ public function placeholder( $w = 300, $h = 300 ) {
}
public function price( $min = 2, $max = 500 ) {
- $c = [ '00', '99', '49', '00', '50', '29' ];
+ $c = array( '00', '99', '49', '00', '50', '29' );
shuffle( $c );
$p = rand( $min, $max ) . '.' . current( $c );
return( $p );
@@ -220,7 +220,7 @@ public function username() {
public function email( $u = false ) {
if ( ! $u ) {
$u = $this->username(); }
- $m = [ '@gmail.com', '@hotmail.com', '@yahoo.com', '@aol.com', '@redlinederby.com' ];
+ $m = array( '@gmail.com', '@hotmail.com', '@yahoo.com', '@aol.com', '@redlinederby.com' );
shuffle( $m );
$m = current( $m );
@@ -241,7 +241,7 @@ public function city() {
}
public function state( $full = false ) {
- $list = [
+ $list = array(
'AL' => 'Alabama',
'AK' => 'Alaska',
'AZ' => 'Arizona',
@@ -293,7 +293,7 @@ public function state( $full = false ) {
'WV' => 'West Virginia',
'WI' => 'Wisconsin',
'WY' => 'Wyoming',
- ];
+ );
$abbv = array_rand( $list, 1 );
if ( $full ) {
diff --git a/tests/acceptance/CustomerProceedsToCheckoutCept.php b/tests/acceptance/CustomerProceedsToCheckoutCept.php
index f6cd96061..b0818b520 100644
--- a/tests/acceptance/CustomerProceedsToCheckoutCept.php
+++ b/tests/acceptance/CustomerProceedsToCheckoutCept.php
@@ -12,9 +12,9 @@
// Make quick helper for managing the session token.
$request_headers = static function () use ( $I ) {
- return [
+ return array(
'woocommerce-session' => 'Session ' . $I->wantHTTPResponseHeaders( 'woocommerce-session' ),
- ];
+ );
};
// Begin test.
@@ -23,11 +23,11 @@
/**
* Add "T-Shirt" to cart and confirm response data.
*/
-$add_to_cart_input = [
+$add_to_cart_input = array(
'clientMutationId' => 'someId',
'productId' => $product_catalog['t-shirt'],
'quantity' => 3,
-];
+);
$success = $I->addToCart( $add_to_cart_input );
@@ -54,18 +54,18 @@
';
$success = $I->sendGraphQLRequest(
$update_session_mutation,
- [
- 'sessionData' => [
- [
+ array(
+ 'sessionData' => array(
+ array(
'key' => 'client_session_id',
'value' => 'test-client-session-id',
- ],
- [
+ ),
+ array(
'key' => 'client_session_id_expiration',
'value' => (string) ( time() + 3600 ),
- ],
- ],
- ],
+ ),
+ ),
+ ),
$request_headers()
);
diff --git a/tests/acceptance/NewCustomerCheckingOutCept.php b/tests/acceptance/NewCustomerCheckingOutCept.php
index 1ac45c8ac..4c4cd962b 100644
--- a/tests/acceptance/NewCustomerCheckingOutCept.php
+++ b/tests/acceptance/NewCustomerCheckingOutCept.php
@@ -5,9 +5,9 @@
// Make quick helper for managing the session token.
$request_headers = function () use ( $I, &$last_request_headers ) {
- $last_request_headers = [
+ $last_request_headers = array(
'woocommerce-session' => 'Session ' . $I->wantHTTPResponseHeaders( 'woocommerce-session' ),
- ];
+ );
return $last_request_headers;
};
@@ -18,11 +18,11 @@
/**
* Add "T-Shirt" to cart and confirm response data.
*/
-$add_to_cart_input = [
+$add_to_cart_input = array(
'clientMutationId' => 'someId',
'productId' => $product_catalog['t-shirt'],
'quantity' => 3,
-];
+);
$success = $I->addToCart( $add_to_cart_input );
@@ -36,11 +36,11 @@
/**
* Add "Belt" to cart and confirm response data.
*/
-$add_to_cart_input = [
+$add_to_cart_input = array(
'clientMutationId' => 'someId',
'productId' => $product_catalog['belt'],
'quantity' => 2,
-];
+);
$success = $I->addToCart(
$add_to_cart_input,
@@ -57,11 +57,11 @@
/**
* Add "Jeans" to cart and confirm response data.
*/
-$add_to_cart_input = [
+$add_to_cart_input = array(
'clientMutationId' => 'someId',
'productId' => $product_catalog['jeans'],
'quantity' => 4,
-];
+);
$success = $I->addToCart(
$add_to_cart_input,
@@ -78,11 +78,11 @@
/**
* Add "Socks" to cart and confirm response data.
*/
-$add_to_cart_input = [
+$add_to_cart_input = array(
'clientMutationId' => 'someId',
'productId' => $product_catalog['socks'],
'quantity' => 1,
-];
+);
$success = $I->addToCart(
$add_to_cart_input,
@@ -101,10 +101,10 @@
/**
* Remove "Socks" from cart and confirm response data.
*/
-$remove_from_cart_input = [
+$remove_from_cart_input = array(
'clientMutationId' => 'someId',
'keys' => $socks_key,
-];
+);
$success = $I->removeItemsFromCart(
$remove_from_cart_input,
@@ -124,19 +124,19 @@
* - Change "Jeans" quantity to "1"
* - Confirm response data.
*/
-$update_quantity_input = [
+$update_quantity_input = array(
'clientMutationId' => 'someId',
- 'items' => [
- [
+ 'items' => array(
+ array(
'key' => $belt_key,
'quantity' => 0,
- ],
- [
+ ),
+ array(
'key' => $jeans_key,
'quantity' => 1,
- ],
- ],
-];
+ ),
+ ),
+);
$success = $I->updateItemQuantities(
$update_quantity_input,
@@ -162,11 +162,11 @@
/**
* Place order for items in the cart using the "Checkout" mutation and confirm response data.
*/
-$checkout_input = [
+$checkout_input = array(
'clientMutationId' => 'someId',
'paymentMethod' => 'bacs',
- 'shippingMethod' => [ 'flat rate' ],
- 'billing' => [
+ 'shippingMethod' => array( 'flat rate' ),
+ 'billing' => array(
'firstName' => 'May',
'lastName' => 'Parker',
'address1' => '20 Ingram St',
@@ -176,8 +176,8 @@
'country' => 'US',
'email' => 'superfreak500@gmail.com',
'phone' => '555-555-1234',
- ],
- 'shipping' => [
+ ),
+ 'shipping' => array(
'firstName' => 'May',
'lastName' => 'Parker',
'address1' => '20 Ingram St',
@@ -185,8 +185,8 @@
'state' => 'NY',
'postcode' => '12345',
'country' => 'US',
- ],
-];
+ ),
+);
$success = $I->checkout(
$checkout_input,
diff --git a/tests/acceptance/ReturningCustomerSessionCept.php b/tests/acceptance/ReturningCustomerSessionCept.php
index db168c842..651346604 100644
--- a/tests/acceptance/ReturningCustomerSessionCept.php
+++ b/tests/acceptance/ReturningCustomerSessionCept.php
@@ -7,11 +7,11 @@
// Begin Tests.
$I->wantTo( 'login' );
-$login_input = [
+$login_input = array(
'clientMutationId' => 'someId',
'username' => 'jimbo1234',
'password' => 'password',
-];
+);
$success = $I->login( $login_input );
@@ -48,20 +48,20 @@
$response = $I->sendGraphQLRequest(
$query,
null,
- [
+ array(
'Authorization' => "Bearer {$authToken}",
'woocommerce-session' => "Session {$initial_session_token}",
- ]
+ )
);
-$expected_results = [
- 'data' => [
- 'customer' => [
+$expected_results = array(
+ 'data' => array(
+ 'customer' => array(
'databaseId' => $customer_id,
'username' => 'jimbo1234',
- ],
- ],
-];
+ ),
+ ),
+);
$I->assertEquals( $expected_results, $response );
@@ -70,18 +70,18 @@
/**
* Add "T-Shirt" to cart and confirm response data.
*/
-$add_to_cart_input = [
+$add_to_cart_input = array(
'clientMutationId' => 'someId',
'productId' => $product_catalog['t-shirt'],
'quantity' => 3,
-];
+);
$success = $I->addToCart(
$add_to_cart_input,
- [
+ array(
'Authorization' => "Bearer {$authToken}",
'woocommerce-session' => "Session {$initial_session_token}",
- ]
+ )
);
$I->assertArrayNotHasKey( 'errors', $success );
@@ -113,29 +113,29 @@
$response = $I->sendGraphQLRequest(
$cart_query,
null,
- [
+ array(
'Authorization' => "Bearer {$authToken}",
'woocommerce-session' => "Session {$initial_session_token}",
- ]
+ )
);
-$expected_results = [
- 'data' => [
- 'cart' => [
- 'contents' => [
- 'nodes' => [
- [
+$expected_results = array(
+ 'data' => array(
+ 'cart' => array(
+ 'contents' => array(
+ 'nodes' => array(
+ array(
'key' => $shirt_key,
- 'product' => [
- 'node' => [
+ 'product' => array(
+ 'node' => array(
'databaseId' => $product_catalog['t-shirt'],
- ],
- ],
- ],
- ],
- ],
- ],
- ],
-];
+ ),
+ ),
+ ),
+ ),
+ ),
+ ),
+ ),
+);
$I->assertEquals( $expected_results, $response );
@@ -147,11 +147,11 @@
$I->wantTo( 'Login and continue previous session.' );
-$login_input = [
+$login_input = array(
'clientMutationId' => 'someId',
'username' => 'jimbo1234',
'password' => 'password',
-];
+);
$success = $I->login( $login_input );
$I->assertArrayNotHasKey( 'errors', $success );
@@ -184,25 +184,25 @@
}
';
-$response = $I->sendGraphQLRequest( $cart_query, null, [ 'Authorization' => "Bearer {$authToken}" ] );
-$expected_results = [
- 'data' => [
- 'cart' => [
- 'contents' => [
- 'nodes' => [
- [
+$response = $I->sendGraphQLRequest( $cart_query, null, array( 'Authorization' => "Bearer {$authToken}" ) );
+$expected_results = array(
+ 'data' => array(
+ 'cart' => array(
+ 'contents' => array(
+ 'nodes' => array(
+ array(
'key' => $shirt_key,
- 'product' => [
- 'node' => [
+ 'product' => array(
+ 'node' => array(
'databaseId' => $product_catalog['t-shirt'],
- ],
- ],
- ],
- ],
- ],
- ],
- ],
-];
+ ),
+ ),
+ ),
+ ),
+ ),
+ ),
+ ),
+);
$I->assertEquals( $expected_results, $response );
@@ -211,13 +211,13 @@
/**
* Add "Belt" to cart and confirm response data.
*/
-$add_to_cart_input = [
+$add_to_cart_input = array(
'clientMutationId' => 'someId',
'productId' => $product_catalog['belt'],
'quantity' => 2,
-];
+);
-$success = $I->addToCart( $add_to_cart_input, [ 'Authorization' => "Bearer {$authToken}" ] );
+$success = $I->addToCart( $add_to_cart_input, array( 'Authorization' => "Bearer {$authToken}" ) );
$I->assertArrayNotHasKey( 'errors', $success );
$I->assertArrayHasKey( 'data', $success );
@@ -254,37 +254,37 @@
$response = $I->sendGraphQLRequest(
$cart_query,
null,
- [
+ array(
'Authorization' => "Bearer {$authToken}",
'woocommerce-session' => "Session {$refreshed_session_token}",
- ]
+ )
);
-$expected_results = [
- 'data' => [
- 'cart' => [
- 'contents' => [
- 'nodes' => [
- [
+$expected_results = array(
+ 'data' => array(
+ 'cart' => array(
+ 'contents' => array(
+ 'nodes' => array(
+ array(
'key' => $shirt_key,
- 'product' => [
- 'node' => [
+ 'product' => array(
+ 'node' => array(
'databaseId' => $product_catalog['t-shirt'],
- ],
- ],
- ],
- [
+ ),
+ ),
+ ),
+ array(
'key' => $belt_key,
- 'product' => [
- 'node' => [
+ 'product' => array(
+ 'node' => array(
'databaseId' => $product_catalog['belt'],
- ],
- ],
- ],
- ],
- ],
- ],
- ],
-];
+ ),
+ ),
+ ),
+ ),
+ ),
+ ),
+ ),
+);
$I->assertEquals( $expected_results, $response );
@@ -296,11 +296,11 @@
$I->wantTo( 'Login and start a new session.' );
-$login_input = [
+$login_input = array(
'clientMutationId' => 'someId',
'username' => 'jimbo1234',
'password' => 'password',
-];
+);
$success = $I->login( $login_input );
$I->assertArrayNotHasKey( 'errors', $success );
@@ -341,19 +341,19 @@
$response = $I->sendGraphQLRequest(
$cart_query,
null,
- [
+ array(
'Authorization' => "Bearer {$authToken}",
'woocommerce-session' => "Session {$new_session_token}",
- ]
+ )
+);
+$expected_results = array(
+ 'data' => array(
+ 'cart' => array(
+ 'contents' => array(
+ 'nodes' => array(),
+ ),
+ ),
+ ),
);
-$expected_results = [
- 'data' => [
- 'cart' => [
- 'contents' => [
- 'nodes' => [],
- ],
- ],
- ],
-];
$I->assertEquals( $expected_results, $response );
diff --git a/tests/functional/CartTransactionQueueCest.php b/tests/functional/CartTransactionQueueCest.php
index 9e3d26c68..f62b92123 100644
--- a/tests/functional/CartTransactionQueueCest.php
+++ b/tests/functional/CartTransactionQueueCest.php
@@ -11,7 +11,7 @@ public function _before( FunctionalTester $I, $scenario ) {
$this->product_catalog = $I->getCatalog();
}
- public function _addTshirtToCart( FunctionalTester $I, $headers = [] ) {
+ public function _addTshirtToCart( FunctionalTester $I, $headers = array() ) {
/**
* Add t-shirt to the cart
*/
@@ -38,25 +38,24 @@ public function _addTshirtToCart( FunctionalTester $I, $headers = [] ) {
}
}
}';
- $success = $I->postRawRequest(
+ $success = $I->postRawRequest(
$add_to_cart_query,
- [
- 'input' => [
+ array(
+ 'input' => array(
'clientMutationId' => 'someId',
'productId' => $this->product_catalog['t-shirt'],
'quantity' => 5,
- ]
- ],
- [ 'headers' => $headers ]
+ ),
+ ),
+ array( 'headers' => $headers )
);
-
$response_body = json_decode( $success->getBody(), true );
$I->assertQuerySuccessful(
$response_body,
- [
+ array(
$I->expectField( 'addToCart.cartItem.key', Signal::NOT_NULL ),
- ]
+ )
);
$key = $I->lodashGet( $response_body, 'data.addToCart.cartItem.key' );
@@ -64,7 +63,7 @@ public function _addTshirtToCart( FunctionalTester $I, $headers = [] ) {
/**
* Assert existence and validity of "woocommerce-session" HTTP header.
*/
- $session_header = $success->getHeader('woocommerce-session');
+ $session_header = $success->getHeader( 'woocommerce-session' );
$I->assertNotEmpty( $session_header );
$session_token = $session_header[0];
@@ -76,23 +75,23 @@ public function _startAuthenticatedSession( $I ) {
// Begin Tests.
$I->wantTo( 'login' );
- $login_input = [
+ $login_input = array(
'clientMutationId' => 'someId',
'username' => 'jimbo1234@example.com',
'password' => 'password',
- ];
+ );
$success = $I->login( $login_input );
// Validate response.
$I->assertQuerySuccessful(
$success,
- [
+ array(
$I->expectField( 'login.customer.databaseId', Signal::NOT_NULL ),
$I->expectField( 'login.authToken', Signal::NOT_NULL ),
$I->expectField( 'login.refreshToken', Signal::NOT_NULL ),
$I->expectField( 'login.sessionToken', Signal::NOT_NULL ),
- ]
+ )
);
// Retrieve JWT Authorization Token for later use.
@@ -103,22 +102,22 @@ public function _startAuthenticatedSession( $I ) {
// You can also retrieve the token from the "woocommerce-session" HTTP response header.
$initial_session_token = $I->lodashGet( $success, 'data.login.sessionToken' );
- $headers = [
+ $headers = array(
'Authorization' => "Bearer {$auth_token}",
'woocommerce-session' => "Session {$initial_session_token}",
- ];
+ );
$tokens = $this->_addTshirtToCart( $I, $headers );
return array_merge(
$tokens,
- [ 'auth_token' => $auth_token ]
+ array( 'auth_token' => $auth_token )
);
}
// tests
public function testCartTransactionQueueWithConcurrentRequest( FunctionalTester $I, $scenario ) {
- //$scenario->skip( 'The test is unstable, and will be skipped until success is guaranteed on each run.' );
+ // $scenario->skip( 'The test is unstable, and will be skipped until success is guaranteed on each run.' );
$tokens = $this->_startAuthenticatedSession( $I );
$key = $tokens['key'];
@@ -188,147 +187,147 @@ public function testCartTransactionQueueWithConcurrentRequest( FunctionalTester
}
';
- $operations = [
- [
+ $operations = array(
+ array(
'query' => $update_item_quantities_mutation,
- 'variables' => [
- 'input' => [
+ 'variables' => array(
+ 'input' => array(
'clientMutationId' => 'some_id',
- 'items' => [
- [
+ 'items' => array(
+ array(
'key' => $key,
'quantity' => 3,
- ],
- ],
- ],
- ],
- ],
- [
+ ),
+ ),
+ ),
+ ),
+ ),
+ array(
'query' => $update_item_quantities_mutation,
- 'variables' => [
- 'input' => [
+ 'variables' => array(
+ 'input' => array(
'clientMutationId' => 'some_id',
- 'items' => [
- [
+ 'items' => array(
+ array(
'key' => $key,
'quantity' => 4,
- ],
- ],
- ],
- ],
- ],
- [
+ ),
+ ),
+ ),
+ ),
+ ),
+ array(
'query' => $remove_item_mutation,
- 'variables' => [
- 'input' => [
+ 'variables' => array(
+ 'input' => array(
'clientMutationId' => 'some_id',
- 'keys' => [ $key ],
- ],
- ],
- ],
- [
+ 'keys' => array( $key ),
+ ),
+ ),
+ ),
+ array(
'query' => $restore_item_mutation,
- 'variables' => [
- 'input' => [
+ 'variables' => array(
+ 'input' => array(
'clientMutationId' => 'some_id',
- 'keys' => [ $key ],
- ],
- ],
- ],
- ];
+ 'keys' => array( $key ),
+ ),
+ ),
+ ),
+ );
- $selected_options = [
- 'headers' => [
+ $selected_options = array(
+ 'headers' => array(
'Content-Type' => 'application/json',
'Authorization' => "Bearer {$auth_token}",
'woocommerce-session' => "Session {$session_token}",
- ],
- ];
- $responses = $I->concurrentRequests( $operations, $selected_options, 800 );
+ ),
+ );
+ $responses = $I->concurrentRequests( $operations, $selected_options, 800 );
$I->assertQuerySuccessful(
$responses[0],
- [
+ array(
$I->expectObject(
'updateItemQuantities',
- [
+ array(
$I->expectObject(
'updated.0',
- [
+ array(
$I->expectField( 'key', $key ),
- $I->expectField( 'quantity', 3 )
- ]
+ $I->expectField( 'quantity', 3 ),
+ )
),
$I->expectField( 'removed', Signal::IS_FALSY ),
$I->expectObject(
'items.0',
- [
+ array(
$I->expectField( 'key', $key ),
- $I->expectField( 'quantity', 3 )
- ]
- )
- ]
- )
- ]
+ $I->expectField( 'quantity', 3 ),
+ )
+ ),
+ )
+ ),
+ )
);
$I->assertQuerySuccessful(
$responses[1],
- [
+ array(
$I->expectObject(
'updateItemQuantities',
- [
+ array(
$I->expectObject(
'updated.0',
- [
+ array(
$I->expectField( 'key', $key ),
- $I->expectField( 'quantity', 4 )
- ]
+ $I->expectField( 'quantity', 4 ),
+ )
),
$I->expectField( 'removed', Signal::IS_FALSY ),
$I->expectObject(
'items.0',
- [
+ array(
$I->expectField( 'key', $key ),
- $I->expectField( 'quantity', 4 )
- ]
- )
- ]
- )
- ]
+ $I->expectField( 'quantity', 4 ),
+ )
+ ),
+ )
+ ),
+ )
);
$I->assertQuerySuccessful(
$responses[2],
- [
+ array(
$I->expectObject(
'removeItemsFromCart',
- [
+ array(
$I->expectField(
'cart.contents.nodes',
Signal::IS_FALSY
- )
- ]
- )
- ]
+ ),
+ )
+ ),
+ )
);
$I->assertQuerySuccessful(
$responses[3],
- [
+ array(
$I->expectObject(
'restoreCartItems',
- [
+ array(
$I->expectObject(
'cart.contents.nodes.0',
- [
+ array(
$I->expectField( 'key', $key ),
- $I->expectField( 'quantity', 4 )
- ]
- )
- ]
- )
- ]
+ $I->expectField( 'quantity', 4 ),
+ )
+ ),
+ )
+ ),
+ )
);
}
}
diff --git a/tests/functional/ProtectedRouterCest.php b/tests/functional/ProtectedRouterCest.php
index 42a848588..d1c696b0b 100644
--- a/tests/functional/ProtectedRouterCest.php
+++ b/tests/functional/ProtectedRouterCest.php
@@ -27,11 +27,11 @@ public function _startNewSession( FunctionalTester $I ) {
* Add t-shirt to the cart
*/
$success = $I->addToCart(
- [
+ array(
'clientMutationId' => 'someId',
'productId' => $this->product_catalog['t-shirt'],
'quantity' => 5,
- ],
+ ),
);
$I->assertArrayNotHasKey( 'errors', $success );
@@ -51,9 +51,9 @@ public function _startNewSession( FunctionalTester $I ) {
}
public function _getLastRequestHeaders( $I ) {
- return [
+ return array(
'woocommerce-session' => 'Session ' . $I->wantHTTPResponseHeaders( 'woocommerce-session' ),
- ];
+ );
}
public function tryToProceedToCheckoutPage( FunctionalTester $I, $scenario ) {
@@ -120,14 +120,14 @@ public function tryToProceedToCheckoutPageWithExpiredUrl( FunctionalTester $I, $
';
$success = $I->sendGraphQLRequest(
$query,
- [
- 'sessionData' => [
- [
+ array(
+ 'sessionData' => array(
+ array(
'key' => 'client_session_id',
'value' => 'test-client-session-id',
- ],
- ],
- ],
+ ),
+ ),
+ ),
$this->_getLastRequestHeaders( $I )
);
@@ -148,14 +148,14 @@ public function tryToProceedToCheckoutPageWithExpiredUrl( FunctionalTester $I, $
$I->wantTo( 'Invalidate Checkout URL by updating the "client_session_id"' );
$success = $I->sendGraphQLRequest(
$query,
- [
- 'sessionData' => [
- [
+ array(
+ 'sessionData' => array(
+ array(
'key' => 'client_session_id',
'value' => 'new-test-client-session-id',
- ],
- ],
- ],
+ ),
+ ),
+ ),
$this->_getLastRequestHeaders( $I )
);
diff --git a/tests/functional/QLSessionHandlerCest.php b/tests/functional/QLSessionHandlerCest.php
index 82206ba14..f811d64ca 100644
--- a/tests/functional/QLSessionHandlerCest.php
+++ b/tests/functional/QLSessionHandlerCest.php
@@ -21,18 +21,18 @@ public function testCartMutationsWithValidCartSessionToken( FunctionalTester $I
* Add item to the cart
*/
$success = $I->addToCart(
- [
+ array(
'clientMutationId' => 'someId',
'productId' => $this->product_catalog['t-shirt'],
'quantity' => 5,
- ]
+ )
);
$I->assertQuerySuccessful(
$success,
- [
+ array(
$I->expectField( 'addToCart.cartItem.key', Signal::NOT_NULL ),
- ]
+ )
);
$cart_item_key = $I->lodashGet( $success, 'data.addToCart.cartItem.key' );
@@ -76,30 +76,30 @@ public function testCartMutationsWithValidCartSessionToken( FunctionalTester $I
}
';
- $actual = $I->sendGraphQLRequest( $query, null, [ 'woocommerce-session' => "Session {$session_token}" ] );
+ $actual = $I->sendGraphQLRequest( $query, null, array( 'woocommerce-session' => "Session {$session_token}" ) );
$I->assertQuerySuccessful(
$actual,
- [
+ array(
$I->expectField( 'cart.contents.nodes.#.key', $cart_item_key ),
- ]
+ )
);
/**
* Remove item from the cart
*/
$success = $I->removeItemsFromCart(
- [
+ array(
'clientMutationId' => 'someId',
'keys' => $cart_item_key,
- ],
- [ 'woocommerce-session' => "Session {$session_token}" ]
+ ),
+ array( 'woocommerce-session' => "Session {$session_token}" )
);
$I->assertQuerySuccessful(
$success,
- [
+ array(
$I->expectField( 'removeItemsFromCart.cartItems.#.key', $cart_item_key ),
- ]
+ )
);
/**
@@ -118,30 +118,30 @@ public function testCartMutationsWithValidCartSessionToken( FunctionalTester $I
}
';
- $actual = $I->sendGraphQLRequest( $query, null, [ 'woocommerce-session' => "Session {$session_token}" ] );
+ $actual = $I->sendGraphQLRequest( $query, null, array( 'woocommerce-session' => "Session {$session_token}" ) );
$I->assertQuerySuccessful(
$actual,
- [
+ array(
$I->expectField( 'cart.contents.nodes', Signal::IS_FALSY ),
- ]
+ )
);
/**
* Restore item to the cart
*/
$success = $I->restoreCartItems(
- [
+ array(
'clientMutationId' => 'someId',
- 'keys' => [ $cart_item_key ],
- ],
- [ 'woocommerce-session' => "Session {$session_token}" ]
+ 'keys' => array( $cart_item_key ),
+ ),
+ array( 'woocommerce-session' => "Session {$session_token}" )
);
$I->assertQuerySuccessful(
$success,
- [
+ array(
$I->expectField( 'restoreCartItems.cartItems.#.key', $cart_item_key ),
- ]
+ )
);
/**
@@ -160,12 +160,12 @@ public function testCartMutationsWithValidCartSessionToken( FunctionalTester $I
}
';
- $actual = $I->sendGraphQLRequest( $query, null, [ 'woocommerce-session' => "Session {$session_token}" ] );
+ $actual = $I->sendGraphQLRequest( $query, null, array( 'woocommerce-session' => "Session {$session_token}" ) );
$I->assertQuerySuccessful(
$actual,
- [
+ array(
$I->expectField( 'cart.contents.nodes.#.key', $cart_item_key ),
- ]
+ )
);
}
@@ -174,18 +174,18 @@ public function testCartMutationsWithInvalidCartSessionToken( FunctionalTester $
* Add item to cart and retrieve session token to corrupt.
*/
$success = $I->addToCart(
- [
+ array(
'clientMutationId' => 'someId',
'productId' => $this->product_catalog['t-shirt'],
'quantity' => 1,
- ]
+ )
);
$I->assertQuerySuccessful(
$success,
- [
+ array(
$I->expectField( 'addToCart.cartItem.key', Signal::NOT_NULL ),
- ]
+ )
);
$cart_item_key = $I->lodashGet( $success, 'data.addToCart.cartItem.key' );
@@ -209,12 +209,12 @@ public function testCartMutationsWithInvalidCartSessionToken( FunctionalTester $
$invalid_token = JWT::encode( (array) $invalid_token, GRAPHQL_WOOCOMMERCE_SECRET_KEY, 'HS256' );
$failed = $I->addToCart(
- [
+ array(
'clientMutationId' => 'someId',
'productId' => $this->product_catalog['t-shirt'],
'quantity' => 1,
- ],
- [ 'woocommerce-session' => "Session {$invalid_token}" ]
+ ),
+ array( 'woocommerce-session' => "Session {$invalid_token}" )
);
$I->assertQueryError( $failed );
@@ -228,11 +228,11 @@ public function testCartMutationsWithInvalidCartSessionToken( FunctionalTester $
$invalid_token = JWT::encode( (array) $invalid_token, GRAPHQL_WOOCOMMERCE_SECRET_KEY, 'HS256' );
$failed = $I->removeItemsFromCart(
- [
+ array(
'clientMutationId' => 'someId',
'keys' => $cart_item_key,
- ],
- [ 'woocommerce-session' => "Session {$invalid_token}" ]
+ ),
+ array( 'woocommerce-session' => "Session {$invalid_token}" )
);
$I->assertQueryError( $failed );
@@ -242,16 +242,16 @@ public function testCartMutationsWithInvalidCartSessionToken( FunctionalTester $
* GraphQL should throw an error and mutation will fail.
*/
$failed = $I->updateItemQuantities(
- [
+ array(
'clientMutationId' => 'someId',
- 'items' => [
- [
+ 'items' => array(
+ array(
'key' => $cart_item_key,
'quantity' => 0,
- ],
- ],
- ],
- [ 'woocommerce-session' => 'Session invalid-jwt-token-string' ]
+ ),
+ ),
+ ),
+ array( 'woocommerce-session' => 'Session invalid-jwt-token-string' )
);
$I->assertQueryError( $failed );
@@ -261,8 +261,8 @@ public function testCartMutationsWithInvalidCartSessionToken( FunctionalTester $
* GraphQL should throw an error and mutation will fail.
*/
$failed = $I->emptyCart(
- [ 'clientMutationId' => 'someId' ],
- [ 'woocommerce-session' => 'Session invalid-jwt-token-string' ]
+ array( 'clientMutationId' => 'someId' ),
+ array( 'woocommerce-session' => 'Session invalid-jwt-token-string' )
);
$I->assertQueryError( $failed );
@@ -272,12 +272,12 @@ public function testCartMutationsWithInvalidCartSessionToken( FunctionalTester $
* GraphQL should throw an error and mutation will fail.
*/
$failed = $I->addFee(
- [
+ array(
'clientMutationId' => 'someId',
'name' => 'extra_fee',
'amount' => 49.99,
- ],
- [ 'woocommerce-session' => 'Session invalid-jwt-token-string' ]
+ ),
+ array( 'woocommerce-session' => 'Session invalid-jwt-token-string' )
);
$I->assertQueryError( $failed );
@@ -289,11 +289,11 @@ public function testCartMutationsWithInvalidCartSessionToken( FunctionalTester $
* @Note: No coupons exist in the database, but mutation should fail before that becomes a factor.
*/
$failed = $I->applyCoupon(
- [
+ array(
'clientMutationId' => 'someId',
'code' => 'some_coupon',
- ],
- [ 'woocommerce-session' => 'Session invalid-jwt-token-string' ]
+ ),
+ array( 'woocommerce-session' => 'Session invalid-jwt-token-string' )
);
$I->assertQueryError( $failed );
@@ -305,11 +305,11 @@ public function testCartMutationsWithInvalidCartSessionToken( FunctionalTester $
* @Note: No coupons exist on the cart, but mutation should failed before that becomes a factor.
*/
$failed = $I->removeCoupons(
- [
+ array(
'clientMutationId' => 'someId',
- 'codes' => [ 'some_coupon' ],
- ],
- [ 'woocommerce-session' => 'Session invalid-jwt-token-string' ]
+ 'codes' => array( 'some_coupon' ),
+ ),
+ array( 'woocommerce-session' => 'Session invalid-jwt-token-string' )
);
$I->assertQueryError( $failed );
@@ -322,11 +322,11 @@ public function testCartMutationsWithInvalidCartSessionToken( FunctionalTester $
* but mutation should failed before that becomes a factor.
*/
$failed = $I->restoreCartItems(
- [
+ array(
'clientMutationId' => 'someId',
- 'keys' => [ $cart_item_key ],
- ],
- [ 'woocommerce-session' => 'Session invalid-jwt-token-string' ]
+ 'keys' => array( $cart_item_key ),
+ ),
+ array( 'woocommerce-session' => 'Session invalid-jwt-token-string' )
);
$I->assertQueryError( $failed );
@@ -339,11 +339,11 @@ public function testCartMutationsWithInvalidCartSessionToken( FunctionalTester $
* but mutation should failed before that becomes a factor.
*/
$failed = $I->updateShippingMethod(
- [
+ array(
'clientMutationId' => 'someId',
- 'shippingMethods' => [ 'legacy_flat_rate' ],
- ],
- [ 'woocommerce-session' => 'Session invalid-jwt-token-string' ]
+ 'shippingMethods' => array( 'legacy_flat_rate' ),
+ ),
+ array( 'woocommerce-session' => 'Session invalid-jwt-token-string' )
);
$I->assertQueryError( $failed );
@@ -367,30 +367,30 @@ public function testCartMutationsWithInvalidCartSessionToken( FunctionalTester $
$failed = $I->sendGraphQLRequest(
$query,
null,
- [ 'woocommerce-session' => 'Session invalid-jwt-token-string' ]
+ array( 'woocommerce-session' => 'Session invalid-jwt-token-string' )
);
$I->assertQueryError( $failed );
}
public function testCartSessionDataMutations( FunctionalTester $I, $scenario ) {
- //$scenario->skip( 'Test skipped until scenario can be created properly again.' );
+ // $scenario->skip( 'Test skipped until scenario can be created properly again.' );
/**
* Add item to the cart
*/
$success = $I->addToCart(
- [
+ array(
'clientMutationId' => 'someId',
'productId' => $this->product_catalog['socks'],
'quantity' => 2,
- ]
+ )
);
$I->assertQuerySuccessful(
$success,
- [
+ array(
$I->expectField( 'addToCart.cartItem.key', Signal::NOT_NULL ),
- ]
+ )
);
$cart_item_key = $I->lodashGet( $success, 'data.addToCart.cartItem.key' );
@@ -420,14 +420,14 @@ public function testCartSessionDataMutations( FunctionalTester $I, $scenario ) {
/**
* Set shipping address, so shipping rates can be calculated
*/
- $input = [
+ $input = array(
'clientMutationId' => 'someId',
- 'shipping' => [
+ 'shipping' => array(
'state' => 'New York',
'country' => 'US',
'postcode' => '12345',
- ],
- ];
+ ),
+ );
$mutation = '
mutation ( $input: UpdateCustomerInput! ){
@@ -443,19 +443,19 @@ public function testCartSessionDataMutations( FunctionalTester $I, $scenario ) {
}
';
- $actual = $I->sendGraphQLRequest( $mutation, $input, [ 'woocommerce-session' => "Session {$session_token}" ] );
+ $actual = $I->sendGraphQLRequest( $mutation, $input, array( 'woocommerce-session' => "Session {$session_token}" ) );
$I->assertQuerySuccessful(
$actual,
- [
+ array(
$I->expectObject(
'updateCustomer.customer.shipping',
- [
+ array(
$I->expectField( 'state', 'New York' ),
$I->expectField( 'country', 'US' ),
$I->expectField( 'postcode', '12345' ),
- ]
- )
- ]
+ )
+ ),
+ )
);
/**
@@ -483,34 +483,34 @@ public function testCartSessionDataMutations( FunctionalTester $I, $scenario ) {
}
';
- $actual = $I->sendGraphQLRequest( $query, null, [ 'woocommerce-session' => "Session {$session_token}" ] );
+ $actual = $I->sendGraphQLRequest( $query, null, array( 'woocommerce-session' => "Session {$session_token}" ) );
$I->assertQuerySuccessful(
$actual,
- [
+ array(
$I->expectField( 'cart.contents.nodes.#.key', $cart_item_key ),
$I->expectNode(
'cart.availableShippingMethods',
- [
+ array(
$I->expectField( 'packageDetails', \html_entity_decode( 'socks ×2' ) ),
$I->expectField( 'supportsShippingCalculator', true ),
$I->expectNode(
'rates',
- [
+ array(
$I->expectField( 'cost', '0.00' ),
$I->expectField( 'label', 'Flat rate' ),
- ]
+ )
),
$I->expectNode(
'rates',
- [
+ array(
$I->expectField( 'cost', '0.00' ),
$I->expectField( 'label', 'Free shipping' ),
- ]
+ )
),
- ],
+ ),
0
),
- ]
+ )
);
$chosen_shipping_method = $I->lodashGet( $actual, 'data.cart.availableShippingMethods.0.rates.0.id' );
@@ -544,21 +544,21 @@ public function testCartSessionDataMutations( FunctionalTester $I, $scenario ) {
$success = $I->sendGraphQLRequest(
$mutation,
- [
+ array(
'clientMutationId' => 'someId',
- 'shippingMethods' => [ $chosen_shipping_method ],
- ],
- [ 'woocommerce-session' => "Session {$session_token}" ]
+ 'shippingMethods' => array( $chosen_shipping_method ),
+ ),
+ array( 'woocommerce-session' => "Session {$session_token}" )
);
$I->assertQuerySuccessful(
$success,
- [
+ array(
$I->expectField(
'updateShippingMethod.cart.chosenShippingMethods.#',
$chosen_shipping_method
),
- ]
+ )
);
}
}
diff --git a/tests/functional/_bootstrap.php b/tests/functional/_bootstrap.php
index 1a1b96e50..f48f9c2ff 100644
--- a/tests/functional/_bootstrap.php
+++ b/tests/functional/_bootstrap.php
@@ -1,5 +1,5 @@
- [
+ $variables = array(
+ 'input' => array(
'clientMutationId' => 'someId',
'productId' => $product_id,
'quantity' => 2,
- ],
- ];
+ ),
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
@@ -55,7 +55,7 @@ public function testAddToCartMutationWithProduct() {
$this->assertQuerySuccessful(
$response,
- [
+ array(
$this->expectedField( 'addToCart.clientMutationId', 'someId' ),
$this->expectedField( 'addToCart.cartItem.key', $cart_item_key ),
$this->expectedField( 'addToCart.cartItem.product.node.id', $this->toRelayId( 'post', $product_id ) ),
@@ -64,7 +64,7 @@ public function testAddToCartMutationWithProduct() {
$this->expectedField( 'addToCart.cartItem.subtotalTax', wc_graphql_price( $cart_item['line_subtotal_tax'] ) ),
$this->expectedField( 'addToCart.cartItem.total', wc_graphql_price( $cart_item['line_total'] ) ),
$this->expectedField( 'addToCart.cartItem.tax', wc_graphql_price( $cart_item['line_tax'] ) ),
- ]
+ )
);
}
@@ -97,20 +97,20 @@ public function testAddToCartMutationWithProductVariation() {
}
';
- $variables = [
- 'input' => [
+ $variables = array(
+ 'input' => array(
'clientMutationId' => 'someId',
'productId' => $ids['product'],
'quantity' => 3,
'variationId' => $ids['variations'][0],
- 'variation' => [
- [
+ 'variation' => array(
+ array(
'attributeName' => 'color',
'attributeValue' => 'red',
- ],
- ],
- ],
- ];
+ ),
+ ),
+ ),
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
@@ -128,7 +128,7 @@ public function testAddToCartMutationWithProductVariation() {
$this->assertQuerySuccessful(
$response,
- [
+ array(
$this->expectedField( 'addToCart.clientMutationId', 'someId' ),
$this->expectedField( 'addToCart.cartItem.key', $cart_item_key ),
$this->expectedField( 'addToCart.cartItem.product.node.id', $this->toRelayId( 'post', $ids['product'] ) ),
@@ -138,26 +138,26 @@ public function testAddToCartMutationWithProductVariation() {
$this->expectedField( 'addToCart.cartItem.subtotalTax', wc_graphql_price( $cart_item['line_subtotal_tax'] ) ),
$this->expectedField( 'addToCart.cartItem.total', wc_graphql_price( $cart_item['line_total'] ) ),
$this->expectedField( 'addToCart.cartItem.tax', wc_graphql_price( $cart_item['line_tax'] ) ),
- ]
+ )
);
}
public function testUpdateCartItemQuantitiesMutation() {
// Create/add some products to the cart.
- $cart_item_data = [
- [
+ $cart_item_data = array(
+ array(
'product_id' => $this->factory->product->createSimple(),
'quantity' => 2,
- ],
- [
+ ),
+ array(
'product_id' => $this->factory->product->createSimple(),
'quantity' => 5,
- ],
- [
+ ),
+ array(
'product_id' => $this->factory->product->createSimple(),
'quantity' => 1,
- ],
- ];
+ ),
+ );
// Store cart item keys for use in mutation.
$keys = $this->factory->cart->add( ...$cart_item_data );
@@ -184,95 +184,95 @@ public function testUpdateCartItemQuantitiesMutation() {
';
// Define variables
- $variables = [
- 'input' => [
+ $variables = array(
+ 'input' => array(
'clientMutationId' => 'someId',
- 'items' => [
- [
+ 'items' => array(
+ array(
'key' => $keys[0],
'quantity' => 4,
- ],
- [
+ ),
+ array(
'key' => $keys[1],
'quantity' => 2,
- ],
- [
+ ),
+ array(
'key' => $keys[2],
'quantity' => 0,
- ],
- ],
- ],
- ];
+ ),
+ ),
+ ),
+ );
// Execute mutation.
$response = $this->graphql( compact( 'query', 'variables' ) );
$this->assertQuerySuccessful(
$response,
- [
+ array(
$this->expectedField( 'updateItemQuantities.clientMutationId', 'someId' ),
$this->expectedNode(
'updateItemQuantities.updated',
- [
+ array(
'key' => $keys[0],
'quantity' => 4,
- ]
+ )
),
$this->expectedNode(
'updateItemQuantities.updated',
- [
+ array(
'key' => $keys[1],
'quantity' => 2,
- ]
+ )
),
$this->expectedNode(
'updateItemQuantities.removed',
- [
+ array(
'key' => $keys[2],
'quantity' => 1,
- ]
+ )
),
$this->expectedNode(
'updateItemQuantities.items',
- [
+ array(
'key' => $keys[0],
'quantity' => 4,
- ]
+ )
),
$this->expectedNode(
'updateItemQuantities.items',
- [
+ array(
'key' => $keys[1],
'quantity' => 2,
- ]
+ )
),
$this->expectedNode(
'updateItemQuantities.items',
- [
+ array(
'key' => $keys[2],
'quantity' => 1,
- ]
+ )
),
- ]
+ )
);
}
public function testRemoveItemsFromCartMutation() {
// Create/add some products to the cart.
- $cart_item_data = [
- [
+ $cart_item_data = array(
+ array(
'product_id' => $this->factory->product->createSimple(),
'quantity' => 2,
- ],
- [
+ ),
+ array(
'product_id' => $this->factory->product->createSimple(),
'quantity' => 5,
- ],
- [
+ ),
+ array(
'product_id' => $this->factory->product->createSimple(),
'quantity' => 1,
- ],
- ];
+ ),
+ );
// Store cart item keys for use in mutation.
$keys = $this->factory->cart->add( ...$cart_item_data );
@@ -289,17 +289,17 @@ public function testRemoveItemsFromCartMutation() {
';
// Define expected response data.
- $expected = [ $this->expectedField( 'removeItemsFromCart.clientMutationId', 'someId' ) ];
+ $expected = array( $this->expectedField( 'removeItemsFromCart.clientMutationId', 'someId' ) );
foreach ( $keys as $key ) {
$expected[] = $this->expectedNode( 'removeItemsFromCart.cartItems', compact( 'key' ) );
}
- $variables = [
- 'input' => [
+ $variables = array(
+ 'input' => array(
'clientMutationId' => 'someId',
'keys' => $keys,
- ],
- ];
+ ),
+ );
// Execute mutation w/ "keys" array.
$response = $this->graphql( compact( 'query', 'variables' ) );
@@ -317,12 +317,12 @@ public function testRemoveItemsFromCartMutation() {
// Add more items and execute mutation with "all" flag.
$keys = $this->factory->cart->add( ...$cart_item_data );
- $variables = [
- 'input' => [
+ $variables = array(
+ 'input' => array(
'clientMutationId' => 'someId',
'all' => true,
- ],
- ];
+ ),
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
@@ -339,20 +339,20 @@ public function testRemoveItemsFromCartMutation() {
public function testRestoreCartItemsMutation() {
// Create/add some products to the cart.
- $cart_item_data = [
- [
+ $cart_item_data = array(
+ array(
'product_id' => $this->factory->product->createSimple(),
'quantity' => 2,
- ],
- [
+ ),
+ array(
'product_id' => $this->factory->product->createSimple(),
'quantity' => 5,
- ],
- [
+ ),
+ array(
'product_id' => $this->factory->product->createSimple(),
'quantity' => 1,
- ],
- ];
+ ),
+ );
$keys = $this->factory->cart->add( ...$cart_item_data );
$this->factory->cart->remove( ...$keys );
@@ -367,16 +367,16 @@ public function testRestoreCartItemsMutation() {
}
';
- $variables = [
- 'input' => [
+ $variables = array(
+ 'input' => array(
'clientMutationId' => 'someId',
'keys' => $keys,
- ],
- ];
+ ),
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [ $this->expectedField( 'restoreCartItems.clientMutationId', 'someId' ) ];
+ $expected = array( $this->expectedField( 'restoreCartItems.clientMutationId', 'someId' ) );
foreach ( $keys as $key ) {
$expected[] = $this->expectedNode( 'restoreCartItems.cartItems', compact( 'key' ) );
}
@@ -429,33 +429,33 @@ public function testEmptyCartMutation() {
}
';
- $variables = [
- 'input' => [ 'clientMutationId' => 'someId' ],
- ];
+ $variables = array(
+ 'input' => array( 'clientMutationId' => 'someId' ),
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
$this->assertQuerySuccessful(
$response,
- [
+ array(
$this->expectedField( 'emptyCart.clientMutationId', 'someId' ),
$this->expectedNode(
'emptyCart.deletedCart.contents.nodes',
- [
+ array(
'key' => $cart_item['key'],
- 'product' => [
- 'node' => [
+ 'product' => array(
+ 'node' => array(
'id' => $this->toRelayId( 'post', $cart_item['product_id'] ),
- ],
- ],
+ ),
+ ),
'variation' => null,
'quantity' => $cart_item['quantity'],
'subtotal' => wc_graphql_price( $cart_item['line_subtotal'] ),
'subtotalTax' => wc_graphql_price( $cart_item['line_subtotal_tax'] ),
'total' => wc_graphql_price( $cart_item['line_total'] ),
'tax' => wc_graphql_price( $cart_item['line_tax'] ),
- ]
+ )
),
- ]
+ )
);
$this->assertTrue( \WC()->cart->is_empty() );
@@ -464,17 +464,17 @@ public function testEmptyCartMutation() {
public function testApplyCouponMutation() {
// Create products.
$product_id = $this->factory->product->createSimple(
- [ 'regular_price' => 100 ]
+ array( 'regular_price' => 100 )
);
// Create coupon.
$coupon_code = wc_get_coupon_code_by_id(
$this->factory->coupon->create(
- [
+ array(
'amount' => 0.5,
- 'product_ids' => [ $product_id ],
+ 'product_ids' => array( $product_id ),
'description' => 'lorem ipsum dolor',
- ]
+ )
)
);
@@ -513,12 +513,12 @@ public function testApplyCouponMutation() {
}
';
- $variables = [
- 'input' => [
+ $variables = array(
+ 'input' => array(
'clientMutationId' => 'someId',
'code' => $coupon_code,
- ],
- ];
+ ),
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
// Get updated cart item.
@@ -526,42 +526,42 @@ public function testApplyCouponMutation() {
$this->assertQuerySuccessful(
$response,
- [
+ array(
$this->expectedField( 'applyCoupon.clientMutationId', 'someId' ),
$this->expectedNode(
'applyCoupon.cart.appliedCoupons',
- [
+ array(
'code' => $coupon_code,
'description' => 'lorem ipsum dolor',
- ]
+ )
),
$this->expectedNode(
'applyCoupon.cart.contents.nodes',
- [
+ array(
'key' => $cart_item['key'],
- 'product' => [
- 'node' => [
+ 'product' => array(
+ 'node' => array(
'id' => $this->toRelayId( 'post', $cart_item['product_id'] ),
- ],
- ],
+ ),
+ ),
'quantity' => $cart_item['quantity'],
'subtotal' => wc_graphql_price( $cart_item['line_subtotal'] ),
'subtotalTax' => wc_graphql_price( $cart_item['line_subtotal_tax'] ),
'total' => wc_graphql_price( $cart_item['line_total'] ),
'tax' => wc_graphql_price( $cart_item['line_tax'] ),
- ]
+ )
),
- ]
+ )
);
$new_total = \WC()->cart->get_cart_contents_total();
// Use --debug to view.
codecept_debug(
- [
+ array(
'old' => $old_total,
'new' => $new_total,
- ]
+ )
);
$this->assertTrue( $old_total > $new_total );
@@ -575,19 +575,19 @@ public function testApplyCouponMutationWithInvalidCoupons() {
// Create invalid coupon codes.
$coupon_id = $this->factory->coupon->create(
- [ 'product_ids' => [ $product_id ] ]
+ array( 'product_ids' => array( $product_id ) )
);
$expired_coupon_code = wc_get_coupon_code_by_id(
$this->factory->coupon->create(
- [
- 'product_ids' => [ $product_id ],
+ array(
+ 'product_ids' => array( $product_id ),
'date_expires' => time() - 20,
- ]
+ )
)
);
$applied_coupon_code = wc_get_coupon_code_by_id(
$this->factory->coupon->create(
- [ 'product_ids' => [ $product_id ] ]
+ array( 'product_ids' => array( $product_id ) )
)
);
@@ -610,12 +610,12 @@ public function testApplyCouponMutationWithInvalidCoupons() {
*
* Can't pass coupon ID as coupon 'code'. Mutation should fail.
*/
- $variables = [
- 'input' => [
+ $variables = array(
+ 'input' => array(
'clientMutationId' => 'someId',
'code' => '$coupon_id',
- ],
- ];
+ ),
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
$this->assertNotEmpty( $response['errors'] );
@@ -626,12 +626,12 @@ public function testApplyCouponMutationWithInvalidCoupons() {
*
* Can't pass expired coupon code. Mutation should fail.
*/
- $variables = [
- 'input' => [
+ $variables = array(
+ 'input' => array(
'clientMutationId' => 'someId',
'code' => $expired_coupon_code,
- ],
- ];
+ ),
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
$this->assertNotEmpty( $response['errors'] );
@@ -642,12 +642,12 @@ public function testApplyCouponMutationWithInvalidCoupons() {
*
* Can't pass coupon already applied to the cart. Mutation should fail.
*/
- $variables = [
- 'input' => [
+ $variables = array(
+ 'input' => array(
'clientMutationId' => 'someId',
'code' => $applied_coupon_code,
- ],
- ];
+ ),
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
$this->assertNotEmpty( $response['errors'] );
@@ -661,7 +661,7 @@ public function testRemoveCouponMutation() {
$product_id = $this->factory->product->createSimple();
$coupon_code = wc_get_coupon_code_by_id(
$this->factory->coupon->create(
- [ 'product_ids' => [ $product_id ] ]
+ array( 'product_ids' => array( $product_id ) )
)
);
@@ -698,12 +698,12 @@ public function testRemoveCouponMutation() {
}
';
- $variables = [
- 'input' => [
+ $variables = array(
+ 'input' => array(
'clientMutationId' => 'someId',
- 'codes' => [ $coupon_code ],
- ],
- ];
+ 'codes' => array( $coupon_code ),
+ ),
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
// Get updated cart item.
@@ -711,26 +711,26 @@ public function testRemoveCouponMutation() {
$this->assertQuerySuccessful(
$response,
- [
+ array(
$this->expectedField( 'removeCoupons.clientMutationId', 'someId' ),
$this->expectedField( 'removeCoupons.cart.appliedCoupons', static::IS_NULL ),
$this->expectedNode(
'removeCoupons.cart.contents.nodes',
- [
+ array(
'key' => $cart_item['key'],
- 'product' => [
- 'node' => [
+ 'product' => array(
+ 'node' => array(
'id' => $this->toRelayId( 'post', $cart_item['product_id'] ),
- ],
- ],
+ ),
+ ),
'quantity' => $cart_item['quantity'],
'subtotal' => wc_graphql_price( $cart_item['line_subtotal'] ),
'subtotalTax' => wc_graphql_price( $cart_item['line_subtotal_tax'] ),
'total' => wc_graphql_price( $cart_item['line_total'] ),
'tax' => wc_graphql_price( $cart_item['line_tax'] ),
- ]
+ )
),
- ]
+ )
);
}
@@ -739,7 +739,7 @@ public function testAddFeeMutation() {
$product_id = $this->factory->product->createSimple();
$coupon_code = wc_get_coupon_code_by_id(
$this->factory->coupon->create(
- [ 'product_ids' => [ $product_id ] ]
+ array( 'product_ids' => array( $product_id ) )
)
);
@@ -764,13 +764,13 @@ public function testAddFeeMutation() {
}
';
- $variables = [
- 'input' => [
+ $variables = array(
+ 'input' => array(
'clientMutationId' => 'someId',
'name' => 'extra_fee',
'amount' => 49.99,
- ],
- ];
+ ),
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
$this->assertArrayHasKey( 'errors', $response );
@@ -782,30 +782,30 @@ public function testAddFeeMutation() {
$this->assertQuerySuccessful(
$response,
- [
+ array(
$this->expectedField( 'addFee.clientMutationId', 'someId' ),
$this->expectedField(
'addFee.cartFee',
- [
+ array(
'id' => $fee->id,
'name' => $fee->name,
'taxClass' => ! empty( $fee->tax_class ) ? $fee->tax_class : null,
'taxable' => $fee->taxable,
'amount' => (float) $fee->amount,
'total' => (float) $fee->total,
- ]
+ )
),
- ]
+ )
);
}
public function testAddToCartMutationErrors() {
// Create products.
$product_id = $this->factory->product->createSimple(
- [
+ array(
'manage_stock' => true,
'stock_quantity' => 1,
- ]
+ )
);
$variation_ids = $this->factory->product_variation->createSome();
@@ -813,7 +813,7 @@ public function testAddToCartMutationErrors() {
$attribute = new WC_Product_Attribute();
$attribute->set_id( 0 );
$attribute->set_name( 'test' );
- $attribute->set_options( [ 'yes', 'no' ] );
+ $attribute->set_options( array( 'yes', 'no' ) );
$attribute->set_position( 3 );
$attribute->set_visible( true );
$attribute->set_variation( true );
@@ -849,25 +849,25 @@ public function testAddToCartMutationErrors() {
';
\WC()->session->set( 'wc_notices', null );
- $variables = [
- 'input' => [
+ $variables = array(
+ 'input' => array(
'clientMutationId' => 'someId',
'productId' => $variation_ids['product'],
'quantity' => 5,
'variationId' => $variation_ids['variations'][0],
- ],
- ];
+ ),
+ );
$missing_attributes = $this->graphql( compact( 'query', 'variables' ) );
$this->assertArrayHasKey( 'errors', $missing_attributes );
\WC()->session->set( 'wc_notices', null );
- $variables = [
- 'input' => [
+ $variables = array(
+ 'input' => array(
'clientMutationId' => 'someId',
'productId' => $product_id,
'quantity' => 5,
- ],
- ];
+ ),
+ );
$not_enough_stock = $this->graphql( compact( 'query', 'variables' ) );
$this->assertArrayHasKey( 'errors', $not_enough_stock );
}
@@ -879,7 +879,7 @@ public function testAddToCartMutationItemEdgeData() {
$attribute = new WC_Product_Attribute();
$attribute->set_id( 0 );
$attribute->set_name( 'test' );
- $attribute->set_options( [ 'yes', 'no' ] );
+ $attribute->set_options( array( 'yes', 'no' ) );
$attribute->set_position( 3 );
$attribute->set_visible( true );
$attribute->set_variation( true );
@@ -906,48 +906,48 @@ public function testAddToCartMutationItemEdgeData() {
}
';
- $variables = [
- 'input' => [
+ $variables = array(
+ 'input' => array(
'clientMutationId' => 'someId',
'productId' => $variation_ids['product'],
'quantity' => 3,
'variationId' => $variation_ids['variations'][1],
- 'variation' => [
- [
+ 'variation' => array(
+ array(
'attributeName' => 'test',
'attributeValue' => 'yes',
- ],
- [
+ ),
+ array(
'attributeName' => 'color',
'attributeValue' => 'green',
- ],
- ],
- ],
- ];
+ ),
+ ),
+ ),
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedObject(
'addToCart.cartItem.product',
- [
+ array(
$this->expectedField( 'node.databaseId', $variation_ids['product'] ),
$this->expectedObject(
'simpleVariations.#',
- [
+ array(
$this->expectedField( 'name', 'attribute_test' ),
$this->expectedField( 'value', 'yes' ),
- ]
+ )
),
$this->expectedObject(
'simpleVariations.#',
- [
+ array(
$this->expectedField( 'name', 'attribute_pa_color' ),
$this->expectedField( 'value', 'green' ),
- ]
+ )
),
- ]
+ )
),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
}
@@ -959,7 +959,7 @@ public function testAddCartItemsMutationAndErrors() {
$attribute = new WC_Product_Attribute();
$attribute->set_id( 0 );
$attribute->set_name( 'test' );
- $attribute->set_options( [ 'yes', 'no' ] );
+ $attribute->set_options( array( 'yes', 'no' ) );
$attribute->set_position( 3 );
$attribute->set_visible( true );
$attribute->set_variation( true );
@@ -1000,73 +1000,73 @@ public function testAddCartItemsMutationAndErrors() {
}
';
- $variables = [
- 'input' => [
+ $variables = array(
+ 'input' => array(
'clientMutationId' => 'someId',
- 'items' => [
- [
+ 'items' => array(
+ array(
'productId' => $product_one,
'quantity' => 2,
- ],
- [
+ ),
+ array(
'productId' => $variation_ids['product'],
'quantity' => 5,
'variationId' => $variation_ids['variations'][0],
- ],
- [
+ ),
+ array(
'productId' => $invalid_product,
'quantity' => 4,
- ],
- [
+ ),
+ array(
'productId' => $variation_ids['product'],
'quantity' => 3,
'variationId' => $variation_ids['variations'][1],
- 'variation' => [
- [
+ 'variation' => array(
+ array(
'attributeName' => 'test',
'attributeValue' => 'yes',
- ],
- [
+ ),
+ array(
'attributeName' => 'color',
'attributeValue' => 'green',
- ],
- ],
- ],
- ],
- ],
- ];
+ ),
+ ),
+ ),
+ ),
+ ),
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
$this->assertQuerySuccessful(
$response,
- [
+ array(
$this->expectedField( 'addCartItems.clientMutationId', 'someId' ),
$this->expectedNode(
'addCartItems.added',
- [
- 'product' => [
- 'node' => [ 'databaseId' => $product_one ],
- ],
+ array(
+ 'product' => array(
+ 'node' => array( 'databaseId' => $product_one ),
+ ),
'variation' => null,
'quantity' => 2,
- ]
+ )
),
$this->expectedNode(
'addCartItems.added',
- [
- 'product' => [
- 'node' => [ 'databaseId' => $variation_ids['product'] ],
- ],
- 'variation' => [
- 'node' => [ 'databaseId' => $variation_ids['variations'][1] ],
- ],
+ array(
+ 'product' => array(
+ 'node' => array( 'databaseId' => $variation_ids['product'] ),
+ ),
+ 'variation' => array(
+ 'node' => array( 'databaseId' => $variation_ids['variations'][1] ),
+ ),
'quantity' => 3,
- ]
+ )
),
$this->expectedNode(
'addCartItems.cartErrors',
- [
+ array(
$this->expectedField( 'type', 'INVALID_CART_ITEM' ),
$this->expectedField( 'reasons.0', static::NOT_NULL ),
$this->expectedField( 'productId', $variation_ids['product'] ),
@@ -1074,11 +1074,11 @@ public function testAddCartItemsMutationAndErrors() {
$this->expectedField( 'variationId', $variation_ids['variations'][0] ),
$this->expectedField( 'variation', static::IS_NULL ),
$this->expectedField( 'extraData', static::IS_NULL ),
- ]
+ )
),
$this->expectedNode(
'addCartItems.cartErrors',
- [
+ array(
$this->expectedField( 'type', 'INVALID_CART_ITEM' ),
$this->expectedField( 'reasons.0', 'No product found matching the ID provided' ),
$this->expectedField( 'productId', $invalid_product ),
@@ -1086,32 +1086,32 @@ public function testAddCartItemsMutationAndErrors() {
$this->expectedField( 'variationId', static::IS_NULL ),
$this->expectedField( 'variation', static::IS_NULL ),
$this->expectedField( 'extraData', static::IS_NULL ),
- ]
+ )
),
- ]
+ )
);
}
public function testFillCartMutationAndErrors() {
// Create products.
- $product_one = $this->factory->product->createSimple( [ 'regular_price' => 100 ] );
- $product_two = $this->factory->product->createSimple( [ 'regular_price' => 40 ] );
+ $product_one = $this->factory->product->createSimple( array( 'regular_price' => 100 ) );
+ $product_two = $this->factory->product->createSimple( array( 'regular_price' => 40 ) );
// Create coupons.
$coupon_code_one = wc_get_coupon_code_by_id(
$this->factory->coupon->create(
- [
+ array(
'amount' => 0.5,
- 'product_ids' => [ $product_one ],
- ]
+ 'product_ids' => array( $product_one ),
+ )
)
);
$coupon_code_two = wc_get_coupon_code_by_id(
$this->factory->coupon->create(
- [
+ array(
'amount' => 0.2,
- 'product_ids' => [ $product_two ],
- ]
+ 'product_ids' => array( $product_two ),
+ )
)
);
@@ -1164,62 +1164,62 @@ public function testFillCartMutationAndErrors() {
}
';
- $variables = [
- 'input' => [
+ $variables = array(
+ 'input' => array(
'clientMutationId' => 'someId',
- 'items' => [
- [
+ 'items' => array(
+ array(
'productId' => $product_one,
'quantity' => 3,
- ],
- [
+ ),
+ array(
'productId' => $product_two,
'quantity' => 2,
- ],
- [
+ ),
+ array(
'productId' => $invalid_product,
'quantity' => 4,
- ],
- ],
- 'coupons' => [ $coupon_code_one, $coupon_code_two, $invalid_coupon ],
- 'shippingMethods' => [ 'legacy_flat_rate', $invalid_shipping_method ],
- ],
- ];
+ ),
+ ),
+ 'coupons' => array( $coupon_code_one, $coupon_code_two, $invalid_coupon ),
+ 'shippingMethods' => array( 'legacy_flat_rate', $invalid_shipping_method ),
+ ),
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedObject(
'fillCart',
- [
+ array(
$this->expectedField( 'clientMutationId', 'someId' ),
$this->expectedObject(
'cart',
- [
+ array(
$this->expectedField( 'chosenShippingMethods.0', 'legacy_flat_rate' ),
$this->expectedObject(
'contents',
- [
+ array(
$this->expectedNode(
'nodes',
- [
+ array(
$this->expectedField( 'product.node.databaseId', $product_one ),
$this->expectedField( 'quantity', 3 ),
$this->expectedField( 'variation', static::IS_NULL ),
- ]
+ )
),
$this->expectedNode(
'nodes',
- [
+ array(
$this->expectedField( 'product.node.databaseId', $product_two ),
$this->expectedField( 'quantity', 2 ),
$this->expectedField( 'variation', static::IS_NULL ),
- ]
+ )
),
- ]
+ )
),
$this->expectedNode(
'appliedCoupons',
- [
+ array(
$this->expectedField( 'code', $coupon_code_one ),
$this->expectedField(
'discountAmount',
@@ -1229,11 +1229,11 @@ public function testFillCartMutationAndErrors() {
'discountTax',
\wc_graphql_price( \WC()->cart->get_coupon_discount_tax_amount( $coupon_code_one ) )
),
- ]
+ )
),
$this->expectedNode(
'appliedCoupons',
- [
+ array(
$this->expectedField( 'code', $coupon_code_two ),
$this->expectedField(
'discountAmount',
@@ -1243,38 +1243,38 @@ public function testFillCartMutationAndErrors() {
'discountTax',
\wc_graphql_price( \WC()->cart->get_coupon_discount_tax_amount( $coupon_code_two ) )
),
- ]
+ )
),
- ]
+ )
),
$this->expectedNode(
'cartErrors',
- [
+ array(
$this->expectedField( 'type', 'INVALID_CART_ITEM' ),
- $this->expectedField( 'reasons', [ 'No product found matching the ID provided' ] ),
+ $this->expectedField( 'reasons', array( 'No product found matching the ID provided' ) ),
$this->expectedField( 'productId', $invalid_product ),
$this->expectedField( 'quantity', 4 ),
- ]
+ )
),
$this->expectedNode(
'cartErrors',
- [
+ array(
$this->expectedField( 'type', 'INVALID_COUPON' ),
- $this->expectedField( 'reasons', [ "Coupon \"{$invalid_coupon}\" does not exist!" ] ),
+ $this->expectedField( 'reasons', array( "Coupon \"{$invalid_coupon}\" does not exist!" ) ),
$this->expectedField( 'code', $invalid_coupon ),
- ]
+ )
),
$this->expectedNode(
'cartErrors',
- [
+ array(
$this->expectedField( 'type', 'INVALID_SHIPPING_METHOD' ),
$this->expectedField( 'chosenMethod', $invalid_shipping_method ),
$this->expectedField( 'package', 1 ),
- ]
+ )
),
- ]
+ )
),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
}
diff --git a/tests/wpunit/CartQueriesTest.php b/tests/wpunit/CartQueriesTest.php
index 312d333c5..8f31bd8fa 100644
--- a/tests/wpunit/CartQueriesTest.php
+++ b/tests/wpunit/CartQueriesTest.php
@@ -8,7 +8,7 @@ private function key_to_cursor( $key ) {
public function getExpectedCartData() {
$cart = WC()->cart;
- return [
+ return array(
$this->expectedField( 'cart.subtotal', \wc_graphql_price( $cart->get_subtotal() ) ),
$this->expectedField( 'cart.subtotalTax', \wc_graphql_price( $cart->get_subtotal_tax() ) ),
$this->expectedField( 'cart.discountTotal', \wc_graphql_price( $cart->get_discount_total() ) ),
@@ -36,16 +36,16 @@ public function getExpectedCartData() {
$this->expectedField( 'cart.rawFeeTax', static::NOT_NULL ),
$this->expectedField( 'cart.rawtotal', static::NOT_NULL ),
$this->expectedField( 'cart.rawTotalTax', static::NOT_NULL ),
- ];
+ );
}
public function getExpectedCartItemData( $path, $cart_item_key ) {
$cart = WC()->cart;
$item = $cart->get_cart_item( $cart_item_key );
- return [
+ return array(
$this->expectedObject(
$path,
- [
+ array(
$this->expectedField( 'key', $item['key'] ),
$this->expectedField( 'product.node.id', $this->toRelayId( 'post', $item['product_id'] ) ),
$this->expectedField( 'product.node.databaseId', $item['product_id'] ),
@@ -64,23 +64,23 @@ public function getExpectedCartItemData( $path, $cart_item_key ) {
$this->expectedField( 'subtotalTax', \wc_graphql_price( $item['line_subtotal_tax'] ) ),
$this->expectedField( 'total', \wc_graphql_price( $item['line_total'] ) ),
$this->expectedField( 'tax', \wc_graphql_price( $item['line_tax'] ) ),
- ]
+ )
),
- ];
+ );
}
// tests
public function testCartQuery() {
$cart = WC()->cart;
$this->factory->cart->add(
- [
+ array(
'product_id' => $this->factory->product->createSimple(),
'quantity' => 2,
- ],
- [
+ ),
+ array(
'product_id' => $this->factory->product->createSimple(),
'quantity' => 1,
- ]
+ )
);
$query = '
@@ -139,7 +139,7 @@ public function testCartItemQuery() {
$variations['product'],
3,
$variations['variations'][0],
- [ 'attribute_pa_color' => 'red' ]
+ array( 'attribute_pa_color' => 'red' )
);
$query = '
@@ -177,7 +177,7 @@ public function testCartItemQuery() {
/**
* Assertion One
*/
- $variables = [ 'key' => $key ];
+ $variables = array( 'key' => $key );
$response = $this->graphql( compact( 'query', 'variables' ) );
$this->assertQuerySuccessful( $response, $this->getExpectedCartItemData( 'cartItem', $key ) );
@@ -185,28 +185,28 @@ public function testCartItemQuery() {
public function testCartItemConnection() {
$keys = $this->factory->cart->add(
- [
+ array(
'product_id' => $this->factory->product->createSimple(
- [ 'virtual' => true ]
+ array( 'virtual' => true )
),
'quantity' => 2,
- ],
- [
+ ),
+ array(
'product_id' => $this->factory->product->createSimple(),
'quantity' => 1,
- ],
- [
+ ),
+ array(
'product_id' => $this->factory->product->createSimple(),
'quantity' => 10,
- ]
+ )
);
$code = \wc_get_coupon_code_by_id(
$this->factory->coupon->create(
- [
+ array(
'amount' => 45.50,
'discount_type' => 'fixed_cart',
- ]
+ )
)
);
$cart = \WC()->cart;
@@ -230,9 +230,9 @@ public function testCartItemConnection() {
$response = $this->graphql( compact( 'query' ) );
- $expected = [];
+ $expected = array();
foreach ( $keys as $key ) {
- $expected[] = $this->expectedNode( 'cart.contents.nodes', [ 'key' => $key ] );
+ $expected[] = $this->expectedNode( 'cart.contents.nodes', array( 'key' => $key ) );
}
$this->assertQuerySuccessful( $response, $expected );
@@ -242,15 +242,15 @@ public function testCartItemConnection() {
*
* Tests "needsShipping" parameter.
*/
- $variables = [ 'needsShipping' => true ];
+ $variables = array( 'needsShipping' => true );
$response = $this->graphql( compact( 'query', 'variables' ) );
$this->assertQuerySuccessful(
$response,
- [
- $this->expectedNode( 'cart.contents.nodes', [ 'key' => $keys[1] ] ),
- $this->expectedNode( 'cart.contents.nodes', [ 'key' => $keys[2] ] ),
- ]
+ array(
+ $this->expectedNode( 'cart.contents.nodes', array( 'key' => $keys[1] ) ),
+ $this->expectedNode( 'cart.contents.nodes', array( 'key' => $keys[2] ) ),
+ )
);
/**
@@ -258,14 +258,14 @@ public function testCartItemConnection() {
*
* Tests "needsShipping" parameter reversed.
*/
- $variables = [ 'needsShipping' => false ];
+ $variables = array( 'needsShipping' => false );
$response = $this->graphql( compact( 'query', 'variables' ) );
$this->assertQuerySuccessful(
$response,
- [
- $this->expectedNode( 'cart.contents.nodes', [ 'key' => $keys[0] ] ),
- ]
+ array(
+ $this->expectedNode( 'cart.contents.nodes', array( 'key' => $keys[0] ) ),
+ )
);
}
@@ -291,21 +291,21 @@ public function testCartFeeQuery() {
/**
* Assertion One
*/
- $variables = [ 'id' => $fee_ids[0] ];
+ $variables = array( 'id' => $fee_ids[0] );
$response = $this->graphql( compact( 'query', 'variables' ) );
$fee = ( \WC()->cart->get_fees() )[ $fee_ids[0] ];
$this->assertQuerySuccessful(
$response,
- [
+ array(
$this->expectedField( 'cartFee.id', $fee->id ),
$this->expectedField( 'cartFee.name', $fee->name ),
$this->expectedField( 'cartFee.taxClass', $this->maybe( $fee->tax_class ) ),
$this->expectedField( 'cartFee.taxable', $fee->taxable ),
$this->expectedField( 'cartFee.amount', (float) $fee->amount ),
$this->expectedField( 'cartFee.total', (float) $fee->total ),
- ]
+ )
);
}
@@ -329,9 +329,9 @@ public function testCartToCartFeeQuery() {
*/
$response = $this->graphql( compact( 'query' ) );
- $expected = [];
+ $expected = array();
foreach ( \WC()->cart->get_fees() as $fee_id => $value ) {
- $expected[] = $this->expectedNode( 'cart.fees', [ 'id' => $fee_id ] );
+ $expected[] = $this->expectedNode( 'cart.fees', array( 'id' => $fee_id ) );
}
$this->assertQuerySuccessful( $response, $expected );
@@ -339,26 +339,26 @@ public function testCartToCartFeeQuery() {
public function testCartItemPagination() {
$cart_items = $this->factory->cart->add(
- [
+ array(
'product_id' => $this->factory->product->createSimple(),
'quantity' => 2,
- ],
- [
+ ),
+ array(
'product_id' => $this->factory->product->createSimple(),
'quantity' => 1,
- ],
- [
+ ),
+ array(
'product_id' => $this->factory->product->createSimple(),
'quantity' => 1,
- ],
- [
+ ),
+ array(
'product_id' => $this->factory->product->createSimple(),
'quantity' => 1,
- ],
- [
+ ),
+ array(
'product_id' => $this->factory->product->createSimple(),
'quantity' => 1,
- ]
+ )
);
$query = '
@@ -387,29 +387,29 @@ public function testCartItemPagination() {
*
* Tests "first" parameter.
*/
- $variables = [
+ $variables = array(
'first' => 2,
'after' => '',
- ];
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'cart.contents.itemCount', 6 ),
$this->expectedField( 'cart.contents.productCount', 5 ),
$this->expectedField( 'cart.contents.pageInfo.hasNextPage', true ),
$this->expectedField( 'cart.contents.pageInfo.hasPreviousPage', false ),
$this->expectedEdge(
'cart.contents.edges',
- [ $this->expectedField( 'key', $cart_items[0] ) ],
+ array( $this->expectedField( 'key', $cart_items[0] ) ),
0
),
$this->expectedEdge(
'cart.contents.edges',
- [ $this->expectedField( 'key', $cart_items[1] ) ],
+ array( $this->expectedField( 'key', $cart_items[1] ) ),
1
),
$this->expectedField( 'cart.contents.edges.0.cursor', $this->key_to_cursor( $cart_items[0] ) ),
$this->expectedField( 'cart.contents.edges.1.cursor', $this->key_to_cursor( $cart_items[1] ) ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
@@ -418,27 +418,27 @@ public function testCartItemPagination() {
*
* Tests "after" parameter.
*/
- $variables = [
+ $variables = array(
'first' => 2,
'after' => $this->key_to_cursor( $cart_items[1] ),
- ];
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'cart.contents.pageInfo.hasNextPage', true ),
$this->expectedField( 'cart.contents.pageInfo.hasPreviousPage', true ),
$this->expectedField( 'cart.contents.edges.0.cursor', $this->key_to_cursor( $cart_items[2] ) ),
$this->expectedField( 'cart.contents.edges.1.cursor', $this->key_to_cursor( $cart_items[3] ) ),
$this->expectedEdge(
'cart.contents.edges',
- [ $this->expectedField( 'key', $cart_items[2] ) ],
+ array( $this->expectedField( 'key', $cart_items[2] ) ),
0
),
$this->expectedEdge(
'cart.contents.edges',
- [ $this->expectedField( 'key', $cart_items[3] ) ],
+ array( $this->expectedField( 'key', $cart_items[3] ) ),
1
),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
@@ -447,24 +447,24 @@ public function testCartItemPagination() {
*
* Tests "last" parameter.
*/
- $variables = [ 'last' => 2 ];
+ $variables = array( 'last' => 2 );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'cart.contents.pageInfo.hasNextPage', false ),
$this->expectedField( 'cart.contents.pageInfo.hasPreviousPage', true ),
$this->expectedEdge(
'cart.contents.edges',
- [ $this->expectedField( 'key', $cart_items[3] ) ],
+ array( $this->expectedField( 'key', $cart_items[3] ) ),
0
),
$this->expectedEdge(
'cart.contents.edges',
- [ $this->expectedField( 'key', $cart_items[4] ) ],
+ array( $this->expectedField( 'key', $cart_items[4] ) ),
1
),
$this->expectedField( 'cart.contents.edges.0.cursor', $this->key_to_cursor( $cart_items[3] ) ),
$this->expectedField( 'cart.contents.edges.1.cursor', $this->key_to_cursor( $cart_items[4] ) ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
@@ -473,12 +473,12 @@ public function testCartItemPagination() {
*
* Tests "before" parameter.
*/
- $variables = [
+ $variables = array(
'last' => 4,
'before' => $this->key_to_cursor( $cart_items[3] ),
- ];
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'cart.contents.pageInfo.hasNextPage', true ),
$this->expectedField( 'cart.contents.pageInfo.hasPreviousPage', false ),
$this->expectedField( 'cart.contents.edges.0.cursor', $this->key_to_cursor( $cart_items[0] ) ),
@@ -486,20 +486,20 @@ public function testCartItemPagination() {
$this->expectedField( 'cart.contents.edges.2.cursor', $this->key_to_cursor( $cart_items[2] ) ),
$this->expectedEdge(
'cart.contents.edges',
- [ $this->expectedField( 'key', $cart_items[0] ) ],
+ array( $this->expectedField( 'key', $cart_items[0] ) ),
0
),
$this->expectedEdge(
'cart.contents.edges',
- [ $this->expectedField( 'key', $cart_items[1] ) ],
+ array( $this->expectedField( 'key', $cart_items[1] ) ),
1
),
$this->expectedEdge(
'cart.contents.edges',
- [ $this->expectedField( 'key', $cart_items[2] ) ],
+ array( $this->expectedField( 'key', $cart_items[2] ) ),
2
),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
}
diff --git a/tests/wpunit/CheckoutMutationTest.php b/tests/wpunit/CheckoutMutationTest.php
index 3ac4b0893..766de426b 100644
--- a/tests/wpunit/CheckoutMutationTest.php
+++ b/tests/wpunit/CheckoutMutationTest.php
@@ -20,18 +20,18 @@ public function setUp(): void {
// Enable payment gateways.
update_option(
'woocommerce_bacs_settings',
- [
+ array(
'enabled' => 'yes',
'title' => 'Direct bank transfer',
'description' => 'Make your payment directly into our bank account. Please use your Order ID as the payment reference. Your order will not be shipped until the funds have cleared in our account.',
'instructions' => 'Instructions that will be added to the thank you page and emails.',
'account' => '',
- ]
+ )
);
update_option(
'woocommerce_stripe_settings',
- [
+ array(
'enabled' => 'yes',
'title' => 'Credit Card (Stripe)',
'description' => 'Pay with your credit card via Stripe',
@@ -56,7 +56,7 @@ public function setUp(): void {
'payment_request_button_height' => '44',
'saved_cards' => 'yes',
'logging' => 'no',
- ]
+ )
);
// Additional cart fees.
@@ -71,7 +71,7 @@ static function () {
// Create a tax rate.
$this->factory->tax_rate->create(
- [
+ array(
'country' => '',
'state' => '',
'rate' => 20.000,
@@ -80,7 +80,7 @@ static function () {
'compound' => '0',
'shipping' => '1',
'class' => '',
- ]
+ )
);
}
@@ -275,13 +275,13 @@ private function getCartQuery() {
';
}
- private function getCheckoutInput( $overwrite = [] ) {
+ private function getCheckoutInput( $overwrite = array() ) {
return array_merge(
- [
+ array(
'paymentMethod' => 'bacs',
- 'shippingMethod' => [ 'flat rate' ],
+ 'shippingMethod' => array( 'flat rate' ),
'customerNote' => 'Test customer note',
- 'billing' => [
+ 'billing' => array(
'firstName' => 'May',
'lastName' => 'Parker',
'address1' => '20 Ingram St',
@@ -292,8 +292,8 @@ private function getCheckoutInput( $overwrite = [] ) {
'email' => 'superfreak500@gmail.com',
'phone' => '555-555-1234',
'overwrite' => true,
- ],
- 'shipping' => [
+ ),
+ 'shipping' => array(
'firstName' => 'May',
'lastName' => 'Parker',
'address1' => '20 Ingram St',
@@ -301,14 +301,14 @@ private function getCheckoutInput( $overwrite = [] ) {
'state' => 'NY',
'postcode' => '12345',
'country' => 'US',
- ],
- 'metaData' => [
- [
+ ),
+ 'metaData' => array(
+ array(
'key' => 'test_key',
'value' => 'test value',
- ],
- ],
- ],
+ ),
+ ),
+ ),
$overwrite
);
}
@@ -320,14 +320,14 @@ public function testCheckoutMutation() {
WC()->customer->save();
$variable = $this->factory->product_variation->createSome();
- $product_ids = [
+ $product_ids = array(
$this->factory->product->createSimple(),
$this->factory->product->createSimple(),
$variable['product'],
- ];
+ );
$coupon = new WC_Coupon(
$this->factory->coupon->create(
- [ 'product_ids' => $product_ids ]
+ array( 'product_ids' => $product_ids )
)
);
@@ -337,11 +337,11 @@ public function testCheckoutMutation() {
$product_ids[2],
2,
$variable['variations'][0],
- [ 'attribute_pa_color' => 'red' ]
+ array( 'attribute_pa_color' => 'red' )
);
WC()->cart->apply_coupon( $coupon->get_code() );
- $variables = [ 'input' => $this->getCheckoutInput() ];
+ $variables = array( 'input' => $this->getCheckoutInput() );
$query = $this->getCheckoutMutation();
/**
@@ -350,30 +350,30 @@ public function testCheckoutMutation() {
* Test mutation and input.
*/
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'checkout.order.id', static::NOT_NULL ),
$this->expectedField( 'checkout.order.status', 'ON_HOLD' ),
$this->expectedNode(
'checkout.order.metaData',
- [
+ array(
$this->expectedField( 'key', 'test_key' ),
$this->expectedField( 'value', 'test value' ),
- ]
+ )
),
$this->expectedNode(
'checkout.order.couponLines.nodes',
- [
+ array(
$this->expectedField( 'code', $coupon->get_code() ),
$this->expectedField( 'databaseId', static::NOT_NULL ),
$this->expectedField( 'orderId', static::NOT_NULL ),
$this->expectedField( 'discount', static::NOT_NULL ),
$this->expectedField( 'discountTax', static::NOT_NULL ),
$this->expectedField( 'coupon', static::NOT_NULL ),
- ]
+ )
),
$this->expectedNode(
'checkout.order.feeLines.nodes',
- [
+ array(
$this->expectedField( 'name', 'Surcharge' ),
$this->expectedField( 'databaseId', static::NOT_NULL ),
$this->expectedField( 'orderId', static::NOT_NULL ),
@@ -382,33 +382,33 @@ public function testCheckoutMutation() {
$this->expectedField( 'total', static::NOT_NULL ),
$this->expectedField( 'totalTax', static::NOT_NULL ),
$this->expectedField( 'taxClass', static::NOT_NULL ),
- ]
+ )
),
$this->expectedNode(
'checkout.order.shippingLines.nodes',
- [
+ array(
$this->expectedField( 'methodTitle', 'Flat rate' ),
$this->expectedField( 'databaseId', static::NOT_NULL ),
$this->expectedField( 'orderId', static::NOT_NULL ),
$this->expectedField( 'total', static::NOT_NULL ),
$this->expectedField( 'totalTax', static::NOT_NULL ),
$this->expectedField( 'taxClass', static::NOT_NULL ),
- ]
+ )
),
$this->expectedNode(
'checkout.order.taxLines.nodes',
- [
+ array(
$this->expectedField( 'label', 'VAT' ),
$this->expectedField( 'rateCode', static::NOT_NULL ),
$this->expectedField( 'taxTotal', static::NOT_NULL ),
$this->expectedField( 'shippingTaxTotal', static::NOT_NULL ),
$this->expectedField( 'isCompound', static::NOT_NULL ),
$this->expectedField( 'taxRate', static::NOT_NULL ),
- ]
+ )
),
$this->expectedNode(
'checkout.order.lineItems.nodes',
- [
+ array(
$this->expectedField( 'productId', $product_ids[0] ),
$this->expectedField( 'quantity', static::NOT_NULL ),
$this->expectedField( 'taxClass', static::NOT_NULL ),
@@ -418,11 +418,11 @@ public function testCheckoutMutation() {
$this->expectedField( 'totalTax', static::NOT_NULL ),
$this->expectedField( 'taxStatus', static::NOT_NULL ),
$this->expectedField( 'product.node.id', static::NOT_NULL ),
- ]
+ )
),
$this->expectedNode(
'checkout.order.lineItems.nodes',
- [
+ array(
$this->expectedField( 'productId', $product_ids[1] ),
$this->expectedField( 'quantity', static::NOT_NULL ),
$this->expectedField( 'taxClass', static::NOT_NULL ),
@@ -432,11 +432,11 @@ public function testCheckoutMutation() {
$this->expectedField( 'totalTax', static::NOT_NULL ),
$this->expectedField( 'taxStatus', static::NOT_NULL ),
$this->expectedField( 'product.node.id', static::NOT_NULL ),
- ]
+ )
),
$this->expectedNode(
'checkout.order.lineItems.nodes',
- [
+ array(
$this->expectedField( 'productId', $product_ids[2] ),
$this->expectedField( 'variationId', static::NOT_NULL ),
$this->expectedField( 'quantity', static::NOT_NULL ),
@@ -448,7 +448,7 @@ public function testCheckoutMutation() {
$this->expectedField( 'taxStatus', static::NOT_NULL ),
$this->expectedField( 'product.node.id', static::NOT_NULL ),
$this->expectedField( 'variation.node.id', static::NOT_NULL ),
- ]
+ )
),
$this->expectedField(
'checkout.customer.id',
@@ -456,31 +456,31 @@ public function testCheckoutMutation() {
),
$this->expectedField( 'checkout.result', 'success' ),
$this->expectedField( 'checkout.redirect', static::NOT_NULL ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
// Confirm cart empty after successful checkout.
$query = $this->getCartQuery();
$response = $this->graphql( compact( 'query' ) );
- $expected = [
- $this->expectedField( 'cart.contents.nodes', [] ),
+ $expected = array(
+ $this->expectedField( 'cart.contents.nodes', array() ),
$this->expectedField( 'cart.total', '$0.00' ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
}
public function testCheckoutMutationWithNewAccount() {
$variable = $this->factory->product_variation->createSome();
- $product_ids = [
+ $product_ids = array(
$this->factory->product->createSimple(),
$this->factory->product->createSimple(),
$variable['product'],
- ];
+ );
$coupon = new WC_Coupon(
$this->factory->coupon->create(
- [ 'product_ids' => $product_ids ]
+ array( 'product_ids' => $product_ids )
)
);
@@ -490,17 +490,17 @@ public function testCheckoutMutationWithNewAccount() {
$product_ids[2],
2,
$variable['variations'][0],
- [ 'attribute_pa_color' => 'red' ]
+ array( 'attribute_pa_color' => 'red' )
);
WC()->cart->apply_coupon( $coupon->get_code() );
- $input = [
- 'account' => [
+ $input = array(
+ 'account' => array(
'username' => 'test_user_1',
'password' => 'test_pass',
- ],
- ];
- $variables = [ 'input' => $this->getCheckoutInput( $input ) ];
+ ),
+ );
+ $variables = array( 'input' => $this->getCheckoutInput( $input ) );
$query = $this->getCheckoutMutation();
/**
@@ -509,19 +509,19 @@ public function testCheckoutMutationWithNewAccount() {
* Test mutation and input.
*/
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'checkout.order.id', static::NOT_NULL ),
$this->expectedField( 'checkout.order.status', 'ON_HOLD' ),
$this->expectedNode(
'checkout.order.metaData',
- [
+ array(
$this->expectedField( 'key', 'test_key' ),
$this->expectedField( 'value', 'test value' ),
- ]
+ )
),
$this->expectedNode(
'checkout.order.feeLines.nodes',
- [
+ array(
$this->expectedField( 'name', 'Surcharge' ),
$this->expectedField( 'databaseId', static::NOT_NULL ),
$this->expectedField( 'orderId', static::NOT_NULL ),
@@ -530,33 +530,33 @@ public function testCheckoutMutationWithNewAccount() {
$this->expectedField( 'total', static::NOT_NULL ),
$this->expectedField( 'totalTax', static::NOT_NULL ),
$this->expectedField( 'taxClass', static::NOT_NULL ),
- ]
+ )
),
$this->expectedNode(
'checkout.order.shippingLines.nodes',
- [
+ array(
$this->expectedField( 'methodTitle', 'Flat rate' ),
$this->expectedField( 'databaseId', static::NOT_NULL ),
$this->expectedField( 'orderId', static::NOT_NULL ),
$this->expectedField( 'total', static::NOT_NULL ),
$this->expectedField( 'totalTax', static::NOT_NULL ),
$this->expectedField( 'taxClass', static::NOT_NULL ),
- ]
+ )
),
$this->expectedNode(
'checkout.order.taxLines.nodes',
- [
+ array(
$this->expectedField( 'label', 'VAT' ),
$this->expectedField( 'rateCode', static::NOT_NULL ),
$this->expectedField( 'taxTotal', static::NOT_NULL ),
$this->expectedField( 'shippingTaxTotal', static::NOT_NULL ),
$this->expectedField( 'isCompound', static::NOT_NULL ),
$this->expectedField( 'taxRate', static::NOT_NULL ),
- ]
+ )
),
$this->expectedNode(
'checkout.order.lineItems.nodes',
- [
+ array(
$this->expectedField( 'productId', $product_ids[0] ),
$this->expectedField( 'quantity', static::NOT_NULL ),
$this->expectedField( 'taxClass', static::NOT_NULL ),
@@ -566,11 +566,11 @@ public function testCheckoutMutationWithNewAccount() {
$this->expectedField( 'totalTax', static::NOT_NULL ),
$this->expectedField( 'taxStatus', static::NOT_NULL ),
$this->expectedField( 'product.node.id', static::NOT_NULL ),
- ]
+ )
),
$this->expectedNode(
'checkout.order.lineItems.nodes',
- [
+ array(
$this->expectedField( 'productId', $product_ids[1] ),
$this->expectedField( 'quantity', static::NOT_NULL ),
$this->expectedField( 'taxClass', static::NOT_NULL ),
@@ -580,11 +580,11 @@ public function testCheckoutMutationWithNewAccount() {
$this->expectedField( 'totalTax', static::NOT_NULL ),
$this->expectedField( 'taxStatus', static::NOT_NULL ),
$this->expectedField( 'product.node.id', static::NOT_NULL ),
- ]
+ )
),
$this->expectedNode(
'checkout.order.lineItems.nodes',
- [
+ array(
$this->expectedField( 'productId', $product_ids[2] ),
$this->expectedField( 'variationId', static::NOT_NULL ),
$this->expectedField( 'quantity', static::NOT_NULL ),
@@ -596,22 +596,22 @@ public function testCheckoutMutationWithNewAccount() {
$this->expectedField( 'taxStatus', static::NOT_NULL ),
$this->expectedField( 'product.node.id', static::NOT_NULL ),
$this->expectedField( 'variation.node.id', static::NOT_NULL ),
- ]
+ )
),
$this->expectedField( 'checkout.customer.id', static::NOT_NULL ),
$this->expectedField( 'checkout.result', 'success' ),
$this->expectedField( 'checkout.redirect', static::NOT_NULL ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
// Confirm cart empty after successful checkout.
$query = $this->getCartQuery();
$response = $this->graphql( compact( 'query' ) );
- $expected = [
- $this->expectedField( 'cart.contents.nodes', [] ),
+ $expected = array(
+ $this->expectedField( 'cart.contents.nodes', array() ),
$this->expectedField( 'cart.total', '$0.00' ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
}
@@ -621,14 +621,14 @@ public function testCheckoutMutationWithNoAccount() {
WC()->customer->save();
$variable = $this->factory->product_variation->createSome();
- $product_ids = [
+ $product_ids = array(
$this->factory->product->createSimple(),
$this->factory->product->createSimple(),
$variable['product'],
- ];
+ );
$coupon = new WC_Coupon(
$this->factory->coupon->create(
- [ 'product_ids' => $product_ids ]
+ array( 'product_ids' => $product_ids )
)
);
@@ -638,11 +638,11 @@ public function testCheckoutMutationWithNoAccount() {
$product_ids[2],
2,
$variable['variations'][0],
- [ 'attribute_pa_color' => 'red' ]
+ array( 'attribute_pa_color' => 'red' )
);
WC()->cart->apply_coupon( $coupon->get_code() );
- $variables = [ 'input' => $this->getCheckoutInput() ];
+ $variables = array( 'input' => $this->getCheckoutInput() );
$query = $this->getCheckoutMutation();
/**
@@ -651,19 +651,19 @@ public function testCheckoutMutationWithNoAccount() {
* Test mutation and input.
*/
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'checkout.order.id', static::NOT_NULL ),
$this->expectedField( 'checkout.order.status', 'ON_HOLD' ),
$this->expectedNode(
'checkout.order.metaData',
- [
+ array(
$this->expectedField( 'key', 'test_key' ),
$this->expectedField( 'value', 'test value' ),
- ]
+ )
),
$this->expectedNode(
'checkout.order.feeLines.nodes',
- [
+ array(
$this->expectedField( 'name', 'Surcharge' ),
$this->expectedField( 'databaseId', static::NOT_NULL ),
$this->expectedField( 'orderId', static::NOT_NULL ),
@@ -672,33 +672,33 @@ public function testCheckoutMutationWithNoAccount() {
$this->expectedField( 'total', static::NOT_NULL ),
$this->expectedField( 'totalTax', static::NOT_NULL ),
$this->expectedField( 'taxClass', static::NOT_NULL ),
- ]
+ )
),
$this->expectedNode(
'checkout.order.shippingLines.nodes',
- [
+ array(
$this->expectedField( 'methodTitle', 'Flat rate' ),
$this->expectedField( 'databaseId', static::NOT_NULL ),
$this->expectedField( 'orderId', static::NOT_NULL ),
$this->expectedField( 'total', static::NOT_NULL ),
$this->expectedField( 'totalTax', static::NOT_NULL ),
$this->expectedField( 'taxClass', static::NOT_NULL ),
- ]
+ )
),
$this->expectedNode(
'checkout.order.taxLines.nodes',
- [
+ array(
$this->expectedField( 'label', 'VAT' ),
$this->expectedField( 'rateCode', static::NOT_NULL ),
$this->expectedField( 'taxTotal', static::NOT_NULL ),
$this->expectedField( 'shippingTaxTotal', static::NOT_NULL ),
$this->expectedField( 'isCompound', static::NOT_NULL ),
$this->expectedField( 'taxRate', static::NOT_NULL ),
- ]
+ )
),
$this->expectedNode(
'checkout.order.lineItems.nodes',
- [
+ array(
$this->expectedField( 'productId', $product_ids[0] ),
$this->expectedField( 'quantity', static::NOT_NULL ),
$this->expectedField( 'taxClass', static::NOT_NULL ),
@@ -708,11 +708,11 @@ public function testCheckoutMutationWithNoAccount() {
$this->expectedField( 'totalTax', static::NOT_NULL ),
$this->expectedField( 'taxStatus', static::NOT_NULL ),
$this->expectedField( 'product.node.id', static::NOT_NULL ),
- ]
+ )
),
$this->expectedNode(
'checkout.order.lineItems.nodes',
- [
+ array(
$this->expectedField( 'productId', $product_ids[1] ),
$this->expectedField( 'quantity', static::NOT_NULL ),
$this->expectedField( 'taxClass', static::NOT_NULL ),
@@ -722,11 +722,11 @@ public function testCheckoutMutationWithNoAccount() {
$this->expectedField( 'totalTax', static::NOT_NULL ),
$this->expectedField( 'taxStatus', static::NOT_NULL ),
$this->expectedField( 'product.node.id', static::NOT_NULL ),
- ]
+ )
),
$this->expectedNode(
'checkout.order.lineItems.nodes',
- [
+ array(
$this->expectedField( 'productId', $product_ids[2] ),
$this->expectedField( 'variationId', static::NOT_NULL ),
$this->expectedField( 'quantity', static::NOT_NULL ),
@@ -738,22 +738,22 @@ public function testCheckoutMutationWithNoAccount() {
$this->expectedField( 'taxStatus', static::NOT_NULL ),
$this->expectedField( 'product.node.id', static::NOT_NULL ),
$this->expectedField( 'variation.node.id', static::NOT_NULL ),
- ]
+ )
),
$this->expectedField( 'checkout.customer.id', 'guest' ),
$this->expectedField( 'checkout.result', 'success' ),
$this->expectedField( 'checkout.redirect', static::NOT_NULL ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
// Confirm cart empty after successful checkout.
$query = $this->getCartQuery();
$response = $this->graphql( compact( 'query' ) );
- $expected = [
- $this->expectedField( 'cart.contents.nodes', [] ),
+ $expected = array(
+ $this->expectedField( 'cart.contents.nodes', array() ),
$this->expectedField( 'cart.total', '$0.00' ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
}
@@ -762,35 +762,35 @@ public function testCheckoutMutationWithPrepaidOrder() {
WC()->customer->set_billing_email( 'superfreak500@gmail.com' );
WC()->customer->save();
- $product_ids = [
+ $product_ids = array(
$this->factory->product->createSimple(
- [
+ array(
'virtual' => true,
'downloadable' => true,
- ]
+ )
),
$this->factory->product->createSimple(
- [
+ array(
'virtual' => true,
'downloadable' => true,
- ]
+ )
),
- ];
+ );
$coupon = new WC_Coupon(
- $this->factory->coupon->create( [ 'product_ids' => $product_ids ] )
+ $this->factory->coupon->create( array( 'product_ids' => $product_ids ) )
);
WC()->cart->add_to_cart( $product_ids[0], 3 );
WC()->cart->add_to_cart( $product_ids[1], 6 );
WC()->cart->apply_coupon( $coupon->get_code() );
- $input = [
+ $input = array(
'isPaid' => true,
'transactionId' => 'transaction_id',
- ];
+ );
- $variables = [ 'input' => $this->getCheckoutInput( $input ) ];
+ $variables = array( 'input' => $this->getCheckoutInput( $input ) );
$query = $this->getCheckoutMutation();
/**
@@ -799,19 +799,19 @@ public function testCheckoutMutationWithPrepaidOrder() {
* Test mutation and input.
*/
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'checkout.order.id', static::NOT_NULL ),
$this->expectedField( 'checkout.order.status', 'COMPLETED' ),
$this->expectedNode(
'checkout.order.metaData',
- [
+ array(
$this->expectedField( 'key', 'test_key' ),
$this->expectedField( 'value', 'test value' ),
- ]
+ )
),
$this->expectedNode(
'checkout.order.feeLines.nodes',
- [
+ array(
$this->expectedField( 'name', 'Surcharge' ),
$this->expectedField( 'databaseId', static::NOT_NULL ),
$this->expectedField( 'orderId', static::NOT_NULL ),
@@ -820,22 +820,22 @@ public function testCheckoutMutationWithPrepaidOrder() {
$this->expectedField( 'total', static::NOT_NULL ),
$this->expectedField( 'totalTax', static::NOT_NULL ),
$this->expectedField( 'taxClass', static::NOT_NULL ),
- ]
+ )
),
$this->expectedNode(
'checkout.order.taxLines.nodes',
- [
+ array(
$this->expectedField( 'label', 'VAT' ),
$this->expectedField( 'rateCode', static::NOT_NULL ),
$this->expectedField( 'taxTotal', static::NOT_NULL ),
$this->expectedField( 'shippingTaxTotal', static::NOT_NULL ),
$this->expectedField( 'isCompound', static::NOT_NULL ),
$this->expectedField( 'taxRate', static::NOT_NULL ),
- ]
+ )
),
$this->expectedNode(
'checkout.order.lineItems.nodes',
- [
+ array(
$this->expectedField( 'productId', $product_ids[0] ),
$this->expectedField( 'quantity', static::NOT_NULL ),
$this->expectedField( 'taxClass', static::NOT_NULL ),
@@ -845,11 +845,11 @@ public function testCheckoutMutationWithPrepaidOrder() {
$this->expectedField( 'totalTax', static::NOT_NULL ),
$this->expectedField( 'taxStatus', static::NOT_NULL ),
$this->expectedField( 'product.node.id', static::NOT_NULL ),
- ]
+ )
),
$this->expectedNode(
'checkout.order.lineItems.nodes',
- [
+ array(
$this->expectedField( 'productId', $product_ids[1] ),
$this->expectedField( 'quantity', static::NOT_NULL ),
$this->expectedField( 'taxClass', static::NOT_NULL ),
@@ -859,22 +859,22 @@ public function testCheckoutMutationWithPrepaidOrder() {
$this->expectedField( 'totalTax', static::NOT_NULL ),
$this->expectedField( 'taxStatus', static::NOT_NULL ),
$this->expectedField( 'product.node.id', static::NOT_NULL ),
- ]
+ )
),
$this->expectedField( 'checkout.customer.id', 'guest' ),
$this->expectedField( 'checkout.result', 'success' ),
$this->expectedField( 'checkout.redirect', static::NOT_NULL ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
// Confirm cart empty after successful checkout.
$query = $this->getCartQuery();
$response = $this->graphql( compact( 'query' ) );
- $expected = [
- $this->expectedField( 'cart.contents.nodes', [] ),
+ $expected = array(
+ $this->expectedField( 'cart.contents.nodes', array() ),
$this->expectedField( 'cart.total', '$0.00' ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
}
@@ -887,7 +887,7 @@ public function testCheckoutMutationWithPrepaidOrder() {
* @return array
*/
private function create_stripe_customer( $email ) {
- $customer = \Stripe\Customer::create( [ 'email' => $email ] );
+ $customer = \Stripe\Customer::create( array( 'email' => $email ) );
// use --debug flag to view.
codecept_debug( $customer );
@@ -905,7 +905,7 @@ private function create_stripe_customer( $email ) {
private function create_stripe_source( $customer ) {
$source = \Stripe\Customer::createSource(
$customer['id'],
- [ 'source' => 'tok_visa' ]
+ array( 'source' => 'tok_visa' )
);
// use --debug flag to view.
@@ -927,13 +927,13 @@ private function create_stripe_source( $customer ) {
*/
private function create_stripe_payment_intent( $amount, $customer ) {
$payment_intent = \Stripe\PaymentIntent::create(
- [
+ array(
'amount' => $amount,
'currency' => 'gbp',
- 'payment_method_types' => [ 'card' ],
+ 'payment_method_types' => array( 'card' ),
'customer' => $customer['id'],
'payment_method' => $customer['invoice_settings']['default_payment_method'],
- ]
+ )
);
// use --debug flag to view.
@@ -947,10 +947,10 @@ public function testCheckoutMutationWithStripe() {
WC()->customer->save();
// Add items to the cart.
- $product_ids = [
+ $product_ids = array(
$this->factory->product->createSimple(),
$this->factory->product->createSimple(),
- ];
+ );
WC()->cart->add_to_cart( $product_ids[0], 1 );
WC()->cart->add_to_cart( $product_ids[1], 1 );
@@ -964,25 +964,25 @@ public function testCheckoutMutationWithStripe() {
$this->markTestSkipped( $e->getMessage() );
}
- $input = [
+ $input = array(
'paymentMethod' => 'stripe',
- 'metaData' => [
- [
+ 'metaData' => array(
+ array(
'key' => '_stripe_source_id',
'value' => $stripe_source['id'],
- ],
- [
+ ),
+ array(
'key' => '_stripe_customer_id',
'value' => $stripe_customer['id'],
- ],
- [
+ ),
+ array(
'key' => '_stripe_intent_id',
'value' => $payment_intent['id'],
- ],
- ],
- ];
+ ),
+ ),
+ );
- $variables = [ 'input' => $this->getCheckoutInput( $input ) ];
+ $variables = array( 'input' => $this->getCheckoutInput( $input ) );
// Remove "metaData" value field and "redirect" link from the mutation output.
$query = '
mutation checkout( $input: CheckoutInput! ) {
@@ -1032,24 +1032,24 @@ public function testCheckoutMutationWithStripe() {
* Test mutation and input.
*/
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'checkout.order.id', static::NOT_NULL ),
$this->expectedField( 'checkout.order.status', 'PROCESSING' ),
$this->expectedNode(
'checkout.order.metaData',
- [ $this->expectedField( 'key', '_stripe_source_id' ) ]
+ array( $this->expectedField( 'key', '_stripe_source_id' ) )
),
$this->expectedNode(
'checkout.order.metaData',
- [ $this->expectedField( 'key', '_stripe_customer_id' ) ]
+ array( $this->expectedField( 'key', '_stripe_customer_id' ) )
),
$this->expectedNode(
'checkout.order.metaData',
- [ $this->expectedField( 'key', '_stripe_intent_id' ) ]
+ array( $this->expectedField( 'key', '_stripe_intent_id' ) )
),
$this->expectedNode(
'checkout.order.lineItems.nodes',
- [
+ array(
$this->expectedField( 'productId', $product_ids[0] ),
$this->expectedField( 'quantity', static::NOT_NULL ),
$this->expectedField( 'taxClass', static::NOT_NULL ),
@@ -1059,11 +1059,11 @@ public function testCheckoutMutationWithStripe() {
$this->expectedField( 'totalTax', static::NOT_NULL ),
$this->expectedField( 'taxStatus', static::NOT_NULL ),
$this->expectedField( 'product.node.id', static::NOT_NULL ),
- ]
+ )
),
$this->expectedNode(
'checkout.order.lineItems.nodes',
- [
+ array(
$this->expectedField( 'productId', $product_ids[1] ),
$this->expectedField( 'quantity', static::NOT_NULL ),
$this->expectedField( 'taxClass', static::NOT_NULL ),
@@ -1073,20 +1073,20 @@ public function testCheckoutMutationWithStripe() {
$this->expectedField( 'totalTax', static::NOT_NULL ),
$this->expectedField( 'taxStatus', static::NOT_NULL ),
$this->expectedField( 'product.node.id', static::NOT_NULL ),
- ]
+ )
),
$this->expectedField( 'checkout.result', 'success' ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
// Confirm cart empty after successful checkout.
$query = $this->getCartQuery();
$response = $this->graphql( compact( 'query' ) );
- $expected = [
- $this->expectedField( 'cart.contents.nodes', [] ),
+ $expected = array(
+ $this->expectedField( 'cart.contents.nodes', array() ),
$this->expectedField( 'cart.total', '$0.00' ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
}
@@ -1095,22 +1095,22 @@ public function testCheckoutMutationCartItemValidation() {
add_filter( 'woocommerce_hold_stock_for_checkout', '__return_false' );
$product_id = $this->factory->product->createSimple(
- [
+ array(
'manage_stock' => true,
'stock_quantity' => 3,
- ]
+ )
);
$key = WC()->cart->add_to_cart( $product_id, 3 );
WC()->cart->set_quantity( $key, 5 );
- $input = [
- 'account' => [
+ $input = array(
+ 'account' => array(
'username' => 'test_user_1',
'password' => 'test_pass',
- ],
- ];
- $variables = [ 'input' => $this->getCheckoutInput( $input ) ];
+ ),
+ );
+ $variables = array( 'input' => $this->getCheckoutInput( $input ) );
$query = $this->getCheckoutMutation();
/**
@@ -1119,7 +1119,7 @@ public function testCheckoutMutationCartItemValidation() {
* Ensure that checkout failed when stock is too low.
*/
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [ $this->expectedField( 'checkout', static::IS_NULL ) ];
+ $expected = array( $this->expectedField( 'checkout', static::IS_NULL ) );
$this->assertQueryError( $response, $expected );
}
diff --git a/tests/wpunit/CollectionStatsQueryTest.php b/tests/wpunit/CollectionStatsQueryTest.php
index 48cf49899..0b2a7e693 100644
--- a/tests/wpunit/CollectionStatsQueryTest.php
+++ b/tests/wpunit/CollectionStatsQueryTest.php
@@ -9,7 +9,7 @@ public function setUp(): void {
update_option( 'woocommerce_attribute_lookup_enabled', 'yes' );
update_option( 'woocommerce_attribute_lookup_direct_updates', 'yes' );
}
-
+
public function testCollectionStatsQuery() {
$this->factory->product_variation->createSome(
$this->factory->product->createVariable()
@@ -47,106 +47,106 @@ public function testCollectionStatsQuery() {
}
';
- $variables = [
- 'where' => [
- 'attributes' => [
- 'queries' => [
- [
+ $variables = array(
+ 'where' => array(
+ 'attributes' => array(
+ 'queries' => array(
+ array(
'taxonomy' => 'PA_COLOR',
'terms' => 'red',
'operator' => 'IN',
- ],
- ],
- ],
- ],
- 'taxonomies' => [
- [
+ ),
+ ),
+ ),
+ ),
+ 'taxonomies' => array(
+ array(
'taxonomy' => 'PA_COLOR',
'relation' => 'AND',
- ],
- ],
- ];
+ ),
+ ),
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedNode(
- 'collectionStats.attributeCounts',
- [
+ 'collectionStats.attributeCounts',
+ array(
$this->expectedField( 'slug', 'PA_COLOR' ),
$this->expectedNode(
'terms',
- [
+ array(
$this->expectedField( 'node.slug', 'red' ),
$this->expectedField( 'count', 2 ),
$this->expectedField( 'termId', static::NOT_FALSY ),
- ]
+ )
),
$this->expectedNode(
'terms',
- [
+ array(
$this->expectedField( 'node.slug', 'blue' ),
$this->expectedField( 'count', 2 ),
$this->expectedField( 'termId', static::NOT_FALSY ),
- ]
+ )
),
$this->expectedNode(
'terms',
- [
+ array(
$this->expectedField( 'node.slug', 'green' ),
$this->expectedField( 'count', 2 ),
$this->expectedField( 'termId', static::NOT_FALSY ),
- ]
+ )
),
- ],
+ ),
0
),
$this->expectedNode(
'collectionStats.stockStatusCounts',
- [
+ array(
$this->expectedField( 'status', 'IN_STOCK' ),
$this->expectedField( 'count', 2 ),
- ]
+ )
),
$this->expectedNode(
'collectionStats.stockStatusCounts',
- [
+ array(
$this->expectedField( 'status', 'OUT_OF_STOCK' ),
$this->expectedField( 'count', 0 ),
- ]
+ )
),
$this->expectedNode(
'collectionStats.stockStatusCounts',
- [
+ array(
$this->expectedField( 'status', 'ON_BACKORDER' ),
$this->expectedField( 'count', 0 ),
- ]
+ )
),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
}
public function testCollectionStatsQueryWithWhereArgs() {
// 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;
+ $kind_attribute = $this->factory->product->createAttribute( 'kind', array( '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 ]
+ array( $normal_term_id )
);
-
+
$kind_attribute_special_only = $this->factory->product->createAttributeObject(
$kind_attribute['attribute_id'],
$kind_attribute['attribute_taxonomy'],
- [ $special_term_id ]
+ array( $special_term_id )
);
$kind_attribute_both = $this->factory->product->createAttributeObject(
$kind_attribute['attribute_id'],
$kind_attribute['attribute_taxonomy'],
- [ $normal_term_id, $special_term_id ]
+ array( $normal_term_id, $special_term_id )
);
// Create taxonomies.
@@ -156,38 +156,37 @@ public function testCollectionStatsQueryWithWhereArgs() {
// Create products.
$post_ids = $this->factory->product->createManySimple(
20,
- [
- 'attributes' => [ $kind_attribute_normal_only ],
- 'category_ids' => [ $clothing_category_id ],
- 'default_attributes' => [ 'pa_kind' => 'normal' ],
- ]
+ array(
+ 'attributes' => array( $kind_attribute_normal_only ),
+ 'category_ids' => array( $clothing_category_id ),
+ 'default_attributes' => array( 'pa_kind' => 'normal' ),
+ )
);
$this->factory->product->createManySimple(
5,
- [
- 'category_ids' => [ $clothing_category_id ],
- 'attributes' => [ $kind_attribute_special_only ],
- 'default_attributes' => [ 'pa_kind' => 'special' ],
- ]
+ array(
+ 'category_ids' => array( $clothing_category_id ),
+ 'attributes' => array( $kind_attribute_special_only ),
+ 'default_attributes' => array( 'pa_kind' => 'special' ),
+ )
);
$this->factory->product->createManySimple(
5,
- [
- 'category_ids' => [ $clothing_category_id ],
- 'tag_ids' => [ $shoes_tag_id ],
- 'attributes' => [ $kind_attribute_special_only ],
- 'default_attributes' => [ 'pa_kind' => 'special' ],
- ]
+ array(
+ 'category_ids' => array( $clothing_category_id ),
+ 'tag_ids' => array( $shoes_tag_id ),
+ 'attributes' => array( $kind_attribute_special_only ),
+ 'default_attributes' => array( 'pa_kind' => 'special' ),
+ )
);
- $this->factory->product->createManySimple( 3, [ 'attributes' => [ $kind_attribute_both ] ] );
-
+ $this->factory->product->createManySimple( 3, array( 'attributes' => array( $kind_attribute_both ) ) );
- $query = "
- query (\$where: CollectionStatsWhereArgs, \$taxonomies: [CollectionStatsQueryInput]) {
+ $query = '
+ query ($where: CollectionStatsWhereArgs, $taxonomies: [CollectionStatsQueryInput]) {
collectionStats(
calculateRatingCounts: true
- taxonomies: \$taxonomies
- where: \$where
+ taxonomies: $taxonomies
+ where: $where
) {
attributeCounts {
@@ -200,249 +199,255 @@ public function testCollectionStatsQueryWithWhereArgs() {
}
}
}
- ";
+ ';
/**
* Query for products with the "clothing" category and confirm correct count.
*/
- $variables = [
+ $variables = array(
'calculateRatingCounts' => true,
- 'where' => [
- 'categoryIdIn' => [ $clothing_category_id ],
- ],
- 'taxonomies' => [
- [
+ 'where' => array(
+ 'categoryIdIn' => array( $clothing_category_id ),
+ ),
+ 'taxonomies' => array(
+ array(
'taxonomy' => 'PA_KIND',
- 'relation' => "AND",
- ],
- ],
- ];
+ 'relation' => 'AND',
+ ),
+ ),
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedNode(
- 'collectionStats.attributeCounts',
- [
+ 'collectionStats.attributeCounts',
+ array(
$this->expectedField( 'slug', 'PA_KIND' ),
$this->expectedNode(
'terms',
- [
+ array(
$this->expectedField( 'node.slug', 'normal' ),
$this->expectedField( 'count', 20 ),
$this->expectedField( 'termId', static::NOT_FALSY ),
- ]
+ )
),
$this->expectedNode(
'terms',
- [
+ array(
$this->expectedField( 'node.slug', 'special' ),
$this->expectedField( 'count', 10 ),
$this->expectedField( 'termId', static::NOT_FALSY ),
- ]
+ )
),
- ],
+ ),
0
- )
- ];
+ ),
+ );
$this->assertQuerySuccessful( $response, $expected );
// Test again with the "categoryIn" where arg.
- $variables = [
+ $variables = array(
'calculateRatingCounts' => true,
- 'where' => [
- 'categoryIn' => [ 'clothing' ],
- ],
- 'taxonomies' => [
- [
+ 'where' => array(
+ 'categoryIn' => array( 'clothing' ),
+ ),
+ 'taxonomies' => array(
+ array(
'taxonomy' => 'PA_KIND',
- 'relation' => "AND",
- ],
- ],
- ];
+ 'relation' => 'AND',
+ ),
+ ),
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
$this->assertQuerySuccessful( $response, $expected );
/**
* Query for products with the "shoes" tag and confirm correct count.
*/
- $variables = [
+ $variables = array(
'calculateRatingCounts' => true,
- 'where' => [
- 'tagIdIn' => [ $shoes_tag_id ],
- ],
- 'taxonomies' => [
- [
+ 'where' => array(
+ 'tagIdIn' => array( $shoes_tag_id ),
+ ),
+ 'taxonomies' => array(
+ array(
'taxonomy' => 'PA_KIND',
- ],
- ],
- ];
+ ),
+ ),
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedNode(
- 'collectionStats.attributeCounts',
- [
+ 'collectionStats.attributeCounts',
+ array(
$this->expectedField( 'slug', 'PA_KIND' ),
$this
->not()
- ->expectedNode( 'terms', [ $this->expectedField( 'node.slug', 'normal' ) ] ),
+ ->expectedNode( 'terms', array( $this->expectedField( 'node.slug', 'normal' ) ) ),
$this->expectedNode(
'terms',
- [
+ array(
$this->expectedField( 'node.slug', 'special' ),
$this->expectedField( 'count', 5 ),
$this->expectedField( 'termId', static::NOT_FALSY ),
- ]
+ )
),
- ],
+ ),
0
- )
- ];
+ ),
+ );
$this->assertQuerySuccessful( $response, $expected );
// Test again with the "tagIn" where arg.
- $variables = [
+ $variables = array(
'calculateRatingCounts' => true,
- 'where' => [
- 'tagIn' => [ 'shoes' ],
- ],
- 'taxonomies' => [
- [
+ 'where' => array(
+ 'tagIn' => array( 'shoes' ),
+ ),
+ 'taxonomies' => array(
+ array(
'taxonomy' => 'PA_KIND',
- ],
- ],
- ];
+ ),
+ ),
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
$this->assertQuerySuccessful( $response, $expected );
/**
* Query for products with the "shoes" tag and confirm correct count.
*/
- $variables = [
+ $variables = array(
'calculateRatingCounts' => true,
- 'where' => [
- 'categoryIn' => [ 'clothing' ],
- 'attributes' => [
- 'queries' => [
- [
+ 'where' => array(
+ 'categoryIn' => array( 'clothing' ),
+ 'attributes' => array(
+ 'queries' => array(
+ array(
'taxonomy' => 'PA_KIND',
'ids' => $normal_term_id,
'operator' => 'IN',
- ],
- ]
- ],
- ],
- 'taxonomies' => [
- [
+ ),
+ ),
+ ),
+ ),
+ 'taxonomies' => array(
+ array(
'taxonomy' => 'PA_KIND',
- 'relation' => "AND",
- ],
- ],
- ];
+ 'relation' => 'AND',
+ ),
+ ),
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedNode(
- 'collectionStats.attributeCounts',
- [
+ 'collectionStats.attributeCounts',
+ array(
$this->expectedField( 'slug', 'PA_KIND' ),
$this->expectedNode(
'terms',
- [
+ array(
$this->expectedField( 'node.slug', 'normal' ),
$this->expectedField( 'count', 20 ),
$this->expectedField( 'termId', static::NOT_FALSY ),
- ]
+ )
),
$this
->not()
- ->expectedNode( 'terms', [ $this->expectedField( 'node.slug', 'special' ) ] ),
- ],
+ ->expectedNode( 'terms', array( $this->expectedField( 'node.slug', 'special' ) ) ),
+ ),
0
),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
}
public function testCollectionStatsQueryWithOrTaxQueries() {
// Create product attributes.
- $kind_attribute = $this->factory->product->createAttribute( 'kind', [ 'normal', 'special' ], 'Product type' );
- $pattern_attribute = $this->factory->product->createAttribute( 'pattern', [ 'polka-dot', 'striped' ], 'Product pattern' );
+ $kind_attribute = $this->factory->product->createAttribute( 'kind', array( 'normal', 'special' ), 'Product type' );
+ $pattern_attribute = $this->factory->product->createAttribute( 'pattern', array( 'polka-dot', 'striped' ), 'Product pattern' );
- $normal_term_id = get_term_by( 'slug', 'normal', 'pa_kind' )->term_id;
- $special_term_id = get_term_by( 'slug', 'special', 'pa_kind' )->term_id;
- $kind_attribute_normal_only = $this->factory->product->createAttributeObject(
+ $normal_term_id = get_term_by( 'slug', 'normal', 'pa_kind' )->term_id;
+ $special_term_id = get_term_by( 'slug', 'special', 'pa_kind' )->term_id;
+ $kind_attribute_normal_only = $this->factory->product->createAttributeObject(
$kind_attribute['attribute_id'],
$kind_attribute['attribute_taxonomy'],
- [ $normal_term_id ]
+ array( $normal_term_id )
);
$kind_attribute_special_only = $this->factory->product->createAttributeObject(
$kind_attribute['attribute_id'],
$kind_attribute['attribute_taxonomy'],
- [ $special_term_id ]
+ array( $special_term_id )
);
- $polka_dot_term_id = get_term_by( 'slug', 'polka-dot', 'pa_pattern' )->term_id;
- $striped_term_id = get_term_by( 'slug', 'striped', 'pa_pattern' )->term_id;
+ $polka_dot_term_id = get_term_by( 'slug', 'polka-dot', 'pa_pattern' )->term_id;
+ $striped_term_id = get_term_by( 'slug', 'striped', 'pa_pattern' )->term_id;
$pattern_attribute_polka_dot_only = $this->factory->product->createAttributeObject(
$pattern_attribute['attribute_id'],
$pattern_attribute['attribute_taxonomy'],
- [ $polka_dot_term_id ]
+ array( $polka_dot_term_id )
);
- $pattern_attribute_striped_only = $this->factory->product->createAttributeObject(
+ $pattern_attribute_striped_only = $this->factory->product->createAttributeObject(
$pattern_attribute['attribute_id'],
$pattern_attribute['attribute_taxonomy'],
- [ $striped_term_id ]
+ array( $striped_term_id )
);
// Create products.
$this->factory->product->createManySimple(
3,
- [
- 'attributes' => [ $kind_attribute_normal_only ],
- 'default_attributes' => [ 'pa_kind' => 'normal' ],
- ]
+ array(
+ 'attributes' => array( $kind_attribute_normal_only ),
+ 'default_attributes' => array( 'pa_kind' => 'normal' ),
+ )
);
$this->factory->product->createManySimple(
7,
- [
- 'attributes' => [ $kind_attribute_special_only ],
- 'default_attributes' => [ 'pa_kind' => 'special' ],
- ]
+ array(
+ 'attributes' => array( $kind_attribute_special_only ),
+ 'default_attributes' => array( 'pa_kind' => 'special' ),
+ )
);
$this->factory->product->createManySimple(
4,
- [
- 'attributes' => [ $pattern_attribute_polka_dot_only ],
- 'default_attributes' => [ 'pa_pattern' => 'polka-dot' ],
- ]
+ array(
+ 'attributes' => array( $pattern_attribute_polka_dot_only ),
+ 'default_attributes' => array( 'pa_pattern' => 'polka-dot' ),
+ )
);
$this->factory->product->createManySimple(
6,
- [
- 'attributes' => [ $pattern_attribute_striped_only ],
- 'default_attributes' => [ 'pa_pattern' => 'striped' ],
- ]
+ array(
+ 'attributes' => array( $pattern_attribute_striped_only ),
+ 'default_attributes' => array( 'pa_pattern' => 'striped' ),
+ )
);
$this->factory->product->createManySimple(
2,
- [
- 'attributes' => [
+ array(
+ 'attributes' => array(
$kind_attribute_normal_only,
$pattern_attribute_polka_dot_only,
- ],
- 'default_attributes' => [ 'pa_kind' => 'normal', 'pa_pattern' => 'polka-dot' ],
- ]
+ ),
+ 'default_attributes' => array(
+ 'pa_kind' => 'normal',
+ 'pa_pattern' => 'polka-dot',
+ ),
+ )
);
$this->factory->product->createManySimple(
8,
- [
- 'attributes' => [
+ array(
+ 'attributes' => array(
$kind_attribute_special_only,
$pattern_attribute_striped_only,
- ],
- 'default_attributes' => [ 'pa_kind' => 'special', 'pa_pattern' => 'striped' ],
- ]
+ ),
+ 'default_attributes' => array(
+ 'pa_kind' => 'special',
+ 'pa_pattern' => 'striped',
+ ),
+ )
);
$query = '
@@ -466,102 +471,102 @@ public function testCollectionStatsQueryWithOrTaxQueries() {
}
';
- $variables = [
- 'taxonomies' => [
- [
+ $variables = array(
+ 'taxonomies' => array(
+ array(
'taxonomy' => 'PA_KIND',
'relation' => 'OR',
- ],
- [
+ ),
+ array(
'taxonomy' => 'PA_PATTERN',
'relation' => 'OR',
- ],
- ],
- ];
+ ),
+ ),
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedNode(
- 'collectionStats.attributeCounts',
- [
+ 'collectionStats.attributeCounts',
+ array(
$this->expectedField( 'slug', 'PA_KIND' ),
$this->expectedNode(
'terms',
- [
+ array(
$this->expectedField( 'node.slug', 'normal' ),
$this->expectedField( 'count', 5 ),
$this->expectedField( 'termId', static::NOT_FALSY ),
- ],
+ ),
0
),
$this->expectedNode(
'terms',
- [
+ array(
$this->expectedField( 'node.slug', 'special' ),
$this->expectedField( 'count', 15 ),
$this->expectedField( 'termId', static::NOT_FALSY ),
- ],
+ ),
1
),
- ],
+ ),
),
$this->expectedNode(
- 'collectionStats.attributeCounts',
- [
+ 'collectionStats.attributeCounts',
+ array(
$this->expectedField( 'slug', 'PA_PATTERN' ),
$this->expectedNode(
'terms',
- [
+ array(
$this->expectedField( 'node.slug', 'polka-dot' ),
$this->expectedField( 'count', 6 ),
$this->expectedField( 'termId', static::NOT_FALSY ),
- ],
+ ),
0
),
$this->expectedNode(
'terms',
- [
+ array(
$this->expectedField( 'node.slug', 'striped' ),
$this->expectedField( 'count', 14 ),
$this->expectedField( 'termId', static::NOT_FALSY ),
- ],
+ ),
1
),
- ],
+ ),
),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
}
public function testCollectionStatsQueryWithAndTaxQueries() {
// Create product attributes.
- $kind_attribute = $this->factory->product->createAttribute( 'kind', [ 'normal', 'special' ], 'Product type' );
- $pattern_attribute = $this->factory->product->createAttribute( 'pattern', [ 'polka-dot', 'striped' ], 'Product pattern' );
+ $kind_attribute = $this->factory->product->createAttribute( 'kind', array( 'normal', 'special' ), 'Product type' );
+ $pattern_attribute = $this->factory->product->createAttribute( 'pattern', array( 'polka-dot', 'striped' ), 'Product pattern' );
- $normal_term_id = get_term_by( 'slug', 'normal', 'pa_kind' )->term_id;
- $special_term_id = get_term_by( 'slug', 'special', 'pa_kind' )->term_id;
- $kind_attribute_normal_only = $this->factory->product->createAttributeObject(
+ $normal_term_id = get_term_by( 'slug', 'normal', 'pa_kind' )->term_id;
+ $special_term_id = get_term_by( 'slug', 'special', 'pa_kind' )->term_id;
+ $kind_attribute_normal_only = $this->factory->product->createAttributeObject(
$kind_attribute['attribute_id'],
$kind_attribute['attribute_taxonomy'],
- [ $normal_term_id ]
+ array( $normal_term_id )
);
$kind_attribute_special_only = $this->factory->product->createAttributeObject(
$kind_attribute['attribute_id'],
$kind_attribute['attribute_taxonomy'],
- [ $special_term_id ]
+ array( $special_term_id )
);
- $polka_dot_term_id = get_term_by( 'slug', 'polka-dot', 'pa_pattern' )->term_id;
- $striped_term_id = get_term_by( 'slug', 'striped', 'pa_pattern' )->term_id;
+ $polka_dot_term_id = get_term_by( 'slug', 'polka-dot', 'pa_pattern' )->term_id;
+ $striped_term_id = get_term_by( 'slug', 'striped', 'pa_pattern' )->term_id;
$pattern_attribute_polka_dot_only = $this->factory->product->createAttributeObject(
$pattern_attribute['attribute_id'],
$pattern_attribute['attribute_taxonomy'],
- [ $polka_dot_term_id ]
+ array( $polka_dot_term_id )
);
- $pattern_attribute_striped_only = $this->factory->product->createAttributeObject(
+ $pattern_attribute_striped_only = $this->factory->product->createAttributeObject(
$pattern_attribute['attribute_id'],
$pattern_attribute['attribute_taxonomy'],
- [ $striped_term_id ]
+ array( $striped_term_id )
);
// Create taxonomies.
@@ -570,54 +575,60 @@ public function testCollectionStatsQueryWithAndTaxQueries() {
// Create products.
$this->factory->product->createManySimple(
3,
- [
- 'category_ids' => [ $clothing_category_id ],
- 'attributes' => [ $kind_attribute_normal_only ],
- 'default_attributes' => [ 'pa_kind' => 'normal' ],
- ]
+ array(
+ 'category_ids' => array( $clothing_category_id ),
+ 'attributes' => array( $kind_attribute_normal_only ),
+ 'default_attributes' => array( 'pa_kind' => 'normal' ),
+ )
);
$this->factory->product->createManySimple(
7,
- [
- 'attributes' => [ $kind_attribute_special_only ],
- 'default_attributes' => [ 'pa_kind' => 'special' ],
- ]
+ array(
+ 'attributes' => array( $kind_attribute_special_only ),
+ 'default_attributes' => array( 'pa_kind' => 'special' ),
+ )
);
$this->factory->product->createManySimple(
4,
- [
- 'category_ids' => [ $clothing_category_id ],
- 'attributes' => [ $pattern_attribute_polka_dot_only ],
- 'default_attributes' => [ 'pa_pattern' => 'polka-dot' ],
- ]
+ array(
+ 'category_ids' => array( $clothing_category_id ),
+ 'attributes' => array( $pattern_attribute_polka_dot_only ),
+ 'default_attributes' => array( 'pa_pattern' => 'polka-dot' ),
+ )
);
$this->factory->product->createManySimple(
6,
- [
- 'attributes' => [ $pattern_attribute_striped_only ],
- 'default_attributes' => [ 'pa_pattern' => 'striped' ],
- ]
+ array(
+ 'attributes' => array( $pattern_attribute_striped_only ),
+ 'default_attributes' => array( 'pa_pattern' => 'striped' ),
+ )
);
$this->factory->product->createManySimple(
2,
- [
- 'attributes' => [
+ array(
+ 'attributes' => array(
$kind_attribute_normal_only,
$pattern_attribute_polka_dot_only,
- ],
- 'default_attributes' => [ 'pa_kind' => 'normal', 'pa_pattern' => 'polka-dot' ],
- ]
+ ),
+ 'default_attributes' => array(
+ 'pa_kind' => 'normal',
+ 'pa_pattern' => 'polka-dot',
+ ),
+ )
);
$this->factory->product->createManySimple(
8,
- [
- 'category_ids' => [ $clothing_category_id ],
- 'attributes' => [
+ array(
+ 'category_ids' => array( $clothing_category_id ),
+ 'attributes' => array(
$kind_attribute_special_only,
$pattern_attribute_striped_only,
- ],
- 'default_attributes' => [ 'pa_kind' => 'special', 'pa_pattern' => 'striped' ],
- ]
+ ),
+ 'default_attributes' => array(
+ 'pa_kind' => 'special',
+ 'pa_pattern' => 'striped',
+ ),
+ )
);
$query = '
@@ -641,72 +652,72 @@ public function testCollectionStatsQueryWithAndTaxQueries() {
}
';
- $variables = [
- 'where' => [
- 'categoryIn' => [ 'clothing' ],
- ],
- 'taxonomies' => [
- [
+ $variables = array(
+ 'where' => array(
+ 'categoryIn' => array( 'clothing' ),
+ ),
+ 'taxonomies' => array(
+ array(
'taxonomy' => 'PA_PATTERN',
'relation' => 'OR',
- ],
- [
+ ),
+ array(
'taxonomy' => 'PA_KIND',
'relation' => 'AND',
- ],
- ],
- ];
+ ),
+ ),
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedNode(
- 'collectionStats.attributeCounts',
- [
+ 'collectionStats.attributeCounts',
+ array(
$this->expectedField( 'slug', 'PA_KIND' ),
$this->expectedNode(
'terms',
- [
+ array(
$this->expectedField( 'node.slug', 'normal' ),
$this->expectedField( 'count', 3 ),
$this->expectedField( 'termId', static::NOT_FALSY ),
- ],
+ ),
0
),
$this->expectedNode(
'terms',
- [
+ array(
$this->expectedField( 'node.slug', 'special' ),
$this->expectedField( 'count', 8 ),
$this->expectedField( 'termId', static::NOT_FALSY ),
- ],
+ ),
1
),
- ],
+ ),
),
$this->expectedNode(
- 'collectionStats.attributeCounts',
- [
+ 'collectionStats.attributeCounts',
+ array(
$this->expectedField( 'slug', 'PA_PATTERN' ),
$this->expectedNode(
'terms',
- [
+ array(
$this->expectedField( 'node.slug', 'polka-dot' ),
$this->expectedField( 'count', 4 ),
$this->expectedField( 'termId', static::NOT_FALSY ),
- ],
+ ),
0
),
$this->expectedNode(
'terms',
- [
+ array(
$this->expectedField( 'node.slug', 'striped' ),
$this->expectedField( 'count', 8 ),
$this->expectedField( 'termId', static::NOT_FALSY ),
- ],
+ ),
1
),
- ],
+ ),
),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
}
diff --git a/tests/wpunit/ConnectionPaginationTest.php b/tests/wpunit/ConnectionPaginationTest.php
index 687cd34cf..4b3eeea0b 100644
--- a/tests/wpunit/ConnectionPaginationTest.php
+++ b/tests/wpunit/ConnectionPaginationTest.php
@@ -13,13 +13,13 @@ public function toCursor( $id ) {
// tests
public function testCouponsPagination() {
- $coupons = [
+ $coupons = array(
$this->factory->coupon->create(),
$this->factory->coupon->create(),
$this->factory->coupon->create(),
$this->factory->coupon->create(),
$this->factory->coupon->create(),
- ];
+ );
usort(
$coupons,
@@ -51,16 +51,16 @@ static function ( $key_a, $key_b ) {
*
* Test "first" parameter.
*/
- $variables = [ 'first' => 2 ];
+ $variables = array( 'first' => 2 );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'coupons.pageInfo.hasPreviousPage', false ),
$this->expectedField( 'coupons.pageInfo.hasNextPage', true ),
$this->expectedField( 'coupons.pageInfo.startCursor', $this->toCursor( $coupons[0] ) ),
$this->expectedField( 'coupons.pageInfo.endCursor', $this->toCursor( $coupons[1] ) ),
$this->expectedField( 'coupons.nodes.0.databaseId', $coupons[0] ),
$this->expectedField( 'coupons.nodes.1.databaseId', $coupons[1] ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
@@ -69,12 +69,12 @@ static function ( $key_a, $key_b ) {
*
* Test "after" parameter.
*/
- $variables = [
+ $variables = array(
'first' => 3,
'after' => $this->toCursor( $coupons[1] ),
- ];
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'coupons.pageInfo.hasPreviousPage', true ),
$this->expectedField( 'coupons.pageInfo.hasNextPage', false ),
$this->expectedField( 'coupons.pageInfo.startCursor', $this->toCursor( $coupons[2] ) ),
@@ -82,7 +82,7 @@ static function ( $key_a, $key_b ) {
$this->expectedField( 'coupons.nodes.0.databaseId', $coupons[2] ),
$this->expectedField( 'coupons.nodes.1.databaseId', $coupons[3] ),
$this->expectedField( 'coupons.nodes.2.databaseId', $coupons[4] ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
@@ -92,18 +92,18 @@ static function ( $key_a, $key_b ) {
* Test "last" parameter.
*/
\WPGraphQL::set_is_graphql_request( true );
- $variables = [
+ $variables = array(
'last' => 2,
- ];
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'coupons.pageInfo.hasPreviousPage', true ),
$this->expectedField( 'coupons.pageInfo.hasNextPage', false ),
$this->expectedField( 'coupons.pageInfo.startCursor', $this->toCursor( $coupons[3] ) ),
$this->expectedField( 'coupons.pageInfo.endCursor', $this->toCursor( $coupons[4] ) ),
$this->expectedField( 'coupons.nodes.0.databaseId', $coupons[3] ),
$this->expectedField( 'coupons.nodes.1.databaseId', $coupons[4] ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
@@ -112,31 +112,31 @@ static function ( $key_a, $key_b ) {
*
* Test "before" parameter.
*/
- $variables = [
+ $variables = array(
'last' => 2,
'before' => $this->toCursor( $coupons[3] ),
- ];
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'coupons.pageInfo.hasPreviousPage', true ),
$this->expectedField( 'coupons.pageInfo.hasNextPage', true ),
$this->expectedField( 'coupons.pageInfo.startCursor', $this->toCursor( $coupons[1] ) ),
$this->expectedField( 'coupons.pageInfo.endCursor', $this->toCursor( $coupons[2] ) ),
$this->expectedField( 'coupons.nodes.0.databaseId', $coupons[1] ),
$this->expectedField( 'coupons.nodes.1.databaseId', $coupons[2] ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
}
public function testProductsPagination() {
- $products = [
- $this->factory->product->createSimple( [ 'menu_order' => 0 ] ),
- $this->factory->product->createSimple( [ 'menu_order' => 1 ] ),
- $this->factory->product->createSimple( [ 'menu_order' => 2 ] ),
- $this->factory->product->createSimple( [ 'menu_order' => 3 ] ),
- $this->factory->product->createSimple( [ 'menu_order' => 4 ] ),
- ];
+ $products = array(
+ $this->factory->product->createSimple( array( 'menu_order' => 0 ) ),
+ $this->factory->product->createSimple( array( 'menu_order' => 1 ) ),
+ $this->factory->product->createSimple( array( 'menu_order' => 2 ) ),
+ $this->factory->product->createSimple( array( 'menu_order' => 3 ) ),
+ $this->factory->product->createSimple( array( 'menu_order' => 4 ) ),
+ );
usort(
$products,
@@ -167,9 +167,9 @@ static function ( $key_a, $key_b ) {
*
* Test "first" parameter.
*/
- $variables = [ 'first' => 2 ];
+ $variables = array( 'first' => 2 );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'products.found', 5 ),
$this->expectedField( 'products.pageInfo.hasPreviousPage', false ),
$this->expectedField( 'products.pageInfo.hasNextPage', true ),
@@ -177,7 +177,7 @@ static function ( $key_a, $key_b ) {
$this->expectedField( 'products.pageInfo.endCursor', $this->toCursor( $products[1] ) ),
$this->expectedField( 'products.nodes.0.databaseId', $products[0] ),
$this->expectedField( 'products.nodes.1.databaseId', $products[1] ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
@@ -186,12 +186,12 @@ static function ( $key_a, $key_b ) {
*
* Test "after" parameter.
*/
- $variables = [
+ $variables = array(
'first' => 3,
'after' => $this->toCursor( $products[1] ),
- ];
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'products.found', static::IS_NULL ),
$this->expectedField( 'products.pageInfo.hasPreviousPage', true ),
$this->expectedField( 'products.pageInfo.hasNextPage', false ),
@@ -200,7 +200,7 @@ static function ( $key_a, $key_b ) {
$this->expectedField( 'products.nodes.0.databaseId', $products[2] ),
$this->expectedField( 'products.nodes.1.databaseId', $products[3] ),
$this->expectedField( 'products.nodes.2.databaseId', $products[4] ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
@@ -209,9 +209,9 @@ static function ( $key_a, $key_b ) {
*
* Test "last" parameter.
*/
- $variables = [ 'last' => 2 ];
+ $variables = array( 'last' => 2 );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'products.found', 5 ),
$this->expectedField( 'products.pageInfo.hasPreviousPage', true ),
$this->expectedField( 'products.pageInfo.hasNextPage', false ),
@@ -219,7 +219,7 @@ static function ( $key_a, $key_b ) {
$this->expectedField( 'products.pageInfo.endCursor', $this->toCursor( $products[4] ) ),
$this->expectedField( 'products.nodes.0.databaseId', $products[3] ),
$this->expectedField( 'products.nodes.1.databaseId', $products[4] ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
@@ -228,12 +228,12 @@ static function ( $key_a, $key_b ) {
*
* Test "before" parameter.
*/
- $variables = [
+ $variables = array(
'last' => 2,
'before' => $this->toCursor( $products[3] ),
- ];
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'products.found', static::IS_NULL ),
$this->expectedField( 'products.pageInfo.hasPreviousPage', true ),
$this->expectedField( 'products.pageInfo.hasNextPage', true ),
@@ -241,19 +241,45 @@ static function ( $key_a, $key_b ) {
$this->expectedField( 'products.pageInfo.endCursor', $this->toCursor( $products[2] ) ),
$this->expectedField( 'products.nodes.0.databaseId', $products[1] ),
$this->expectedField( 'products.nodes.1.databaseId', $products[2] ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
}
public function testProductsPaginationWithOrderby() {
- $products = [
- $this->factory->product->createSimple( [ 'menu_order' => 0, 'regular_price' => 5 ] ),
- $this->factory->product->createSimple( [ 'menu_order' => 1, 'regular_price' => 4 ] ),
- $this->factory->product->createSimple( [ 'menu_order' => 2, 'regular_price' => 3, 'sale_price' => 0.50 ] ),
- $this->factory->product->createSimple( [ 'menu_order' => 3, 'regular_price' => 2 ] ),
- $this->factory->product->createSimple( [ 'menu_order' => 4, 'regular_price' => 1 ] ),
- ];
+ $products = array(
+ $this->factory->product->createSimple(
+ array(
+ 'menu_order' => 0,
+ 'regular_price' => 5,
+ )
+ ),
+ $this->factory->product->createSimple(
+ array(
+ 'menu_order' => 1,
+ 'regular_price' => 4,
+ )
+ ),
+ $this->factory->product->createSimple(
+ array(
+ 'menu_order' => 2,
+ 'regular_price' => 3,
+ 'sale_price' => 0.50,
+ )
+ ),
+ $this->factory->product->createSimple(
+ array(
+ 'menu_order' => 3,
+ 'regular_price' => 2,
+ )
+ ),
+ $this->factory->product->createSimple(
+ array(
+ 'menu_order' => 4,
+ 'regular_price' => 1,
+ )
+ ),
+ );
usort(
$products,
@@ -285,9 +311,19 @@ static function ( $key_a, $key_b ) {
*
* Test "first" parameter with the "orderby.MENU_ORDER".
*/
- $variables = [ 'first' => 2, 'where' => [ 'orderby' => [ [ 'field' => 'MENU_ORDER', 'order' => 'DESC' ] ] ] ];
+ $variables = array(
+ 'first' => 2,
+ 'where' => array(
+ 'orderby' => array(
+ array(
+ 'field' => 'MENU_ORDER',
+ 'order' => 'DESC',
+ ),
+ ),
+ ),
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'products.found', 5 ),
$this->expectedField( 'products.pageInfo.hasPreviousPage', false ),
$this->expectedField( 'products.pageInfo.hasNextPage', true ),
@@ -295,7 +331,7 @@ static function ( $key_a, $key_b ) {
$this->expectedField( 'products.pageInfo.endCursor', $this->toCursor( $products[1] ) ),
$this->expectedField( 'products.nodes.0.databaseId', $products[0] ),
$this->expectedField( 'products.nodes.1.databaseId', $products[1] ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
@@ -304,13 +340,20 @@ static function ( $key_a, $key_b ) {
*
* Test "after" parameter with the "orderby.MENU_ORDER".
*/
- $variables = [
+ $variables = array(
'first' => 3,
'after' => $this->toCursor( $products[1] ),
- 'where' => [ 'orderby' => [ [ 'field' => 'MENU_ORDER', 'order' => 'DESC' ] ] ],
- ];
+ 'where' => array(
+ 'orderby' => array(
+ array(
+ 'field' => 'MENU_ORDER',
+ 'order' => 'DESC',
+ ),
+ ),
+ ),
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'products.found', static::IS_NULL ),
$this->expectedField( 'products.pageInfo.hasPreviousPage', true ),
$this->expectedField( 'products.pageInfo.hasNextPage', false ),
@@ -319,7 +362,7 @@ static function ( $key_a, $key_b ) {
$this->expectedField( 'products.nodes.0.databaseId', $products[2] ),
$this->expectedField( 'products.nodes.1.databaseId', $products[3] ),
$this->expectedField( 'products.nodes.2.databaseId', $products[4] ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
@@ -328,9 +371,19 @@ static function ( $key_a, $key_b ) {
*
* Test "last" parameter with the "orderby.MENU_ORDER".
*/
- $variables = [ 'last' => 2, 'where' => [ 'orderby' => [ [ 'field' => 'MENU_ORDER', 'order' => 'DESC' ] ] ] ];
+ $variables = array(
+ 'last' => 2,
+ 'where' => array(
+ 'orderby' => array(
+ array(
+ 'field' => 'MENU_ORDER',
+ 'order' => 'DESC',
+ ),
+ ),
+ ),
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'products.found', 5 ),
$this->expectedField( 'products.pageInfo.hasPreviousPage', true ),
$this->expectedField( 'products.pageInfo.hasNextPage', false ),
@@ -338,7 +391,7 @@ static function ( $key_a, $key_b ) {
$this->expectedField( 'products.pageInfo.endCursor', $this->toCursor( $products[0] ) ),
$this->expectedField( 'products.nodes.0.databaseId', $products[1] ),
$this->expectedField( 'products.nodes.1.databaseId', $products[0] ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
@@ -347,13 +400,20 @@ static function ( $key_a, $key_b ) {
*
* Test "before" parameter with the "orderby.MENU_ORDER".
*/
- $variables = [
+ $variables = array(
'last' => 2,
'before' => $this->toCursor( $products[1] ),
- 'where' => [ 'orderby' => [ [ 'field' => 'MENU_ORDER', 'order' => 'DESC' ] ] ]
- ];
+ 'where' => array(
+ 'orderby' => array(
+ array(
+ 'field' => 'MENU_ORDER',
+ 'order' => 'DESC',
+ ),
+ ),
+ ),
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'products.found', static::IS_NULL ),
$this->expectedField( 'products.pageInfo.hasPreviousPage', true ),
$this->expectedField( 'products.pageInfo.hasNextPage', true ),
@@ -361,7 +421,7 @@ static function ( $key_a, $key_b ) {
$this->expectedField( 'products.pageInfo.endCursor', $this->toCursor( $products[2] ) ),
$this->expectedField( 'products.nodes.0.databaseId', $products[3] ),
$this->expectedField( 'products.nodes.1.databaseId', $products[2] ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
@@ -370,9 +430,19 @@ static function ( $key_a, $key_b ) {
*
* Test "first" parameter with the "orderby.PRICE".
*/
- $variables = [ 'first' => 2, 'where' => [ 'orderby' => [ [ 'field' => 'PRICE', 'order' => 'DESC' ] ] ] ];
+ $variables = array(
+ 'first' => 2,
+ 'where' => array(
+ 'orderby' => array(
+ array(
+ 'field' => 'PRICE',
+ 'order' => 'DESC',
+ ),
+ ),
+ ),
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'products.found', 5 ),
$this->expectedField( 'products.pageInfo.hasPreviousPage', false ),
$this->expectedField( 'products.pageInfo.hasNextPage', true ),
@@ -380,7 +450,7 @@ static function ( $key_a, $key_b ) {
$this->expectedField( 'products.pageInfo.endCursor', $this->toCursor( $products[3] ) ),
$this->expectedField( 'products.nodes.0.databaseId', $products[4] ),
$this->expectedField( 'products.nodes.1.databaseId', $products[3] ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
@@ -389,13 +459,20 @@ static function ( $key_a, $key_b ) {
*
* Test "after" parameter with the "orderby.PRICE".
*/
- $variables = [
+ $variables = array(
'first' => 3,
'after' => $this->toCursor( $products[3] ),
- 'where' => [ 'orderby' => [ [ 'field' => 'PRICE', 'order' => 'DESC' ] ] ],
- ];
+ 'where' => array(
+ 'orderby' => array(
+ array(
+ 'field' => 'PRICE',
+ 'order' => 'DESC',
+ ),
+ ),
+ ),
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'products.found', static::IS_NULL ),
$this->expectedField( 'products.pageInfo.hasPreviousPage', true ),
$this->expectedField( 'products.pageInfo.hasNextPage', false ),
@@ -404,7 +481,7 @@ static function ( $key_a, $key_b ) {
$this->expectedField( 'products.nodes.0.databaseId', $products[1] ),
$this->expectedField( 'products.nodes.1.databaseId', $products[0] ),
$this->expectedField( 'products.nodes.2.databaseId', $products[2] ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
@@ -413,9 +490,19 @@ static function ( $key_a, $key_b ) {
*
* Test "last" parameter with the "orderby.PRICE".
*/
- $variables = [ 'last' => 2, 'where' => [ 'orderby' => [ [ 'field' => 'PRICE', 'order' => 'ASC' ] ] ] ];
+ $variables = array(
+ 'last' => 2,
+ 'where' => array(
+ 'orderby' => array(
+ array(
+ 'field' => 'PRICE',
+ 'order' => 'ASC',
+ ),
+ ),
+ ),
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'products.found', 5 ),
$this->expectedField( 'products.pageInfo.hasPreviousPage', true ),
$this->expectedField( 'products.pageInfo.hasNextPage', false ),
@@ -423,7 +510,7 @@ static function ( $key_a, $key_b ) {
$this->expectedField( 'products.pageInfo.endCursor', $this->toCursor( $products[2] ) ),
$this->expectedField( 'products.nodes.0.databaseId', $products[0] ),
$this->expectedField( 'products.nodes.1.databaseId', $products[2] ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
@@ -432,13 +519,20 @@ static function ( $key_a, $key_b ) {
*
* Test "before" parameter with the "orderby.PRICE".
*/
- $variables = [
+ $variables = array(
'last' => 2,
'before' => $this->toCursor( $products[0] ),
- 'where' => [ 'orderby' => [ [ 'field' => 'PRICE', 'order' => 'ASC' ] ] ]
- ];
+ 'where' => array(
+ 'orderby' => array(
+ array(
+ 'field' => 'PRICE',
+ 'order' => 'ASC',
+ ),
+ ),
+ ),
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'products.found', static::IS_NULL ),
$this->expectedField( 'products.pageInfo.hasPreviousPage', true ),
$this->expectedField( 'products.pageInfo.hasNextPage', true ),
@@ -446,7 +540,7 @@ static function ( $key_a, $key_b ) {
$this->expectedField( 'products.pageInfo.endCursor', $this->toCursor( $products[1] ) ),
$this->expectedField( 'products.nodes.0.databaseId', $products[3] ),
$this->expectedField( 'products.nodes.1.databaseId', $products[1] ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
}
@@ -462,13 +556,13 @@ public function testOrdersPagination() {
unset( $old_orders );
unset( $query );
- $orders = [
+ $orders = array(
$this->factory->order->createNew(),
$this->factory->order->createNew(),
$this->factory->order->createNew(),
$this->factory->order->createNew(),
$this->factory->order->createNew(),
- ];
+ );
usort(
$orders,
@@ -499,16 +593,16 @@ static function ( $key_a, $key_b ) {
*
* Test "first" parameter.
*/
- $variables = [ 'first' => 2 ];
+ $variables = array( 'first' => 2 );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'orders.pageInfo.hasPreviousPage', false ),
$this->expectedField( 'orders.pageInfo.hasNextPage', true ),
$this->expectedField( 'orders.pageInfo.startCursor', $this->toCursor( $orders[0] ) ),
$this->expectedField( 'orders.pageInfo.endCursor', $this->toCursor( $orders[1] ) ),
$this->expectedField( 'orders.nodes.0.databaseId', $orders[0] ),
$this->expectedField( 'orders.nodes.1.databaseId', $orders[1] ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
@@ -517,12 +611,12 @@ static function ( $key_a, $key_b ) {
*
* Test "after" parameter.
*/
- $variables = [
+ $variables = array(
'first' => 3,
'after' => $this->toCursor( $orders[1] ),
- ];
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'orders.pageInfo.hasPreviousPage', true ),
$this->expectedField( 'orders.pageInfo.hasNextPage', false ),
$this->expectedField( 'orders.pageInfo.startCursor', $this->toCursor( $orders[2] ) ),
@@ -530,7 +624,7 @@ static function ( $key_a, $key_b ) {
$this->expectedField( 'orders.nodes.0.databaseId', $orders[2] ),
$this->expectedField( 'orders.nodes.1.databaseId', $orders[3] ),
$this->expectedField( 'orders.nodes.2.databaseId', $orders[4] ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
@@ -539,16 +633,16 @@ static function ( $key_a, $key_b ) {
*
* Test "last" parameter.
*/
- $variables = [ 'last' => 2 ];
+ $variables = array( 'last' => 2 );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'orders.pageInfo.hasPreviousPage', true ),
$this->expectedField( 'orders.pageInfo.hasNextPage', false ),
$this->expectedField( 'orders.pageInfo.startCursor', $this->toCursor( $orders[3] ) ),
$this->expectedField( 'orders.pageInfo.endCursor', $this->toCursor( $orders[4] ) ),
$this->expectedField( 'orders.nodes.0.databaseId', $orders[3] ),
$this->expectedField( 'orders.nodes.1.databaseId', $orders[4] ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
@@ -557,32 +651,32 @@ static function ( $key_a, $key_b ) {
*
* Test "before" parameter.
*/
- $variables = [
+ $variables = array(
'last' => 2,
'before' => $this->toCursor( $orders[3] ),
- ];
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'orders.pageInfo.hasPreviousPage', true ),
$this->expectedField( 'orders.pageInfo.hasNextPage', true ),
$this->expectedField( 'orders.pageInfo.startCursor', $this->toCursor( $orders[1] ) ),
$this->expectedField( 'orders.pageInfo.endCursor', $this->toCursor( $orders[2] ) ),
$this->expectedField( 'orders.nodes.0.databaseId', $orders[1] ),
$this->expectedField( 'orders.nodes.1.databaseId', $orders[2] ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
}
public function testRefundsPagination() {
$order = $this->factory->order->createNew();
- $refunds = [
- $this->factory->refund->createNew( $order, [ 'amount' => 0.5 ] ),
- $this->factory->refund->createNew( $order, [ 'amount' => 0.5 ] ),
- $this->factory->refund->createNew( $order, [ 'amount' => 0.5 ] ),
- $this->factory->refund->createNew( $order, [ 'amount' => 0.5 ] ),
- $this->factory->refund->createNew( $order, [ 'amount' => 0.5 ] ),
- ];
+ $refunds = array(
+ $this->factory->refund->createNew( $order, array( 'amount' => 0.5 ) ),
+ $this->factory->refund->createNew( $order, array( 'amount' => 0.5 ) ),
+ $this->factory->refund->createNew( $order, array( 'amount' => 0.5 ) ),
+ $this->factory->refund->createNew( $order, array( 'amount' => 0.5 ) ),
+ $this->factory->refund->createNew( $order, array( 'amount' => 0.5 ) ),
+ );
usort(
$refunds,
@@ -614,16 +708,16 @@ static function ( $key_a, $key_b ) {
*
* Test "first" parameter.
*/
- $variables = [ 'first' => 2 ];
+ $variables = array( 'first' => 2 );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'refunds.pageInfo.hasPreviousPage', false ),
$this->expectedField( 'refunds.pageInfo.hasNextPage', true ),
$this->expectedField( 'refunds.pageInfo.startCursor', $this->toCursor( $refunds[0] ) ),
$this->expectedField( 'refunds.pageInfo.endCursor', $this->toCursor( $refunds[1] ) ),
$this->expectedField( 'refunds.nodes.0.databaseId', $refunds[0] ),
$this->expectedField( 'refunds.nodes.1.databaseId', $refunds[1] ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
@@ -632,12 +726,12 @@ static function ( $key_a, $key_b ) {
*
* Test "after" parameter.
*/
- $variables = [
+ $variables = array(
'first' => 3,
'after' => $this->toCursor( $refunds[1] ),
- ];
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'refunds.pageInfo.hasPreviousPage', true ),
$this->expectedField( 'refunds.pageInfo.hasNextPage', false ),
$this->expectedField( 'refunds.pageInfo.startCursor', $this->toCursor( $refunds[2] ) ),
@@ -645,7 +739,7 @@ static function ( $key_a, $key_b ) {
$this->expectedField( 'refunds.nodes.0.databaseId', $refunds[2] ),
$this->expectedField( 'refunds.nodes.1.databaseId', $refunds[3] ),
$this->expectedField( 'refunds.nodes.2.databaseId', $refunds[4] ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
@@ -654,16 +748,16 @@ static function ( $key_a, $key_b ) {
*
* Test "last" parameter.
*/
- $variables = [ 'last' => 2 ];
+ $variables = array( 'last' => 2 );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'refunds.pageInfo.hasPreviousPage', true ),
$this->expectedField( 'refunds.pageInfo.hasNextPage', false ),
$this->expectedField( 'refunds.pageInfo.startCursor', $this->toCursor( $refunds[3] ) ),
$this->expectedField( 'refunds.pageInfo.endCursor', $this->toCursor( $refunds[4] ) ),
$this->expectedField( 'refunds.nodes.0.databaseId', $refunds[3] ),
$this->expectedField( 'refunds.nodes.1.databaseId', $refunds[4] ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
@@ -672,39 +766,39 @@ static function ( $key_a, $key_b ) {
*
* Test "before" parameter.
*/
- $variables = [
+ $variables = array(
'last' => 2,
'before' => $this->toCursor( $refunds[3] ),
- ];
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'refunds.pageInfo.hasPreviousPage', true ),
$this->expectedField( 'refunds.pageInfo.hasNextPage', true ),
$this->expectedField( 'refunds.pageInfo.startCursor', $this->toCursor( $refunds[1] ) ),
$this->expectedField( 'refunds.pageInfo.endCursor', $this->toCursor( $refunds[2] ) ),
$this->expectedField( 'refunds.nodes.0.databaseId', $refunds[1] ),
$this->expectedField( 'refunds.nodes.1.databaseId', $refunds[2] ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
}
public function testCustomersPagination() {
- $some_customers = [
+ $some_customers = array(
$this->factory->customer->create(),
$this->factory->customer->create(),
$this->factory->customer->create(),
$this->factory->customer->create(),
$this->factory->customer->create(),
- ];
+ );
$customers = get_users(
- [
+ array(
'fields' => 'id',
'role' => 'customer',
'orderby' => 'user_login',
'order' => 'ASC',
- ]
+ )
);
$customers = array_map( 'absint', $customers );
@@ -733,16 +827,16 @@ public function testCustomersPagination() {
*
* Test "first" parameter.
*/
- $variables = [ 'first' => 2 ];
+ $variables = array( 'first' => 2 );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'customers.pageInfo.hasPreviousPage', false ),
$this->expectedField( 'customers.pageInfo.hasNextPage', true ),
$this->expectedField( 'customers.nodes.0.databaseId', $customers[0] ),
$this->expectedField( 'customers.nodes.1.databaseId', $customers[1] ),
$this->expectedField( 'customers.pageInfo.startCursor', $this->toCursor( $customers[0] ) ),
$this->expectedField( 'customers.pageInfo.endCursor', $this->toCursor( $customers[1] ) ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
@@ -751,19 +845,19 @@ public function testCustomersPagination() {
*
* Test "after" parameter.
*/
- $variables = [
+ $variables = array(
'first' => 3,
'after' => $this->toCursor( $customers[1] ),
- ];
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'customers.pageInfo.hasPreviousPage', true ),
$this->expectedField( 'customers.pageInfo.startCursor', $this->toCursor( $customers[2] ) ),
$this->expectedField( 'customers.pageInfo.endCursor', $this->toCursor( $customers[4] ) ),
$this->expectedField( 'customers.nodes.0.databaseId', $customers[2] ),
$this->expectedField( 'customers.nodes.1.databaseId', $customers[3] ),
$this->expectedField( 'customers.nodes.2.databaseId', $customers[4] ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
@@ -772,16 +866,16 @@ public function testCustomersPagination() {
*
* Test "last" parameter.
*/
- $variables = [ 'last' => 2 ];
+ $variables = array( 'last' => 2 );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'customers.pageInfo.hasPreviousPage', true ),
$this->expectedField( 'customers.pageInfo.hasNextPage', false ),
$this->expectedField( 'customers.pageInfo.startCursor', $this->toCursor( $customers[3] ) ),
$this->expectedField( 'customers.pageInfo.endCursor', $this->toCursor( $customers[4] ) ),
$this->expectedField( 'customers.nodes.0.databaseId', $customers[3] ),
$this->expectedField( 'customers.nodes.1.databaseId', $customers[4] ),
- ];
+ );
// $this->assertQuerySuccessful( $response, $expected );
@@ -790,19 +884,19 @@ public function testCustomersPagination() {
*
* Test "before" parameter.
*/
- $variables = [
+ $variables = array(
'last' => 2,
'before' => $this->toCursor( $customers[3] ),
- ];
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'customers.pageInfo.hasPreviousPage', true ),
$this->expectedField( 'customers.pageInfo.hasNextPage', true ),
$this->expectedField( 'customers.pageInfo.startCursor', $this->toCursor( $customers[1] ) ),
$this->expectedField( 'customers.pageInfo.endCursor', $this->toCursor( $customers[2] ) ),
$this->expectedField( 'customers.nodes.0.databaseId', $customers[1] ),
$this->expectedField( 'customers.nodes.1.databaseId', $customers[2] ),
- ];
+ );
// $this->assertQuerySuccessful( $response, $expected );
}
@@ -810,42 +904,42 @@ public function testCustomersPagination() {
public function testDownloadableItemsPagination() {
$customer_id = $this->factory->customer->create();
- $downloads = [
+ $downloads = array(
$this->factory->product->createDownload(),
$this->factory->product->createDownload(),
$this->factory->product->createDownload(),
$this->factory->product->createDownload(),
$this->factory->product->createDownload(),
- ];
+ );
$products = array_map(
function ( $download ) {
return $this->factory->product->createSimple(
- [
+ array(
'downloadable' => true,
- 'downloads' => [ $download ],
- ]
+ 'downloads' => array( $download ),
+ )
);
},
$downloads
);
$order_id = $this->factory->order->createNew(
- [
+ array(
'status' => 'completed',
'customer_id' => $customer_id,
- ],
- [
+ ),
+ array(
'line_items' => array_map(
static function ( $product_id ) {
- return [
+ return array(
'product' => $product_id,
'qty' => 1,
- ];
+ );
},
$products
),
- ]
+ )
);
$order = \wc_get_order( $order_id );
@@ -885,16 +979,16 @@ static function ( $product_id ) {
*
* Test "first" parameter.
*/
- $variables = [ 'first' => 2 ];
+ $variables = array( 'first' => 2 );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'customer.orders.nodes.0.downloadableItems.pageInfo.hasPreviousPage', false ),
$this->expectedField( 'customer.orders.nodes.0.downloadableItems.pageInfo.hasNextPage', true ),
$this->expectedField( 'customer.orders.nodes.0.downloadableItems.pageInfo.startCursor', $this->toCursor( $downloads[0] ) ),
$this->expectedField( 'customer.orders.nodes.0.downloadableItems.pageInfo.endCursor', $this->toCursor( $downloads[1] ) ),
$this->expectedField( 'customer.orders.nodes.0.downloadableItems.nodes.0.product.databaseId', $products[0] ),
$this->expectedField( 'customer.orders.nodes.0.downloadableItems.nodes.1.product.databaseId', $products[1] ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
@@ -903,12 +997,12 @@ static function ( $product_id ) {
*
* Test "after" parameter.
*/
- $variables = [
+ $variables = array(
'first' => 3,
'after' => $this->toCursor( $downloads[1] ),
- ];
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'customer.orders.nodes.0.downloadableItems.pageInfo.hasPreviousPage', true ),
$this->expectedField( 'customer.orders.nodes.0.downloadableItems.pageInfo.hasNextPage', false ),
$this->expectedField( 'customer.orders.nodes.0.downloadableItems.pageInfo.startCursor', $this->toCursor( $downloads[2] ) ),
@@ -916,7 +1010,7 @@ static function ( $product_id ) {
$this->expectedField( 'customer.orders.nodes.0.downloadableItems.nodes.0.product.databaseId', $products[2] ),
$this->expectedField( 'customer.orders.nodes.0.downloadableItems.nodes.1.product.databaseId', $products[3] ),
$this->expectedField( 'customer.orders.nodes.0.downloadableItems.nodes.2.product.databaseId', $products[4] ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
@@ -925,16 +1019,16 @@ static function ( $product_id ) {
*
* Test "last" parameter.
*/
- $variables = [ 'last' => 2 ];
+ $variables = array( 'last' => 2 );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'customer.orders.nodes.0.downloadableItems.pageInfo.hasPreviousPage', true ),
$this->expectedField( 'customer.orders.nodes.0.downloadableItems.pageInfo.hasNextPage', false ),
$this->expectedField( 'customer.orders.nodes.0.downloadableItems.pageInfo.startCursor', $this->toCursor( $downloads[3] ) ),
$this->expectedField( 'customer.orders.nodes.0.downloadableItems.pageInfo.endCursor', $this->toCursor( $downloads[4] ) ),
$this->expectedField( 'customer.orders.nodes.0.downloadableItems.nodes.0.product.databaseId', $products[3] ),
$this->expectedField( 'customer.orders.nodes.0.downloadableItems.nodes.1.product.databaseId', $products[4] ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
@@ -943,12 +1037,12 @@ static function ( $product_id ) {
*
* Test "before" parameter.
*/
- $variables = [
+ $variables = array(
'last' => 3,
'before' => $this->toCursor( $downloads[3] ),
- ];
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'customer.orders.nodes.0.downloadableItems.pageInfo.hasPreviousPage', false ),
$this->expectedField( 'customer.orders.nodes.0.downloadableItems.pageInfo.hasNextPage', true ),
$this->expectedField( 'customer.orders.nodes.0.downloadableItems.pageInfo.startCursor', $this->toCursor( $downloads[0] ) ),
@@ -956,7 +1050,7 @@ static function ( $product_id ) {
$this->expectedField( 'customer.orders.nodes.0.downloadableItems.nodes.0.product.databaseId', $products[0] ),
$this->expectedField( 'customer.orders.nodes.0.downloadableItems.nodes.1.product.databaseId', $products[1] ),
$this->expectedField( 'customer.orders.nodes.0.downloadableItems.nodes.2.product.databaseId', $products[2] ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
}
diff --git a/tests/wpunit/CoreInterfaceQueriesTest.php b/tests/wpunit/CoreInterfaceQueriesTest.php
index b7d610d55..5a7306dac 100644
--- a/tests/wpunit/CoreInterfaceQueriesTest.php
+++ b/tests/wpunit/CoreInterfaceQueriesTest.php
@@ -25,14 +25,14 @@ public function testProductAsNodeWithComments() {
// Create product and review to be queried.
$product_id = $this->products->create_simple();
$comment_id = $this->factory()->comment->create(
- [
+ array(
'comment_author' => 'Rude customer',
'comment_author_email' => 'rude-guy@example.com',
'comment_post_ID' => $product_id,
'comment_content' => 'It came covered in poop!!!',
'comment_approved' => 1,
'comment_type' => 'review',
- ]
+ )
);
update_comment_meta( $comment_id, 'rating', 1 );
@@ -48,21 +48,21 @@ public function testProductAsNodeWithComments() {
}
}
';
- $variables = [ 'id' => $product_id ];
+ $variables = array( 'id' => $product_id );
// Execute query and retrieve response.
$response = $this->graphql( compact( 'query', 'variables' ) );
// Define expected data object.
- $expected = [
- 'data' => [
- 'product' => [
+ $expected = array(
+ 'data' => array(
+ 'product' => array(
'id' => \GraphQLRelay\Relay::toGlobalId( 'post', $product_id ),
'commentCount' => 1,
'commentStatus' => 'open',
- ],
- ],
- ];
+ ),
+ ),
+ );
// Assert query response valid.
$this->assertEquals( $expected, $response );
@@ -87,26 +87,26 @@ public function testOrderAsNodeWithComments() {
}
}
';
- $variables = [ 'id' => $order_id ];
+ $variables = array( 'id' => $order_id );
/**
* Assertion One
*
* Authenticate as a shop manager and execute query and validate response.
*/
- wp_set_current_user( $this->factory->user->create( [ 'role' => 'shop_manager' ] ) );
+ wp_set_current_user( $this->factory->user->create( array( 'role' => 'shop_manager' ) ) );
$response = $this->graphql( compact( 'query', 'variables' ) );
// Define expected data object.
- $expected = [
- 'data' => [
- 'order' => [
+ $expected = array(
+ 'data' => array(
+ 'order' => array(
'id' => \GraphQLRelay\Relay::toGlobalId( 'order', $order_id ),
'commentCount' => 2,
'commentStatus' => 'open',
- ],
- ],
- ];
+ ),
+ ),
+ );
// Assert query response valid.
$this->assertEquals( $expected, $response );
@@ -120,15 +120,15 @@ public function testOrderAsNodeWithComments() {
$response = $this->graphql( compact( 'query', 'variables' ) );
// Define expected data object.
- $expected = [
- 'data' => [
- 'order' => [
+ $expected = array(
+ 'data' => array(
+ 'order' => array(
'id' => \GraphQLRelay\Relay::toGlobalId( 'order', $order_id ),
'commentCount' => 1,
'commentStatus' => 'closed',
- ],
- ],
- ];
+ ),
+ ),
+ );
// Assert query response valid.
$this->assertEquals( $expected, $response );
@@ -140,7 +140,7 @@ public function testProductAsNodeWithContentEditor() {
$product = \wc_get_product( $product_id );
// Authenticate to view RAW content.
- wp_set_current_user( $this->factory->user->create( [ 'role' => 'shop_manager' ] ) );
+ wp_set_current_user( $this->factory->user->create( array( 'role' => 'shop_manager' ) ) );
// Define query and variables.
$query = '
@@ -153,23 +153,23 @@ public function testProductAsNodeWithContentEditor() {
}
}
';
- $variables = [
+ $variables = array(
'id' => $product_id,
'format' => 'RAW',
- ];
+ );
// Execute query and retrieve response.
$response = $this->graphql( compact( 'query', 'variables' ) );
// Define expected data object.
- $expected = [
- 'data' => [
- 'product' => [
+ $expected = array(
+ 'data' => array(
+ 'product' => array(
'id' => \GraphQLRelay\Relay::toGlobalId( 'post', $product_id ),
'content' => $product->get_description(),
- ],
- ],
- ];
+ ),
+ ),
+ );
// Assert query response valid.
$this->assertEquals( $expected, $response );
@@ -178,12 +178,12 @@ public function testProductAsNodeWithContentEditor() {
public function testProductAsNodeWithFeaturedImage() {
// Create product to be queried.
$attachment_id = $this->factory()->attachment->create(
- [
+ array(
'post_mime_type' => 'image/gif',
'post_author' => $this->admin,
- ]
+ )
);
- $product_id = $this->products->create_simple( [ 'image_id' => $attachment_id ] );
+ $product_id = $this->products->create_simple( array( 'image_id' => $attachment_id ) );
// Define query and variables.
$query = '
@@ -197,21 +197,21 @@ public function testProductAsNodeWithFeaturedImage() {
}
}
';
- $variables = [ 'id' => $product_id ];
+ $variables = array( 'id' => $product_id );
// Execute query and retrieve response.
$response = $this->graphql( compact( 'query', 'variables' ) );
// Define expected data object.
- $expected = [
- 'data' => [
- 'product' => [
+ $expected = array(
+ 'data' => array(
+ 'product' => array(
'id' => \GraphQLRelay\Relay::toGlobalId( 'post', $product_id ),
'featuredImageId' => \GraphQLRelay\Relay::toGlobalId( 'post', $attachment_id ),
'featuredImageDatabaseId' => $attachment_id,
- ],
- ],
- ];
+ ),
+ ),
+ );
// Assert query response valid.
$this->assertEquals( $expected, $response );
@@ -250,15 +250,15 @@ public function testProductAsContentNode() {
}
}
';
- $variables = [ 'id' => $product_id ];
+ $variables = array( 'id' => $product_id );
// Execute query and retrieve response.
$response = $this->graphql( compact( 'query', 'variables' ) );
// Define expected data object.
- $expected = [
- 'data' => [
- 'product' => [
+ $expected = array(
+ 'data' => array(
+ 'product' => array(
'id' => \GraphQLRelay\Relay::toGlobalId( 'post', $product_id ),
'databaseId' => $wp_product->ID,
'date' => (string) $wc_product->get_date_created(),
@@ -276,9 +276,9 @@ public function testProductAsContentNode() {
'isPreview' => null,
'previewRevisionDatabaseId' => null,
'previewRevisionId' => null,
- ],
- ],
- ];
+ ),
+ ),
+ );
// Assert query response valid.
$this->assertEquals( $expected, $response );
@@ -301,20 +301,20 @@ public function testProductAsUniformResourceIdentifiable() {
}
}
';
- $variables = [ 'id' => $product_id ];
+ $variables = array( 'id' => $product_id );
// Execute query and retrieve response.
$response = $this->graphql( compact( 'query', 'variables' ) );
// Define expected data object.
- $expected = [
- 'data' => [
- 'product' => [
+ $expected = array(
+ 'data' => array(
+ 'product' => array(
'id' => \GraphQLRelay\Relay::toGlobalId( 'post', $product_id ),
'uri' => str_ireplace( home_url(), '', get_permalink( $wp_product->ID ) ),
- ],
- ],
- ];
+ ),
+ ),
+ );
// Assert query response valid.
$this->assertEquals( $expected, $response );
@@ -357,15 +357,15 @@ public function testNodeInterfacesOnProductVariation() {
}
}
';
- $variables = [ 'id' => $variation_id ];
+ $variables = array( 'id' => $variation_id );
// Execute query and retrieve response.
$response = $this->graphql( compact( 'query', 'variables' ) );
// Define expected data object.
- $expected = [
- 'data' => [
- 'productVariation' => [
+ $expected = array(
+ 'data' => array(
+ 'productVariation' => array(
'id' => \GraphQLRelay\Relay::toGlobalId( 'post', $variation_id ),
'databaseId' => $wp_product->ID,
'date' => (string) $wc_product->get_date_created(),
@@ -385,9 +385,9 @@ public function testNodeInterfacesOnProductVariation() {
'previewRevisionId' => null,
'featuredImageId' => \GraphQLRelay\Relay::toGlobalId( 'post', $wc_product->get_image_id() ),
'featuredImageDatabaseId' => $wc_product->get_image_id(),
- ],
- ],
- ];
+ ),
+ ),
+ );
// Assert query response valid.
$this->assertEquals( $expected, $response );
diff --git a/tests/wpunit/CouponMutationsTest.php b/tests/wpunit/CouponMutationsTest.php
index c8e0211c8..e967a246f 100644
--- a/tests/wpunit/CouponMutationsTest.php
+++ b/tests/wpunit/CouponMutationsTest.php
@@ -17,14 +17,14 @@ public function testCreateCoupon() {
}
';
- $variables = [
- 'input' => [
+ $variables = array(
+ 'input' => array(
'clientMutationId' => 'some_id',
'code' => 'testcode',
'amount' => 0.25,
'discountType' => 'PERCENT',
- ],
- ];
+ ),
+ );
/**
* Assertion One
@@ -32,10 +32,10 @@ public function testCreateCoupon() {
* Expect mutation to failed due to lack of capabilities
*/
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedErrorPath( 'createCoupon' ),
$this->expectedField( 'createCoupon', static::IS_NULL ),
- ];
+ );
$this->assertQueryError( $response, $expected );
@@ -55,18 +55,18 @@ public function testCreateCoupon() {
*/
$this->loginAsShopManager();
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedObject(
'createCoupon.coupon',
- [
+ array(
$this->expectedField( 'id', static::NOT_FALSY ),
$this->expectedField( 'databaseId', static::NOT_FALSY ),
$this->expectedField( 'code', 'testcode' ),
$this->expectedField( 'amount', 0.25 ),
$this->expectedField( 'discountType', 'PERCENT' ),
- ]
+ )
),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
}
@@ -88,15 +88,15 @@ public function testUpdateCoupon() {
}
';
- $variables = [
- 'input' => [
+ $variables = array(
+ 'input' => array(
'clientMutationId' => 'some_id',
'id' => $this->toRelayId( 'shop_coupon', $coupon_id ),
'code' => 'blahblah',
'amount' => 0.25,
'discountType' => 'PERCENT',
- ],
- ];
+ ),
+ );
/**
* Assertion One
@@ -104,10 +104,10 @@ public function testUpdateCoupon() {
* Expect mutation to failed due to lack of capabilities
*/
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedErrorPath( 'updateCoupon' ),
$this->expectedField( 'updateCoupon', static::IS_NULL ),
- ];
+ );
$this->assertQueryError( $response, $expected );
@@ -127,18 +127,18 @@ public function testUpdateCoupon() {
*/
$this->loginAsShopManager();
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedObject(
'updateCoupon.coupon',
- [
+ array(
$this->expectedField( 'id', $this->toRelayId( 'shop_coupon', $coupon_id ) ),
$this->expectedField( 'databaseId', $coupon_id ),
$this->expectedField( 'code', 'blahblah' ),
$this->expectedField( 'amount', 0.25 ),
$this->expectedField( 'discountType', 'PERCENT' ),
- ]
+ )
),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
}
@@ -157,12 +157,12 @@ public function testDeleteCoupon() {
}
';
- $variables = [
- 'input' => [
+ $variables = array(
+ 'input' => array(
'clientMutationId' => 'some_id',
'id' => $this->toRelayId( 'shop_coupon', $coupon_id ),
- ],
- ];
+ ),
+ );
/**
* Assertion One
@@ -170,10 +170,10 @@ public function testDeleteCoupon() {
* Expect mutation to failed due to lack of capabilities
*/
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedErrorPath( 'deleteCoupon' ),
$this->expectedField( 'deleteCoupon', static::IS_NULL ),
- ];
+ );
$this->assertQueryError( $response, $expected );
@@ -193,15 +193,15 @@ public function testDeleteCoupon() {
*/
$this->loginAsShopManager();
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedObject(
'deleteCoupon.coupon',
- [
+ array(
$this->expectedField( 'id', $this->toRelayId( 'shop_coupon', $coupon_id ) ),
$this->expectedField( 'databaseId', $coupon_id ),
- ]
+ )
),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
}
diff --git a/tests/wpunit/CouponQueriesTest.php b/tests/wpunit/CouponQueriesTest.php
index e5fc9623f..2dbc7da41 100644
--- a/tests/wpunit/CouponQueriesTest.php
+++ b/tests/wpunit/CouponQueriesTest.php
@@ -4,7 +4,7 @@ class CouponQueriesTest extends \Tests\WPGraphQL\WooCommerce\TestCase\WooGraphQL
public function expectedCouponData( $coupon_id ) {
$coupon = new \WC_Coupon( $coupon_id );
- $expected = [
+ $expected = array(
$this->expectedField( 'coupon.id', $this->toRelayId( 'shop_coupon', $coupon_id ) ),
$this->expectedField( 'coupon.databaseId', $coupon->get_id() ),
$this->expectedField( 'coupon.code', $coupon->get_code() ),
@@ -24,26 +24,26 @@ public function expectedCouponData( $coupon_id ) {
$this->expectedField( 'coupon.minimumAmount', $this->maybe( $coupon->get_minimum_amount(), static::IS_NULL ) ),
$this->expectedField( 'coupon.maximumAmount', $this->maybe( $coupon->get_maximum_amount(), static::IS_NULL ) ),
$this->expectedField( 'coupon.emailRestrictions', $this->maybe( $coupon->get_email_restrictions(), static::IS_NULL ) ),
- ];
+ );
foreach ( $coupon->get_product_ids() as $product_id ) {
- $expected[] = $this->expectedNode( 'coupon.products.nodes', [ 'databaseId' => $product_id ] );
+ $expected[] = $this->expectedNode( 'coupon.products.nodes', array( 'databaseId' => $product_id ) );
}
foreach ( $coupon->get_excluded_product_ids() as $product_id ) {
- $expected[] = $this->expectedNode( 'coupon.excludedProducts.nodes', [ 'databaseId' => $product_id ] );
+ $expected[] = $this->expectedNode( 'coupon.excludedProducts.nodes', array( 'databaseId' => $product_id ) );
}
foreach ( $coupon->get_product_categories() as $category_id ) {
- $expected[] = $this->expectedNode( 'coupon.productCategories.nodes', [ 'productCategoryId' => $category_id ] );
+ $expected[] = $this->expectedNode( 'coupon.productCategories.nodes', array( 'productCategoryId' => $category_id ) );
}
foreach ( $coupon->get_excluded_product_categories() as $category_id ) {
- $expected[] = $this->expectedNode( 'coupon.excludedProductCategories.nodes', [ 'productCategoryId' => $category_id ] );
+ $expected[] = $this->expectedNode( 'coupon.excludedProductCategories.nodes', array( 'productCategoryId' => $category_id ) );
}
foreach ( $coupon->get_used_by() as $customer_id ) {
- $expected[] = $this->expectedNode( 'coupon.usedBy.nodes', [ 'databaseId' => $customer_id ] );
+ $expected[] = $this->expectedNode( 'coupon.usedBy.nodes', array( 'databaseId' => $customer_id ) );
}
return $expected;
@@ -52,13 +52,13 @@ public function expectedCouponData( $coupon_id ) {
// tests
public function testCouponQuery() {
$coupon_id = $this->factory->coupon->create(
- [
+ array(
'code' => '10off',
'amount' => 10,
'discount_type' => 'percent',
- 'product_ids' => [ $this->factory->product->createSimple() ],
- 'excluded_product_ids' => [ $this->factory->product->createSimple() ],
- ]
+ 'product_ids' => array( $this->factory->product->createSimple() ),
+ 'excluded_product_ids' => array( $this->factory->product->createSimple() ),
+ )
);
$query = '
@@ -122,9 +122,9 @@ public function testCouponQuery() {
* Confirm customer's can't query coupons by ID.
*/
$this->loginAsCustomer();
- $variables = [ 'id' => $this->toRelayId( 'shop_coupon', $coupon_id ) ];
+ $variables = array( 'id' => $this->toRelayId( 'shop_coupon', $coupon_id ) );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [ $this->expectedField( 'coupon', static::IS_NULL ) ];
+ $expected = array( $this->expectedField( 'coupon', static::IS_NULL ) );
$this->assertQuerySuccessful( $response, $expected );
@@ -157,12 +157,12 @@ public function testCouponQueryAndIds() {
* Testing "ID" ID type.
*/
$this->loginAsShopManager();
- $variables = [
+ $variables = array(
'id' => $relay_id,
'idType' => 'ID',
- ];
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [ $this->expectedField( 'coupon.id', $relay_id ) ];
+ $expected = array( $this->expectedField( 'coupon.id', $relay_id ) );
$this->assertQuerySuccessful( $response, $expected );
@@ -171,10 +171,10 @@ public function testCouponQueryAndIds() {
*
* Testing "DATABASE_ID" ID type
*/
- $variables = [
+ $variables = array(
'id' => $coupon_id,
'idType' => 'DATABASE_ID',
- ];
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
$this->assertQuerySuccessful( $response, $expected );
@@ -184,33 +184,33 @@ public function testCouponQueryAndIds() {
*
* Testing "CODE" ID type.
*/
- $variables = [
+ $variables = array(
'id' => $coupon->get_code(),
'idType' => 'CODE',
- ];
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
$this->assertQuerySuccessful( $response, $expected );
}
public function testCouponsQueryAndWhereArgs() {
- $coupons = [
+ $coupons = array(
$this->factory->coupon->create(),
$this->factory->coupon->create(
- [
+ array(
'code' => '20off',
'amount' => 20,
'discount_type' => 'percent',
- ]
+ )
),
$this->factory->coupon->create(
- [
+ array(
'code' => 'testcode',
'amount' => 30,
'discount_type' => 'percent',
- ]
+ )
),
- ];
+ );
$query = '
query ($code: String, $include: [Int], $exclude: [Int]) {
@@ -229,9 +229,9 @@ public function testCouponsQueryAndWhereArgs() {
*/
$this->loginAsCustomer();
$response = $this->graphql( compact( 'query' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'coupons.nodes', static::IS_FALSY ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
@@ -244,11 +244,11 @@ public function testCouponsQueryAndWhereArgs() {
*/
$this->loginAsShopManager();
$response = $this->graphql( compact( 'query' ) );
- $expected = [
- $this->expectedNode( 'coupons.nodes', [ 'id' => $this->toRelayId( 'shop_coupon', $coupons['0'] ) ] ),
- $this->expectedNode( 'coupons.nodes', [ 'id' => $this->toRelayId( 'shop_coupon', $coupons['1'] ) ] ),
- $this->expectedNode( 'coupons.nodes', [ 'id' => $this->toRelayId( 'shop_coupon', $coupons['2'] ) ] ),
- ];
+ $expected = array(
+ $this->expectedNode( 'coupons.nodes', array( 'id' => $this->toRelayId( 'shop_coupon', $coupons['0'] ) ) ),
+ $this->expectedNode( 'coupons.nodes', array( 'id' => $this->toRelayId( 'shop_coupon', $coupons['1'] ) ) ),
+ $this->expectedNode( 'coupons.nodes', array( 'id' => $this->toRelayId( 'shop_coupon', $coupons['2'] ) ) ),
+ );
$this->assertQuerySuccessful( $response, $expected );
@@ -259,13 +259,13 @@ public function testCouponsQueryAndWhereArgs() {
*
* Tests 'code' where argument
*/
- $variables = [ 'code' => 'testcode' ];
+ $variables = array( 'code' => 'testcode' );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
- $this->expectedNode( 'coupons.nodes', [ 'id' => $this->toRelayId( 'shop_coupon', $coupons['2'] ) ] ),
- $this->not()->expectedNode( 'coupons.nodes', [ 'id' => $this->toRelayId( 'shop_coupon', $coupons['0'] ) ] ),
- $this->not()->expectedNode( 'coupons.nodes', [ 'id' => $this->toRelayId( 'shop_coupon', $coupons['1'] ) ] ),
- ];
+ $expected = array(
+ $this->expectedNode( 'coupons.nodes', array( 'id' => $this->toRelayId( 'shop_coupon', $coupons['2'] ) ) ),
+ $this->not()->expectedNode( 'coupons.nodes', array( 'id' => $this->toRelayId( 'shop_coupon', $coupons['0'] ) ) ),
+ $this->not()->expectedNode( 'coupons.nodes', array( 'id' => $this->toRelayId( 'shop_coupon', $coupons['1'] ) ) ),
+ );
$this->assertQuerySuccessful( $response, $expected );
@@ -276,13 +276,13 @@ public function testCouponsQueryAndWhereArgs() {
*
* Tests 'include' where argument
*/
- $variables = [ 'include' => $coupons[0] ];
+ $variables = array( 'include' => $coupons[0] );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
- $this->expectedNode( 'coupons.nodes', [ 'id' => $this->toRelayId( 'shop_coupon', $coupons['0'] ) ] ),
- $this->not()->expectedNode( 'coupons.nodes', [ 'id' => $this->toRelayId( 'shop_coupon', $coupons['1'] ) ] ),
- $this->not()->expectedNode( 'coupons.nodes', [ 'id' => $this->toRelayId( 'shop_coupon', $coupons['2'] ) ] ),
- ];
+ $expected = array(
+ $this->expectedNode( 'coupons.nodes', array( 'id' => $this->toRelayId( 'shop_coupon', $coupons['0'] ) ) ),
+ $this->not()->expectedNode( 'coupons.nodes', array( 'id' => $this->toRelayId( 'shop_coupon', $coupons['1'] ) ) ),
+ $this->not()->expectedNode( 'coupons.nodes', array( 'id' => $this->toRelayId( 'shop_coupon', $coupons['2'] ) ) ),
+ );
$this->assertQuerySuccessful( $response, $expected );
@@ -291,14 +291,14 @@ public function testCouponsQueryAndWhereArgs() {
*
* Tests 'exclude' where argument
*/
- $variables = [ 'exclude' => $coupons[0] ];
+ $variables = array( 'exclude' => $coupons[0] );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
- $this->not()->expectedNode( 'coupons.nodes', [ 'id' => $this->toRelayId( 'shop_coupon', $coupons['0'] ) ] ),
- $this->expectedNode( 'coupons.nodes', [ 'id' => $this->toRelayId( 'shop_coupon', $coupons['1'] ) ] ),
- $this->expectedNode( 'coupons.nodes', [ 'id' => $this->toRelayId( 'shop_coupon', $coupons['2'] ) ] ),
+ $expected = array(
+ $this->not()->expectedNode( 'coupons.nodes', array( 'id' => $this->toRelayId( 'shop_coupon', $coupons['0'] ) ) ),
+ $this->expectedNode( 'coupons.nodes', array( 'id' => $this->toRelayId( 'shop_coupon', $coupons['1'] ) ) ),
+ $this->expectedNode( 'coupons.nodes', array( 'id' => $this->toRelayId( 'shop_coupon', $coupons['2'] ) ) ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
}
diff --git a/tests/wpunit/CustomerMutationsTest.php b/tests/wpunit/CustomerMutationsTest.php
index 57d71fe5f..0c4493ab3 100644
--- a/tests/wpunit/CustomerMutationsTest.php
+++ b/tests/wpunit/CustomerMutationsTest.php
@@ -43,13 +43,13 @@ public function generateCustomerInput() {
$postcode = $this->faker->postcode();
$country = 'US';
- return [
+ return array(
'firstName' => $first_name,
'lastName' => $last_name,
'username' => $username,
'password' => $password,
'email' => $email,
- 'billing' => [
+ 'billing' => array(
'firstName' => $first_name,
'lastName' => $last_name,
'address1' => $address,
@@ -59,8 +59,8 @@ public function generateCustomerInput() {
'country' => $country,
'email' => $email,
'phone' => $phone,
- ],
- 'shipping' => [
+ ),
+ 'shipping' => array(
'firstName' => $first_name,
'lastName' => $last_name,
'address1' => $address,
@@ -69,12 +69,12 @@ public function generateCustomerInput() {
'postcode' => $postcode,
'country' => $country,
'phone' => $phone,
- ],
- ];
+ ),
+ );
}
private function empty_shipping() {
- return [
+ return array(
'firstName' => null,
'lastName' => null,
'company' => null,
@@ -85,11 +85,11 @@ private function empty_shipping() {
'postcode' => null,
'country' => null,
'phone' => null,
- ];
+ );
}
private function empty_billing() {
- return [
+ return array(
'firstName' => null,
'lastName' => null,
'company' => null,
@@ -101,7 +101,7 @@ private function empty_billing() {
'country' => null,
'email' => null,
'phone' => null,
- ];
+ );
}
private function executeRegisterCustomerMutation( $input ) {
@@ -150,7 +150,7 @@ private function executeRegisterCustomerMutation( $input ) {
}
';
- $variables = [ 'input' => $input ];
+ $variables = array( 'input' => $input );
return $this->graphql( compact( 'query', 'variables' ) );
}
@@ -194,7 +194,7 @@ private function executeUpdateCustomerMutation( $input ) {
}
';
- $variables = [ 'input' => $input ];
+ $variables = array( 'input' => $input );
return $this->graphql( compact( 'query', 'variables' ) );
}
@@ -212,10 +212,10 @@ public function testRegisterMutationWithoutCustomerInfo() {
$response = $this->executeRegisterCustomerMutation(
array_merge(
$customer_input,
- [
- 'billing' => [],
- 'shipping' => [],
- ]
+ array(
+ 'billing' => array(),
+ 'shipping' => array(),
+ )
)
);
@@ -223,12 +223,12 @@ public function testRegisterMutationWithoutCustomerInfo() {
$user = get_user_by( 'email', $customer_input['email'] );
$this->assertTrue( is_a( $user, WP_User::class ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'registerCustomer.authToken', \WPGraphQL\JWT_Authentication\Auth::get_token( $user ) ),
$this->expectedField( 'registerCustomer.refreshToken', \WPGraphQL\JWT_Authentication\Auth::get_refresh_token( $user ) ),
$this->expectedObject(
'registerCustomer.customer',
- [
+ array(
$this->expectedField( 'databaseId', $user->ID ),
$this->expectedField( 'email', $customer_input['email'] ),
$this->expectedField( 'username', $customer_input['username'] ),
@@ -236,10 +236,10 @@ public function testRegisterMutationWithoutCustomerInfo() {
$this->expectedField( 'lastName', $customer_input['lastName'] ),
$this->expectedField( 'billing', $this->empty_billing() ),
$this->expectedField( 'shipping', $this->empty_shipping() ),
- ]
+ )
),
$this->expectedField( 'registerCustomer.viewer.userId', $user->ID ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
}
@@ -258,21 +258,21 @@ public function testRegisterMutationWithBillingInfo() {
$response = $this->executeRegisterCustomerMutation(
array_merge(
$customer_input,
- [
- 'shipping' => [],
- ]
+ array(
+ 'shipping' => array(),
+ )
)
);
$user = get_user_by( 'email', $customer_input['email'] );
$this->assertTrue( is_a( $user, WP_User::class ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'registerCustomer.authToken', \WPGraphQL\JWT_Authentication\Auth::get_token( $user ) ),
$this->expectedField( 'registerCustomer.refreshToken', \WPGraphQL\JWT_Authentication\Auth::get_refresh_token( $user ) ),
$this->expectedObject(
'registerCustomer.customer',
- [
+ array(
$this->expectedField( 'databaseId', $user->ID ),
$this->expectedField( 'email', $customer_input['email'] ),
$this->expectedField( 'username', $customer_input['username'] ),
@@ -280,10 +280,10 @@ public function testRegisterMutationWithBillingInfo() {
$this->expectedField( 'lastName', $customer_input['lastName'] ),
$this->expectedField( 'billing', array_merge( $this->empty_billing(), $customer_input['billing'] ) ),
$this->expectedField( 'shipping', $this->empty_shipping() ),
- ]
+ )
),
$this->expectedField( 'registerCustomer.viewer.userId', $user->ID ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
}
@@ -302,22 +302,22 @@ public function testRegisterMutationWithShippingSameAsBillingInfo() {
$response = $this->executeRegisterCustomerMutation(
array_merge(
$customer_input,
- [
- 'shipping' => [],
+ array(
+ 'shipping' => array(),
'shippingSameAsBilling' => true,
- ]
+ )
)
);
$user = get_user_by( 'email', $customer_input['email'] );
$this->assertTrue( is_a( $user, WP_User::class ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'registerCustomer.authToken', \WPGraphQL\JWT_Authentication\Auth::get_token( $user ) ),
$this->expectedField( 'registerCustomer.refreshToken', \WPGraphQL\JWT_Authentication\Auth::get_refresh_token( $user ) ),
$this->expectedObject(
'registerCustomer.customer',
- [
+ array(
$this->expectedField( 'databaseId', $user->ID ),
$this->expectedField( 'email', $customer_input['email'] ),
$this->expectedField( 'username', $customer_input['username'] ),
@@ -331,10 +331,10 @@ public function testRegisterMutationWithShippingSameAsBillingInfo() {
array_intersect_key( $customer_input['billing'], $this->empty_shipping() )
)
),
- ]
+ )
),
$this->expectedField( 'registerCustomer.viewer.userId', $user->ID ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
}
@@ -355,12 +355,12 @@ public function testRegisterMutationWithBillingAndShippingInfo() {
$user = get_user_by( 'email', $customer_input['email'] );
$this->assertTrue( is_a( $user, WP_User::class ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'registerCustomer.authToken', \WPGraphQL\JWT_Authentication\Auth::get_token( $user ) ),
$this->expectedField( 'registerCustomer.refreshToken', \WPGraphQL\JWT_Authentication\Auth::get_refresh_token( $user ) ),
$this->expectedObject(
'registerCustomer.customer',
- [
+ array(
$this->expectedField( 'databaseId', $user->ID ),
$this->expectedField( 'email', $customer_input['email'] ),
$this->expectedField( 'username', $customer_input['username'] ),
@@ -368,10 +368,10 @@ public function testRegisterMutationWithBillingAndShippingInfo() {
$this->expectedField( 'lastName', $customer_input['lastName'] ),
$this->expectedField( 'billing', array_merge( $this->empty_billing(), $customer_input['billing'] ) ),
$this->expectedField( 'shipping', array_merge( $this->empty_shipping(), $customer_input['shipping'] ) ),
- ]
+ )
),
$this->expectedField( 'registerCustomer.viewer.userId', $user->ID ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
}
@@ -392,10 +392,10 @@ public function testUpdateMutation() {
$user = get_user_by( 'email', $initial_customer_input['email'] );
$this->assertTrue( is_a( $user, WP_User::class ) );
- $expected = [
+ $expected = array(
$this->expectedObject(
'registerCustomer.customer',
- [
+ array(
$this->expectedField( 'databaseId', $user->ID ),
$this->expectedField( 'email', $initial_customer_input['email'] ),
$this->expectedField( 'username', $initial_customer_input['username'] ),
@@ -403,9 +403,9 @@ public function testUpdateMutation() {
$this->expectedField( 'lastName', $initial_customer_input['lastName'] ),
$this->expectedField( 'billing', array_merge( $this->empty_billing(), $initial_customer_input['billing'] ) ),
$this->expectedField( 'shipping', array_merge( $this->empty_shipping(), $initial_customer_input['shipping'] ) ),
- ]
+ )
),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
@@ -417,16 +417,16 @@ public function testUpdateMutation() {
$response = $this->executeUpdateCustomerMutation(
array_merge(
$customer_input,
- [
+ array(
'id' => $this->toRelayId( 'customer', $user->ID ),
- ]
+ )
)
);
- $expected = [
+ $expected = array(
$this->expectedObject(
'updateCustomer.customer',
- [
+ array(
$this->expectedField( 'databaseId', $user->ID ),
$this->expectedField( 'email', $customer_input['email'] ),
$this->expectedField( 'username', $initial_customer_input['username'] ),
@@ -434,9 +434,9 @@ public function testUpdateMutation() {
$this->expectedField( 'lastName', $customer_input['lastName'] ),
$this->expectedField( 'billing', array_merge( $this->empty_billing(), $customer_input['billing'] ) ),
$this->expectedField( 'shipping', array_merge( $this->empty_shipping(), $customer_input['shipping'] ) ),
- ]
+ )
),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
}
@@ -457,10 +457,10 @@ public function testUpdateMutationWithoutID() {
$user = get_user_by( 'email', $initial_customer_input['email'] );
$this->assertTrue( is_a( $user, WP_User::class ) );
- $expected = [
+ $expected = array(
$this->expectedObject(
'registerCustomer.customer',
- [
+ array(
$this->expectedField( 'databaseId', $user->ID ),
$this->expectedField( 'email', $initial_customer_input['email'] ),
$this->expectedField( 'username', $initial_customer_input['username'] ),
@@ -468,9 +468,9 @@ public function testUpdateMutationWithoutID() {
$this->expectedField( 'lastName', $initial_customer_input['lastName'] ),
$this->expectedField( 'billing', array_merge( $this->empty_billing(), $initial_customer_input['billing'] ) ),
$this->expectedField( 'shipping', array_merge( $this->empty_shipping(), $initial_customer_input['shipping'] ) ),
- ]
+ )
),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
@@ -483,10 +483,10 @@ public function testUpdateMutationWithoutID() {
unset( $customer_input['username'] );
$response = $this->executeUpdateCustomerMutation( $customer_input );
- $expected = [
+ $expected = array(
$this->expectedObject(
'updateCustomer.customer',
- [
+ array(
$this->expectedField( 'databaseId', $user->ID ),
$this->expectedField( 'email', $customer_input['email'] ),
$this->expectedField( 'username', $initial_customer_input['username'] ),
@@ -494,9 +494,9 @@ public function testUpdateMutationWithoutID() {
$this->expectedField( 'lastName', $customer_input['lastName'] ),
$this->expectedField( 'billing', array_merge( $this->empty_billing(), $customer_input['billing'] ) ),
$this->expectedField( 'shipping', array_merge( $this->empty_shipping(), $customer_input['shipping'] ) ),
- ]
+ )
),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
}
@@ -515,9 +515,9 @@ public function testUpdateMutationWithShippingSameAsBilling() {
$this->executeRegisterCustomerMutation(
array_merge(
$customer_input,
- [
- 'shipping' => [],
- ]
+ array(
+ 'shipping' => array(),
+ )
)
);
@@ -525,17 +525,17 @@ public function testUpdateMutationWithShippingSameAsBilling() {
$this->assertTrue( is_a( $user, WP_User::class ) );
$response = $this->executeUpdateCustomerMutation(
- [
+ array(
'clientMutationId' => 'someId',
'id' => $this->toRelayId( 'customer', $user->ID ),
'shippingSameAsBilling' => true,
- ]
+ )
);
- $expected = [
+ $expected = array(
$this->expectedObject(
'updateCustomer.customer',
- [
+ array(
$this->expectedField( 'databaseId', $user->ID ),
$this->expectedField( 'email', $customer_input['email'] ),
$this->expectedField( 'username', $customer_input['username'] ),
@@ -549,9 +549,9 @@ public function testUpdateMutationWithShippingSameAsBilling() {
array_intersect_key( $customer_input['billing'], $this->empty_shipping() )
)
),
- ]
+ )
),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
}
@@ -568,29 +568,29 @@ public function testRegisterMutationWithoutAnyInfo() {
* Tests mutation without a providing an username and password.
*/
$response = $this->executeRegisterCustomerMutation(
- [
+ array(
'email' => $customer_input['email'],
'firstName' => $customer_input['firstName'],
'lastName' => $customer_input['lastName'],
- ]
+ )
);
$user = get_user_by( 'email', $customer_input['email'] );
$this->assertTrue( is_a( $user, WP_User::class ) );
- $expected = [
+ $expected = array(
$this->expectedObject(
'registerCustomer.customer',
- [
+ array(
$this->expectedField( 'databaseId', $user->ID ),
$this->expectedField( 'email', $customer_input['email'] ),
$this->expectedField( 'firstName', $customer_input['firstName'] ),
$this->expectedField( 'lastName', $customer_input['lastName'] ),
$this->expectedField( 'billing', $this->empty_billing() ),
$this->expectedField( 'shipping', $this->empty_shipping() ),
- ]
+ )
),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
}
@@ -615,40 +615,40 @@ public function testCustomerMutationsWithMeta() {
}
}
';
- $variables = [
- 'input' => [
+ $variables = array(
+ 'input' => array(
'clientMutationId' => 'some_id',
'email' => 'user@woographql.test',
- 'metaData' => [
- [
+ 'metaData' => array(
+ array(
'key' => 'test_meta_key',
'value' => 'test_meta_value',
- ],
- ],
- ],
- ];
+ ),
+ ),
+ ),
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
$user = get_user_by( 'email', 'user@woographql.test' );
$this->assertTrue( is_a( $user, WP_User::class ) );
- $expected = [
+ $expected = array(
$this->expectedObject(
'registerCustomer.customer',
- [
+ array(
$this->expectedField( 'databaseId', $user->ID ),
$this->expectedField( 'email', 'user@woographql.test' ),
$this->expectedNode(
'metaData',
- [
+ array(
$this->expectedField( 'key', 'test_meta_key' ),
$this->expectedField( 'value', 'test_meta_value' ),
- ]
+ )
),
- ]
+ )
),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
@@ -673,36 +673,36 @@ public function testCustomerMutationsWithMeta() {
';
$this->loginAs( $user->ID );
\WC()->initialize_session();
- $variables = [
- 'input' => [
+ $variables = array(
+ 'input' => array(
'clientMutationId' => 'some_id',
'id' => $this->toRelayId( 'customer', $user->ID ),
- 'metaData' => [
- [
+ 'metaData' => array(
+ array(
'key' => 'test_meta_key',
'value' => 'new_meta_value',
- ],
- ],
- ],
- ];
+ ),
+ ),
+ ),
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedObject(
'updateCustomer.customer',
- [
+ array(
$this->expectedField( 'databaseId', $user->ID ),
$this->expectedField( 'email', 'user@woographql.test' ),
$this->expectedNode(
'metaData',
- [
+ array(
$this->expectedField( 'key', 'test_meta_key' ),
$this->expectedField( 'value', 'new_meta_value' ),
- ]
+ )
),
- ]
+ )
),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
@@ -726,34 +726,34 @@ public function testCustomerMutationsWithMeta() {
';
$this->loginAs( 0 );
\WC()->initialize_session();
- $variables = [
- 'input' => [
+ $variables = array(
+ 'input' => array(
'clientMutationId' => 'some_id',
- 'metaData' => [
- [
+ 'metaData' => array(
+ array(
'key' => 'test_meta_key',
'value' => 'test_meta_value',
- ],
- ],
- ],
- ];
+ ),
+ ),
+ ),
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedObject(
'updateCustomer.customer',
- [
+ array(
$this->expectedField( 'id', 'guest' ),
$this->expectedNode(
'metaData',
- [
+ array(
$this->expectedField( 'key', 'test_meta_key' ),
$this->expectedField( 'value', 'test_meta_value' ),
- ]
+ )
),
- ]
+ )
),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
}
diff --git a/tests/wpunit/CustomerQueriesTest.php b/tests/wpunit/CustomerQueriesTest.php
index 4e7fa34ac..711fbdc08 100644
--- a/tests/wpunit/CustomerQueriesTest.php
+++ b/tests/wpunit/CustomerQueriesTest.php
@@ -14,10 +14,10 @@ public function expectedCustomerData( $id ) {
$billing = $customer->get_billing();
$shipping = $customer->get_shipping();
- return [
+ return array(
$this->expectedObject(
'customer',
- [
+ array(
$this->expectedField( 'id', $this->toRelayId( 'user', $id ) ),
$this->expectedField( 'databaseId', $id ),
$this->expectedField( 'isVatExempt', $customer->get_is_vat_exempt() ),
@@ -41,7 +41,7 @@ public function expectedCustomerData( $id ) {
),
$this->expectedObject(
'billing',
- [
+ array(
$this->expectedField( 'firstName', $this->maybe( $billing['first_name'] ) ),
$this->expectedField( 'lastName', $this->maybe( $billing['last_name'] ) ),
$this->expectedField( 'company', $this->maybe( $billing['company'] ) ),
@@ -51,11 +51,11 @@ public function expectedCustomerData( $id ) {
$this->expectedField( 'postcode', $this->maybe( $billing['postcode'] ) ),
$this->expectedField( 'email', $this->maybe( $billing['email'] ) ),
$this->expectedField( 'phone', $this->maybe( $billing['phone'] ) ),
- ]
+ )
),
$this->expectedObject(
'shipping',
- [
+ array(
$this->expectedField( 'firstName', $this->maybe( $shipping['first_name'] ) ),
$this->expectedField( 'lastName', $this->maybe( $shipping['last_name'] ) ),
$this->expectedField( 'company', $this->maybe( $shipping['company'] ) ),
@@ -63,7 +63,7 @@ public function expectedCustomerData( $id ) {
$this->expectedField( 'address2', $this->maybe( $shipping['address_2'] ) ),
$this->expectedField( 'city', $this->maybe( $shipping['city'] ) ),
$this->expectedField( 'postcode', $this->maybe( $shipping['postcode'] ) ),
- ]
+ )
),
$this->expectedField( 'isPayingCustomer', $customer->get_is_paying_customer() ),
$this->expectedField(
@@ -78,9 +78,9 @@ public function expectedCustomerData( $id ) {
? \WPGraphQL\JWT_Authentication\Auth::get_refresh_token( $wp_user )
: static::IS_NULL
),
- ]
+ )
),
- ];
+ );
}
// tests
@@ -142,12 +142,12 @@ public function testCustomerQueryAndArgs() {
* Query should return null value due to lack of permissions.
*/
$this->loginAsCustomer();
- $variables = [ 'id' => $this->toRelayId( 'user', $new_customer_id ) ];
+ $variables = array( 'id' => $this->toRelayId( 'user', $new_customer_id ) );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedErrorPath( 'customer' ),
$this->expectedField( 'customer', static::IS_NULL ),
- ];
+ );
$this->assertQueryError( $response, $expected );
@@ -159,7 +159,7 @@ public function testCustomerQueryAndArgs() {
*
* Query should return requested data because user queried themselves.
*/
- $variables = [ 'id' => $this->toRelayId( 'user', $this->customer ) ];
+ $variables = array( 'id' => $this->toRelayId( 'user', $this->customer ) );
$response = $this->graphql( compact( 'query', 'variables' ) );
$expected = $this->expectedCustomerData( $this->customer );
@@ -175,15 +175,15 @@ public function testCustomerQueryAndArgs() {
* but should not have access to JWT fields.
*/
$this->loginAsShopManager();
- $variables = [ 'id' => $this->toRelayId( 'user', $new_customer_id ) ];
+ $variables = array( 'id' => $this->toRelayId( 'user', $new_customer_id ) );
$response = $this->graphql( compact( 'query', 'variables' ) );
$expected = array_merge(
- [
+ array(
$this->expectedErrorPath( 'customer.jwtAuthToken' ),
$this->expectedField( 'customer.jwtAuthToken', static::IS_NULL ),
$this->expectedErrorPath( 'customer.jwtRefreshToken' ),
$this->expectedField( 'customer.jwtRefreshToken', static::IS_NULL ),
- ],
+ ),
$this->expectedCustomerData( $new_customer_id )
);
@@ -212,7 +212,7 @@ public function testCustomerQueryAndArgs() {
* Query should return requested data because user queried themselves.
*/
$this->loginAs( $new_customer_id );
- $variables = [ 'customerId' => $new_customer_id ];
+ $variables = array( 'customerId' => $new_customer_id );
$response = $this->graphql( compact( 'query', 'variables' ) );
$this->assertQuerySuccessful( $response, $expected );
@@ -226,12 +226,12 @@ public function testCustomerQueryAndArgs() {
* Query should return null value due to lack of permissions..
*/
$this->loginAsCustomer();
- $variables = [ 'customerId' => $new_customer_id ];
+ $variables = array( 'customerId' => $new_customer_id );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedErrorPath( 'customer' ),
$this->expectedField( 'customer', static::IS_NULL ),
- ];
+ );
$this->assertQueryError( $response, $expected );
@@ -240,17 +240,17 @@ public function testCustomerQueryAndArgs() {
}
public function testCustomersQueryAndWhereArgs() {
- $users = [
+ $users = array(
$this->factory->customer->create(
- [
+ array(
'email' => 'gotcha@example.com',
'username' => 'megaman8080',
- ]
+ )
),
$this->factory->customer->create(),
$this->factory->customer->create(),
$this->factory->customer->create(),
- ];
+ );
$query = '
query (
@@ -284,7 +284,7 @@ public function testCustomersQueryAndWhereArgs() {
*/
$this->loginAs( $users[0] );
$response = $this->graphql( compact( 'query' ) );
- $expected = [ $this->expectedField( 'customers.nodes', [] ) ];
+ $expected = array( $this->expectedField( 'customers.nodes', array() ) );
$this->assertQuerySuccessful( $response, $expected );
@@ -295,7 +295,7 @@ public function testCustomersQueryAndWhereArgs() {
*/
$this->loginAsShopManager();
$response = $this->graphql( compact( 'query' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'customers.nodes.#.databaseId', $users[0] ),
$this->expectedField( 'customers.nodes.#.databaseId', $users[1] ),
$this->expectedField( 'customers.nodes.#.databaseId', $users[2] ),
@@ -304,7 +304,7 @@ public function testCustomersQueryAndWhereArgs() {
$this->expectedField( 'customers.nodes.1.billing.email', static::NOT_NULL ),
$this->expectedField( 'customers.nodes.2.billing.email', static::NOT_NULL ),
$this->expectedField( 'customers.nodes.3.billing.email', static::NOT_NULL ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
@@ -313,12 +313,12 @@ public function testCustomersQueryAndWhereArgs() {
*
* Tests "search" where argument.
*/
- $variables = [ 'search' => 'megaman8080' ];
+ $variables = array( 'search' => 'megaman8080' );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'customers.nodes.0.databaseId', $users[0] ),
$this->expectedField( 'customers.nodes.0.billing.email', static::NOT_NULL ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
@@ -327,12 +327,12 @@ public function testCustomersQueryAndWhereArgs() {
*
* Tests "include" where argument.
*/
- $variables = [ 'include' => [ $users[2] ] ];
+ $variables = array( 'include' => array( $users[2] ) );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'customers.nodes.0.databaseId', $users[2] ),
$this->expectedField( 'customers.nodes.0.billing.email', static::NOT_NULL ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
@@ -341,9 +341,9 @@ public function testCustomersQueryAndWhereArgs() {
*
* Tests "exclude" where argument.
*/
- $variables = [ 'exclude' => [ $users[2] ] ];
+ $variables = array( 'exclude' => array( $users[2] ) );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'customers.nodes.#.databaseId', $users[0] ),
$this->expectedField( 'customers.nodes.#.databaseId', $users[1] ),
$this->expectedField( 'customers.nodes.#.databaseId', $users[3] ),
@@ -351,7 +351,7 @@ public function testCustomersQueryAndWhereArgs() {
$this->expectedField( 'customers.nodes.1.billing.email', static::NOT_NULL ),
$this->expectedField( 'customers.nodes.2.billing.email', static::NOT_NULL ),
$this->not()->expectedField( 'customers.nodes.#.databaseId', $users[2] ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
@@ -360,14 +360,14 @@ public function testCustomersQueryAndWhereArgs() {
*
* Tests "email" where argument.
*/
- $variables = [ 'email' => 'gotcha@example.com' ];
+ $variables = array( 'email' => 'gotcha@example.com' );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'customers.nodes.0.databaseId', $users[0] ),
$this->not()->expectedField( 'customers.nodes.#.databaseId', $users[1] ),
$this->not()->expectedField( 'customers.nodes.#.databaseId', $users[2] ),
$this->not()->expectedField( 'customers.nodes.#.databaseId', $users[3] ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
@@ -376,21 +376,21 @@ public function testCustomersQueryAndWhereArgs() {
*
* Tests "orderby" and "order" where arguments.
*/
- $variables = [
+ $variables = array(
'orderby' => 'USERNAME',
'order' => 'ASC',
- ];
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
$all_users = get_users(
- [
+ array(
'fields' => 'ID',
'role' => 'customer',
'orderby' => 'username',
'order' => 'ASC',
- ]
+ )
);
- $expected = [];
+ $expected = array();
foreach ( $all_users as $index => $user_id ) {
$expected[] = $this->expectedField(
"customers.nodes.{$index}.databaseId",
@@ -405,19 +405,19 @@ public function testCustomerToOrdersConnection() {
$new_customer_id = $this->factory->customer->create();
$order_1 = $this->factory->order->createNew(
- [ 'customer_id' => $this->customer ]
+ array( 'customer_id' => $this->customer )
);
$order_2 = $this->factory->order->createNew(
- [ 'customer_id' => $new_customer_id ]
+ array( 'customer_id' => $new_customer_id )
);
$guest_customer = new \WC_Customer();
$guest_customer->set_billing_email( 'test@test.com' );
$order_3 = $this->factory->order->createNew(
- [
+ array(
'customer_id' => $guest_customer->get_id(),
'billing_email' => $guest_customer->get_billing_email(),
- ]
+ )
);
$query = '
@@ -441,9 +441,9 @@ public function testCustomerToOrdersConnection() {
*/
$this->loginAsCustomer();
$response = $this->graphql( compact( 'query' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'customer.orders.nodes.#.databaseId', $order_1 ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
@@ -458,9 +458,9 @@ public function testCustomerToOrdersConnection() {
$this->loginAs( 0 );
WC()->customer = $guest_customer;
$response = $this->graphql( compact( 'query' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'customer.orders.nodes.#.databaseId', $order_3 ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
}
@@ -474,20 +474,20 @@ public function testCustomerAvailablePaymentMethodsField() {
$expiry_year = gmdate( 'Y', strtotime( '+1 year' ) );
$token_cc = $this->factory->payment_token->createCCToken(
$customer_id,
- [
+ array(
'last4' => 1234,
'expiry_month' => $expiry_month,
'expiry_year' => $expiry_year,
'card_type' => 'visa',
'token' => time(),
- ]
+ )
);
$token_ec = $this->factory->payment_token->createECheckToken(
$customer_id,
- [
+ array(
'last4' => 4567,
'token' => time(),
- ]
+ )
);
// Create query.
@@ -528,19 +528,19 @@ public function testCustomerAvailablePaymentMethodsField() {
/**
* Assert tokens are inaccessible as guest or admin
*/
- $variables = [ 'id' => $this->toRelayId( 'user', $customer_id ) ];
+ $variables = array( 'id' => $this->toRelayId( 'user', $customer_id ) );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [ $this->expectedField( 'customer', static::IS_NULL ) ];
+ $expected = array( $this->expectedField( 'customer', static::IS_NULL ) );
$this->assertQueryError( $response, $expected );
// Again, as admin.
$this->loginAsShopManager();
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'customer.id', $this->toRelayId( 'user', $customer_id ) ),
$this->expectedField( 'customer.availablePaymentMethods', static::IS_NULL ),
- ];
+ );
$this->assertQueryError( $response, $expected );
@@ -549,66 +549,66 @@ public function testCustomerAvailablePaymentMethodsField() {
*/
$this->loginAs( $customer_id );
$response = $this->graphql( compact( 'query' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'customer.id', $this->toRelayId( 'user', $customer_id ) ),
$this->expectedNode(
'customer.availablePaymentMethods',
- [
+ array(
$this->expectedField( 'id', $this->toRelayId( 'token', $token_cc->get_id() ) ),
$this->expectedField( 'tokenId', $token_cc->get_id() ),
$this->expectedField( 'last4', 1234 ),
$this->expectedField( 'expiryMonth', $expiry_month ),
$this->expectedField( 'expiryYear', $expiry_year ),
$this->expectedField( 'cardType', 'visa' ),
- ]
+ )
),
$this->expectedNode(
'customer.availablePaymentMethodsCC',
- [
+ array(
$this->expectedField( 'id', $this->toRelayId( 'token', $token_cc->get_id() ) ),
$this->expectedField( 'tokenId', $token_cc->get_id() ),
$this->expectedField( 'last4', 1234 ),
$this->expectedField( 'expiryMonth', $expiry_month ),
$this->expectedField( 'expiryYear', $expiry_year ),
$this->expectedField( 'cardType', 'visa' ),
- ]
+ )
),
$this->expectedNode(
'customer.availablePaymentMethodsEC',
- [
+ array(
$this->not()->expectedField( 'id', $this->toRelayId( 'token', $token_cc->get_id() ) ),
$this->not()->expectedField( 'tokenId', $token_cc->get_id() ),
$this->not()->expectedField( 'last4', 1234 ),
$this->not()->expectedField( 'expiryMonth', $expiry_month ),
$this->not()->expectedField( 'expiryYear', $expiry_year ),
$this->not()->expectedField( 'cardType', 'visa' ),
- ]
+ )
),
$this->expectedNode(
'customer.availablePaymentMethods',
- [
+ array(
$this->expectedField( 'id', $this->toRelayId( 'token', $token_ec->get_id() ) ),
$this->expectedField( 'tokenId', $token_ec->get_id() ),
$this->expectedField( 'last4', 4567 ),
- ]
+ )
),
$this->expectedNode(
'customer.availablePaymentMethodsCC',
- [
+ array(
$this->not()->expectedField( 'id', $this->toRelayId( 'token', $token_ec->get_id() ) ),
$this->not()->expectedField( 'tokenId', $token_ec->get_id() ),
$this->not()->expectedField( 'last4', 4567 ),
- ]
+ )
),
$this->expectedNode(
'customer.availablePaymentMethodsEC',
- [
+ array(
$this->expectedField( 'id', $this->toRelayId( 'token', $token_ec->get_id() ) ),
$this->expectedField( 'tokenId', $token_ec->get_id() ),
$this->expectedField( 'last4', 4567 ),
- ]
+ )
),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
}
@@ -645,9 +645,9 @@ static function ( $session_class ) {
* Assert NULL values when querying as admin
*/
$this->loginAsShopManager();
- $variables = [ 'id' => $this->toRelayId( 'user', $customer_id ) ];
+ $variables = array( 'id' => $this->toRelayId( 'user', $customer_id ) );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'customer.id', $this->toRelayId( 'user', $customer_id ) ),
$this->expectedField( 'customer.cartUrl', static::IS_NULL ),
$this->expectedField( 'customer.cartNonce', static::IS_NULL ),
@@ -655,7 +655,7 @@ static function ( $session_class ) {
$this->expectedField( 'customer.checkoutNonce', static::IS_NULL ),
$this->expectedField( 'customer.addPaymentMethodUrl', static::IS_NULL ),
$this->expectedField( 'customer.addPaymentMethodNonce', static::IS_NULL ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
/**
@@ -663,7 +663,7 @@ static function ( $session_class ) {
*/
$this->loginAs( $customer_id );
$response = $this->graphql( compact( 'query' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'customer.id', $this->toRelayId( 'user', $customer_id ) ),
$this->expectedField( 'customer.cartUrl', static::NOT_NULL ),
$this->expectedField( 'customer.cartNonce', static::NOT_NULL ),
@@ -671,7 +671,7 @@ static function ( $session_class ) {
$this->expectedField( 'customer.checkoutNonce', static::NOT_NULL ),
$this->expectedField( 'customer.addPaymentMethodUrl', static::NOT_NULL ),
$this->expectedField( 'customer.addPaymentMethodNonce', static::NOT_NULL ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
}
}
diff --git a/tests/wpunit/DownloadableItemQueriesTest.php b/tests/wpunit/DownloadableItemQueriesTest.php
index 76bd11b1c..ad684b0fa 100644
--- a/tests/wpunit/DownloadableItemQueriesTest.php
+++ b/tests/wpunit/DownloadableItemQueriesTest.php
@@ -11,24 +11,24 @@ public function setUp(): void {
// tests
public function testOrderToDownloadableItemsQuery() {
$downloadable_product = $this->factory->product->createSimple(
- [
+ array(
'downloadable' => true,
- 'downloads' => [ $this->factory->product->createDownload() ],
- ]
+ 'downloads' => array( $this->factory->product->createDownload() ),
+ )
);
$order_id = $this->factory->order->createNew(
- [
+ array(
'status' => 'completed',
'customer_id' => $this->customer,
- ],
- [
- 'line_items' => [
- [
+ ),
+ array(
+ 'line_items' => array(
+ array(
'product' => $downloadable_product,
'qty' => 1,
- ],
- ],
- ]
+ ),
+ ),
+ )
);
// Force download permission updated.
@@ -74,10 +74,10 @@ public function testOrderToDownloadableItemsQuery() {
function ( $item ) {
return $this->expectedNode(
'customer.orders.nodes',
- [
+ array(
$this->expectedNode(
'downloadableItems.nodes',
- [
+ array(
$this->expectedField( 'url', $item['download_url'] ),
$this->expectedField( 'accessExpires', $item['access_expires'] ),
$this->expectedField( 'downloadId', $item['download_id'] ),
@@ -90,9 +90,9 @@ function ( $item ) {
$this->expectedField( 'name', $item['download_name'] ),
$this->expectedField( 'product.databaseId', $item['product_id'] ),
$this->expectedField( 'download.downloadId', $item['download_id'] ),
- ]
+ )
),
- ],
+ ),
0
);
},
@@ -104,48 +104,48 @@ function ( $item ) {
public function testOrderToDownloadableItemsQueryArgs() {
$valid_product = $this->factory->product->createSimple(
- [
+ array(
'downloadable' => true,
- 'downloads' => [ $this->factory->product->createDownload() ],
- ]
+ 'downloads' => array( $this->factory->product->createDownload() ),
+ )
);
$downloadable_product = $this->factory->product->createSimple(
- [
+ array(
'download_expiry' => 5,
'download_limit' => 3,
'downloadable' => true,
- 'downloads' => [ $this->factory->product->createDownload() ],
- ]
+ 'downloads' => array( $this->factory->product->createDownload() ),
+ )
);
$downloaded_product = $this->factory->product->createSimple(
- [
+ array(
'download_limit' => 0,
'downloadable' => true,
- 'downloads' => [ $this->factory->product->createDownload() ],
- ]
+ 'downloads' => array( $this->factory->product->createDownload() ),
+ )
);
$order_id = $this->factory->order->createNew(
- [
+ array(
'status' => 'completed',
'customer_id' => $this->customer,
- ],
- [
- 'line_items' => [
- [
+ ),
+ array(
+ 'line_items' => array(
+ array(
'product' => $valid_product,
'qty' => 1,
- ],
- [
+ ),
+ array(
'product' => $downloadable_product,
'qty' => 1,
- ],
- [
+ ),
+ array(
'product' => $downloaded_product,
'qty' => 1,
- ],
- ],
- ]
+ ),
+ ),
+ )
);
// Force download permission updated.
@@ -175,28 +175,28 @@ public function testOrderToDownloadableItemsQueryArgs() {
* Tests "active" whereArg
*/
$this->loginAsCustomer();
- $variables = [ 'active' => true ];
+ $variables = array( 'active' => true );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedNode(
'customer.orders.nodes',
- [
+ array(
$this->expectedNode(
'downloadableItems.nodes',
- [ $this->expectedField( 'product.databaseId', $valid_product ) ]
+ array( $this->expectedField( 'product.databaseId', $valid_product ) )
),
$this->expectedNode(
'downloadableItems.nodes',
- [ $this->expectedField( 'product.databaseId', $downloadable_product ) ]
+ array( $this->expectedField( 'product.databaseId', $downloadable_product ) )
),
$this->not()->expectedNode(
'downloadableItems.nodes',
- [ $this->expectedField( 'product.databaseId', $downloaded_product ) ]
+ array( $this->expectedField( 'product.databaseId', $downloaded_product ) )
),
- ],
+ ),
0
),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
@@ -205,28 +205,28 @@ public function testOrderToDownloadableItemsQueryArgs() {
*
* Tests "active" whereArg reversed
*/
- $variables = [ 'active' => false ];
+ $variables = array( 'active' => false );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedNode(
'customer.orders.nodes',
- [
+ array(
$this->expectedNode(
'downloadableItems.nodes',
- [ $this->expectedField( 'product.databaseId', $downloaded_product ) ]
+ array( $this->expectedField( 'product.databaseId', $downloaded_product ) )
),
$this->not()->expectedNode(
'downloadableItems.nodes',
- [ $this->expectedField( 'product.databaseId', $valid_product ) ]
+ array( $this->expectedField( 'product.databaseId', $valid_product ) )
),
$this->not()->expectedNode(
'downloadableItems.nodes',
- [ $this->expectedField( 'product.databaseId', $downloadable_product ) ]
+ array( $this->expectedField( 'product.databaseId', $downloadable_product ) )
),
- ],
+ ),
0
),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
@@ -235,28 +235,28 @@ public function testOrderToDownloadableItemsQueryArgs() {
*
* Tests "hasDownloadsRemaining" whereArg
*/
- $variables = [ 'hasDownloadsRemaining' => true ];
+ $variables = array( 'hasDownloadsRemaining' => true );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedNode(
'customer.orders.nodes',
- [
+ array(
$this->not()->expectedNode(
'downloadableItems.nodes',
- [ $this->expectedField( 'product.databaseId', $downloaded_product ) ]
+ array( $this->expectedField( 'product.databaseId', $downloaded_product ) )
),
$this->expectedNode(
'downloadableItems.nodes',
- [ $this->expectedField( 'product.databaseId', $valid_product ) ]
+ array( $this->expectedField( 'product.databaseId', $valid_product ) )
),
$this->expectedNode(
'downloadableItems.nodes',
- [ $this->expectedField( 'product.databaseId', $downloadable_product ) ]
+ array( $this->expectedField( 'product.databaseId', $downloadable_product ) )
),
- ],
+ ),
0
),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
@@ -265,52 +265,52 @@ public function testOrderToDownloadableItemsQueryArgs() {
*
* Tests "hasDownloadsRemaining" whereArg reversed
*/
- $variables = [ 'hasDownloadsRemaining' => false ];
+ $variables = array( 'hasDownloadsRemaining' => false );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedNode(
'customer.orders.nodes',
- [
+ array(
$this->expectedNode(
'downloadableItems.nodes',
- [ $this->expectedField( 'product.databaseId', $downloaded_product ) ]
+ array( $this->expectedField( 'product.databaseId', $downloaded_product ) )
),
$this->not()->expectedNode(
'downloadableItems.nodes',
- [ $this->expectedField( 'product.databaseId', $valid_product ) ]
+ array( $this->expectedField( 'product.databaseId', $valid_product ) )
),
$this->not()->expectedNode(
'downloadableItems.nodes',
- [ $this->expectedField( 'product.databaseId', $downloadable_product ) ]
+ array( $this->expectedField( 'product.databaseId', $downloadable_product ) )
),
- ],
+ ),
0
),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
}
public function testCustomerToDownloadableItemsQuery() {
$downloadable_product = $this->factory->product->createSimple(
- [
+ array(
'downloadable' => true,
- 'downloads' => [ $this->factory->product->createDownload() ],
- ]
+ 'downloads' => array( $this->factory->product->createDownload() ),
+ )
);
$order_id = $this->factory->order->createNew(
- [
+ array(
'status' => 'completed',
'customer_id' => $this->customer,
- ],
- [
- 'line_items' => [
- [
+ ),
+ array(
+ 'line_items' => array(
+ array(
'product' => $downloadable_product,
'qty' => 1,
- ],
- ],
- ]
+ ),
+ ),
+ )
);
// Force download permission updated.
@@ -351,7 +351,7 @@ public function testCustomerToDownloadableItemsQuery() {
function ( $item ) {
return $this->expectedNode(
'customer.downloadableItems.nodes',
- [
+ array(
$this->expectedField( 'url', $item['download_url'] ),
$this->expectedField(
'accessExpires',
@@ -367,7 +367,7 @@ function ( $item ) {
$this->expectedField( 'name', $item['download_name'] ),
$this->expectedField( 'product.databaseId', $item['product_id'] ),
$this->expectedField( 'download.downloadId', $item['download_id'] ),
- ],
+ ),
0
);
},
diff --git a/tests/wpunit/IntrospectionQueryTest.php b/tests/wpunit/IntrospectionQueryTest.php
index 34ec34d75..d9f3629e1 100644
--- a/tests/wpunit/IntrospectionQueryTest.php
+++ b/tests/wpunit/IntrospectionQueryTest.php
@@ -7,7 +7,7 @@ public function setUp(): void {
$settings = get_option( 'graphql_general_settings' );
if ( ! $settings ) {
- $settings = [];
+ $settings = array();
}
$settings['public_introspection_enabled'] = 'on';
update_option( 'graphql_general_settings', $settings );
@@ -36,7 +36,7 @@ public function testSchema() {
// Test introspection query.
public function testIntrospectionQuery() {
$query = \GraphQL\Type\Introspection::getIntrospectionQuery();
- $results = graphql( [ 'query' => $query ] );
+ $results = graphql( array( 'query' => $query ) );
$this->assertArrayNotHasKey( 'errors', $results );
}
diff --git a/tests/wpunit/MetaDataQueriesTest.php b/tests/wpunit/MetaDataQueriesTest.php
index ba0682c89..b0cc47496 100644
--- a/tests/wpunit/MetaDataQueriesTest.php
+++ b/tests/wpunit/MetaDataQueriesTest.php
@@ -7,20 +7,20 @@ public function testCartMetaDataQueries() {
// Create Variation Product.
$product_ids = $this->factory->product_variation->createSome();
// Create Cart Item with meta data.
- $meta_data = [
+ $meta_data = array(
'meta_1' => 'test_meta_1',
'meta_2' => 'test_meta_2',
- ];
+ );
// Add item to cart.
$cart_item_key = $this->factory->cart->add(
- [
+ array(
'product_id' => $product_ids['product'],
'quantity' => 2,
'variation_id' => $product_ids['variations'][0],
- 'variation' => [ 'attribute_pa_color' => 'red' ],
+ 'variation' => array( 'attribute_pa_color' => 'red' ),
'cart_item_data' => $meta_data,
- ]
+ )
)[0];
$query = '
@@ -45,28 +45,28 @@ public function testCartMetaDataQueries() {
* Query w/o filter
*/
$response = $this->graphql( compact( 'query' ) );
- $expected = [
+ $expected = array(
$this->expectedObject(
'cart.contents.nodes.0',
- [
+ array(
$this->expectedField( 'key', $cart_item_key ),
$this->expectedObject(
'extraData.#',
- [
+ array(
$this->expectedField( 'key', 'meta_1' ),
$this->expectedField( 'value', 'test_meta_1' ),
- ]
+ )
),
$this->expectedObject(
'extraData.#',
- [
+ array(
$this->expectedField( 'key', 'meta_2' ),
$this->expectedField( 'value', 'test_meta_2' ),
- ]
+ )
),
- ]
+ )
),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
@@ -75,30 +75,30 @@ public function testCartMetaDataQueries() {
*
* Query w/ "key" filter
*/
- $variables = [ 'key' => 'meta_2' ];
+ $variables = array( 'key' => 'meta_2' );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedObject(
'cart.contents.nodes.0',
- [
+ array(
$this->expectedField( 'key', $cart_item_key ),
$this->expectedObject(
'extraData.0',
- [
+ array(
$this->expectedField( 'key', 'meta_2' ),
$this->expectedField( 'value', 'test_meta_2' ),
- ]
+ )
),
$this->expectedObject(
'extraData.#',
- [
+ array(
$this->not()->expectedField( 'key', 'meta_1' ),
$this->not()->expectedField( 'value', 'test_meta_1' ),
- ]
+ )
),
- ]
+ )
),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
@@ -107,30 +107,30 @@ public function testCartMetaDataQueries() {
*
* Query w/ "keysIn" filter
*/
- $variables = [ 'keysIn' => [ 'meta_2' ] ];
+ $variables = array( 'keysIn' => array( 'meta_2' ) );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedObject(
'cart.contents.nodes.0',
- [
+ array(
$this->expectedField( 'key', $cart_item_key ),
$this->expectedObject(
'extraData.0',
- [
+ array(
$this->expectedField( 'key', 'meta_2' ),
$this->expectedField( 'value', 'test_meta_2' ),
- ]
+ )
),
$this->expectedObject(
'extraData.#',
- [
+ array(
$this->not()->expectedField( 'key', 'meta_1' ),
$this->not()->expectedField( 'value', 'test_meta_1' ),
- ]
+ )
),
- ]
+ )
),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
}
@@ -138,25 +138,25 @@ public function testCartMetaDataQueries() {
public function testCouponMetaDataQueries() {
// Create Coupon with meta data.
$coupon_id = $this->factory->coupon->create(
- [
- 'meta_data' => [
- [
+ array(
+ 'meta_data' => array(
+ array(
'id' => 0,
'key' => 'meta_1',
'value' => 'test_meta_1',
- ],
- [
+ ),
+ array(
'id' => 0,
'key' => 'meta_2',
'value' => 'test_meta_2',
- ],
- [
+ ),
+ array(
'id' => 0,
'key' => 'meta_1',
'value' => 75,
- ],
- ],
- ]
+ ),
+ ),
+ )
);
$query = '
query ($id: ID!, $key: String, $keysIn: [String], $multiple: Boolean) {
@@ -176,25 +176,25 @@ public function testCouponMetaDataQueries() {
* Query w/o filters
*/
wp_set_current_user( $this->shop_manager );
- $variables = [ 'id' => $this->toRelayId( 'shop_coupon', $coupon_id ) ];
+ $variables = array( 'id' => $this->toRelayId( 'shop_coupon', $coupon_id ) );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedObject(
'coupon.metaData.#',
- [
+ array(
$this->expectedField( 'key', 'meta_1' ),
$this->expectedField( 'value', 'test_meta_1' ),
$this->not()->expectedField( 'value', 75 ),
- ]
+ )
),
$this->expectedObject(
'coupon.metaData.#',
- [
+ array(
$this->expectedField( 'key', 'meta_2' ),
$this->expectedField( 'value', 'test_meta_2' ),
- ]
+ )
),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
@@ -203,28 +203,28 @@ public function testCouponMetaDataQueries() {
*
* Query w/ "key" filter
*/
- $variables = [
+ $variables = array(
'id' => $this->toRelayId( 'shop_coupon', $coupon_id ),
'key' => 'meta_2',
- ];
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedObject(
'coupon.metaData.0',
- [
+ array(
$this->expectedField( 'key', 'meta_2' ),
$this->expectedField( 'value', 'test_meta_2' ),
- ]
+ )
),
$this->expectedObject(
'coupon.metaData.#',
- [
+ array(
$this->not()->expectedField( 'key', 'meta_1' ),
$this->not()->expectedField( 'value', 'test_meta_1' ),
$this->not()->expectedField( 'value', '75' ),
- ]
+ )
),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
@@ -233,28 +233,28 @@ public function testCouponMetaDataQueries() {
*
* Query w/ "keysIn" filter
*/
- $variables = [
+ $variables = array(
'id' => $this->toRelayId( 'shop_coupon', $coupon_id ),
- 'keysIn' => [ 'meta_2' ],
- ];
+ 'keysIn' => array( 'meta_2' ),
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedObject(
'coupon.metaData.0',
- [
+ array(
$this->expectedField( 'key', 'meta_2' ),
$this->expectedField( 'value', 'test_meta_2' ),
- ]
+ )
),
$this->expectedObject(
'coupon.metaData.#',
- [
+ array(
$this->not()->expectedField( 'key', 'meta_1' ),
$this->not()->expectedField( 'value', 'test_meta_1' ),
$this->not()->expectedField( 'value', '75' ),
- ]
+ )
),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
@@ -263,35 +263,35 @@ public function testCouponMetaDataQueries() {
*
* Query w/ "key" filter and "multiple" set to true to get non-unique results.
*/
- $variables = [
+ $variables = array(
'id' => $this->toRelayId( 'shop_coupon', $coupon_id ),
'key' => 'meta_1',
'multiple' => true,
- ];
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedObject(
'coupon.metaData.#',
- [
+ array(
$this->expectedField( 'key', 'meta_1' ),
$this->expectedField( 'value', 'test_meta_1' ),
- ]
+ )
),
$this->expectedObject(
'coupon.metaData.#',
- [
+ array(
$this->expectedField( 'key', 'meta_1' ),
$this->expectedField( 'value', '75' ),
- ]
+ )
),
$this->expectedObject(
'coupon.metaData.#',
- [
+ array(
$this->not()->expectedField( 'key', 'meta_2' ),
$this->not()->expectedField( 'value', 'test_meta_2' ),
- ]
+ )
),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
@@ -300,35 +300,35 @@ public function testCouponMetaDataQueries() {
*
* Query w/ "keysIn" filter and "multiple" set to true to get non-unique results.
*/
- $variables = [
+ $variables = array(
'id' => $this->toRelayId( 'shop_coupon', $coupon_id ),
- 'keysIn' => [ 'meta_1' ],
+ 'keysIn' => array( 'meta_1' ),
'multiple' => true,
- ];
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedObject(
'coupon.metaData.#',
- [
+ array(
$this->expectedField( 'key', 'meta_1' ),
$this->expectedField( 'value', 'test_meta_1' ),
- ]
+ )
),
$this->expectedObject(
'coupon.metaData.#',
- [
+ array(
$this->expectedField( 'key', 'meta_1' ),
$this->expectedField( 'value', '75' ),
- ]
+ )
),
$this->expectedObject(
'coupon.metaData.#',
- [
+ array(
$this->not()->expectedField( 'key', 'meta_2' ),
$this->not()->expectedField( 'value', 'test_meta_2' ),
- ]
+ )
),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
@@ -337,34 +337,34 @@ public function testCouponMetaDataQueries() {
*
* Query w/o filters and "multiple" set to true to get non-unique results.
*/
- $variables = [
+ $variables = array(
'id' => $this->toRelayId( 'shop_coupon', $coupon_id ),
'multiple' => true,
- ];
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedObject(
'coupon.metaData.#',
- [
+ array(
$this->expectedField( 'key', 'meta_1' ),
$this->expectedField( 'value', 'test_meta_1' ),
- ]
+ )
),
$this->expectedObject(
'coupon.metaData.#',
- [
+ array(
$this->expectedField( 'key', 'meta_2' ),
$this->expectedField( 'value', 'test_meta_2' ),
- ]
+ )
),
$this->expectedObject(
'coupon.metaData.#',
- [
+ array(
$this->expectedField( 'key', 'meta_1' ),
$this->expectedField( 'value', '75' ),
- ]
+ )
),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
}
@@ -372,20 +372,20 @@ public function testCouponMetaDataQueries() {
public function testCustomerMetaDataQueries() {
// Create Customer with meta data.
$customer_id = $this->factory->customer->create(
- [
- 'meta_data' => [
- [
+ array(
+ 'meta_data' => array(
+ array(
'id' => 0,
'key' => 'meta_1',
'value' => 'test_meta_1',
- ],
- [
+ ),
+ array(
'id' => 0,
'key' => 'meta_2',
'value' => 'test_meta_2',
- ],
- ],
- ]
+ ),
+ ),
+ )
);
$query = '
query {
@@ -404,47 +404,47 @@ public function testCustomerMetaDataQueries() {
*/
$this->loginAs( $customer_id );
$response = $this->graphql( compact( 'query' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'customer.id', $this->toRelayId( 'user', $customer_id ) ),
$this->expectedObject(
'customer.metaData.#',
- [
+ array(
$this->expectedField( 'key', 'meta_1' ),
$this->expectedField( 'value', 'test_meta_1' ),
- ]
+ )
),
$this->expectedObject(
'customer.metaData.#',
- [
+ array(
$this->expectedField( 'key', 'meta_2' ),
$this->expectedField( 'value', 'test_meta_2' ),
- ]
+ )
),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
}
public function testOrderMetaDataQueries() {
// Create Order with meta data.
- $meta_data = [
- [
+ $meta_data = array(
+ array(
'id' => 0,
'key' => 'meta_1',
'value' => 'test_meta_1',
- ],
- [
+ ),
+ array(
'id' => 0,
'key' => 'meta_2',
'value' => 'test_meta_2',
- ],
- ];
- $customer_id = $this->factory->customer->create( [ 'meta_data' => $meta_data ] );
+ ),
+ );
+ $customer_id = $this->factory->customer->create( array( 'meta_data' => $meta_data ) );
$order_id = $this->factory->order->createNew(
- [
+ array(
'customer_id' => $customer_id,
'meta_data' => $meta_data,
- ]
+ )
);
$this->factory->order->add_fee( $order_id, compact( 'meta_data' ) );
$query = '
@@ -472,57 +472,57 @@ public function testOrderMetaDataQueries() {
/**
* Assertion One
*/
- $variables = [ 'id' => $this->toRelayId( 'order', $order_id ) ];
+ $variables = array( 'id' => $this->toRelayId( 'order', $order_id ) );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'order.id', $this->toRelayId( 'order', $order_id ) ),
$this->expectedObject(
'order.metaData.#',
- [
+ array(
$this->expectedField( 'key', 'meta_1' ),
$this->expectedField( 'value', 'test_meta_1' ),
- ]
+ )
),
$this->expectedObject(
'order.metaData.#',
- [
+ array(
$this->expectedField( 'key', 'meta_2' ),
$this->expectedField( 'value', 'test_meta_2' ),
- ]
+ )
),
$this->expectedObject(
'order.feeLines.nodes.0.metaData.#',
- [
+ array(
$this->expectedField( 'key', 'meta_1' ),
$this->expectedField( 'value', 'test_meta_1' ),
- ]
+ )
),
$this->expectedObject(
'order.feeLines.nodes.0.metaData.#',
- [
+ array(
$this->expectedField( 'key', 'meta_2' ),
$this->expectedField( 'value', 'test_meta_2' ),
- ]
+ )
),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
}
public function testProductMetaDataQueries() {
// Create Product with meta data.
- $meta_data = [
- [
+ $meta_data = array(
+ array(
'id' => 0,
'key' => 'meta_1',
'value' => 'test_meta_1',
- ],
- [
+ ),
+ array(
'id' => 0,
'key' => 'meta_2',
'value' => 'test_meta_2',
- ],
- ];
+ ),
+ );
$product_id = $this->factory->product->createVariable( compact( 'meta_data' ) );
$query = '
query ($id: ID!) {
@@ -541,43 +541,43 @@ public function testProductMetaDataQueries() {
/**
* Assertion One
*/
- $variables = [ 'id' => $this->toRelayId( 'post', $product_id ) ];
+ $variables = array( 'id' => $this->toRelayId( 'post', $product_id ) );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'product.id', $this->toRelayId( 'post', $product_id ) ),
$this->expectedObject(
'product.metaData.#',
- [
+ array(
$this->expectedField( 'key', 'meta_1' ),
$this->expectedField( 'value', 'test_meta_1' ),
- ]
+ )
),
$this->expectedObject(
'product.metaData.#',
- [
+ array(
$this->expectedField( 'key', 'meta_2' ),
$this->expectedField( 'value', 'test_meta_2' ),
- ]
+ )
),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
}
public function testProductVariationMetaDataQueries() {
// Create Product with meta data.
- $meta_data = [
- [
+ $meta_data = array(
+ array(
'id' => 0,
'key' => 'meta_1',
'value' => 'test_meta_1',
- ],
- [
+ ),
+ array(
'id' => 0,
'key' => 'meta_2',
'value' => 'test_meta_2',
- ],
- ];
+ ),
+ );
$product_id = $this->factory->product->createVariable( compact( 'meta_data' ) );
$product_ids = $this->factory->product_variation->createSome( $product_id, compact( 'meta_data' ) );
$variation_id = $product_ids['variations'][0];
@@ -596,48 +596,48 @@ public function testProductVariationMetaDataQueries() {
/**
* Assertion One
*/
- $variables = [ 'id' => $this->toRelayId( 'post', $variation_id ) ];
+ $variables = array( 'id' => $this->toRelayId( 'post', $variation_id ) );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'productVariation.id', $this->toRelayId( 'post', $variation_id ) ),
$this->expectedObject(
'productVariation.metaData.#',
- [
+ array(
$this->expectedField( 'key', 'meta_1' ),
$this->expectedField( 'value', 'test_meta_1' ),
- ]
+ )
),
$this->expectedObject(
'productVariation.metaData.#',
- [
+ array(
$this->expectedField( 'key', 'meta_2' ),
$this->expectedField( 'value', 'test_meta_2' ),
- ]
+ )
),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
}
public function testRefundMetaDataQueries() {
- $meta_data = [
- [
+ $meta_data = array(
+ array(
'id' => 0,
'key' => 'meta_1',
'value' => 'test_meta_1',
- ],
- [
+ ),
+ array(
'id' => 0,
'key' => 'meta_2',
'value' => 'test_meta_2',
- ],
- ];
- $customer_id = $this->factory->customer->create( [ 'meta_data' => $meta_data ] );
+ ),
+ );
+ $customer_id = $this->factory->customer->create( array( 'meta_data' => $meta_data ) );
$order_id = $this->factory->order->createNew(
- [
+ array(
'customer_id' => $customer_id,
'meta_data' => $meta_data,
- ]
+ )
);
$refund_id = $this->factory->refund->createNew( $order_id, compact( 'meta_data' ) );
$query = '
@@ -656,25 +656,25 @@ public function testRefundMetaDataQueries() {
* Assertion One
*/
$this->loginAs( $customer_id );
- $variables = [ 'id' => $this->toRelayId( 'order', $refund_id ) ];
+ $variables = array( 'id' => $this->toRelayId( 'order', $refund_id ) );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'refund.id', $this->toRelayId( 'order', $refund_id ) ),
$this->expectedObject(
'refund.metaData.#',
- [
+ array(
$this->expectedField( 'key', 'meta_1' ),
$this->expectedField( 'value', 'test_meta_1' ),
- ]
+ )
),
$this->expectedObject(
'refund.metaData.#',
- [
+ array(
$this->expectedField( 'key', 'meta_2' ),
$this->expectedField( 'value', 'test_meta_2' ),
- ]
+ )
),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
}
diff --git a/tests/wpunit/OrderItemQueriesTest.php b/tests/wpunit/OrderItemQueriesTest.php
index 978f6c4c5..2833a688f 100644
--- a/tests/wpunit/OrderItemQueriesTest.php
+++ b/tests/wpunit/OrderItemQueriesTest.php
@@ -36,20 +36,20 @@ public function testCouponLinesQuery() {
* Tests query and results
*/
$this->loginAsShopManager();
- $variables = [ 'id' => $id ];
+ $variables = array( 'id' => $id );
$response = $this->graphql( compact( 'query', 'variables' ) );
$expected = array_map(
function ( $item ) {
return $this->expectedNode(
'order.couponLines.nodes',
- [
+ array(
$this->expectedField( 'databaseId', $item->get_id() ),
$this->expectedField( 'orderId', $item->get_order_id() ),
$this->expectedField( 'code', $item->get_code() ),
$this->expectedField( 'discount', $this->maybe( $item->get_discount(), static::IS_NULL ) ),
$this->expectedField( 'discountTax', $this->maybe( $item->get_discount_tax(), static::IS_NULL ) ),
$this->expectedField( 'coupon.id', $this->toRelayId( 'shop_coupon', \wc_get_coupon_id_by_code( $item->get_code() ) ) ),
- ]
+ )
);
},
$coupon_lines
@@ -90,13 +90,13 @@ public function testFeeLinesQuery() {
* Tests query and results
*/
$this->loginAsShopManager();
- $variables = [ 'id' => $id ];
+ $variables = array( 'id' => $id );
$response = $this->graphql( compact( 'query', 'variables' ) );
$expected = array_map(
function ( $item ) {
return $this->expectedNode(
'order.feeLines.nodes',
- [
+ array(
$this->expectedField( 'databaseId', $item->get_id() ),
$this->expectedField( 'orderId', $item->get_order_id() ),
$this->expectedField( 'amount', $item->get_amount() ),
@@ -110,7 +110,7 @@ function ( $item ) {
? WPEnumType::get_safe_name( $item->get_tax_class() )
: 'STANDARD'
),
- ]
+ )
);
},
$fee_lines
@@ -148,13 +148,13 @@ public function testShippingLinesQuery() {
* Tests query and results
*/
$this->loginAsShopManager();
- $variables = [ 'id' => $id ];
+ $variables = array( 'id' => $id );
$response = $this->graphql( compact( 'query', 'variables' ) );
$expected = array_map(
function ( $item ) {
return $this->expectedNode(
'order.shippingLines.nodes',
- [
+ array(
$this->expectedField( 'databaseId', $item->get_id() ),
$this->expectedField( 'orderId', $item->get_order_id() ),
$this->expectedField( 'methodTitle', $item->get_method_title() ),
@@ -168,7 +168,7 @@ function ( $item ) {
: WPEnumType::get_safe_name( $item->get_tax_class() )
: 'STANDARD'
),
- ]
+ )
);
},
$shipping_lines
@@ -209,20 +209,20 @@ public function testTaxLinesQuery() {
* Tests query and results
*/
$this->loginAsShopManager();
- $variables = [ 'id' => $id ];
+ $variables = array( 'id' => $id );
$response = $this->graphql( compact( 'query', 'variables' ) );
$expected = array_map(
function ( $item ) {
return $this->expectedNode(
'order.taxLines.nodes',
- [
+ array(
$this->expectedField( 'rateCode', $item->get_rate_code() ),
$this->expectedField( 'label', $item->get_label() ),
$this->expectedField( 'taxTotal', $item->get_tax_total() ),
$this->expectedField( 'shippingTaxTotal', $item->get_shipping_tax_total() ),
$this->expectedField( 'isCompound', $item->is_compound() ),
$this->expectedField( 'taxRate.databaseId', $item->get_rate_id() ),
- ]
+ )
);
},
$tax_lines
@@ -279,13 +279,13 @@ public function testLineItemsQuery() {
* Tests query and results
*/
$this->loginAsShopManager();
- $variables = [ 'id' => $id ];
+ $variables = array( 'id' => $id );
$response = $this->graphql( compact( 'query', 'variables' ) );
$expected = array_map(
function ( $item ) {
return $this->expectedNode(
'order.lineItems.nodes',
- [
+ array(
$this->expectedField( 'productId', $item->get_product_id() ),
$this->expectedField( 'variationId', $this->maybe( $item->get_variation_id(), static::IS_NULL ) ),
$this->expectedField( 'quantity', $item->get_quantity() ),
@@ -308,7 +308,7 @@ function ( $item ) {
? $this->toRelayId( 'post', $item->get_variation_id() )
: static::IS_NULL
),
- ]
+ )
);
},
$line_items
diff --git a/tests/wpunit/OrderMutationsTest.php b/tests/wpunit/OrderMutationsTest.php
index b3977f82c..e56056448 100644
--- a/tests/wpunit/OrderMutationsTest.php
+++ b/tests/wpunit/OrderMutationsTest.php
@@ -8,8 +8,8 @@ public function setUp(): void {
parent::setUp();
// Create users.
- $this->shop_manager = $this->factory->user->create( [ 'role' => 'shop_manager' ] );
- $this->customer = $this->factory->user->create( [ 'role' => 'customer' ] );
+ $this->shop_manager = $this->factory->user->create( array( 'role' => 'shop_manager' ) );
+ $this->customer = $this->factory->user->create( array( 'role' => 'customer' ) );
// Get helper instances
$this->order = $this->getModule( '\Helper\Wpunit' )->order();
@@ -26,7 +26,7 @@ public function setUp(): void {
// Create a tax rate.
$this->tax->create(
- [
+ array(
'country' => '',
'state' => '',
'rate' => 20.000,
@@ -35,7 +35,7 @@ public function setUp(): void {
'compound' => '0',
'shipping' => '1',
'class' => '',
- ]
+ )
);
// Create sample order to be used as a parent order.
$this->order_id = $this->order->create();
@@ -206,36 +206,36 @@ private function orderMutation( $input, $operation_name = 'createOrder', $input_
";
return graphql(
- [
+ array(
'query' => $mutation,
'operation_name' => $operation_name,
- 'variables' => [ 'input' => $input ],
- ]
+ 'variables' => array( 'input' => $input ),
+ )
);
}
// tests
public function testCreateOrderMutation() {
$variable = $this->variation->create( $this->product->create_variable() );
- $product_ids = [
+ $product_ids = array(
$this->product->create_simple(),
$this->product->create_simple(),
$variable['product'],
- ];
+ );
$coupon = new WC_Coupon(
- $this->coupon->create( [ 'product_ids' => $product_ids ] )
+ $this->coupon->create( array( 'product_ids' => $product_ids ) )
);
- $input = [
+ $input = array(
'clientMutationId' => 'someId',
'customerId' => $this->customer,
'customerNote' => 'Customer test note',
- 'coupons' => [
+ 'coupons' => array(
$coupon->get_code(),
- ],
+ ),
'paymentMethod' => 'bacs',
'paymentMethodTitle' => 'Direct Bank Transfer',
- 'billing' => [
+ 'billing' => array(
'firstName' => 'May',
'lastName' => 'Parker',
'address1' => '20 Ingram St',
@@ -245,8 +245,8 @@ public function testCreateOrderMutation() {
'country' => 'US',
'email' => 'superfreak500@gmail.com',
'phone' => '555-555-1234',
- ],
- 'shipping' => [
+ ),
+ 'shipping' => array(
'firstName' => 'May',
'lastName' => 'Parker',
'address1' => '20 Ingram St',
@@ -254,52 +254,52 @@ public function testCreateOrderMutation() {
'state' => 'NY',
'postcode' => '12345',
'country' => 'US',
- ],
- 'lineItems' => [
- [
+ ),
+ 'lineItems' => array(
+ array(
'productId' => $product_ids[0],
'quantity' => 5,
- 'metaData' => [
- [
+ 'metaData' => array(
+ array(
'key' => 'test_product_key',
'value' => 'test product value',
- ],
- ],
- ],
- [
+ ),
+ ),
+ ),
+ array(
'productId' => $product_ids[1],
'quantity' => 2,
- ],
- [
+ ),
+ array(
'productId' => $product_ids[2],
'quantity' => 6,
'variationId' => $variable['variations'][0],
- ],
- ],
- 'shippingLines' => [
- [
+ ),
+ ),
+ 'shippingLines' => array(
+ array(
'methodId' => 'flat_rate_shipping',
'methodTitle' => 'Flat Rate shipping',
'total' => '10',
- ],
- ],
- 'feeLines' => [
- [
+ ),
+ ),
+ 'feeLines' => array(
+ array(
'name' => 'Some Fee',
'taxStatus' => 'TAXABLE',
'total' => '100',
'taxClass' => 'STANDARD',
- ],
- ],
- 'metaData' => [
- [
+ ),
+ ),
+ 'metaData' => array(
+ array(
'key' => 'test_key',
'value' => 'test value',
- ],
- ],
- 'currency' => 'VND',
+ ),
+ ),
+ 'currency' => 'VND',
'isPaid' => true,
- ];
+ );
/**
* Assertion One
@@ -331,37 +331,37 @@ public function testCreateOrderMutation() {
$this->assertArrayHasKey( 'id', $actual['data']['createOrder']['order'] );
$order = \WC_Order_Factory::get_order( $actual['data']['createOrder']['order']['databaseId'] );
- $expected = [
- 'data' => [
- 'createOrder' => [
+ $expected = array(
+ 'data' => array(
+ 'createOrder' => array(
'clientMutationId' => 'someId',
'order' => array_merge(
$this->order->print_query( $order->get_id() ),
- [
- 'couponLines' => [
+ array(
+ 'couponLines' => array(
'nodes' => array_reverse(
array_map(
function ( $item ) {
- return [
+ return array(
'databaseId' => $item->get_id(),
'orderId' => $item->get_order_id(),
'code' => $item->get_code(),
'discount' => ! empty( $item->get_discount() ) ? $item->get_discount() : null,
'discountTax' => ! empty( $item->get_discount_tax() ) ? $item->get_discount_tax() : null,
- 'coupon' => [
+ 'coupon' => array(
'id' => $this->coupon->to_relay_id( \wc_get_coupon_id_by_code( $item->get_code() ) ),
- ],
- ];
+ ),
+ );
},
$order->get_items( 'coupon' )
)
),
- ],
- 'feeLines' => [
+ ),
+ 'feeLines' => array(
'nodes' => array_reverse(
array_map(
static function ( $item ) {
- return [
+ return array(
'databaseId' => $item->get_id(),
'orderId' => $item->get_order_id(),
'amount' => $item->get_amount(),
@@ -372,17 +372,17 @@ static function ( $item ) {
'taxClass' => ! empty( $item->get_tax_class() )
? WPEnumType::get_safe_name( $item->get_tax_class() )
: 'STANDARD',
- ];
+ );
},
$order->get_items( 'fee' )
)
),
- ],
- 'shippingLines' => [
+ ),
+ 'shippingLines' => array(
'nodes' => array_reverse(
array_map(
static function ( $item ) {
- return [
+ return array(
'databaseId' => $item->get_id(),
'orderId' => $item->get_order_id(),
'methodTitle' => $item->get_method_title(),
@@ -395,34 +395,34 @@ static function ( $item ) {
? WPEnumType::get_safe_name( 'inherit cart' )
: WPEnumType::get_safe_name( $item->get_tax_class() )
: 'STANDARD',
- ];
+ );
},
$order->get_items( 'shipping' )
)
),
- ],
- 'taxLines' => [
+ ),
+ 'taxLines' => array(
'nodes' => array_reverse(
array_map(
static function ( $item ) {
- return [
+ return array(
'rateCode' => $item->get_rate_code(),
'label' => $item->get_label(),
'taxTotal' => $item->get_tax_total(),
'shippingTaxTotal' => $item->get_shipping_tax_total(),
'isCompound' => $item->is_compound(),
- 'taxRate' => [ 'databaseId' => $item->get_rate_id() ],
- ];
+ 'taxRate' => array( 'databaseId' => $item->get_rate_id() ),
+ );
},
$order->get_items( 'tax' )
)
),
- ],
- 'lineItems' => [
+ ),
+ 'lineItems' => array(
'nodes' => array_values(
array_map(
function ( $item ) {
- return [
+ return array(
'productId' => $item->get_product_id(),
'variationId' => ! empty( $item->get_variation_id() )
? $item->get_variation_id()
@@ -436,25 +436,25 @@ function ( $item ) {
'total' => ! empty( $item->get_total() ) ? $item->get_total() : null,
'totalTax' => ! empty( $item->get_total_tax() ) ? $item->get_total_tax() : null,
'taxStatus' => strtoupper( $item->get_tax_status() ),
- 'product' => [ 'node' => [ 'id' => $this->product->to_relay_id( $item->get_product_id() ) ] ],
+ 'product' => array( 'node' => array( 'id' => $this->product->to_relay_id( $item->get_product_id() ) ) ),
'variation' => ! empty( $item->get_variation_id() )
- ? [
- 'node' => [
+ ? array(
+ 'node' => array(
'id' => $this->variation->to_relay_id( $item->get_variation_id() ),
- ],
- ]
+ ),
+ )
: null,
- ];
+ );
},
$order->get_items()
)
),
- ],
- ]
+ ),
+ )
),
- ],
- ],
- ];
+ ),
+ ),
+ );
$this->assertEquals( $expected, $actual );
}
@@ -462,26 +462,26 @@ function ( $item ) {
public function testUpdateOrderMutation() {
// Create products and coupons to be used in order creation.
$variable = $this->variation->create( $this->product->create_variable() );
- $product_ids = [
+ $product_ids = array(
$this->product->create_simple(),
$this->product->create_simple(),
$variable['product'],
- ];
+ );
$coupon = new WC_Coupon(
- $this->coupon->create( [ 'product_ids' => $product_ids ] )
+ $this->coupon->create( array( 'product_ids' => $product_ids ) )
);
// Create initial order input.
- $initial_input = [
+ $initial_input = array(
'clientMutationId' => 'someId',
'customerId' => $this->customer,
'customerNote' => 'Customer test note',
- 'coupons' => [
+ 'coupons' => array(
$coupon->get_code(),
- ],
+ ),
'paymentMethod' => 'bacs',
'paymentMethodTitle' => 'Direct Bank Transfer',
- 'billing' => [
+ 'billing' => array(
'firstName' => 'May',
'lastName' => 'Parker',
'address1' => '20 Ingram St',
@@ -491,8 +491,8 @@ public function testUpdateOrderMutation() {
'country' => 'US',
'email' => 'superfreak500@gmail.com',
'phone' => '555-555-1234',
- ],
- 'shipping' => [
+ ),
+ 'shipping' => array(
'firstName' => 'May',
'lastName' => 'Parker',
'address1' => '20 Ingram St',
@@ -500,51 +500,51 @@ public function testUpdateOrderMutation() {
'state' => 'NY',
'postcode' => '12345',
'country' => 'US',
- ],
- 'lineItems' => [
- [
+ ),
+ 'lineItems' => array(
+ array(
'productId' => $product_ids[0],
'quantity' => 5,
- 'metaData' => [
- [
+ 'metaData' => array(
+ array(
'key' => 'test_product_key',
'value' => 'test product value',
- ],
- ],
- ],
- [
+ ),
+ ),
+ ),
+ array(
'productId' => $product_ids[1],
'quantity' => 2,
- ],
- [
+ ),
+ array(
'productId' => $product_ids[2],
'quantity' => 6,
'variationId' => $variable['variations'][0],
- ],
- ],
- 'shippingLines' => [
- [
+ ),
+ ),
+ 'shippingLines' => array(
+ array(
'methodId' => 'flat_rate_shipping',
'methodTitle' => 'Flat Rate shipping',
'total' => '10',
- ],
- ],
- 'feeLines' => [
- [
+ ),
+ ),
+ 'feeLines' => array(
+ array(
'name' => 'Some Fee',
'taxStatus' => 'TAXABLE',
'total' => '100',
'taxClass' => 'STANDARD',
- ],
- ],
- 'metaData' => [
- [
+ ),
+ ),
+ 'metaData' => array(
+ array(
'key' => 'test_key',
'value' => 'test value',
- ],
- ],
+ ),
+ ),
'isPaid' => false,
- ];
+ );
// Create order to update.
wp_set_current_user( $this->shop_manager );
@@ -560,72 +560,72 @@ public function testUpdateOrderMutation() {
$fee_lines = $order->get_items( 'fee' );
// Create update order input.
- $updated_input = [
+ $updated_input = array(
'id' => $this->order->to_relay_id( $order->get_id() ),
'clientMutationId' => 'someId',
'customerNote' => 'Customer test note',
- 'coupons' => [
+ 'coupons' => array(
$coupon->get_code(),
- ],
- 'billing' => [
+ ),
+ 'billing' => array(
'firstName' => 'Ben',
- ],
- 'shipping' => [
+ ),
+ 'shipping' => array(
'firstName' => 'Ben',
- ],
- 'lineItems' => [
- [
+ ),
+ 'lineItems' => array(
+ array(
'id' => array_keys( $line_items )[0],
'quantity' => 6,
- 'metaData' => [
- [
+ 'metaData' => array(
+ array(
'key' => 'test_product_key',
'value' => 'updated test product value',
- ],
- ],
- ],
- [
+ ),
+ ),
+ ),
+ array(
'id' => array_keys( $line_items )[1],
'quantity' => 1,
- ],
- [
+ ),
+ array(
'id' => array_keys( $line_items )[2],
'quantity' => 10,
- ],
- ],
- 'shippingLines' => [
- [
+ ),
+ ),
+ 'shippingLines' => array(
+ array(
'id' => array_keys( $shipping_lines )[0],
'methodId' => 'reduced_rate_shipping',
'methodTitle' => 'reduced Rate shipping',
'total' => '7',
- ],
- ],
- 'feeLines' => [
- [
+ ),
+ ),
+ 'feeLines' => array(
+ array(
'id' => array_keys( $fee_lines )[0],
'name' => 'Some Updated Fee',
'taxStatus' => 'TAXABLE',
'total' => '125',
'taxClass' => 'STANDARD',
- ],
- ],
- 'metaData' => [
- [
+ ),
+ ),
+ 'metaData' => array(
+ array(
'key' => 'test_key',
'value' => 'new test value',
- ],
- ],
+ ),
+ ),
'isPaid' => true,
- ];
+ );
/**
* Assertion One
*
* User without necessary capabilities cannot update order an order.
*/
- wp_set_current_user( $this->factory->user->create( [ 'role' => 'customer' ] ) );
+ wp_set_current_user( $this->factory->user->create( array( 'role' => 'customer' ) ) );
$actual = $this->orderMutation(
$updated_input,
'updateOrder',
@@ -655,37 +655,37 @@ public function testUpdateOrderMutation() {
// Apply new changes to order instances.
$order = \WC_Order_Factory::get_order( $order->get_id() );
- $expected = [
- 'data' => [
- 'updateOrder' => [
+ $expected = array(
+ 'data' => array(
+ 'updateOrder' => array(
'clientMutationId' => 'someId',
'order' => array_merge(
$this->order->print_query( $order->get_id() ),
- [
- 'couponLines' => [
+ array(
+ 'couponLines' => array(
'nodes' => array_reverse(
array_map(
function ( $item ) {
- return [
+ return array(
'databaseId' => $item->get_id(),
'orderId' => $item->get_order_id(),
'code' => $item->get_code(),
'discount' => ! empty( $item->get_discount() ) ? $item->get_discount() : null,
'discountTax' => ! empty( $item->get_discount_tax() ) ? $item->get_discount_tax() : null,
- 'coupon' => [
+ 'coupon' => array(
'id' => $this->coupon->to_relay_id( \wc_get_coupon_id_by_code( $item->get_code() ) ),
- ],
- ];
+ ),
+ );
},
$order->get_items( 'coupon' )
)
),
- ],
- 'feeLines' => [
+ ),
+ 'feeLines' => array(
'nodes' => array_reverse(
array_map(
static function ( $item ) {
- return [
+ return array(
'databaseId' => $item->get_id(),
'orderId' => $item->get_order_id(),
'amount' => ! empty( $item->get_amount() ) ? $item->get_amount() : null,
@@ -696,17 +696,17 @@ static function ( $item ) {
'taxClass' => ! empty( $item->get_tax_class() )
? WPEnumType::get_safe_name( $item->get_tax_class() )
: 'STANDARD',
- ];
+ );
},
$order->get_items( 'fee' )
)
),
- ],
- 'shippingLines' => [
+ ),
+ 'shippingLines' => array(
'nodes' => array_reverse(
array_map(
static function ( $item ) {
- return [
+ return array(
'databaseId' => $item->get_id(),
'orderId' => $item->get_order_id(),
'methodTitle' => $item->get_method_title(),
@@ -719,34 +719,34 @@ static function ( $item ) {
? WPEnumType::get_safe_name( 'inherit cart' )
: WPEnumType::get_safe_name( $item->get_tax_class() )
: 'STANDARD',
- ];
+ );
},
$order->get_items( 'shipping' )
)
),
- ],
- 'taxLines' => [
+ ),
+ 'taxLines' => array(
'nodes' => array_reverse(
array_map(
static function ( $item ) {
- return [
+ return array(
'rateCode' => $item->get_rate_code(),
'label' => $item->get_label(),
'taxTotal' => $item->get_tax_total(),
'shippingTaxTotal' => $item->get_shipping_tax_total(),
'isCompound' => $item->is_compound(),
- 'taxRate' => [ 'databaseId' => $item->get_rate_id() ],
- ];
+ 'taxRate' => array( 'databaseId' => $item->get_rate_id() ),
+ );
},
$order->get_items( 'tax' )
)
),
- ],
- 'lineItems' => [
+ ),
+ 'lineItems' => array(
'nodes' => array_values(
array_map(
function ( $item ) {
- return [
+ return array(
'productId' => $item->get_product_id(),
'variationId' => ! empty( $item->get_variation_id() )
? $item->get_variation_id()
@@ -760,25 +760,25 @@ function ( $item ) {
'total' => ! empty( $item->get_total() ) ? $item->get_total() : null,
'totalTax' => ! empty( $item->get_total_tax() ) ? $item->get_total_tax() : null,
'taxStatus' => strtoupper( $item->get_tax_status() ),
- 'product' => [ 'node' => [ 'id' => $this->product->to_relay_id( $item->get_product_id() ) ] ],
+ 'product' => array( 'node' => array( 'id' => $this->product->to_relay_id( $item->get_product_id() ) ) ),
'variation' => ! empty( $item->get_variation_id() )
- ? [
- 'node' => [
+ ? array(
+ 'node' => array(
'id' => $this->variation->to_relay_id( $item->get_variation_id() ),
- ],
- ]
+ ),
+ )
: null,
- ];
+ );
},
$order->get_items()
)
),
- ],
- ]
+ ),
+ )
),
- ],
- ],
- ];
+ ),
+ ),
+ );
$this->assertEquals( $expected, $actual );
$this->assertNotEquals( $initial_response, $actual );
@@ -787,26 +787,26 @@ function ( $item ) {
public function testDeleteOrderMutation() {
// Create products and coupons to be used in order creation.
$variable = $this->variation->create( $this->product->create_variable() );
- $product_ids = [
+ $product_ids = array(
$this->product->create_simple(),
$this->product->create_simple(),
$variable['product'],
- ];
+ );
$coupon = new WC_Coupon(
- $this->coupon->create( [ 'product_ids' => $product_ids ] )
+ $this->coupon->create( array( 'product_ids' => $product_ids ) )
);
// Create initial order input.
- $initial_input = [
+ $initial_input = array(
'clientMutationId' => 'someId',
'customerId' => $this->customer,
'customerNote' => 'Customer test note',
- 'coupons' => [
+ 'coupons' => array(
$coupon->get_code(),
- ],
+ ),
'paymentMethod' => 'bacs',
'paymentMethodTitle' => 'Direct Bank Transfer',
- 'billing' => [
+ 'billing' => array(
'firstName' => 'May',
'lastName' => 'Parker',
'address1' => '20 Ingram St',
@@ -816,8 +816,8 @@ public function testDeleteOrderMutation() {
'country' => 'US',
'email' => 'superfreak500@gmail.com',
'phone' => '555-555-1234',
- ],
- 'shipping' => [
+ ),
+ 'shipping' => array(
'firstName' => 'May',
'lastName' => 'Parker',
'address1' => '20 Ingram St',
@@ -825,51 +825,51 @@ public function testDeleteOrderMutation() {
'state' => 'NY',
'postcode' => '12345',
'country' => 'US',
- ],
- 'lineItems' => [
- [
+ ),
+ 'lineItems' => array(
+ array(
'productId' => $product_ids[0],
'quantity' => 5,
- 'metaData' => [
- [
+ 'metaData' => array(
+ array(
'key' => 'test_product_key',
'value' => 'test product value',
- ],
- ],
- ],
- [
+ ),
+ ),
+ ),
+ array(
'productId' => $product_ids[1],
'quantity' => 2,
- ],
- [
+ ),
+ array(
'productId' => $product_ids[2],
'quantity' => 6,
'variationId' => $variable['variations'][0],
- ],
- ],
- 'shippingLines' => [
- [
+ ),
+ ),
+ 'shippingLines' => array(
+ array(
'methodId' => 'flat_rate_shipping',
'methodTitle' => 'Flat Rate shipping',
'total' => '10',
- ],
- ],
- 'feeLines' => [
- [
+ ),
+ ),
+ 'feeLines' => array(
+ array(
'name' => 'Some Fee',
'taxStatus' => 'TAXABLE',
'total' => '100',
'taxClass' => 'STANDARD',
- ],
- ],
- 'metaData' => [
- [
+ ),
+ ),
+ 'metaData' => array(
+ array(
'key' => 'test_key',
'value' => 'test value',
- ],
- ],
+ ),
+ ),
'isPaid' => false,
- ];
+ );
// Create order to delete.
wp_set_current_user( $this->shop_manager );
@@ -891,18 +891,18 @@ public function testDeleteOrderMutation() {
$tax_lines = $order->get_items( 'tax' );
// Create DeleteOrderInput.
- $deleted_input = [
+ $deleted_input = array(
'clientMutationId' => 'someId',
'id' => $this->order->to_relay_id( $order->get_id() ),
'forceDelete' => true,
- ];
+ );
/**
* Assertion One
*
* User without necessary capabilities cannot delete order an order.
*/
- wp_set_current_user( $this->factory->user->create( [ 'role' => 'customer' ] ) );
+ wp_set_current_user( $this->factory->user->create( array( 'role' => 'customer' ) ) );
$actual = $this->orderMutation(
$deleted_input,
'deleteOrder',
@@ -938,26 +938,26 @@ public function testDeleteOrderMutation() {
public function testDeleteOrderItemsMutation() {
// Create products and coupons to be used in order creation.
$variable = $this->variation->create( $this->product->create_variable() );
- $product_ids = [
+ $product_ids = array(
$this->product->create_simple(),
$this->product->create_simple(),
$variable['product'],
- ];
+ );
$coupon = new WC_Coupon(
- $this->coupon->create( [ 'product_ids' => $product_ids ] )
+ $this->coupon->create( array( 'product_ids' => $product_ids ) )
);
// Create initial order input.
- $initial_input = [
+ $initial_input = array(
'clientMutationId' => 'someId',
'customerId' => $this->customer,
'customerNote' => 'Customer test note',
- 'coupons' => [
+ 'coupons' => array(
$coupon->get_code(),
- ],
+ ),
'paymentMethod' => 'bacs',
'paymentMethodTitle' => 'Direct Bank Transfer',
- 'billing' => [
+ 'billing' => array(
'firstName' => 'May',
'lastName' => 'Parker',
'address1' => '20 Ingram St',
@@ -967,8 +967,8 @@ public function testDeleteOrderItemsMutation() {
'country' => 'US',
'email' => 'superfreak500@gmail.com',
'phone' => '555-555-1234',
- ],
- 'shipping' => [
+ ),
+ 'shipping' => array(
'firstName' => 'May',
'lastName' => 'Parker',
'address1' => '20 Ingram St',
@@ -976,51 +976,51 @@ public function testDeleteOrderItemsMutation() {
'state' => 'NY',
'postcode' => '12345',
'country' => 'US',
- ],
- 'lineItems' => [
- [
+ ),
+ 'lineItems' => array(
+ array(
'productId' => $product_ids[0],
'quantity' => 5,
- 'metaData' => [
- [
+ 'metaData' => array(
+ array(
'key' => 'test_product_key',
'value' => 'test product value',
- ],
- ],
- ],
- [
+ ),
+ ),
+ ),
+ array(
'productId' => $product_ids[1],
'quantity' => 2,
- ],
- [
+ ),
+ array(
'productId' => $product_ids[2],
'quantity' => 6,
'variationId' => $variable['variations'][0],
- ],
- ],
- 'shippingLines' => [
- [
+ ),
+ ),
+ 'shippingLines' => array(
+ array(
'methodId' => 'flat_rate_shipping',
'methodTitle' => 'Flat Rate shipping',
'total' => '10',
- ],
- ],
- 'feeLines' => [
- [
+ ),
+ ),
+ 'feeLines' => array(
+ array(
'name' => 'Some Fee',
'taxStatus' => 'TAXABLE',
'total' => '100',
'taxClass' => 'STANDARD',
- ],
- ],
- 'metaData' => [
- [
+ ),
+ ),
+ 'metaData' => array(
+ array(
'key' => 'test_key',
'value' => 'test value',
- ],
- ],
+ ),
+ ),
'isPaid' => false,
- ];
+ );
// Create order to delete.
wp_set_current_user( $this->shop_manager );
@@ -1042,21 +1042,21 @@ public function testDeleteOrderItemsMutation() {
$tax_lines = $order->get_items( 'tax' );
// Create DeleteOrderInput.
- $deleted_items_input = [
+ $deleted_items_input = array(
'clientMutationId' => 'someId',
'orderId' => $order->get_id(),
- 'itemIds' => [
+ 'itemIds' => array(
current( $line_items )->get_id(),
current( $coupon_lines )->get_id(),
- ],
- ];
+ ),
+ );
/**
* Assertion One
*
* User without necessary capabilities cannot delete order an order.
*/
- wp_set_current_user( $this->factory->user->create( [ 'role' => 'customer' ] ) );
+ wp_set_current_user( $this->factory->user->create( array( 'role' => 'customer' ) ) );
$actual = $this->orderMutation(
$deleted_items_input,
'deleteOrderItems',
diff --git a/tests/wpunit/OrderQueriesTest.php b/tests/wpunit/OrderQueriesTest.php
index 62fafcbc4..d7d296057 100644
--- a/tests/wpunit/OrderQueriesTest.php
+++ b/tests/wpunit/OrderQueriesTest.php
@@ -6,10 +6,10 @@ class OrderQueriesTest extends \Tests\WPGraphQL\WooCommerce\TestCase\WooGraphQLT
public function expectedOrderData( $order_id ) {
$order = \wc_get_order( $order_id );
- return [
+ return array(
$this->expectedObject(
'order',
- [
+ array(
$this->expectedField( 'id', $this->toRelayId( 'order', $order_id ) ),
$this->expectedField( 'databaseId', $order->get_id() ),
$this->expectedField( 'currency', $this->maybe( $order->get_currency() ) ),
@@ -17,14 +17,14 @@ public function expectedOrderData( $order_id ) {
$this->expectedField( 'date', $order->get_date_created()->__toString() ),
$this->expectedField( 'modified', $order->get_date_modified()->__toString() ),
$this->expectedField( 'status', WPEnumType::get_safe_name( $order->get_status() ) ),
- $this->expectedField( 'discountTotal', \wc_graphql_price( $order->get_discount_total(), [ 'currency' => $order->get_currency() ] ) ),
- $this->expectedField( 'discountTax', \wc_graphql_price( $order->get_discount_tax(), [ 'currency' => $order->get_currency() ] ) ),
- $this->expectedField( 'shippingTotal', \wc_graphql_price( $order->get_shipping_total(), [ 'currency' => $order->get_currency() ] ) ),
- $this->expectedField( 'shippingTax', \wc_graphql_price( $order->get_shipping_tax(), [ 'currency' => $order->get_currency() ] ) ),
- $this->expectedField( 'cartTax', \wc_graphql_price( $order->get_cart_tax(), [ 'currency' => $order->get_currency() ] ) ),
- $this->expectedField( 'total', \wc_graphql_price( $order->get_total(), [ 'currency' => $order->get_currency() ] ) ),
- $this->expectedField( 'totalTax', \wc_graphql_price( $order->get_total_tax(), [ 'currency' => $order->get_currency() ] ) ),
- $this->expectedField( 'subtotal', \wc_graphql_price( $order->get_subtotal(), [ 'currency' => $order->get_currency() ] ) ),
+ $this->expectedField( 'discountTotal', \wc_graphql_price( $order->get_discount_total(), array( 'currency' => $order->get_currency() ) ) ),
+ $this->expectedField( 'discountTax', \wc_graphql_price( $order->get_discount_tax(), array( 'currency' => $order->get_currency() ) ) ),
+ $this->expectedField( 'shippingTotal', \wc_graphql_price( $order->get_shipping_total(), array( 'currency' => $order->get_currency() ) ) ),
+ $this->expectedField( 'shippingTax', \wc_graphql_price( $order->get_shipping_tax(), array( 'currency' => $order->get_currency() ) ) ),
+ $this->expectedField( 'cartTax', \wc_graphql_price( $order->get_cart_tax(), array( 'currency' => $order->get_currency() ) ) ),
+ $this->expectedField( 'total', \wc_graphql_price( $order->get_total(), array( 'currency' => $order->get_currency() ) ) ),
+ $this->expectedField( 'totalTax', \wc_graphql_price( $order->get_total_tax(), array( 'currency' => $order->get_currency() ) ) ),
+ $this->expectedField( 'subtotal', \wc_graphql_price( $order->get_subtotal(), array( 'currency' => $order->get_currency() ) ) ),
$this->expectedField( 'orderNumber', $order->get_order_number() ),
$this->expectedField( 'orderKey', $order->get_order_key() ),
$this->expectedField( 'createdVia', $this->maybe( $order->get_created_via() ) ),
@@ -33,10 +33,10 @@ public function expectedOrderData( $order_id ) {
$this->expectedField(
'customer',
$this->maybe(
- [
+ array(
$order->get_customer_id(),
- [ 'id' => $this->toRelayId( 'user', $order->get_customer_id() ) ],
- ],
+ array( 'id' => $this->toRelayId( 'user', $order->get_customer_id() ) ),
+ ),
static::IS_NULL
)
),
@@ -45,7 +45,7 @@ public function expectedOrderData( $order_id ) {
$this->expectedField( 'customerNote', $this->maybe( $order->get_customer_note() ) ),
$this->expectedObject(
'billing',
- [
+ array(
$this->expectedField( 'firstName', $this->maybe( $order->get_billing_first_name() ) ),
$this->expectedField( 'lastName', $this->maybe( $order->get_billing_last_name() ) ),
$this->expectedField( 'company', $this->maybe( $order->get_billing_company() ) ),
@@ -57,11 +57,11 @@ public function expectedOrderData( $order_id ) {
$this->expectedField( 'country', $this->maybe( $order->get_billing_country() ) ),
$this->expectedField( 'email', $this->maybe( $order->get_billing_email() ) ),
$this->expectedField( 'phone', $this->maybe( $order->get_billing_phone() ) ),
- ]
+ )
),
$this->expectedObject(
'shipping',
- [
+ array(
$this->expectedField( 'firstName', $this->maybe( $order->get_shipping_first_name() ) ),
$this->expectedField( 'lastName', $this->maybe( $order->get_shipping_last_name() ) ),
$this->expectedField( 'company', $this->maybe( $order->get_shipping_company() ) ),
@@ -71,7 +71,7 @@ public function expectedOrderData( $order_id ) {
$this->expectedField( 'state', $this->maybe( $order->get_shipping_state() ) ),
$this->expectedField( 'postcode', $this->maybe( $order->get_shipping_postcode() ) ),
$this->expectedField( 'country', $this->maybe( $order->get_shipping_country() ) ),
- ]
+ )
),
$this->expectedField( 'paymentMethod', $this->maybe( $order->get_payment_method() ) ),
$this->expectedField( 'paymentMethodTitle', $this->maybe( $order->get_payment_method_title() ) ),
@@ -87,9 +87,9 @@ public function expectedOrderData( $order_id ) {
$this->expectedField( 'hasDownloadableItem', $order->has_downloadable_item() ),
$this->expectedField( 'needsPayment', $order->needs_payment() ),
$this->expectedField( 'needsProcessing', $order->needs_processing() ),
- ]
+ )
),
- ];
+ );
}
// tests
@@ -191,9 +191,9 @@ public function testOrderQuery() {
* Tests query as customer, should return "null" because the customer isn't authorized.
*/
$this->loginAsCustomer();
- $variables = [ 'id' => $id ];
+ $variables = array( 'id' => $id );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [ $this->expectedField( 'order', static::IS_NULL ) ];
+ $expected = array( $this->expectedField( 'order', static::IS_NULL ) );
$this->assertQueryError( $response, $expected );
@@ -229,12 +229,12 @@ public function testOrderQueryAndIds() {
*
* Tests "ID" ID type.
*/
- $variables = [
+ $variables = array(
'id' => $id,
'idType' => 'ID',
- ];
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [ $this->expectedField( 'order.id', $id ) ];
+ $expected = array( $this->expectedField( 'order.id', $id ) );
$this->assertQuerySuccessful( $response, $expected );
@@ -243,10 +243,10 @@ public function testOrderQueryAndIds() {
*
* Tests "DATABASE_ID" ID type.
*/
- $variables = [
+ $variables = array(
'id' => $order_id,
'idType' => 'DATABASE_ID',
- ];
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
$this->assertQuerySuccessful( $response, $expected );
@@ -256,10 +256,10 @@ public function testOrderQueryAndIds() {
*
* Tests "ORDER_KEY" ID type
*/
- $variables = [
+ $variables = array(
'id' => $this->factory->order->get_order_key( $order_id ),
'idType' => 'ORDER_KEY',
- ];
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
$this->assertQuerySuccessful( $response, $expected );
@@ -278,35 +278,35 @@ public function testOrdersQueryAndWhereArgs() {
// Create order for query response.
$customer = $this->factory->customer->create();
$product = $this->factory->product->createSimple();
- $orders = [
+ $orders = array(
$this->factory->order->createNew(
- [
+ array(
'billing_email' => 'test@example.com',
- ],
- [
- 'line_items' => [
- [
+ ),
+ array(
+ 'line_items' => array(
+ array(
'product' => $product,
'qty' => 4,
- ],
- ],
- ]
+ ),
+ ),
+ )
),
$this->factory->order->createNew(
- [
+ array(
'status' => 'completed',
'customer_id' => $customer,
- ],
- [
- 'line_items' => [
- [
+ ),
+ array(
+ 'line_items' => array(
+ array(
'product' => $product,
'qty' => 2,
- ],
- ],
- ]
+ ),
+ ),
+ )
),
- ];
+ );
$query = '
query ($statuses: [OrderStatusEnum], $customerId: Int, $customersIn: [Int], $billingEmail: String, $productId: Int) {
@@ -335,7 +335,7 @@ public function testOrdersQueryAndWhereArgs() {
*/
$this->loginAsCustomer();
$response = $this->graphql( compact( 'query' ) );
- $expected = [ $this->expectedField( 'orders.nodes', [] ) ];
+ $expected = array( $this->expectedField( 'orders.nodes', array() ) );
$this->assertQuerySuccessful( $response, $expected );
$this->clearLoaderCache( 'wc_post' );
@@ -347,11 +347,11 @@ public function testOrdersQueryAndWhereArgs() {
*/
$this->loginAsShopManager();
$response = $this->graphql( compact( 'query' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'orders.nodes.#.id', $this->toRelayId( 'order', $orders[0] ) ),
$this->expectedField( 'orders.nodes.#.id', $this->toRelayId( 'order', $orders[1] ) ),
$this->not()->expectedField( 'orders.nodes.#.id', $this->toRelayId( 'order', $old_orders[0]->get_id() ) ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
$this->clearLoaderCache( 'wc_post' );
@@ -361,11 +361,11 @@ public function testOrdersQueryAndWhereArgs() {
*
* Tests "statuses" where argument
*/
- $variables = [ 'statuses' => [ 'COMPLETED' ] ];
+ $variables = array( 'statuses' => array( 'COMPLETED' ) );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'orders.nodes.#.id', $this->toRelayId( 'order', $orders[1] ) ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
$this->clearLoaderCache( 'wc_post' );
@@ -375,7 +375,7 @@ public function testOrdersQueryAndWhereArgs() {
*
* Tests "customerId" where argument
*/
- $variables = [ 'customerId' => $customer ];
+ $variables = array( 'customerId' => $customer );
$response = $this->graphql( compact( 'query', 'variables' ) );
$this->assertQuerySuccessful( $response, $expected );
@@ -386,7 +386,7 @@ public function testOrdersQueryAndWhereArgs() {
*
* Tests "customerIn" where argument
*/
- $variables = [ 'customersIn' => [ $customer ] ];
+ $variables = array( 'customersIn' => array( $customer ) );
$response = $this->graphql( compact( 'query', 'variables' ) );
$this->assertQuerySuccessful( $response, $expected );
@@ -397,16 +397,16 @@ public function testOrdersQueryAndWhereArgs() {
*
* Tests "billingEmail" where argument
*/
- $variables = [ 'billingEmail' => 'test@example.com' ];
+ $variables = array( 'billingEmail' => 'test@example.com' );
$response = $this->graphql( compact( 'query', 'variables' ) );
$this->assertQuerySuccessful(
$response,
- [
+ array(
$this->expectedField( 'orders.nodes.#.id', $this->toRelayId( 'order', $orders[0] ) ),
$this->not()->expectedField( 'orders.nodes.#.id', $this->toRelayId( 'order', $orders[1] ) ),
$this->not()->expectedField( 'orders.nodes.#.id', $this->toRelayId( 'order', $old_orders[0] ) ),
- ]
+ )
);
$this->clearLoaderCache( 'wc_post' );
@@ -415,7 +415,7 @@ public function testOrdersQueryAndWhereArgs() {
*
* Tests "productId" where argument
*/
- $variables = [ 'productId' => $product ];
+ $variables = array( 'productId' => $product );
$response = $this->graphql( compact( 'query', 'variables' ) );
$this->assertQuerySuccessful( $response, $expected );
diff --git a/tests/wpunit/PaymentGatewayQueriesTest.php b/tests/wpunit/PaymentGatewayQueriesTest.php
index 73607214e..97b7ec9b2 100644
--- a/tests/wpunit/PaymentGatewayQueriesTest.php
+++ b/tests/wpunit/PaymentGatewayQueriesTest.php
@@ -8,29 +8,29 @@ public function setUp(): void {
// Enable payment gateway.
update_option(
'woocommerce_bacs_settings',
- [
+ array(
'enabled' => 'yes',
'title' => 'Direct bank transfer',
'description' => 'Make your payment directly into our bank account. Please use your Order ID as the payment reference. Your order will not be shipped until the funds have cleared in our account.',
'instructions' => 'Instructions that will be added to the thank you page and emails.',
'account' => '',
- ]
+ )
);
update_option(
'woocommerce_cheque_settings',
- [
+ array(
'enabled' => 'no',
'title' => 'Check payments',
'description' => 'Please send a check to Store Name, Store Street, Store Town, Store State / County, Store Postcode.',
'instructions' => 'Instructions that will be added to the thank you page and emails.',
'account' => '',
- ]
+ )
);
delete_option(
'woocommerce_stripe_settings',
- [
+ array(
'enabled' => 'no',
'title' => 'Credit Card (Stripe)',
'description' => 'Pay with your credit card via Stripe',
@@ -55,7 +55,7 @@ public function setUp(): void {
'payment_request_button_height' => '44',
'saved_cards' => 'yes',
'logging' => 'no',
- ]
+ )
);
// Reload gateways.
@@ -82,16 +82,16 @@ public function testPaymentGatewaysQueryAndWhereArgs() {
* Tests query.
*/
$response = $this->graphql( compact( 'query' ) );
- $expected = [
+ $expected = array(
$this->expectedNode(
'paymentGateways.nodes',
- [
+ array(
$this->expectedField( 'id', 'bacs' ),
$this->expectedField( 'title', 'Direct bank transfer' ),
$this->expectedField( 'icon', static::IS_NULL ),
- ]
+ )
),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
@@ -100,12 +100,12 @@ public function testPaymentGatewaysQueryAndWhereArgs() {
*
* Tests query and "all" where argument response, expects errors due lack of capabilities.
*/
- $variables = [ 'all' => true ];
+ $variables = array( 'all' => true );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedErrorPath( 'paymentGateways' ),
$this->expectedField( 'paymentGateways', static::IS_NULL ),
- ];
+ );
$this->assertQueryError( $response, $expected );
@@ -115,43 +115,43 @@ public function testPaymentGatewaysQueryAndWhereArgs() {
* Tests query and "all" where argument response with proper capabilities.
*/
$this->loginAsShopManager();
- $variables = [ 'all' => true ];
+ $variables = array( 'all' => true );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedNode(
'paymentGateways.nodes',
- [
+ array(
$this->expectedField( 'id', 'bacs' ),
$this->expectedField( 'title', 'Direct bank transfer' ),
$this->expectedField( 'icon', static::IS_NULL ),
- ]
+ )
),
$this->expectedNode(
'paymentGateways.nodes',
- [
+ array(
$this->expectedField( 'id', 'cheque' ),
$this->expectedField( 'title', 'Check payments' ),
$this->expectedField( 'icon', static::IS_NULL ),
- ]
+ )
),
$this->expectedNode(
'paymentGateways.nodes',
- [
+ array(
$this->expectedField( 'id', 'cod' ),
$this->expectedField( 'title', 'Cash on delivery' ),
$this->expectedField( 'icon', static::IS_NULL ),
- ]
+ )
),
$this->expectedNode(
'paymentGateways.nodes',
- [
+ array(
$this->expectedField( 'id', 'stripe' ),
$this->expectedField( 'title', 'Credit Card (Stripe)' ),
$this->expectedField( 'icon', static::IS_NULL ),
- ]
+ )
),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
}
diff --git a/tests/wpunit/PaymentMethodMutationsTest.php b/tests/wpunit/PaymentMethodMutationsTest.php
index 8c591de8b..2b14f3111 100644
--- a/tests/wpunit/PaymentMethodMutationsTest.php
+++ b/tests/wpunit/PaymentMethodMutationsTest.php
@@ -11,20 +11,20 @@ public function testSetDefaultPaymentMethodMutation() {
$expiry_year = gmdate( 'Y', strtotime( '+1 year' ) );
$token_cc = $this->factory->payment_token->createCCToken(
$customer_id,
- [
+ array(
'last4' => 1234,
'expiry_month' => $expiry_month,
'expiry_year' => $expiry_year,
'card_type' => 'visa',
'token' => time(),
- ]
+ )
);
$token_ec = $this->factory->payment_token->createECheckToken(
$customer_id,
- [
+ array(
'last4' => 4567,
'token' => time(),
- ]
+ )
);
// Create query and variables.
@@ -39,21 +39,21 @@ public function testSetDefaultPaymentMethodMutation() {
}
}
';
- $variables = [ 'tokenId' => $token_ec->get_id() ];
+ $variables = array( 'tokenId' => $token_ec->get_id() );
/**
* Assert default payment method can't be set by guests or admin.
*/
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [ $this->expectedField( 'setDefaultPaymentMethod', static::IS_NULL ) ];
+ $expected = array( $this->expectedField( 'setDefaultPaymentMethod', static::IS_NULL ) );
$this->assertQueryError( $response, $expected );
// Again, as admin.
$this->loginAsShopManager();
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [ $this->expectedField( 'setDefaultPaymentMethod', static::IS_NULL ) ];
+ $expected = array( $this->expectedField( 'setDefaultPaymentMethod', static::IS_NULL ) );
$this->assertQueryError( $response, $expected );
@@ -62,32 +62,32 @@ public function testSetDefaultPaymentMethodMutation() {
*/
$this->loginAs( $customer_id );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'setDefaultPaymentMethod.status', 'SUCCESS' ),
$this->expectedObject(
'setDefaultPaymentMethod.token',
- [
+ array(
$this->expectedField( 'id', $this->toRelayId( 'token', $token_ec->get_id() ) ),
$this->expectedField( 'isDefault', true ),
- ]
+ )
),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
// Change default payment method back to credit card token.
- $variables = [ 'tokenId' => $token_cc->get_id() ];
+ $variables = array( 'tokenId' => $token_cc->get_id() );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'setDefaultPaymentMethod.status', 'SUCCESS' ),
$this->expectedObject(
'setDefaultPaymentMethod.token',
- [
+ array(
$this->expectedField( 'id', $this->toRelayId( 'token', $token_cc->get_id() ) ),
$this->expectedField( 'isDefault', true ),
- ]
+ )
),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
}
@@ -101,20 +101,20 @@ public function testDeletePaymentMethodMutation() {
$expiry_year = gmdate( 'Y', strtotime( '+1 year' ) );
$token_cc = $this->factory->payment_token->createCCToken(
$customer_id,
- [
+ array(
'last4' => 1234,
'expiry_month' => $expiry_month,
'expiry_year' => $expiry_year,
'card_type' => 'visa',
'token' => time(),
- ]
+ )
);
$token_ec = $this->factory->payment_token->createECheckToken(
$customer_id,
- [
+ array(
'last4' => 4567,
'token' => time(),
- ]
+ )
);
// Create query and variables.
@@ -125,21 +125,21 @@ public function testDeletePaymentMethodMutation() {
}
}
';
- $variables = [ 'tokenId' => $token_cc->get_id() ];
+ $variables = array( 'tokenId' => $token_cc->get_id() );
/**
* Assert payment method can't be deleted by guests or admin.
*/
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [ $this->expectedField( 'deletePaymentMethod', static::IS_NULL ) ];
+ $expected = array( $this->expectedField( 'deletePaymentMethod', static::IS_NULL ) );
$this->assertQueryError( $response, $expected );
// Again, as admin.
$this->loginAsShopManager();
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [ $this->expectedField( 'deletePaymentMethod', static::IS_NULL ) ];
+ $expected = array( $this->expectedField( 'deletePaymentMethod', static::IS_NULL ) );
$this->assertQueryError( $response, $expected );
@@ -148,7 +148,7 @@ public function testDeletePaymentMethodMutation() {
*/
$this->loginAs( $customer_id );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [ $this->expectedField( 'deletePaymentMethod.status', 'SUCCESS' ) ];
+ $expected = array( $this->expectedField( 'deletePaymentMethod.status', 'SUCCESS' ) );
$this->assertQuerySuccessful( $response, $expected );
}
diff --git a/tests/wpunit/ProductAttributeQueriesTest.php b/tests/wpunit/ProductAttributeQueriesTest.php
index acd201ca6..e22f1e3c9 100644
--- a/tests/wpunit/ProductAttributeQueriesTest.php
+++ b/tests/wpunit/ProductAttributeQueriesTest.php
@@ -5,12 +5,12 @@ public function expectedProductAttributeData( $product_id, $path ) {
$product = wc_get_product( $product_id );
$attributes = $product->get_attributes();
- $expected = [];
+ $expected = array();
foreach ( $attributes as $attribute_name => $attribute ) {
$expected[] = $this->expectedNode(
$path,
- [
+ array(
$this->expectedField( 'id', base64_encode( $attribute_name . ':' . $product_id . ':' . $attribute->get_name() ) ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode
$this->expectedField( 'attributeId', $attribute->get_id() ),
$this->expectedField( 'name', $attribute->get_name() ),
@@ -24,7 +24,7 @@ public function expectedProductAttributeData( $product_id, $path ) {
$this->expectedField( 'position', $attribute->get_position() ),
$this->expectedField( 'visible', $attribute->get_visible() ),
$this->expectedField( 'variation', $attribute->get_variation() ),
- ]
+ )
);
}
@@ -58,10 +58,10 @@ public function testProductAttributeQuery() {
}
';
- $variables = [ 'id' => $this->toRelayId( 'post', $product_id ) ];
+ $variables = array( 'id' => $this->toRelayId( 'post', $product_id ) );
$response = $this->graphql( compact( 'query', 'variables' ) );
$expected = array_merge(
- [ $this->expectedField( 'product.id', $this->toRelayId( 'post', $product_id ) ) ],
+ array( $this->expectedField( 'product.id', $this->toRelayId( 'post', $product_id ) ) ),
$this->expectedProductAttributeData( $product_id, 'product.attributes.nodes' )
);
@@ -69,37 +69,36 @@ public function testProductAttributeQuery() {
}
public function testProductAttributeToProductConnectionQuery() {
-
// Create noise products.
$product_id = $this->factory->product->createVariable(
- [
- 'attribute_data' => [ $this->factory->product->createAttribute( 'pattern', [ 'polka-dot', 'stripe', 'flames' ] ) ],
- ],
+ array(
+ 'attribute_data' => array( $this->factory->product->createAttribute( 'pattern', array( 'polka-dot', 'stripe', 'flames' ) ) ),
+ ),
);
$variation_id = $this->factory->product_variation->create(
- [
+ array(
'parent_id' => $product_id,
- 'attributes' => [
+ 'attributes' => array(
'pattern' => 'polka-dot',
- ],
+ ),
'image_id' => null,
'regular_price' => 10,
- ]
+ )
);
// Create variable product with attribute.
$other_product_id = $this->factory->product->createVariable();
$other_variation_id = $this->factory->product_variation->create(
- [
+ array(
'parent_id' => $product_id,
- 'attributes' => [
+ 'attributes' => array(
'pattern' => 'stripe',
- ],
+ ),
'image_id' => null,
'regular_price' => 10,
- ]
- );
+ )
+ );
$other_product_id_2 = $this->factory->product->createSimple();
$this->clearSchema();
@@ -120,11 +119,11 @@ public function testProductAttributeToProductConnectionQuery() {
/**
* Assert correct products are queried.
*/
- $variables = [ 'pattern' => 'polka-dot' ];
+ $variables = array( 'pattern' => 'polka-dot' );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'allPaPattern.nodes.0.products.nodes.0.id', $this->toRelayId( 'post', $product_id ) ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
}
@@ -147,7 +146,7 @@ public function testProductAttributeToVariationConnectionQuery() {
}
';
- $variables = [ 'size' => 'small' ];
+ $variables = array( 'size' => 'small' );
$response = $this->graphql( compact( 'query', 'variables' ) );
$expected = array_map(
function ( $id ) {
@@ -206,33 +205,33 @@ public function testProductAttributeMatchesVariationAttributeCounterpart() {
}
';
- $variables = [ 'id' => $this->toRelayId( 'post', $product_id ) ];
+ $variables = array( 'id' => $this->toRelayId( 'post', $product_id ) );
$response = $this->graphql( compact( 'query', 'variables' ) );
/**
* Assert that the product attributes match the variation attributes
* without modification to confirm variations can be identified by product attribute.
*/
- $attributes = $this->lodashGet( $response, 'data.product.attributes.nodes', [] );
- $variations = $this->lodashGet( $response, 'data.product.variations.nodes', [] );
+ $attributes = $this->lodashGet( $response, 'data.product.attributes.nodes', array() );
+ $variations = $this->lodashGet( $response, 'data.product.variations.nodes', array() );
- foreach( $variations as $variation ) {
- $variation_attributes = $this->lodashGet( $variation, 'attributes.nodes', [] );
- foreach( $variation_attributes as $variation_attribute ) {
+ foreach ( $variations as $variation ) {
+ $variation_attributes = $this->lodashGet( $variation, 'attributes.nodes', array() );
+ foreach ( $variation_attributes as $variation_attribute ) {
$attribute_name = $variation_attribute['name'];
- $attribute = array_search( $attribute_name, array_column( $attributes, 'name' ) );
+ $attribute = array_search( $attribute_name, array_column( $attributes, 'name' ) );
$this->assertNotFalse( $attribute, sprintf( 'Variation attribute not found in product attributes for %s', $attribute_name ) );
- if ( "" === $variation_attribute['value'] ) {
+ if ( '' === $variation_attribute['value'] ) {
continue;
}
$this->assertContains( $variation_attribute['value'], $attributes[ $attribute ]['options'] );
}
}
-
+
$this->assertQuerySuccessful(
$response,
- [ $this->expectedField( 'product.id', $this->toRelayId( 'post', $product_id ) ) ]
+ array( $this->expectedField( 'product.id', $this->toRelayId( 'post', $product_id ) ) )
);
}
}
diff --git a/tests/wpunit/ProductDateModifiedTest.php b/tests/wpunit/ProductDateModifiedTest.php
new file mode 100644
index 000000000..abaffd19e
--- /dev/null
+++ b/tests/wpunit/ProductDateModifiedTest.php
@@ -0,0 +1,48 @@
+product_id = $this->factory->product->create(
+ array(
+ 'name' => 'Test Product',
+ )
+ );
+
+ // Modify the product so we know date_modified is set
+ $product = wc_get_product( $this->product_id );
+ $product->set_name( 'Updated Test Product' );
+ $product->save();
+ }
+
+ public function tearDown(): void {
+ parent::tearDown();
+ wp_delete_post( $this->product_id, true );
+ }
+
+ public function testProductHasDateModifiedField() {
+ $query = '
+ {
+ product(id: "' . $this->product_id . '", idType: DATABASE_ID) {
+ ... on SimpleProduct {
+ id
+ name
+ dateModified
+ }
+ }
+ }';
+
+ $response = $this->graphql( array( 'query' => $query ) );
+
+ $this->assertArrayNotHasKey( 'errors', $response, print_r( $response, true ) );
+ $this->assertArrayHasKey( 'data', $response );
+ $this->assertArrayHasKey( 'product', $response['data'] );
+ $this->assertNotNull( $response['data']['product']['dateModified'] );
+ }
+}
diff --git a/tests/wpunit/ProductDateModifiedTesterTest.php b/tests/wpunit/ProductDateModifiedTesterTest.php
new file mode 100644
index 000000000..385a8a422
--- /dev/null
+++ b/tests/wpunit/ProductDateModifiedTesterTest.php
@@ -0,0 +1,30 @@
+post->create_and_get();
+
+ $this->assertInstanceOf( \WP_Post::class, $post );
+ }
+}
diff --git a/tests/wpunit/ProductQueriesTest.php b/tests/wpunit/ProductQueriesTest.php
index b4607c15e..589bfbb58 100644
--- a/tests/wpunit/ProductQueriesTest.php
+++ b/tests/wpunit/ProductQueriesTest.php
@@ -8,7 +8,7 @@ public function getExpectedProductData( $product_id ) {
$is_shop_manager = true;
}
- return [
+ return array(
$this->expectedField( 'product.id', $this->toRelayId( 'post', $product_id ) ),
$this->expectedField( 'product.databaseId', $product->get_id() ),
$this->expectedField( 'product.name', $product->get_name() ),
@@ -19,20 +19,20 @@ public function getExpectedProductData( $product_id ) {
$this->expectedField(
'product.description',
$this->maybe(
- [ $product->get_description(), apply_filters( 'the_content', $product->get_description() ) ],
+ array( $product->get_description(), apply_filters( 'the_content', $product->get_description() ) ),
static::IS_NULL
)
),
$this->expectedField(
'product.shortDescription',
$this->maybe(
- [
+ array(
$product->get_short_description(),
apply_filters(
'get_the_excerpt',
apply_filters( 'the_excerpt', $product->get_short_description() )
),
- ],
+ ),
static::IS_NULL
)
),
@@ -40,21 +40,21 @@ public function getExpectedProductData( $product_id ) {
$this->expectedField(
'product.price',
$this->maybe(
- [ $product->get_price(), \wc_graphql_price( $product->get_price() ) ],
+ array( $product->get_price(), \wc_graphql_price( $product->get_price() ) ),
static::IS_NULL
)
),
$this->expectedField(
'product.regularPrice',
$this->maybe(
- [ $product->get_regular_price(), \wc_graphql_price( $product->get_regular_price() ) ],
+ array( $product->get_regular_price(), \wc_graphql_price( $product->get_regular_price() ) ),
static::IS_NULL
)
),
$this->expectedField(
'product.salePrice',
$this->maybe(
- [ $product->get_sale_price(), \wc_graphql_price( $product->get_sale_price() ) ],
+ array( $product->get_sale_price(), \wc_graphql_price( $product->get_sale_price() ) ),
static::IS_NULL
)
),
@@ -151,24 +151,24 @@ public function getExpectedProductData( $product_id ) {
$this->expectedField(
'product.totalSales',
$this->maybe(
- [
+ array(
$is_shop_manager && $product->get_total_sales(),
$product->get_total_sales(),
- ],
+ ),
static::IS_FALSY
)
),
$this->expectedField(
'product.catalogVisibility',
$this->maybe(
- [
+ array(
$is_shop_manager && ! empty( $product->get_catalog_visibility() ),
strtoupper( $product->get_catalog_visibility() ),
- ],
+ ),
static::IS_NULL
)
),
- ];
+ );
}
public function getExpectedProductDownloadData( $product_id ) {
@@ -178,9 +178,9 @@ public function getExpectedProductDownloadData( $product_id ) {
return null;
}
- $results = [];
+ $results = array();
foreach ( $downloads as $download ) {
- $results[] = [
+ $results[] = array(
'name' => $download->get_name(),
'downloadId' => $download->get_id(),
'filePathType' => $download->get_type_of_file_path(),
@@ -189,7 +189,7 @@ public function getExpectedProductDownloadData( $product_id ) {
'allowedFileType' => $download->is_allowed_filetype(),
'fileExists' => $download->file_exists(),
'file' => $download->get_file(),
- ];
+ );
}
return $results;
@@ -258,7 +258,7 @@ public function testSimpleProductQuery() {
*
* Test querying product.
*/
- $variables = [ 'id' => $this->toRelayId( 'post', $product_id ) ];
+ $variables = array( 'id' => $this->toRelayId( 'post', $product_id ) );
$response = $this->graphql( compact( 'query', 'variables' ) );
$expected = $this->getExpectedProductData( $product_id );
@@ -273,17 +273,17 @@ public function testSimpleProductQuery() {
* Test querying product with unformatted content (edit-product cap required).
*/
$this->loginAsShopManager();
- $variables = [
+ $variables = array(
'id' => $this->toRelayId( 'post', $product_id ),
'format' => 'RAW',
- ];
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$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 );
}
@@ -294,19 +294,19 @@ public function testProductTaxonomies() {
$category_6 = $this->factory->product->createProductCategory( 'category-six', $category_5 );
$tag_2 = $this->factory->product->createProductTag( 'tag-two' );
$attachment_id = $this->factory->attachment->create(
- [
+ array(
'post_mime_type' => 'image/gif',
'post_author' => $this->admin,
- ]
+ )
);
$product_id = $this->factory->product->createSimple(
- [
+ array(
'price' => 10,
'regular_price' => 10,
- 'category_ids' => [ $category_5 ],
- 'tag_ids' => [ $tag_2 ],
+ 'category_ids' => array( $category_5 ),
+ 'tag_ids' => array( $tag_2 ),
'image_id' => $attachment_id,
- ]
+ )
);
$query = '
@@ -345,30 +345,30 @@ public function testProductTaxonomies() {
*
* Test querying product with "productId" argument.
*/
- $variables = [
+ $variables = array(
'id' => $product_id,
'idType' => 'DATABASE_ID',
- ];
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'product.id', $this->toRelayId( 'post', $product_id ) ),
$this->expectedField( 'product.image.id', $this->toRelayId( 'post', $attachment_id ) ),
$this->expectedNode(
'product.productCategories.nodes',
- [
+ array(
'name' => 'category-five',
'image' => null,
'display' => 'DEFAULT',
'menuOrder' => 0,
- 'children' => [
- 'nodes' => [
- [ 'name' => 'category-six' ],
- ],
- ],
- ]
+ 'children' => array(
+ 'nodes' => array(
+ array( 'name' => 'category-six' ),
+ ),
+ ),
+ )
),
- $this->expectedNode( 'product.productTags.nodes', [ 'name' => 'tag-two' ] ),
- ];
+ $this->expectedNode( 'product.productTags.nodes', array( 'name' => 'tag-two' ) ),
+ );
$this->assertQuerySuccessful( $response, $expected );
}
@@ -386,19 +386,19 @@ public function testProductQueryAndIds() {
';
// Define expected data for coming assertions.
- $expected = [
+ $expected = array(
$this->expectedField( 'product.id', $this->toRelayId( 'post', $product_id ) ),
- ];
+ );
/**
* Assertion One
*
* Test querying product with 'DATABASE_ID' set as the "idType".
*/
- $variables = [
+ $variables = array(
'id' => $product_id,
'idType' => 'DATABASE_ID',
- ];
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
$this->assertQuerySuccessful( $response, $expected );
@@ -407,10 +407,10 @@ public function testProductQueryAndIds() {
*
* Test querying product with "ID" set as the "idType".
*/
- $variables = [
+ $variables = array(
'id' => $this->toRelayId( 'post', $product_id ),
'idType' => 'ID',
- ];
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
$this->assertQuerySuccessful( $response, $expected );
@@ -419,10 +419,10 @@ public function testProductQueryAndIds() {
*
* Test querying product with "SLUG" set as the "idType".
*/
- $variables = [
+ $variables = array(
'id' => get_post_field( 'post_name', $product_id ),
'idType' => 'SLUG',
- ];
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
$this->assertQuerySuccessful( $response, $expected );
@@ -431,10 +431,10 @@ public function testProductQueryAndIds() {
*
* Test querying product with "SKU" set as the "idType".
*/
- $variables = [
+ $variables = array(
'id' => get_post_meta( $product_id, '_sku', true ),
'idType' => 'SKU',
- ];
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
$this->assertQuerySuccessful( $response, $expected );
}
@@ -443,10 +443,10 @@ public function testProductToTermConnection() {
$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(
- [
- 'tag_ids' => [ $test_tag ],
- 'category_ids' => [ $test_category ],
- ]
+ array(
+ 'tag_ids' => array( $test_tag ),
+ 'category_ids' => array( $test_category ),
+ )
);
$relay_id = $this->toRelayId( 'post', $product_id );
@@ -470,21 +470,21 @@ public function testProductToTermConnection() {
}
';
- $variables = [ 'id' => $relay_id ];
+ $variables = array( 'id' => $relay_id );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'product.id', $relay_id ),
$this->expectedNode(
'product.productTags.nodes',
- [ 'name' => 'test-product-tag-1' ],
+ array( 'name' => 'test-product-tag-1' ),
0
),
$this->expectedNode(
'product.productCategories.nodes',
- [ 'name' => 'test-product-category-1' ],
+ array( 'name' => 'test-product-category-1' ),
0
),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
}
@@ -492,31 +492,31 @@ public function testProductToTermConnection() {
public function testTermToProductConnection() {
$test_tag = $this->factory->product->createProductTag( 'test-product-tag-2' );
$image_id = $this->factory->post->create(
- [
+ array(
'post_author' => $this->shop_manager,
'post_status' => 'publish',
'post_title' => 'Product Image',
'post_type' => 'attachment',
- ]
+ )
);
$test_category = $this->factory->product->createProductCategory( 'test-product-category-2' );
update_term_meta( $test_category, 'thumbnail_id', $image_id );
$product_id = $this->factory->product->createSimple(
- [
- 'tag_ids' => [ $test_tag ],
- 'category_ids' => [ $test_category ],
+ array(
+ 'tag_ids' => array( $test_tag ),
+ 'category_ids' => array( $test_category ),
'price' => 10,
'regular_price' => 10,
- ]
+ )
);
$expensive_product_id = $this->factory->product->createSimple(
- [
- 'tag_ids' => [ $test_tag ],
- 'category_ids' => [ $test_category ],
+ array(
+ 'tag_ids' => array( $test_tag ),
+ 'category_ids' => array( $test_category ),
'price' => 100,
'regular_price' => 100,
- ]
+ )
);
$query = '
@@ -553,60 +553,60 @@ public function testTermToProductConnection() {
}
';
- $variables = [
- 'orderby' => [
- [
+ $variables = array(
+ 'orderby' => array(
+ array(
'field' => 'PRICE',
'order' => 'ASC',
- ],
- ],
- 'orderby2' => [
- [
+ ),
+ ),
+ 'orderby2' => array(
+ array(
'field' => 'PRICE',
'order' => 'DESC',
- ],
- ],
- ];
+ ),
+ ),
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedNode(
'productTags.nodes',
- [
+ array(
$this->expectedField( 'name', 'test-product-tag-2' ),
$this->expectedField( 'products.nodes.0.id', $this->toRelayId( 'post', $product_id ) ),
$this->expectedField( 'products.nodes.1.id', $this->toRelayId( 'post', $expensive_product_id ) ),
- ],
+ ),
0
),
$this->expectedNode(
'productCategories.nodes',
- [
+ array(
$this->expectedField( 'name', 'test-product-category-2' ),
$this->expectedField( 'image.id', $this->toRelayId( 'post', $image_id ) ),
$this->expectedField( 'products.nodes.1.id', $this->toRelayId( 'post', $product_id ) ),
$this->expectedField( 'products.nodes.0.id', $this->toRelayId( 'post', $expensive_product_id ) ),
- ],
+ ),
0
),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
}
public function testProductToMediaItemConnections() {
$image_id = $this->factory->post->create(
- [
+ array(
'post_author' => $this->shop_manager,
'post_status' => 'publish',
'post_title' => 'Product Image',
'post_type' => 'attachment',
- ]
+ )
);
$product_id = $this->factory->product->createSimple(
- [
+ array(
'image_id' => $image_id,
- 'gallery_image_ids' => [ $image_id ],
- ]
+ 'gallery_image_ids' => array( $image_id ),
+ )
);
$product_relay_id = $this->toRelayId( 'post', $product_id );
@@ -630,23 +630,23 @@ public function testProductToMediaItemConnections() {
}
';
- $variables = [ 'id' => $product_relay_id ];
+ $variables = array( 'id' => $product_relay_id );
$response = graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'product.id', $product_relay_id ),
$this->expectedField( 'product.image.id', $image_relay_id ),
- $this->expectedNode( 'product.galleryImages.nodes', [ 'id' => $image_relay_id ] ),
- ];
+ $this->expectedNode( 'product.galleryImages.nodes', array( 'id' => $image_relay_id ) ),
+ );
$this->assertQuerySuccessful( $response, $expected );
}
public function testProductDownloads() {
$product_id = $this->factory->product->createSimple(
- [
+ array(
'downloadable' => true,
- 'downloads' => [ $this->factory->product->createDownload() ],
- ]
+ 'downloads' => array( $this->factory->product->createDownload() ),
+ )
);
$relay_id = $this->toRelayId( 'post', $product_id );
@@ -671,22 +671,22 @@ public function testProductDownloads() {
}
';
- $variables = [ 'id' => $relay_id ];
+ $variables = array( 'id' => $relay_id );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'product.id', $relay_id ),
$this->expectedField( 'product.downloads', $this->getExpectedProductDownloadData( $product_id ) ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
}
public function testExternalProductQuery() {
$product_id = $this->factory->product->createExternal(
- [
+ array(
'product_url' => 'http://woographql.com',
'button_text' => 'Buy a external product',
- ]
+ )
);
$relay_id = $this->toRelayId( 'post', $product_id );
@@ -702,34 +702,34 @@ public function testExternalProductQuery() {
}
';
- $variables = [ 'id' => $relay_id ];
+ $variables = array( 'id' => $relay_id );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'product.id', $relay_id ),
$this->expectedField( 'product.buttonText', 'Buy a external product' ),
$this->expectedField( 'product.externalUrl', 'http://woographql.com' ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
}
public function testGroupProductConnections() {
$product_id = $this->factory->product->createGrouped(
- [
+ array(
'name' => 'Test Group',
- 'children' => [],
- ]
+ 'children' => array(),
+ )
+ );
+ $grouped_product_ids = array(
+ $this->factory->product->createSimple( array( 'regular_price' => '1.00' ) ),
+ $this->factory->product->createSimple( array( 'regular_price' => '5.00' ) ),
+ $this->factory->product->createSimple( array( 'regular_price' => '10.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' ] ),
- ];
$product = \wc_get_product( $product_id );
$this->factory->product->update_object(
$product,
- [ 'children' => $grouped_product_ids ]
+ array( 'children' => $grouped_product_ids )
);
$relay_id = $this->toRelayId( 'post', $product_id );
@@ -749,9 +749,9 @@ public function testGroupProductConnections() {
}
';
- $variables = [ 'id' => $relay_id ];
+ $variables = array( 'id' => $relay_id );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'product.id', $relay_id ),
$this->expectedField( 'product.addToCartText', 'View products' ),
$this->expectedField(
@@ -759,12 +759,12 @@ public function testGroupProductConnections() {
/* translators: %s: Group name */
sprintf( __( 'View products in the “%s” group', 'wp-graphql-woocommerce' ), 'Test Group' )
),
- ];
+ );
foreach ( $product->get_children() as $grouped_product_id ) {
$expected[] = $this->expectedNode(
'product.products.nodes',
- [ 'id' => $this->toRelayId( 'post', $grouped_product_id ) ]
+ array( 'id' => $this->toRelayId( 'post', $grouped_product_id ) )
);
}
@@ -781,7 +781,7 @@ public function testGroupProductConnections() {
';
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [ $this->expectedField( 'product.price', '$1.00 - $10.00' ) ];
+ $expected = array( $this->expectedField( 'product.price', '$1.00 - $10.00' ) );
$this->assertQuerySuccessful( $response, $expected );
}
@@ -819,25 +819,25 @@ public function testRelatedProductConnections() {
}
';
- $variables = [ 'id' => $this->toRelayId( 'post', $products['product'] ) ];
+ $variables = array( 'id' => $this->toRelayId( 'post', $products['product'] ) );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [];
+ $expected = array();
foreach ( $products['related'] + $products['cross_sell'] + $products['upsell'] as $product_id ) {
$expected[] = $this->expectedNode(
'product.related.nodes',
- [ 'id' => $this->toRelayId( 'post', $product_id ) ]
+ array( 'id' => $this->toRelayId( 'post', $product_id ) )
);
}
foreach ( $products['cross_sell'] as $product_id ) {
$expected[] = $this->expectedNode(
'product.crossSell.nodes',
- [ 'id' => $this->toRelayId( 'post', $product_id ) ]
+ array( 'id' => $this->toRelayId( 'post', $product_id ) )
);
}
foreach ( $products['upsell'] as $product_id ) {
$expected[] = $this->expectedNode(
'product.upsell.nodes',
- [ 'id' => $this->toRelayId( 'post', $product_id ) ]
+ array( 'id' => $this->toRelayId( 'post', $product_id ) )
);
}
@@ -846,13 +846,13 @@ public function testRelatedProductConnections() {
public function testProductToReviewConnections() {
$product_id = $this->factory->product->createSimple();
- $reviews = [
+ $reviews = array(
$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 ),
- ];
+ );
$relay_id = $this->toRelayId( 'post', $product_id );
$product = \wc_get_product( $product_id );
@@ -873,20 +873,20 @@ public function testProductToReviewConnections() {
}
';
- $variables = [ 'id' => $relay_id ];
+ $variables = array( 'id' => $relay_id );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'product.id', $relay_id ),
$this->expectedField( 'product.reviews.averageRating', floatval( $product->get_average_rating() ) ),
- ];
+ );
foreach ( $reviews as $review_id ) {
$expected[] = $this->expectedEdge(
'product.reviews.edges',
- [
+ array(
'rating' => floatval( get_comment_meta( $review_id, 'rating', true ) ),
- 'node' => [ 'id' => $this->toRelayId( 'comment', $review_id ) ],
- ]
+ 'node' => array( 'id' => $this->toRelayId( 'comment', $review_id ) ),
+ )
);
}
@@ -895,13 +895,13 @@ public function testProductToReviewConnections() {
public function testProductGalleryImagesConnection() {
$image_id = $this->factory->post->create(
- [
+ array(
'post_type' => 'attachment',
'post_content' => 'Lorem ipsum dolor...',
- ]
+ )
);
$product_id = $this->factory->product->createSimple(
- [ 'gallery_image_ids' => [ $image_id ] ]
+ array( 'gallery_image_ids' => array( $image_id ) )
);
$query = '
@@ -916,16 +916,16 @@ public function testProductGalleryImagesConnection() {
}
';
- $variables = [ 'id' => $this->toRelayId( 'post', $product_id ) ];
+ $variables = array( 'id' => $this->toRelayId( 'post', $product_id ) );
$response = $this->graphql( compact( 'query', 'variables' ) );
$this->assertQuerySuccessful(
$response,
- [
+ array(
$this->expectedNode(
'product.galleryImages.nodes',
- [ 'id' => $this->toRelayId( 'post', $image_id ) ]
+ array( 'id' => $this->toRelayId( 'post', $image_id ) )
),
- ]
+ )
);
}
@@ -999,7 +999,7 @@ public function testProductQueryWithInterfaces() {
*
* Test querying product.
*/
- $variables = [ 'id' => $this->toRelayId( 'post', $product_id ) ];
+ $variables = array( 'id' => $this->toRelayId( 'post', $product_id ) );
$response = $this->graphql( compact( 'query', 'variables' ) );
$expected = $this->getExpectedProductData( $product_id );
@@ -1014,63 +1014,63 @@ public function testProductQueryWithInterfaces() {
* Test querying product with unformatted content (edit-product cap required).
*/
$this->loginAsShopManager();
- $variables = [
+ $variables = array(
'id' => $this->toRelayId( 'post', $product_id ),
'format' => 'RAW',
- ];
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$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 );
}
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;
+ $kind_attribute = $this->factory->product->createAttribute( 'kind', array( '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 ]
+ array( $normal_term_id )
);
-
+
$kind_attribute_special_only = $this->factory->product->createAttributeObject(
$kind_attribute['attribute_id'],
$kind_attribute['attribute_taxonomy'],
- [ $special_term_id ]
+ array( $special_term_id )
);
$kind_attribute_both = $this->factory->product->createAttributeObject(
$kind_attribute['attribute_id'],
$kind_attribute['attribute_taxonomy'],
- [ $normal_term_id, $special_term_id ]
+ array( $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' ],
- ]
+ array(
+ 'attributes' => array( $kind_attribute_normal_only ),
+ 'default_attributes' => array( 'pa_kind' => 'normal' ),
+ )
);
$special_product_id = $this->factory->product->createSimple(
- [
- 'attributes' => [ $kind_attribute_special_only ],
- 'default_attributes' => [ 'pa_kind' => 'special' ],
- ]
+ array(
+ 'attributes' => array( $kind_attribute_special_only ),
+ 'default_attributes' => array( 'pa_kind' => 'special' ),
+ )
);
$both_product_id = $this->factory->product->createSimple(
- [
- 'attributes' => [ $kind_attribute_both ],
- ]
+ array(
+ 'attributes' => array( $kind_attribute_both ),
+ )
);
// Create query.
@@ -1086,141 +1086,141 @@ public function testProductsQueryWithAttributesFilter() {
}
';
- $variables = [
- 'where' => [
- 'attributes' => [
- 'queries' => [
- [
+ $variables = array(
+ 'where' => array(
+ 'attributes' => array(
+ 'queries' => array(
+ array(
'taxonomy' => 'PA_KIND',
- 'terms' => [ 'normal' ],
- ],
- ],
- ],
- ],
- ];
+ 'terms' => array( 'normal' ),
+ ),
+ ),
+ ),
+ ),
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedNode(
'products.nodes',
- [ 'id' => $this->toRelayId( 'post', $normal_product_id ) ]
+ array( 'id' => $this->toRelayId( 'post', $normal_product_id ) )
),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
- $variables = [
- 'where' => [
- 'attributes' => [
- 'queries' => [
- [
+ $variables = array(
+ 'where' => array(
+ 'attributes' => array(
+ 'queries' => array(
+ array(
'taxonomy' => 'PA_KIND',
- 'terms' => [ 'special' ],
- ],
- ],
- ],
- ],
- ];
- $response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ 'terms' => array( 'special' ),
+ ),
+ ),
+ ),
+ ),
+ );
+ $response = $this->graphql( compact( 'query', 'variables' ) );
+ $expected = array(
$this->expectedNode(
'products.nodes',
- [ 'id' => $this->toRelayId( 'post', $special_product_id ) ]
+ array( 'id' => $this->toRelayId( 'post', $special_product_id ) )
),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
- $variables = [
- 'where' => [
- 'attributes' => [
- 'queries' => [
- [
+ $variables = array(
+ 'where' => array(
+ 'attributes' => array(
+ 'queries' => array(
+ array(
'taxonomy' => 'PA_KIND',
- 'terms' => [ 'normal', 'special' ],
- ],
- ],
- ],
- ],
- ];
- $response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ 'terms' => array( 'normal', 'special' ),
+ ),
+ ),
+ ),
+ ),
+ );
+ $response = $this->graphql( compact( 'query', 'variables' ) );
+ $expected = array(
$this->expectedNode(
'products.nodes',
- [ 'id' => $this->toRelayId( 'post', $both_product_id ) ]
+ array( 'id' => $this->toRelayId( 'post', $both_product_id ) )
),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
- $variables = [
- 'where' => [
- 'attributes' => [
- 'queries' => [
- [
+ $variables = array(
+ 'where' => array(
+ 'attributes' => array(
+ 'queries' => array(
+ array(
'taxonomy' => 'PA_KIND',
- 'terms' => [ 'normal', 'special' ],
+ 'terms' => array( 'normal', 'special' ),
'operator' => 'NOT_IN',
- ],
- ],
- ],
- ],
- ];
- $response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ ),
+ ),
+ ),
+ ),
+ );
+ $response = $this->graphql( compact( 'query', 'variables' ) );
+ $expected = array(
$this->expectedField(
'products.nodes',
static::IS_FALSY
),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
- $variables = [
- 'where' => [
- 'attributes' => [
- 'queries' => [
- [
+ $variables = array(
+ 'where' => array(
+ 'attributes' => array(
+ 'queries' => array(
+ array(
'taxonomy' => 'PA_KIND',
- 'terms' => [ 'normal' ],
+ 'terms' => array( 'normal' ),
'operator' => 'NOT_IN',
- ],
- ]
- ],
- ],
- ];
- $response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ ),
+ ),
+ ),
+ ),
+ );
+ $response = $this->graphql( compact( 'query', 'variables' ) );
+ $expected = array(
$this->expectedNode(
'products.nodes',
- [ 'id' => $this->toRelayId( 'post', $special_product_id ) ]
+ array( 'id' => $this->toRelayId( 'post', $special_product_id ) )
),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
- $variables = [
- 'where' => [
- 'attributes' => [
- 'queries' => [
- [
+ $variables = array(
+ 'where' => array(
+ 'attributes' => array(
+ 'queries' => array(
+ array(
'taxonomy' => 'PA_KIND',
- 'terms' => [ 'normal' ],
- ],
- [
+ 'terms' => array( 'normal' ),
+ ),
+ array(
'taxonomy' => 'PA_KIND',
- 'terms' => [ 'special' ],
- ],
- ],
- 'relation' => 'AND',
- ],
- ],
- ];
- $response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ 'terms' => array( 'special' ),
+ ),
+ ),
+ 'relation' => 'AND',
+ ),
+ ),
+ );
+ $response = $this->graphql( compact( 'query', 'variables' ) );
+ $expected = array(
$this->expectedNode(
'products.nodes',
- [ 'id' => $this->toRelayId( 'post', $both_product_id ) ]
+ array( 'id' => $this->toRelayId( 'post', $both_product_id ) )
),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
}
diff --git a/tests/wpunit/ProductReviewMutationsTest.php b/tests/wpunit/ProductReviewMutationsTest.php
index 0992403c2..c04fbe865 100644
--- a/tests/wpunit/ProductReviewMutationsTest.php
+++ b/tests/wpunit/ProductReviewMutationsTest.php
@@ -8,8 +8,8 @@ public function setUp(): void {
parent::setUp();
// your set up methods here
- $this->shop_manager = $this->factory->user->create( [ 'role' => 'shop_manager' ] );
- $this->customer = $this->factory->user->create( [ 'role' => 'customer' ] );
+ $this->shop_manager = $this->factory->user->create( array( 'role' => 'shop_manager' ) );
+ $this->customer = $this->factory->user->create( array( 'role' => 'customer' ) );
$this->products = $this->getModule( '\Helper\Wpunit' )->product();
}
@@ -28,10 +28,10 @@ private function run_mutation( $mutation_name, $input = null ) {
";
$results = graphql(
- [
+ array(
'query' => $mutation,
- 'variables' => [ 'input' => $input ],
- ]
+ 'variables' => array( 'input' => $input ),
+ )
);
// Use --debug flag to view
@@ -43,134 +43,134 @@ private function run_mutation( $mutation_name, $input = null ) {
// tests
public function testCreateNewReviewMutation() {
wp_set_current_user( $this->shop_manager );
- $input = [
+ $input = array(
'clientMutationId' => 'some_id',
'rating' => 1,
'commentOn' => $this->products->create_simple(),
'content' => 'It came covered in poop!!!',
'author' => 'Rude customer',
'authorEmail' => 'rude-guy@example.com',
- ];
+ );
$actual = $this->run_mutation( 'writeReview', $input );
- $expected = [
- 'data' => [
- 'writeReview' => [
+ $expected = array(
+ 'data' => array(
+ 'writeReview' => array(
'clientMutationId' => 'some_id',
'rating' => 1.0,
- 'review' => [
+ 'review' => array(
'content' => 'It came covered in poop!!!',
- ],
- ],
- ],
- ];
+ ),
+ ),
+ ),
+ );
$this->assertEquals( $expected, $actual );
}
public function testUpdateReviewMutation() {
wp_set_current_user( $this->shop_manager );
$comment_id = $this->factory()->comment->create(
- [
+ array(
'comment_author' => 'Rude customer',
'comment_author_email' => 'rude-guy@example.com',
'comment_post_ID' => $this->products->create_simple(),
'comment_content' => 'It came covered in poop!!!',
'comment_approved' => 1,
'comment_type' => 'review',
- ]
+ )
);
update_comment_meta( $comment_id, 'rating', 1 );
- $input = [
+ $input = array(
'clientMutationId' => 'some_id',
'rating' => 5,
'id' => Relay::toGlobalId( 'comment', $comment_id ),
'content' => 'Turns out it was Nutella. My bad =P',
- ];
+ );
$actual = $this->run_mutation( 'updateReview', $input );
- $expected = [
- 'data' => [
- 'updateReview' => [
+ $expected = array(
+ 'data' => array(
+ 'updateReview' => array(
'clientMutationId' => 'some_id',
'rating' => 5.0,
- 'review' => [
+ 'review' => array(
'content' => 'Turns out it was Nutella. My bad =P',
- ],
- ],
- ],
- ];
+ ),
+ ),
+ ),
+ );
$this->assertEquals( $expected, $actual );
}
public function testDeleteReviewMutation() {
wp_set_current_user( $this->shop_manager );
$comment_id = $this->factory()->comment->create(
- [
+ array(
'comment_author' => 'Rude customer',
'comment_author_email' => 'rude-guy@example.com',
'comment_post_ID' => $this->products->create_simple(),
'comment_content' => 'It came covered in poop!!!',
'comment_approved' => 1,
'comment_type' => 'review',
- ]
+ )
);
update_comment_meta( $comment_id, 'rating', 1 );
- $input = [
+ $input = array(
'clientMutationId' => 'some_id',
'id' => Relay::toGlobalID( 'comment', $comment_id ),
- ];
+ );
$actual = $this->run_mutation( 'deleteReview', $input );
- $expected = [
- 'data' => [
- 'deleteReview' => [
+ $expected = array(
+ 'data' => array(
+ 'deleteReview' => array(
'clientMutationId' => 'some_id',
'rating' => 1.0,
- 'review' => [
+ 'review' => array(
'content' => 'It came covered in poop!!!',
- ],
- ],
- ],
- ];
+ ),
+ ),
+ ),
+ );
$this->assertEquals( $expected, $actual );
}
public function testRestoreReviewMutation() {
wp_set_current_user( $this->shop_manager );
$comment_id = $this->factory()->comment->create(
- [
+ array(
'comment_author' => 'Rude customer',
'comment_author_email' => 'rude-guy@example.com',
'comment_post_ID' => $this->products->create_simple(),
'comment_content' => 'It came covered in poop!!!',
'comment_approved' => 1,
'comment_type' => 'review',
- ]
+ )
);
update_comment_meta( $comment_id, 'rating', 1 );
// Trash comment
wp_delete_comment( $comment_id );
- $input = [
+ $input = array(
'clientMutationId' => 'some_id',
'id' => Relay::toGlobalID( 'comment', $comment_id ),
- ];
+ );
$actual = $this->run_mutation( 'restoreReview', $input );
- $expected = [
- 'data' => [
- 'restoreReview' => [
+ $expected = array(
+ 'data' => array(
+ 'restoreReview' => array(
'clientMutationId' => 'some_id',
'rating' => 1.0,
- 'review' => [
+ 'review' => array(
'content' => 'It came covered in poop!!!',
- ],
- ],
- ],
- ];
+ ),
+ ),
+ ),
+ );
$this->assertEquals( $expected, $actual );
}
}
diff --git a/tests/wpunit/ProductTaxonomyQueriesTest.php b/tests/wpunit/ProductTaxonomyQueriesTest.php
index 146f3d488..0ef6c15d9 100644
--- a/tests/wpunit/ProductTaxonomyQueriesTest.php
+++ b/tests/wpunit/ProductTaxonomyQueriesTest.php
@@ -1,24 +1,24 @@
factory->product->createProductCategory( 'clothing' );
- $shoes_id = $this->factory->product->createProductCategory( 'shoes', [ 'parent' => $clothing_category_id ] );
- $accessories_id = $this->factory->product->createProductCategory( 'accessories', [ 'parent' => $clothing_category_id ] );
- $electronics_category_id = $this->factory->product->createProductCategory( 'electronics' );
- $smartphones_id = $this->factory->product->createProductCategory( 'smartphones', [ 'parent' => $electronics_category_id ] );
- $laptops_id = $this->factory->product->createProductCategory( 'laptops', [ 'parent' => $electronics_category_id ] );
-
- // Create products.
- $clothing_ids = $this->factory->product->create_many( 5, [ 'category_ids' => [ $clothing_category_id ] ] );
- $shoes_ids = $this->factory->product->create_many( 5, [ 'category_ids' => [ $shoes_id, $accessories_id ] ] );
- $accessories_ids = $this->factory->product->create_many( 5, [ 'category_ids' => [ $accessories_id ] ] );
- $electronics_ids = $this->factory->product->create_many( 5, [ 'category_ids' => [ $electronics_category_id ] ] );
- $smartphones_ids = $this->factory->product->create_many( 5, [ 'category_ids' => [ $smartphones_id ] ] );
- $laptops_ids = $this->factory->product->create_many( 5, [ 'category_ids' => [ $laptops_id, $electronics_category_id ] ] );
-
- $query = 'query ($id: ID!) {
+ public function testProductCategoriesToProductsQuery() {
+ // Create categories.
+ $clothing_category_id = $this->factory->product->createProductCategory( 'clothing' );
+ $shoes_id = $this->factory->product->createProductCategory( 'shoes', array( 'parent' => $clothing_category_id ) );
+ $accessories_id = $this->factory->product->createProductCategory( 'accessories', array( 'parent' => $clothing_category_id ) );
+ $electronics_category_id = $this->factory->product->createProductCategory( 'electronics' );
+ $smartphones_id = $this->factory->product->createProductCategory( 'smartphones', array( 'parent' => $electronics_category_id ) );
+ $laptops_id = $this->factory->product->createProductCategory( 'laptops', array( 'parent' => $electronics_category_id ) );
+
+ // Create products.
+ $clothing_ids = $this->factory->product->create_many( 5, array( 'category_ids' => array( $clothing_category_id ) ) );
+ $shoes_ids = $this->factory->product->create_many( 5, array( 'category_ids' => array( $shoes_id, $accessories_id ) ) );
+ $accessories_ids = $this->factory->product->create_many( 5, array( 'category_ids' => array( $accessories_id ) ) );
+ $electronics_ids = $this->factory->product->create_many( 5, array( 'category_ids' => array( $electronics_category_id ) ) );
+ $smartphones_ids = $this->factory->product->create_many( 5, array( 'category_ids' => array( $smartphones_id ) ) );
+ $laptops_ids = $this->factory->product->create_many( 5, array( 'category_ids' => array( $laptops_id, $electronics_category_id ) ) );
+
+ $query = 'query ($id: ID!) {
productCategory(id: $id idType: SLUG) {
id
slug
@@ -36,97 +36,97 @@ public function testProductCategoriesToProductsQuery() {
}
}';
- $variables = [
- 'id' => 'clothing'
- ];
-
- $response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = array_merge(
- [
- $this->expectedField( 'productCategory.id', $this->toRelayId( 'term', $clothing_category_id ) ),
- $this->expectedField( 'productCategory.slug', 'clothing' ),
- ],
- array_map(
- function( $id ) {
- return $this->expectedField( 'productCategory.products.nodes.#.databaseId', $id );
- },
- $clothing_ids
- ),
- array_map(
- function( $id ) {
- return $this->not()->expectedField( 'productCategory.products.nodes.#.databaseId', $id );
- },
- array_merge( $smartphones_ids, $shoes_ids, $accessories_ids )
- ),
- );
-
- $this->assertQuerySuccessful( $response, $expected );
-
- $variables = [
- 'id' => 'accessories'
- ];
-
- $response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = array_merge(
- [
- $this->expectedField( 'productCategory.id', $this->toRelayId( 'term', $accessories_id ) ),
- $this->expectedField( 'productCategory.slug', 'accessories' ),
- ],
- array_map(
- function( $id ) {
- return $this->expectedField( 'productCategory.products.nodes.#.databaseId', $id );
- },
- array_merge( $accessories_ids, $shoes_ids )
- ),
- array_map(
- function( $id ) {
- return $this->not()->expectedField( 'productCategory.products.nodes.#.databaseId', $id );
- },
- array_merge( $clothing_ids, $smartphones_ids, $laptops_ids )
- ),
- );
-
- $this->assertQuerySuccessful( $response, $expected );
-
- $variables = [
- 'id' => 'electronics'
- ];
-
- $response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = array_merge(
- [
- $this->expectedField( 'productCategory.id', $this->toRelayId( 'term', $electronics_category_id ) ),
- $this->expectedField( 'productCategory.slug', 'electronics' ),
- ],
- array_map(
- function( $id ) {
- return $this->expectedField( 'productCategory.products.nodes.#.databaseId', $id );
- },
- array_merge( $electronics_ids, $laptops_ids )
- ),
- array_map(
- function( $id ) {
- return $this->not()->expectedField( 'productCategory.products.nodes.#.databaseId', $id );
- },
- array_merge( $clothing_ids, $shoes_ids, $accessories_ids, $smartphones_ids )
- ),
- );
-
- $this->assertQuerySuccessful( $response, $expected );
- }
-
- public function testProductTagsToProductsQuery() {
- // Create tags.
- $tag1_id = $this->factory->product->createProductTag( 'tag1' );
- $tag2_id = $this->factory->product->createProductTag( 'tag2' );
- $tag3_id = $this->factory->product->createProductTag( 'tag3' );
-
- // Create products.
- $tag1_product_ids = $this->factory->product->create_many( 5, [ 'tag_ids' => [ $tag1_id ] ] );
- $tag2_product_ids = $this->factory->product->create_many( 5, [ 'tag_ids' => [ $tag2_id, $tag3_id ] ] );
- $tag3_product_ids = $this->factory->product->create_many( 5, [ 'tag_ids' => [ $tag3_id ] ] );
-
- $query = 'query ($id: ID!) {
+ $variables = array(
+ 'id' => 'clothing',
+ );
+
+ $response = $this->graphql( compact( 'query', 'variables' ) );
+ $expected = array_merge(
+ array(
+ $this->expectedField( 'productCategory.id', $this->toRelayId( 'term', $clothing_category_id ) ),
+ $this->expectedField( 'productCategory.slug', 'clothing' ),
+ ),
+ array_map(
+ function ( $id ) {
+ return $this->expectedField( 'productCategory.products.nodes.#.databaseId', $id );
+ },
+ $clothing_ids
+ ),
+ array_map(
+ function ( $id ) {
+ return $this->not()->expectedField( 'productCategory.products.nodes.#.databaseId', $id );
+ },
+ array_merge( $smartphones_ids, $shoes_ids, $accessories_ids )
+ ),
+ );
+
+ $this->assertQuerySuccessful( $response, $expected );
+
+ $variables = array(
+ 'id' => 'accessories',
+ );
+
+ $response = $this->graphql( compact( 'query', 'variables' ) );
+ $expected = array_merge(
+ array(
+ $this->expectedField( 'productCategory.id', $this->toRelayId( 'term', $accessories_id ) ),
+ $this->expectedField( 'productCategory.slug', 'accessories' ),
+ ),
+ array_map(
+ function ( $id ) {
+ return $this->expectedField( 'productCategory.products.nodes.#.databaseId', $id );
+ },
+ array_merge( $accessories_ids, $shoes_ids )
+ ),
+ array_map(
+ function ( $id ) {
+ return $this->not()->expectedField( 'productCategory.products.nodes.#.databaseId', $id );
+ },
+ array_merge( $clothing_ids, $smartphones_ids, $laptops_ids )
+ ),
+ );
+
+ $this->assertQuerySuccessful( $response, $expected );
+
+ $variables = array(
+ 'id' => 'electronics',
+ );
+
+ $response = $this->graphql( compact( 'query', 'variables' ) );
+ $expected = array_merge(
+ array(
+ $this->expectedField( 'productCategory.id', $this->toRelayId( 'term', $electronics_category_id ) ),
+ $this->expectedField( 'productCategory.slug', 'electronics' ),
+ ),
+ array_map(
+ function ( $id ) {
+ return $this->expectedField( 'productCategory.products.nodes.#.databaseId', $id );
+ },
+ array_merge( $electronics_ids, $laptops_ids )
+ ),
+ array_map(
+ function ( $id ) {
+ return $this->not()->expectedField( 'productCategory.products.nodes.#.databaseId', $id );
+ },
+ array_merge( $clothing_ids, $shoes_ids, $accessories_ids, $smartphones_ids )
+ ),
+ );
+
+ $this->assertQuerySuccessful( $response, $expected );
+ }
+
+ public function testProductTagsToProductsQuery() {
+ // Create tags.
+ $tag1_id = $this->factory->product->createProductTag( 'tag1' );
+ $tag2_id = $this->factory->product->createProductTag( 'tag2' );
+ $tag3_id = $this->factory->product->createProductTag( 'tag3' );
+
+ // Create products.
+ $tag1_product_ids = $this->factory->product->create_many( 5, array( 'tag_ids' => array( $tag1_id ) ) );
+ $tag2_product_ids = $this->factory->product->create_many( 5, array( 'tag_ids' => array( $tag2_id, $tag3_id ) ) );
+ $tag3_product_ids = $this->factory->product->create_many( 5, array( 'tag_ids' => array( $tag3_id ) ) );
+
+ $query = 'query ($id: ID!) {
productTag(id: $id idType: SLUG) {
id
slug
@@ -144,82 +144,82 @@ public function testProductTagsToProductsQuery() {
}
}';
- $variables = [
- 'id' => 'tag1'
- ];
-
- $response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = array_merge(
- [
- $this->expectedField( 'productTag.id', $this->toRelayId( 'term', $tag1_id ) ),
- $this->expectedField( 'productTag.slug', 'tag1' ),
- ],
- array_map(
- function( $id ) {
- return $this->expectedField( 'productTag.products.nodes.#.databaseId', $id );
- },
- $tag1_product_ids,
- ),
- array_map(
- function( $id ) {
- return $this->not()->expectedField( 'productTag.products.nodes.#.databaseId', $id );
- },
- array_merge( $tag2_product_ids, $tag3_product_ids )
- ),
- );
-
- $this->assertQuerySuccessful( $response, $expected );
-
- $variables = [
- 'id' => 'tag2'
- ];
-
- $response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = array_merge(
- [
- $this->expectedField( 'productTag.id', $this->toRelayId( 'term', $tag2_id ) ),
- $this->expectedField( 'productTag.slug', 'tag2' ),
- ],
- array_map(
- function( $id ) {
- return $this->expectedField( 'productTag.products.nodes.#.databaseId', $id );
- },
- $tag2_product_ids,
- ),
- array_map(
- function( $id ) {
- return $this->not()->expectedField( 'productTag.products.nodes.#.databaseId', $id );
- },
- array_merge( $tag1_product_ids, $tag3_product_ids )
- ),
- );
-
- $this->assertQuerySuccessful( $response, $expected );
-
- $variables = [
- 'id' => 'tag3'
- ];
-
- $response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = array_merge(
- [
- $this->expectedField( 'productTag.id', $this->toRelayId( 'term', $tag3_id ) ),
- $this->expectedField( 'productTag.slug', 'tag3' ),
- ],
- array_map(
- function( $id ) {
- return $this->expectedField( 'productTag.products.nodes.#.databaseId', $id );
- },
- array_merge( $tag2_product_ids, $tag3_product_ids )
- ),
- array_map(
- function( $id ) {
- return $this->not()->expectedField( 'productTag.products.nodes.#.databaseId', $id );
- },
- $tag1_product_ids,
- ),
- );
-
- $this->assertQuerySuccessful( $response, $expected );
- }
+ $variables = array(
+ 'id' => 'tag1',
+ );
+
+ $response = $this->graphql( compact( 'query', 'variables' ) );
+ $expected = array_merge(
+ array(
+ $this->expectedField( 'productTag.id', $this->toRelayId( 'term', $tag1_id ) ),
+ $this->expectedField( 'productTag.slug', 'tag1' ),
+ ),
+ array_map(
+ function ( $id ) {
+ return $this->expectedField( 'productTag.products.nodes.#.databaseId', $id );
+ },
+ $tag1_product_ids,
+ ),
+ array_map(
+ function ( $id ) {
+ return $this->not()->expectedField( 'productTag.products.nodes.#.databaseId', $id );
+ },
+ array_merge( $tag2_product_ids, $tag3_product_ids )
+ ),
+ );
+
+ $this->assertQuerySuccessful( $response, $expected );
+
+ $variables = array(
+ 'id' => 'tag2',
+ );
+
+ $response = $this->graphql( compact( 'query', 'variables' ) );
+ $expected = array_merge(
+ array(
+ $this->expectedField( 'productTag.id', $this->toRelayId( 'term', $tag2_id ) ),
+ $this->expectedField( 'productTag.slug', 'tag2' ),
+ ),
+ array_map(
+ function ( $id ) {
+ return $this->expectedField( 'productTag.products.nodes.#.databaseId', $id );
+ },
+ $tag2_product_ids,
+ ),
+ array_map(
+ function ( $id ) {
+ return $this->not()->expectedField( 'productTag.products.nodes.#.databaseId', $id );
+ },
+ array_merge( $tag1_product_ids, $tag3_product_ids )
+ ),
+ );
+
+ $this->assertQuerySuccessful( $response, $expected );
+
+ $variables = array(
+ 'id' => 'tag3',
+ );
+
+ $response = $this->graphql( compact( 'query', 'variables' ) );
+ $expected = array_merge(
+ array(
+ $this->expectedField( 'productTag.id', $this->toRelayId( 'term', $tag3_id ) ),
+ $this->expectedField( 'productTag.slug', 'tag3' ),
+ ),
+ array_map(
+ function ( $id ) {
+ return $this->expectedField( 'productTag.products.nodes.#.databaseId', $id );
+ },
+ array_merge( $tag2_product_ids, $tag3_product_ids )
+ ),
+ array_map(
+ function ( $id ) {
+ return $this->not()->expectedField( 'productTag.products.nodes.#.databaseId', $id );
+ },
+ $tag1_product_ids,
+ ),
+ );
+
+ $this->assertQuerySuccessful( $response, $expected );
+ }
}
diff --git a/tests/wpunit/ProductVariationQueriesTest.php b/tests/wpunit/ProductVariationQueriesTest.php
index a3e70e8f0..6da0b488a 100644
--- a/tests/wpunit/ProductVariationQueriesTest.php
+++ b/tests/wpunit/ProductVariationQueriesTest.php
@@ -6,7 +6,7 @@ class ProductVariationQueriesTest extends \Tests\WPGraphQL\WooCommerce\TestCase\
public function expectedProductVariationData( $id ) {
$data = new WC_Product_Variation( $id );
- return [
+ return array(
$this->expectedField( 'productVariation.id', $this->toRelayId( 'post', $id ) ),
$this->expectedField( 'productVariation.databaseId', $data->get_id() ),
$this->expectedField( 'productVariation.name', $data->get_name() ),
@@ -79,7 +79,7 @@ public function expectedProductVariationData( $id ) {
$this->expectedField( 'productVariation.hasAttributes', ! empty( $data->has_attributes() ) ? $data->has_attributes() : static::IS_NULL ),
$this->expectedField( 'productVariation.type', WPEnumType::get_safe_name( $data->get_type() ) ),
$this->expectedField( 'productVariation.parent.node.id', $this->toRelayId( 'post', $data->get_parent_id() ) ),
- ];
+ );
}
// tests
@@ -143,10 +143,10 @@ public function testVariationQuery() {
*
* Tests "ID" ID type.
*/
- $variables = [
+ $variables = array(
'id' => $id,
'idType' => 'ID',
- ];
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
$expected = $this->expectedProductVariationData( $variation_id );
@@ -159,11 +159,11 @@ public function testVariationQuery() {
*
* Tests "DATABASE_ID" ID type.
*/
- $variables = [
+ $variables = array(
'id' => $variation_id,
'idType' => 'DATABASE_ID',
- ];
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
$expected = $this->expectedProductVariationData( $variation_id );
@@ -191,12 +191,12 @@ public function testProductVariationToMediaItemConnections() {
}
';
- $variables = [ 'id' => $id ];
+ $variables = array( 'id' => $id );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'productVariation.id', $id ),
$this->expectedField( 'productVariation.image.id', $this->toRelayId( 'post', $product->get_image_id() ) ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
}
@@ -230,13 +230,13 @@ public function testProductVariationDownloads() {
}
';
- $variables = [ 'id' => $id ];
+ $variables = array( 'id' => $id );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'productVariation.id', $id ),
$this->expectedNode(
'productVariation.downloads',
- [
+ array(
$this->expectedField( 'name', $downloads[0]->get_name() ),
$this->expectedField( 'downloadId', $downloads[0]->get_id() ),
$this->expectedField( 'filePathType', $downloads[0]->get_type_of_file_path() ),
@@ -245,9 +245,9 @@ public function testProductVariationDownloads() {
$this->expectedField( 'allowedFileType', $downloads[0]->is_allowed_filetype() ),
$this->expectedField( 'fileExists', $downloads[0]->file_exists() ),
$this->expectedField( 'file', $downloads[0]->get_file() ),
- ]
+ )
),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
}
@@ -255,31 +255,30 @@ public function testProductVariationDownloads() {
public function testProductsQueriesWithVariations() {
// Create noise products.
$product_id = $this->factory->product->createVariable(
- [
- 'attribute_data' => [ $this->factory->product->createAttribute( 'print', [ 'polka-dot', 'stripe', 'flames' ] ) ],
- ],
+ array(
+ 'attribute_data' => array( $this->factory->product->createAttribute( 'print', array( 'polka-dot', 'stripe', 'flames' ) ) ),
+ ),
);
$variation_id = $this->factory->product_variation->create(
- [
+ array(
'parent_id' => $product_id,
- 'attributes' => [
+ 'attributes' => array(
'pattern' => 'polka-dot',
- ],
+ ),
'image_id' => null,
'regular_price' => 10,
- ]
+ )
);
-
$other_variation_id = $this->factory->product_variation->create(
- [
+ array(
'parent_id' => $product_id,
- 'attributes' => [
+ 'attributes' => array(
'pattern' => 'stripe',
- ],
+ ),
'image_id' => null,
'regular_price' => 10,
- ]
+ )
);
$query = '
@@ -296,37 +295,37 @@ public function testProductsQueriesWithVariations() {
* Assert default results without "type", or "typeIn" excludes product variations.
*/
$response = $this->graphql( compact( 'query' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'products.nodes.0.id', $this->toRelayId( 'post', $product_id ) ),
$this->not()->expectedField( 'products.nodes.#.id', $this->toRelayId( 'post', $variation_id ) ),
$this->not()->expectedField( 'products.nodes.#.id', $this->toRelayId( 'post', $other_variation_id ) ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
/**
* Assert result with "type" set to "VARIATION" only return variations.
*/
- $variables = [ 'type' => 'VARIATION' ];
+ $variables = array( 'type' => 'VARIATION' );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->not()->expectedField( 'products.nodes.#.id', $this->toRelayId( 'post', $product_id ) ),
$this->expectedField( 'products.nodes.#.id', $this->toRelayId( 'post', $variation_id ) ),
$this->expectedField( 'products.nodes.#.id', $this->toRelayId( 'post', $other_variation_id ) ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
/**
* Assert result with "typeIn" set to "VARIATION" & "VARIATION" products and variations are returned.
*/
- $variables = [ 'includeVariations' => true ];
+ $variables = array( 'includeVariations' => true );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'products.nodes.#.id', $this->toRelayId( 'post', $product_id ) ),
$this->expectedField( 'products.nodes.#.id', $this->toRelayId( 'post', $variation_id ) ),
$this->expectedField( 'products.nodes.#.id', $this->toRelayId( 'post', $other_variation_id ) ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
}
diff --git a/tests/wpunit/ProductsQueriesTest.php b/tests/wpunit/ProductsQueriesTest.php
index 5c6cddb73..43acdbd70 100644
--- a/tests/wpunit/ProductsQueriesTest.php
+++ b/tests/wpunit/ProductsQueriesTest.php
@@ -2,98 +2,108 @@
class ProductsQueriesTest extends \Tests\WPGraphQL\WooCommerce\TestCase\WooGraphQLTestCase {
private function createProducts() {
- $products = [
- $this->factory->product->createSimple([
- 'name' => 'Product Blue',
- 'slug' => 'product-blue',
- 'description' => 'A peach description',
- 'price' => 100,
- 'regular_price' => 100,
- 'sale_price' => 90,
- 'stock_status' => 'instock',
- 'stock_quantity' => 10,
- 'reviews_allowed' => true,
- 'average_rating' => 4.5,
- ]),
- $this->factory->product->createSimple([
- 'name' => 'Product Green',
- 'slug' => 'product-green',
- 'description' => 'A turquoise description',
- 'sku' => 'green-sku',
- 'price' => 200,
- 'regular_price' => 200,
- 'sale_price' => 180,
- 'stock_status' => 'instock',
- 'stock_quantity' => 20,
- 'reviews_allowed' => true,
- 'average_rating' => 4.0,
- ]),
- $this->factory->product->createSimple([
- 'name' => 'Product Red',
- 'slug' => 'product-red',
- 'description' => 'A maroon description',
- 'price' => 300,
- 'regular_price' => 300,
- 'sale_price' => 270,
- 'stock_status' => 'instock',
- 'stock_quantity' => 30,
- 'reviews_allowed' => true,
- 'average_rating' => 3.5,
- ]),
- $this->factory->product->createSimple([
- 'name' => 'Product Yellow',
- 'slug' => 'product-yellow',
- 'description' => 'A teal description',
- 'price' => 400,
- 'regular_price' => 400,
- 'sale_price' => 360,
- 'stock_status' => 'instock',
- 'stock_quantity' => 40,
- 'reviews_allowed' => true,
- 'average_rating' => 3.0,
- ]),
- $this->factory->product->createSimple([
- 'name' => 'Product Purple',
- 'slug' => 'product-purple',
- 'description' => 'A magenta description',
- 'price' => 500,
- 'regular_price' => 500,
- 'sale_price' => 450,
- 'stock_status' => 'instock',
- 'stock_quantity' => 50,
- 'reviews_allowed' => true,
- 'average_rating' => 2.5,
- ]),
- ];
+ $products = array(
+ $this->factory->product->createSimple(
+ array(
+ 'name' => 'Product Blue',
+ 'slug' => 'product-blue',
+ 'description' => 'A peach description',
+ 'price' => 100,
+ 'regular_price' => 100,
+ 'sale_price' => 90,
+ 'stock_status' => 'instock',
+ 'stock_quantity' => 10,
+ 'reviews_allowed' => true,
+ 'average_rating' => 4.5,
+ )
+ ),
+ $this->factory->product->createSimple(
+ array(
+ 'name' => 'Product Green',
+ 'slug' => 'product-green',
+ 'description' => 'A turquoise description',
+ 'sku' => 'green-sku',
+ 'price' => 200,
+ 'regular_price' => 200,
+ 'sale_price' => 180,
+ 'stock_status' => 'instock',
+ 'stock_quantity' => 20,
+ 'reviews_allowed' => true,
+ 'average_rating' => 4.0,
+ )
+ ),
+ $this->factory->product->createSimple(
+ array(
+ 'name' => 'Product Red',
+ 'slug' => 'product-red',
+ 'description' => 'A maroon description',
+ 'price' => 300,
+ 'regular_price' => 300,
+ 'sale_price' => 270,
+ 'stock_status' => 'instock',
+ 'stock_quantity' => 30,
+ 'reviews_allowed' => true,
+ 'average_rating' => 3.5,
+ )
+ ),
+ $this->factory->product->createSimple(
+ array(
+ 'name' => 'Product Yellow',
+ 'slug' => 'product-yellow',
+ 'description' => 'A teal description',
+ 'price' => 400,
+ 'regular_price' => 400,
+ 'sale_price' => 360,
+ 'stock_status' => 'instock',
+ 'stock_quantity' => 40,
+ 'reviews_allowed' => true,
+ 'average_rating' => 3.0,
+ )
+ ),
+ $this->factory->product->createSimple(
+ array(
+ 'name' => 'Product Purple',
+ 'slug' => 'product-purple',
+ 'description' => 'A magenta description',
+ 'price' => 500,
+ 'regular_price' => 500,
+ 'sale_price' => 450,
+ 'stock_status' => 'instock',
+ 'stock_quantity' => 50,
+ 'reviews_allowed' => true,
+ 'average_rating' => 2.5,
+ )
+ ),
+ );
$order_id = $this->factory->order->createNew(
- [
+ array(
'payment_method' => 'cod',
- ],
- [
- 'line_items' => [
- [
+ ),
+ array(
+ 'line_items' => array(
+ array(
'product' => $products[0],
'qty' => 10,
- ],
- [
+ ),
+ array(
'product' => $products[1],
'qty' => 8,
- ],
- [
+ ),
+ array(
'product' => $products[2],
'qty' => 6,
- ],
- [
+ ),
+ array(
'product' => $products[3],
'qty' => 4,
- ],
- [
+ ),
+ array(
'product' => $products[4],
'qty' => 2,
- ],
- ],
- ]
+ ),
+ ),
+ )
);
$order = \wc_get_order( $order_id );
@@ -103,140 +113,140 @@ private function createProducts() {
wc_update_total_sales_counts( $order_id );
$review_one = $this->factory()->comment->create(
- [
+ array(
'comment_author' => 'Customer',
'comment_author_email' => 'customer@example.com',
'comment_post_ID' => $products[0],
'comment_content' => 'It worked great!',
'comment_approved' => 1,
'comment_type' => 'review',
- ]
+ )
);
update_comment_meta( $review_one, 'rating', 5.0 );
$review_one = $this->factory()->comment->create(
- [
+ array(
'comment_author' => 'Customer',
'comment_author_email' => 'customer@example.com',
'comment_post_ID' => $products[0],
'comment_content' => 'It worked great!',
'comment_approved' => 1,
'comment_type' => 'review',
- ]
+ )
);
update_comment_meta( $review_one, 'rating', 5.0 );
$review_two = $this->factory()->comment->create(
- [
+ array(
'comment_author' => 'Customer',
'comment_author_email' => 'customer@example.com',
'comment_post_ID' => $products[2],
'comment_content' => 'It was basic',
'comment_approved' => 1,
'comment_type' => 'review',
- ]
+ )
);
update_comment_meta( $review_two, 'rating', 3.0 );
$review_three = $this->factory()->comment->create(
- [
+ array(
'comment_author' => 'Customer',
'comment_author_email' => 'customer@example.com',
'comment_post_ID' => $products[2],
'comment_content' => 'Overpriced',
'comment_approved' => 1,
'comment_type' => 'review',
- ]
+ )
);
update_comment_meta( $review_three, 'rating', 2.0 );
$review_four = $this->factory()->comment->create(
- [
+ array(
'comment_author' => 'Customer',
'comment_author_email' => 'customer@example.com',
'comment_post_ID' => $products[4],
'comment_content' => 'Overpriced',
'comment_approved' => 1,
'comment_type' => 'review',
- ]
+ )
);
update_comment_meta( $review_four, 'rating', 3.5 );
$review_five = $this->factory()->comment->create(
- [
+ array(
'comment_author' => 'Customer',
'comment_author_email' => 'customer@example.com',
'comment_post_ID' => $products[4],
'comment_content' => 'Overpriced and ugly',
'comment_approved' => 1,
'comment_type' => 'review',
- ]
+ )
);
update_comment_meta( $review_five, 'rating', 2.5 );
$review_six = $this->factory()->comment->create(
- [
+ array(
'comment_author' => 'Customer',
'comment_author_email' => 'customer@example.com',
'comment_post_ID' => $products[1],
'comment_content' => 'It was cheap!',
'comment_approved' => 1,
'comment_type' => 'review',
- ]
+ )
);
update_comment_meta( $review_six, 'rating', 4.2 );
$review_six = $this->factory()->comment->create(
- [
+ array(
'comment_author' => 'Customer',
'comment_author_email' => 'customer@example.com',
'comment_post_ID' => $products[1],
'comment_content' => 'It was cheap!',
'comment_approved' => 1,
'comment_type' => 'review',
- ]
+ )
);
update_comment_meta( $review_six, 'rating', 4.2 );
wc_update_product_lookup_tables();
return $products;
- }
+ }
// Tests
- public function testProductsQueryAndWhereArgs() {
+ public function testProductsQueryAndWhereArgs() {
$category_3 = $this->factory->product->createProductCategory( 'category-three' );
$category_4 = $this->factory->product->createProductCategory( 'category-four' );
- $product_ids = [
+ $product_ids = array(
$this->factory->product->createSimple(
- [
+ array(
'slug' => 'test-product-1',
'price' => 6000,
'regular_price' => 6000,
- ]
+ )
),
$this->factory->product->createSimple(
- [
+ array(
'price' => 2,
'regular_price' => 2,
- 'category_ids' => [ $category_3, $category_4 ],
- ]
+ 'category_ids' => array( $category_3, $category_4 ),
+ )
),
$this->factory->product->createSimple(
- [
+ array(
'featured' => 'true',
- 'category_ids' => [ $category_3 ],
- ]
+ 'category_ids' => array( $category_3 ),
+ )
),
$this->factory->product->createExternal(),
$this->factory->product->createSimple(
- [
+ array(
'price' => 200,
'regular_price' => 300,
'sale_price' => 200,
'date_on_sale_from' => ( new \DateTime( 'yesterday' ) )->format( 'Y-m-d H:i:s' ),
'date_on_sale_to' => ( new \DateTime( 'tomorrow' ) )->format( 'Y-m-d H:i:s' ),
'stock_status' => 'outofstock',
- ]
+ )
),
- ];
+ );
$query = '
query (
@@ -297,7 +307,7 @@ public function testProductsQueryAndWhereArgs() {
function ( $product_id ) {
return $this->expectedNode(
'products.nodes',
- [ $this->expectedField( 'id', $this->toRelayId( 'post', $product_id ) ) ]
+ array( $this->expectedField( 'id', $this->toRelayId( 'post', $product_id ) ) )
);
},
$product_ids
@@ -317,7 +327,7 @@ function ( $product_id ) {
* Tests query with "slug" where argument, and expect the product with
* the slug "test-product-1" to be returned.
*/
- $variables = [ 'slugIn' => [ 'test-product-1' ] ];
+ $variables = array( 'slugIn' => array( 'test-product-1' ) );
$response = $this->graphql( compact( 'query', 'variables' ) );
$expected = array_filter(
$all_expected_product_nodes,
@@ -337,9 +347,9 @@ static function ( $node, $index ) use ( $product_ids ) {
* a status of "pending" to be returned, which there are none among the test
* product with that status.
*/
- $variables = [ 'status' => 'pending' ];
+ $variables = array( 'status' => 'pending' );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [ $this->expectedField( 'products.nodes', [] ) ];
+ $expected = array( $this->expectedField( 'products.nodes', array() ) );
$this->assertQuerySuccessful( $response, $expected );
@@ -349,7 +359,7 @@ static function ( $node, $index ) use ( $product_ids ) {
* Tests query with "type" where argument, and expect only "simple" products
* to be returned.
*/
- $variables = [ 'type' => 'SIMPLE' ];
+ $variables = array( 'type' => 'SIMPLE' );
$response = $this->graphql( compact( 'query', 'variables' ) );
$expected = array_filter(
$all_expected_product_nodes,
@@ -368,7 +378,7 @@ static function ( $node, $index ) use ( $product_ids ) {
* Tests query with "typeIn" where argument, and expect only "simple" products
* to be returned.
*/
- $variables = [ 'typeIn' => [ 'SIMPLE' ] ];
+ $variables = array( 'typeIn' => array( 'SIMPLE' ) );
$response = $this->graphql( compact( 'query', 'variables' ) );
// No need to reassign the $expected for this assertion.
@@ -380,7 +390,7 @@ static function ( $node, $index ) use ( $product_ids ) {
* Tests query with "typeNotIn" where argument, and expect all types of products
* with except "simple" to be returned.
*/
- $variables = [ 'typeNotIn' => [ 'SIMPLE' ] ];
+ $variables = array( 'typeNotIn' => array( 'SIMPLE' ) );
$response = $this->graphql( compact( 'query', 'variables' ) );
$expected = array_filter(
$all_expected_product_nodes,
@@ -399,7 +409,7 @@ static function ( $node, $index ) use ( $product_ids ) {
* Tests query with "featured" where argument, expect only featured products
* to be returned.
*/
- $variables = [ 'featured' => true ];
+ $variables = array( 'featured' => true );
$response = $this->graphql( compact( 'query', 'variables' ) );
$expected = array_filter(
$all_expected_product_nodes,
@@ -418,7 +428,7 @@ static function ( $node, $index ) use ( $product_ids ) {
* Tests query with "maxPrice" where argument, and expect all product
* with a price of 10.00+ to be returned.
*/
- $variables = [ 'maxPrice' => 10.00 ];
+ $variables = array( 'maxPrice' => 10.00 );
$response = $this->graphql( compact( 'query', 'variables' ) );
$expected = array_filter(
$all_expected_product_nodes,
@@ -437,28 +447,28 @@ static function ( $node, $index ) use ( $product_ids ) {
* Tests query with "orderby" where argument, and expect products to
* be return in descending order by "price".
*/
- $variables = [
- 'orderby' => [
- [
+ $variables = array(
+ 'orderby' => array(
+ array(
'field' => 'PRICE',
'order' => 'DESC',
- ],
- ],
- ];
+ ),
+ ),
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedNode(
'products.nodes',
- [ $this->expectedField( 'id', $this->toRelayId( 'post', $product_ids[0] ) ) ],
+ array( $this->expectedField( 'id', $this->toRelayId( 'post', $product_ids[0] ) ) ),
0
),
$this->expectedNode(
'products.nodes',
- [ $this->expectedField( 'id', $this->toRelayId( 'post', $product_ids[1] ) ) ],
+ array( $this->expectedField( 'id', $this->toRelayId( 'post', $product_ids[1] ) ) ),
4
),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
@@ -468,7 +478,7 @@ static function ( $node, $index ) use ( $product_ids ) {
* Tests query with "category" where argument, and expect products in
* the "category-three" category to be returned.
*/
- $variables = [ 'category' => 'category-three' ];
+ $variables = array( 'category' => 'category-three' );
$response = $this->graphql( compact( 'query', 'variables' ) );
$expected = array_filter(
$all_expected_product_nodes,
@@ -489,7 +499,7 @@ static function ( $node, $index ) use ( $product_ids, $category_3 ) {
* Tests query with "categoryIn" where argument, and expect products in
* the "category-three" category to be returned.
*/
- $variables = [ 'categoryIn' => [ 'category-three' ] ];
+ $variables = array( 'categoryIn' => array( 'category-three' ) );
$response = $this->graphql( compact( 'query', 'variables' ) );
// No need to reassign the $expected for this assertion.
@@ -501,7 +511,7 @@ static function ( $node, $index ) use ( $product_ids, $category_3 ) {
* Tests query with "categoryId" where argument, and expect products in
* the "category-three" category to be returned.
*/
- $variables = [ 'categoryId' => $category_3 ];
+ $variables = array( 'categoryId' => $category_3 );
$response = $this->graphql( compact( 'query', 'variables' ) );
// No need to reassign the $expected for this assertion either.
@@ -513,7 +523,7 @@ static function ( $node, $index ) use ( $product_ids, $category_3 ) {
* Tests query with "categoryNotIn" where argument, and expect all products
* except products in the "category-four" category to be returned.
*/
- $variables = [ 'categoryNotIn' => [ 'category-four' ] ];
+ $variables = array( 'categoryNotIn' => array( 'category-four' ) );
$response = $this->graphql( compact( 'query', 'variables' ) );
$expected = array_filter(
$all_expected_product_nodes,
@@ -532,7 +542,7 @@ static function ( $node, $index ) use ( $product_ids, $category_4 ) {
* Tests query with "categoryIdNotIn" where argument, and expect all products
* except products in the "category-four" category to be returned.
*/
- $variables = [ 'categoryIdNotIn' => [ $category_4 ] ];
+ $variables = array( 'categoryIdNotIn' => array( $category_4 ) );
$response = $this->graphql( compact( 'query', 'variables' ) );
// No need to reassign the $expected for this assertion.
@@ -544,7 +554,7 @@ static function ( $node, $index ) use ( $product_ids, $category_4 ) {
* Tests query with "categoryIdIn" where argument, and expect products in
* the "category-four" category to be returned.
*/
- $variables = [ 'categoryIdIn' => [ $category_4 ] ];
+ $variables = array( 'categoryIdIn' => array( $category_4 ) );
$response = $this->graphql( compact( 'query', 'variables' ) );
$expected = array_filter(
$all_expected_product_nodes,
@@ -562,22 +572,22 @@ static function ( $node, $index ) use ( $product_ids, $category_4 ) {
*
* Tests "taxonomyFilter" where argument
*/
- $variables = [
- 'taxonomyFilter' => [
+ $variables = array(
+ 'taxonomyFilter' => array(
'relation' => 'AND',
- 'filters' => [
- [
+ 'filters' => array(
+ array(
'taxonomy' => 'PRODUCT_CAT',
- 'terms' => [ 'category-three' ],
- ],
- [
+ 'terms' => array( 'category-three' ),
+ ),
+ array(
'taxonomy' => 'PRODUCT_CAT',
- 'terms' => [ 'category-four' ],
+ 'terms' => array( 'category-four' ),
'operator' => 'NOT_IN',
- ],
- ],
- ],
- ];
+ ),
+ ),
+ ),
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
$expected = array_filter(
$all_expected_product_nodes,
@@ -596,28 +606,28 @@ static function ( $node, $index ) use ( $product_ids, $category_4, $category_3 )
*
* Tests "include" where argument
*/
- $variables = [
- 'include' => [ $product_ids[0] ],
- ];
+ $variables = array(
+ 'include' => array( $product_ids[0] ),
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedNode(
'products.nodes',
- [ $this->expectedField( 'id', $this->toRelayId( 'post', $product_ids[0] ) ) ]
+ array( $this->expectedField( 'id', $this->toRelayId( 'post', $product_ids[0] ) ) )
),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
- $variables = [
- 'include' => [ 1000 ],
- ];
+ $variables = array(
+ 'include' => array( 1000 ),
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField(
'products.nodes',
self::IS_FALSY
),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
/**
@@ -625,26 +635,26 @@ static function ( $node, $index ) use ( $product_ids, $category_4, $category_3 )
*
* Tests "exclude" where argument
*/
- $variables = [
- 'exclude' => [ $product_ids[0] ],
- ];
+ $variables = array(
+ 'exclude' => array( $product_ids[0] ),
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->not()->expectedNode(
'products.nodes',
- [ $this->expectedField( 'id', $this->toRelayId( 'post', $product_ids[0] ) ) ]
+ array( $this->expectedField( 'id', $this->toRelayId( 'post', $product_ids[0] ) ) )
),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
- $variables = [ 'exclude' => $product_ids ];
+ $variables = array( 'exclude' => $product_ids );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField(
'products.nodes',
self::IS_FALSY
),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
/**
@@ -652,25 +662,25 @@ static function ( $node, $index ) use ( $product_ids, $category_4, $category_3 )
*
* Tests "stockStatus" where argument
*/
- $variables = [ 'stockStatus' => 'IN_STOCK' ];
+ $variables = array( 'stockStatus' => 'IN_STOCK' );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->not()->expectedNode(
'products.nodes',
- [ $this->expectedField( 'id', $this->toRelayId( 'post', $product_ids[4] ) ) ]
+ array( $this->expectedField( 'id', $this->toRelayId( 'post', $product_ids[4] ) ) )
),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
- $variables = [ 'stockStatus' => 'OUT_OF_STOCK' ];
+ $variables = array( 'stockStatus' => 'OUT_OF_STOCK' );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedNode(
'products.nodes',
- [ $this->expectedField( 'id', $this->toRelayId( 'post', $product_ids[4] ) ) ],
+ array( $this->expectedField( 'id', $this->toRelayId( 'post', $product_ids[4] ) ) ),
0
),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
}
@@ -720,9 +730,9 @@ public function testVariationsQueryAndWhereArgs() {
* Test query with no arguments
*/
$this->loginAsShopManager();
- $variables = [ 'id' => $id ];
+ $variables = array( 'id' => $id );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'product.variations.nodes.#.id', $this->toRelayId( 'post', $variations[0] ) ),
$this->expectedField( 'product.variations.nodes.#.id', $this->toRelayId( 'post', $variations[1] ) ),
$this->expectedField( 'product.variations.nodes.#.id', $this->toRelayId( 'post', $variations[2] ) ),
@@ -739,7 +749,7 @@ public function testVariationsQueryAndWhereArgs() {
. \wc_graphql_price( end( $prices['regular_price'] ) )
),
$this->expectedField( 'product.salePrice', self::IS_NULL ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
@@ -750,16 +760,16 @@ public function testVariationsQueryAndWhereArgs() {
*
* Test "minPrice" where argument
*/
- $variables = [
+ $variables = array(
'id' => $id,
'minPrice' => 15,
- ];
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->not()->expectedField( 'product.variations.nodes.#.id', $this->toRelayId( 'post', $variations[0] ) ),
$this->expectedField( 'product.variations.nodes.#.id', $this->toRelayId( 'post', $variations[1] ) ),
$this->expectedField( 'product.variations.nodes.#.id', $this->toRelayId( 'post', $variations[2] ) ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
}
@@ -799,34 +809,34 @@ public function testProductsOrderbyArg() {
/**
* Assert sorting by price functions correctly.
*/
- $variables = [
+ $variables = array(
'first' => 2,
- 'orderby' => [
- [
+ 'orderby' => array(
+ array(
'field' => 'PRICE',
'order' => 'ASC',
- ],
- ],
- ];
- $response = $this->graphql( compact( 'query', 'variables' ) );
+ ),
+ ),
+ );
+ $response = $this->graphql( compact( 'query', 'variables' ) );
$this->assertQuerySuccessful(
$response,
- [
+ array(
$this->expectedNode(
'products.nodes',
- [
- $this->expectedField( 'id', $this->toRelayId( 'post', $products[0] ) )
- ],
+ array(
+ $this->expectedField( 'id', $this->toRelayId( 'post', $products[0] ) ),
+ ),
0
),
$this->expectedNode(
'products.nodes',
- [
- $this->expectedField( 'id', $this->toRelayId( 'post', $products[1] ) )
- ],
+ array(
+ $this->expectedField( 'id', $this->toRelayId( 'post', $products[1] ) ),
+ ),
1
),
- ],
+ ),
'Failed to sort products by price in ascending order.'
);
@@ -835,71 +845,71 @@ public function testProductsOrderbyArg() {
*/
$endCursor = $this->lodashGet( $response, 'data.products.pageInfo.endCursor' );
$this->logData( $endCursor );
- $variables = [
+ $variables = array(
'first' => 2,
'after' => $endCursor,
- 'orderby' => [
- [
+ 'orderby' => array(
+ array(
'field' => 'PRICE',
'order' => 'ASC',
- ],
- ],
- ];
+ ),
+ ),
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
$this->assertQuerySuccessful(
$response,
- [
+ array(
$this->expectedNode(
'products.nodes',
- [
- $this->expectedField( 'id', $this->toRelayId( 'post', $products[2] ) )
- ],
+ array(
+ $this->expectedField( 'id', $this->toRelayId( 'post', $products[2] ) ),
+ ),
0
),
$this->expectedNode(
'products.nodes',
- [
- $this->expectedField( 'id', $this->toRelayId( 'post', $products[3] ) )
- ],
+ array(
+ $this->expectedField( 'id', $this->toRelayId( 'post', $products[3] ) ),
+ ),
1
),
- ],
+ ),
'Failed to sort products by price in ascending order with pagination.'
);
/**
* Assert sorting by popularity functions correctly.
*/
- $variables = [
+ $variables = array(
'first' => 2,
- 'orderby' => [
- [
+ 'orderby' => array(
+ array(
'field' => 'POPULARITY',
'order' => 'DESC',
- ],
- ],
- ];
+ ),
+ ),
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
$this->assertQuerySuccessful(
$response,
- [
+ array(
$this->expectedNode(
'products.nodes',
- [
- $this->expectedField( 'id', $this->toRelayId( 'post', $products[0] ) )
- ],
+ array(
+ $this->expectedField( 'id', $this->toRelayId( 'post', $products[0] ) ),
+ ),
0
),
$this->expectedNode(
'products.nodes',
- [
- $this->expectedField( 'id', $this->toRelayId( 'post', $products[1] ) )
- ],
+ array(
+ $this->expectedField( 'id', $this->toRelayId( 'post', $products[1] ) ),
+ ),
1
),
- ],
+ ),
'Failed to sort products by popularity in ascending order.'
);
@@ -907,69 +917,69 @@ public function testProductsOrderbyArg() {
* Assert sorting by popularity functions correctly w/ pagination.
*/
$endCursor = $this->lodashGet( $response, 'data.products.pageInfo.endCursor' );
- $variables = [
+ $variables = array(
'first' => 2,
'after' => $endCursor,
- 'orderby' => [
- [
+ 'orderby' => array(
+ array(
'field' => 'POPULARITY',
'order' => 'DESC',
- ],
- ],
- ];
- $response = $this->graphql( compact( 'query', 'variables' ) );
+ ),
+ ),
+ );
+ $response = $this->graphql( compact( 'query', 'variables' ) );
$this->assertQuerySuccessful(
$response,
- [
+ array(
$this->expectedNode(
'products.nodes',
- [
- $this->expectedField( 'id', $this->toRelayId( 'post', $products[2] ) )
- ],
+ array(
+ $this->expectedField( 'id', $this->toRelayId( 'post', $products[2] ) ),
+ ),
0
),
$this->expectedNode(
'products.nodes',
- [
- $this->expectedField( 'id', $this->toRelayId( 'post', $products[3] ) )
- ],
+ array(
+ $this->expectedField( 'id', $this->toRelayId( 'post', $products[3] ) ),
+ ),
1
),
- ],
+ ),
'Failed to sort products by popularity in ascending order with pagination.'
);
/**
* Assert sorting by rating functions correctly.
*/
- $variables = [
+ $variables = array(
'first' => 2,
- 'orderby' => [
- [
+ 'orderby' => array(
+ array(
'field' => 'RATING',
'order' => 'DESC',
- ],
- ],
- ];
- $response = $this->graphql( compact( 'query', 'variables' ) );
+ ),
+ ),
+ );
+ $response = $this->graphql( compact( 'query', 'variables' ) );
$this->assertQuerySuccessful(
$response,
- [
+ array(
$this->expectedNode(
'products.nodes',
- [
- $this->expectedField( 'id', $this->toRelayId( 'post', $products[0] ) )
- ],
+ array(
+ $this->expectedField( 'id', $this->toRelayId( 'post', $products[0] ) ),
+ ),
0
),
$this->expectedNode(
'products.nodes',
- [
- $this->expectedField( 'id', $this->toRelayId( 'post', $products[1] ) )
- ],
+ array(
+ $this->expectedField( 'id', $this->toRelayId( 'post', $products[1] ) ),
+ ),
1
),
- ],
+ ),
'Failed to sort products by rating in ascending order.'
);
@@ -977,35 +987,35 @@ public function testProductsOrderbyArg() {
* Assert sorting by rating functions correctly w/ pagination.
*/
$endCursor = $this->lodashGet( $response, 'data.products.pageInfo.endCursor' );
- $variables = [
+ $variables = array(
'first' => 2,
'after' => $endCursor,
- 'orderby' => [
- [
+ 'orderby' => array(
+ array(
'field' => 'RATING',
'order' => 'DESC',
- ],
- ],
- ];
- $response = $this->graphql( compact( 'query', 'variables' ) );
+ ),
+ ),
+ );
+ $response = $this->graphql( compact( 'query', 'variables' ) );
$this->assertQuerySuccessful(
$response,
- [
+ array(
$this->expectedNode(
'products.nodes',
- [
- $this->expectedField( 'id', $this->toRelayId( 'post', $products[4] ) )
- ],
+ array(
+ $this->expectedField( 'id', $this->toRelayId( 'post', $products[4] ) ),
+ ),
0
),
$this->expectedNode(
'products.nodes',
- [
- $this->expectedField( 'id', $this->toRelayId( 'post', $products[2] ) )
- ],
+ array(
+ $this->expectedField( 'id', $this->toRelayId( 'post', $products[2] ) ),
+ ),
1
),
- ],
+ ),
'Failed to sort products by rating in ascending order with pagination.'
);
}
@@ -1042,74 +1052,74 @@ public function testProductsSearchArg() {
/**
* Assert search by product title functions correctly.
*/
- $variables = [
+ $variables = array(
'search' => 'Green',
- ];
- $response = $this->graphql( compact( 'query', 'variables' ) );
+ );
+ $response = $this->graphql( compact( 'query', 'variables' ) );
$this->assertQuerySuccessful(
$response,
- [
+ array(
$this->expectedNode(
'products.nodes',
- [
- $this->expectedField( 'id', $this->toRelayId( 'post', $products[1] ) )
- ],
+ array(
+ $this->expectedField( 'id', $this->toRelayId( 'post', $products[1] ) ),
+ ),
0
),
- ],
+ ),
'Failed to search products by product title.'
);
/**
* Assert search by product sku.
*/
- $variables = [ 'search' => 'green-sku' ];
- $response = $this->graphql( compact( 'query', 'variables' ) );
+ $variables = array( 'search' => 'green-sku' );
+ $response = $this->graphql( compact( 'query', 'variables' ) );
$this->assertQuerySuccessful(
$response,
- [
+ array(
$this->expectedNode(
'products.nodes',
- [
- $this->expectedField( 'id', $this->toRelayId( 'post', $products[1] ) )
- ],
+ array(
+ $this->expectedField( 'id', $this->toRelayId( 'post', $products[1] ) ),
+ ),
0
),
- ],
+ ),
'Failed to search products by product sku.'
);
// Search by product description.
- $variables = [ 'search' => 'magenta' ];
- $response = $this->graphql( compact( 'query', 'variables' ) );
+ $variables = array( 'search' => 'magenta' );
+ $response = $this->graphql( compact( 'query', 'variables' ) );
$this->assertQuerySuccessful(
$response,
- [
+ array(
$this->expectedNode(
'products.nodes',
- [
- $this->expectedField( 'id', $this->toRelayId( 'post', $products[4] ) )
- ],
+ array(
+ $this->expectedField( 'id', $this->toRelayId( 'post', $products[4] ) ),
+ ),
0
),
- ],
+ ),
'Failed to search products by product description content.'
);
// Search by slug.
- $variables = [ 'search' => 'product-red' ];
- $response = $this->graphql( compact( 'query', 'variables' ) );
+ $variables = array( 'search' => 'product-red' );
+ $response = $this->graphql( compact( 'query', 'variables' ) );
$this->assertQuerySuccessful(
$response,
- [
+ array(
$this->expectedNode(
'products.nodes',
- [
- $this->expectedField( 'id', $this->toRelayId( 'post', $products[2] ) )
- ],
+ array(
+ $this->expectedField( 'id', $this->toRelayId( 'post', $products[2] ) ),
+ ),
0
),
- ],
+ ),
'Failed to search products by product slug.'
);
}
diff --git a/tests/wpunit/ProtectedRouterTest.php b/tests/wpunit/ProtectedRouterTest.php
index 2a3fb2e92..0635f0501 100644
--- a/tests/wpunit/ProtectedRouterTest.php
+++ b/tests/wpunit/ProtectedRouterTest.php
@@ -18,21 +18,21 @@ public function testGraphQLRewriteRule() {
}
public function testAddQueryVar() {
- $query_vars = [];
+ $query_vars = array();
$router = \WPGraphQL\WooCommerce\Utils\Protected_Router::instance();
$actual = $router->add_query_var( $query_vars );
- $this->assertEquals( $actual, [ apply_filters( 'woographql_authorizing_url_endpoint', \WPGraphQL\WooCommerce\Utils\Protected_Router::$route ) ] );
+ $this->assertEquals( $actual, array( apply_filters( 'woographql_authorizing_url_endpoint', \WPGraphQL\WooCommerce\Utils\Protected_Router::$route ) ) );
}
public function testGetNonceNames() {
$router = \WPGraphQL\WooCommerce\Utils\Protected_Router::instance();
$this->assertEquals(
- [
+ array(
'cart_url' => '_wc_cart',
'checkout_url' => '_wc_checkout',
'account_url' => '_wc_account',
'add_payment_method_url' => '_wc_payment',
- ],
+ ),
$router->get_nonce_names()
);
}
diff --git a/tests/wpunit/QLSessionHandlerTest.php b/tests/wpunit/QLSessionHandlerTest.php
index 569b90705..81bd41d62 100644
--- a/tests/wpunit/QLSessionHandlerTest.php
+++ b/tests/wpunit/QLSessionHandlerTest.php
@@ -12,7 +12,7 @@
}
class QLSessionHandlerTest extends \Tests\WPGraphQL\WooCommerce\TestCase\WooGraphQLTestCase {
-
+
public function setUp(): void {
parent::setUp();
@@ -67,9 +67,9 @@ public function test_init_on_graphql_request() {
usleep( 1000000 );
// Initialize session token for next request.
- remove_action( 'woocommerce_set_cart_cookies', [ $session, 'set_customer_session_token' ] );
- remove_action( 'woographql_update_session', [ $session, 'set_customer_session_token' ] );
- remove_action( 'shutdown', [ $session, 'save_data' ] );
+ remove_action( 'woocommerce_set_cart_cookies', array( $session, 'set_customer_session_token' ) );
+ remove_action( 'woographql_update_session', array( $session, 'set_customer_session_token' ) );
+ remove_action( 'shutdown', array( $session, 'save_data' ) );
// Create new session handler.
$session = new QL_Session_Handler();
@@ -222,12 +222,12 @@ public function test_set_customer_session_token() {
// Should fail to set headers if run before initialization.
$session->set_customer_session_token( true );
- $graphql_response_headers = apply_filters( 'graphql_response_headers_to_send', [] );
+ $graphql_response_headers = apply_filters( 'graphql_response_headers_to_send', array() );
$this->assertArrayNotHasKey( 'woocommerce-session', $graphql_response_headers );
// Should success when run after initialization.
$session->init_session_token();
- $graphql_response_headers = apply_filters( 'graphql_response_headers_to_send', [] );
+ $graphql_response_headers = apply_filters( 'graphql_response_headers_to_send', array() );
$this->assertArrayHasKey( 'woocommerce-session', $graphql_response_headers );
}
diff --git a/tests/wpunit/RefundQueriesTest.php b/tests/wpunit/RefundQueriesTest.php
index cd173260b..3be69012a 100644
--- a/tests/wpunit/RefundQueriesTest.php
+++ b/tests/wpunit/RefundQueriesTest.php
@@ -4,21 +4,21 @@ class RefundQueriesTest extends \Tests\WPGraphQL\WooCommerce\TestCase\WooGraphQL
public function expectedRefundData( $refund_id ) {
$refund = \wc_get_order( $refund_id );
- return [
+ return array(
$this->expectedField( 'refund.id', $this->toRelayId( 'order', $refund_id ) ),
$this->expectedField( 'refund.databaseId', $refund->get_id() ),
$this->expectedField( 'refund.title', $refund->get_post_title() ),
$this->expectedField( 'refund.reason', $refund->get_reason() ),
$this->expectedField( 'refund.amount', floatval( $refund->get_amount() ) ),
$this->expectedField( 'refund.date', (string) $refund->get_date_modified() ),
- ];
+ );
}
// tests
public function testRefundQuery() {
$customer_id = $this->factory->customer->create();
$invalid_customer_id = $this->factory->customer->create();
- $order_id = $this->factory->order->createNew( [ 'customer_id' => $customer_id ] );
+ $order_id = $this->factory->order->createNew( array( 'customer_id' => $customer_id ) );
$this->loginAsShopManager();
$refund_id = $this->factory->refund->createNew( $order_id );
$refund = \wc_get_order( $refund_id );
@@ -46,11 +46,11 @@ public function testRefundQuery() {
* Test query and failed results for users lacking required caps
*/
$this->loginAs( $invalid_customer_id );
- $variables = [ 'id' => $relay_id ];
+ $variables = array( 'id' => $relay_id );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'refund', static::IS_NULL ),
- ];
+ );
$this->assertQueryError( $response, $expected );
@@ -86,7 +86,7 @@ public function testRefundQuery() {
public function testRefundQueryAndIds() {
$customer_id = $this->factory->customer->create();
- $order_id = $this->factory->order->createNew( [ 'customer_id' => $customer_id ] );
+ $order_id = $this->factory->order->createNew( array( 'customer_id' => $customer_id ) );
$refund_id = $this->factory->refund->createNew( $order_id );
$relay_id = $this->toRelayId( 'order', $refund_id );
@@ -104,12 +104,12 @@ public function testRefundQueryAndIds() {
* Test query and "id" argument
*/
$this->loginAs( $customer_id );
- $variables = [
+ $variables = array(
'id' => $relay_id,
'idType' => 'ID',
- ];
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [ $this->expectedField( 'refund.id', $relay_id ) ];
+ $expected = array( $this->expectedField( 'refund.id', $relay_id ) );
$this->assertQuerySuccessful( $response, $expected );
@@ -120,10 +120,10 @@ public function testRefundQueryAndIds() {
*
* Test query and "refundId" argument
*/
- $variables = [
+ $variables = array(
'id' => $refund_id,
'idType' => 'DATABASE_ID',
- ];
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
// Same $expected as last assertion.
@@ -132,12 +132,12 @@ public function testRefundQueryAndIds() {
public function testRefundsQueryAndWhereArgs() {
$order_id = $this->factory->order->createNew();
- $refunds = [
+ $refunds = array(
$this->factory->refund->createNew( $order_id ),
$this->factory->refund->createNew( $this->factory->order->createNew() ),
- $this->factory->refund->createNew( $this->factory->order->createNew(), [ 'status' => 'pending' ] ),
+ $this->factory->refund->createNew( $this->factory->order->createNew(), array( 'status' => 'pending' ) ),
$this->factory->refund->createNew( $this->factory->order->createNew() ),
- ];
+ );
$query = '
query ( $statuses: [String], $orderIn: [Int] ) {
@@ -159,9 +159,9 @@ public function testRefundsQueryAndWhereArgs() {
*/
$this->loginAsCustomer();
$response = $this->graphql( compact( 'query' ) );
- $expected = [
- $this->expectedField( 'refunds.nodes', [] ),
- ];
+ $expected = array(
+ $this->expectedField( 'refunds.nodes', array() ),
+ );
$this->assertQuerySuccessful( $response, $expected );
@@ -174,12 +174,12 @@ public function testRefundsQueryAndWhereArgs() {
*/
$this->loginAsShopManager();
$response = $this->graphql( compact( 'query' ) );
- $expected = [
- $this->expectedNode( 'refunds.nodes', [ 'databaseId' => $refunds[0] ] ),
- $this->expectedNode( 'refunds.nodes', [ 'databaseId' => $refunds[1] ] ),
- $this->expectedNode( 'refunds.nodes', [ 'databaseId' => $refunds[2] ] ),
- $this->expectedNode( 'refunds.nodes', [ 'databaseId' => $refunds[3] ] ),
- ];
+ $expected = array(
+ $this->expectedNode( 'refunds.nodes', array( 'databaseId' => $refunds[0] ) ),
+ $this->expectedNode( 'refunds.nodes', array( 'databaseId' => $refunds[1] ) ),
+ $this->expectedNode( 'refunds.nodes', array( 'databaseId' => $refunds[2] ) ),
+ $this->expectedNode( 'refunds.nodes', array( 'databaseId' => $refunds[3] ) ),
+ );
$this->assertQuerySuccessful( $response, $expected );
@@ -191,14 +191,14 @@ public function testRefundsQueryAndWhereArgs() {
* Test "statuses" where argument results should be empty
* Note: This argument is functionally useless Refunds' "post_status" is always set to "completed".
*/
- $variables = [ 'statuses' => [ 'completed' ] ];
+ $variables = array( 'statuses' => array( 'completed' ) );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
- $this->expectedNode( 'refunds.nodes', [ 'databaseId' => $refunds[0] ] ),
- $this->expectedNode( 'refunds.nodes', [ 'databaseId' => $refunds[1] ] ),
- $this->expectedNode( 'refunds.nodes', [ 'databaseId' => $refunds[3] ] ),
- ];
+ $expected = array(
+ $this->expectedNode( 'refunds.nodes', array( 'databaseId' => $refunds[0] ) ),
+ $this->expectedNode( 'refunds.nodes', array( 'databaseId' => $refunds[1] ) ),
+ $this->expectedNode( 'refunds.nodes', array( 'databaseId' => $refunds[3] ) ),
+ );
$this->assertQuerySuccessful( $response, $expected );
@@ -209,29 +209,29 @@ public function testRefundsQueryAndWhereArgs() {
*
* Test "orderIn" where argument
*/
- $variables = [ 'orderIn' => [ $order_id ] ];
+ $variables = array( 'orderIn' => array( $order_id ) );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
- $this->expectedNode( 'refunds.nodes', [ 'databaseId' => $refunds[0] ] ),
- ];
+ $expected = array(
+ $this->expectedNode( 'refunds.nodes', array( 'databaseId' => $refunds[0] ) ),
+ );
$this->assertQuerySuccessful( $response, $expected );
}
public function testOrderToRefundsConnection() {
$order_id = $this->factory->order->createNew();
- $refunds = [
- $this->factory->refund->createNew( $order_id, [ 'amount' => 0.5 ] ),
+ $refunds = array(
+ $this->factory->refund->createNew( $order_id, array( 'amount' => 0.5 ) ),
$this->factory->refund->createNew(
$order_id,
- [
+ array(
'status' => 'pending',
'amount' => 0.5,
- ]
+ )
),
$this->factory->refund->createNew( $this->factory->order->createNew() ),
- ];
+ );
$query = '
query ( $id: ID! ) {
@@ -246,30 +246,30 @@ public function testOrderToRefundsConnection() {
';
$this->loginAsShopManager();
- $variables = [ 'id' => $this->toRelayId( 'order', $order_id ) ];
+ $variables = array( 'id' => $this->toRelayId( 'order', $order_id ) );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
- $this->expectedNode( 'order.refunds.nodes', [ 'databaseId' => $refunds[0] ] ),
- $this->expectedNode( 'order.refunds.nodes', [ 'databaseId' => $refunds[1] ] ),
- ];
+ $expected = array(
+ $this->expectedNode( 'order.refunds.nodes', array( 'databaseId' => $refunds[0] ) ),
+ $this->expectedNode( 'order.refunds.nodes', array( 'databaseId' => $refunds[1] ) ),
+ );
$this->assertQuerySuccessful( $response, $expected );
}
public function testCustomerToRefundsConnection() {
- $order_id = $this->factory->order->createNew( [ 'customer_id' => $this->customer ] );
- $refunds = [
+ $order_id = $this->factory->order->createNew( array( 'customer_id' => $this->customer ) );
+ $refunds = array(
$this->factory->refund->createNew( $this->factory->order->createNew() ),
- $this->factory->refund->createNew( $order_id, [ 'amount' => 0.5 ] ),
+ $this->factory->refund->createNew( $order_id, array( 'amount' => 0.5 ) ),
$this->factory->refund->createNew(
$order_id,
- [
+ array(
'status' => 'pending',
'amount' => 0.5,
- ]
+ )
),
- ];
+ );
$query = '
query {
@@ -286,11 +286,11 @@ public function testCustomerToRefundsConnection() {
$this->loginAsCustomer();
$response = $this->graphql( compact( 'query' ) );
- $expected = [
- $this->not()->expectedNode( 'customer.refunds.nodes', [ 'databaseId' => $refunds[0] ] ),
- $this->expectedNode( 'customer.refunds.nodes', [ 'databaseId' => $refunds[1] ] ),
- $this->expectedNode( 'customer.refunds.nodes', [ 'databaseId' => $refunds[2] ] ),
- ];
+ $expected = array(
+ $this->not()->expectedNode( 'customer.refunds.nodes', array( 'databaseId' => $refunds[0] ) ),
+ $this->expectedNode( 'customer.refunds.nodes', array( 'databaseId' => $refunds[1] ) ),
+ $this->expectedNode( 'customer.refunds.nodes', array( 'databaseId' => $refunds[2] ) ),
+ );
$this->assertQuerySuccessful( $response, $expected );
}
diff --git a/tests/wpunit/RootQueriesTest.php b/tests/wpunit/RootQueriesTest.php
index bd83277dc..202d377f4 100644
--- a/tests/wpunit/RootQueriesTest.php
+++ b/tests/wpunit/RootQueriesTest.php
@@ -4,7 +4,7 @@ class RootQueriesTest extends \Tests\WPGraphQL\WooCommerce\TestCase\WooGraphQLTe
public function testBillingCountriesQuery() {
// Create shipping zones and shipping rates.
update_option( 'woocommerce_allowed_countries', 'specific' );
- update_option( 'woocommerce_specific_allowed_countries', [ 'US', 'CA' ] );
+ update_option( 'woocommerce_specific_allowed_countries', array( 'US', 'CA' ) );
// Create query
$query = '
@@ -14,12 +14,12 @@ public function testBillingCountriesQuery() {
';
$response = $this->graphql( compact( 'query' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'countries.#', 'US' ),
$this->expectedField( 'countries.#', 'CA' ),
$this->expectedField( 'countries.#', 'GB' ),
$this->expectedField( 'countries.#', 'JP' ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
}
@@ -27,7 +27,7 @@ public function testBillingCountriesQuery() {
public function testShippingCountriesQuery() {
// Create shipping zones and shipping rates.
update_option( 'woocommerce_allowed_countries', 'specific' );
- update_option( 'woocommerce_specific_allowed_countries', [ 'US', 'CA' ] );
+ update_option( 'woocommerce_specific_allowed_countries', array( 'US', 'CA' ) );
// Create query
$query = '
@@ -37,11 +37,11 @@ public function testShippingCountriesQuery() {
';
$response = $this->graphql( compact( 'query' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'allowedCountries.#', 'US' ),
$this->expectedField( 'allowedCountries.#', 'CA' ),
$this->not()->expectedField( 'allowedCountries.#', 'GB' ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
}
@@ -49,7 +49,7 @@ public function testShippingCountriesQuery() {
public function testShippingCountryStatesQuery() {
// Create shipping zones and shipping rates.
update_option( 'woocommerce_allowed_countries', 'specific' );
- update_option( 'woocommerce_specific_allowed_countries', [ 'US', 'CA' ] );
+ update_option( 'woocommerce_specific_allowed_countries', array( 'US', 'CA' ) );
// Create query
$query = '
@@ -61,45 +61,45 @@ public function testShippingCountryStatesQuery() {
}
';
- $variables = [ 'country' => 'US' ];
+ $variables = array( 'country' => 'US' );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedObject(
'countryStates.#',
- [
+ array(
$this->expectedField( 'name', 'Alaska' ),
$this->expectedField( 'code', 'AL' ),
- ]
+ )
),
$this->expectedObject(
'countryStates.#',
- [
+ array(
$this->not()->expectedField( 'name', 'Ontario' ),
$this->not()->expectedField( 'code', 'ON' ),
- ]
+ )
),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
- $variables = [ 'country' => 'CA' ];
+ $variables = array( 'country' => 'CA' );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedObject(
'countryStates.#',
- [
+ array(
$this->expectedField( 'name', 'Ontario' ),
$this->expectedField( 'code', 'ON' ),
- ]
+ )
),
$this->expectedObject(
'countryStates.#',
- [
+ array(
$this->not()->expectedField( 'name', 'Alaska' ),
$this->not()->expectedField( 'code', 'AL' ),
- ]
+ )
),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
}
diff --git a/tests/wpunit/SessionMutationsTest.php b/tests/wpunit/SessionMutationsTest.php
index 182e42636..5bffa8cdc 100644
--- a/tests/wpunit/SessionMutationsTest.php
+++ b/tests/wpunit/SessionMutationsTest.php
@@ -27,38 +27,38 @@ public function testUpdateSessionMutation() {
}
';
- $variables = [
- 'input' => [
- 'sessionData' => [
- [
+ $variables = array(
+ 'input' => array(
+ 'sessionData' => array(
+ array(
'key' => 'test-2',
'value' => 'test-value',
- ],
- ],
- ],
- ];
+ ),
+ ),
+ ),
+ );
/**
* Assert working.
*/
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedObject(
'updateSession.session.#',
- [
+ array(
$this->expectedField( 'key', 'test-2' ),
$this->expectedField( 'value', 'test-value' ),
- ]
+ )
),
$this->expectedField( 'updateSession.customer.id', $this->toRelayId( 'user', $registered ) ),
$this->expectedObject(
'updateSession.customer.session.#',
- [
+ array(
$this->expectedField( 'key', 'test-2' ),
$this->expectedField( 'value', 'test-value' ),
- ]
+ )
),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
}
@@ -72,14 +72,14 @@ public function testForgetSessionMutation() {
// Add products to cart.
$this->factory->cart->add(
- [
+ array(
'product_id' => $this->factory->product->createSimple(),
'quantity' => 2,
- ],
- [
+ ),
+ array(
'product_id' => $this->factory->product->createSimple(),
'quantity' => 1,
- ]
+ )
);
// Save session.
@@ -101,10 +101,10 @@ public function testForgetSessionMutation() {
}
';
- $response = $this->graphql( [ 'query' => $cart_query ] );
+ $response = $this->graphql( array( 'query' => $cart_query ) );
$this->assertQuerySuccessful(
$response,
- [ $this->expectedField( 'cart.contents.nodes', static::NOT_FALSY ) ]
+ array( $this->expectedField( 'cart.contents.nodes', static::NOT_FALSY ) )
);
// Forget session.
@@ -125,10 +125,10 @@ public function testForgetSessionMutation() {
\WC()->session->init();
// Confirm cart is empty.
- $response = $this->graphql( [ 'query' => $cart_query ] );
+ $response = $this->graphql( array( 'query' => $cart_query ) );
$this->assertQuerySuccessful(
$response,
- [ $this->expectedField( 'cart.contents.nodes', static::IS_FALSY ) ]
+ array( $this->expectedField( 'cart.contents.nodes', static::IS_FALSY ) )
);
}
-}
\ No newline at end of file
+}
diff --git a/tests/wpunit/ShippingMethodQueriesTest.php b/tests/wpunit/ShippingMethodQueriesTest.php
index 6484ec0bd..df63d158b 100644
--- a/tests/wpunit/ShippingMethodQueriesTest.php
+++ b/tests/wpunit/ShippingMethodQueriesTest.php
@@ -23,7 +23,7 @@ public function testShippingMethodQueryAndArgs() {
*
* Confirm permission check is working
*/
- $variables = [ 'id' => $id ];
+ $variables = array( 'id' => $id );
$response = $this->graphql( compact( 'query', 'variables' ) );
$this->assertQueryError( $response );
@@ -36,14 +36,14 @@ public function testShippingMethodQueryAndArgs() {
*
* Test "ID" ID type.
*/
- $variables = [ 'id' => $id ];
+ $variables = array( 'id' => $id );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'shippingMethod.id', $id ),
$this->expectedField( 'shippingMethod.databaseId', 'flat_rate' ),
$this->expectedField( 'shippingMethod.title', static::NOT_NULL ),
$this->expectedField( 'shippingMethod.description', static::NOT_NULL ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
@@ -52,7 +52,10 @@ public function testShippingMethodQueryAndArgs() {
*
* Test "DATABASE_ID" ID type.
*/
- $variables = [ 'id' => 'flat_rate', 'idType' => 'DATABASE_ID' ];
+ $variables = array(
+ 'id' => 'flat_rate',
+ 'idType' => 'DATABASE_ID',
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
$this->assertQuerySuccessful( $response, $expected );
@@ -74,8 +77,8 @@ public function testShippingMethodsQuery() {
*
* Confirm permission check is working
*/
- $response = $this->graphql( compact( 'query' ) );
- $this->assertQuerySuccessful( $response, [ $this->expectedField( 'shippingMethods.nodes', static::IS_FALSY ) ] );
+ $response = $this->graphql( compact( 'query' ) );
+ $this->assertQuerySuccessful( $response, array( $this->expectedField( 'shippingMethods.nodes', static::IS_FALSY ) ) );
// Login as shop manager.
$this->loginAsShopManager();
@@ -87,12 +90,11 @@ public function testShippingMethodsQuery() {
*/
$response = $this->graphql( compact( 'query' ) );
$expected = array_map(
- function( $method ) {
+ function ( $method ) {
return $this->expectedField( 'shippingMethods.nodes.#.id', $this->toRelayId( 'shipping_method', $method->id ) );
},
array_values( WC_Shipping::instance()->get_shipping_methods() )
);
-
$this->assertQuerySuccessful( $response, $expected );
}
diff --git a/tests/wpunit/ShippingZoneMutationsTest.php b/tests/wpunit/ShippingZoneMutationsTest.php
index 79ced9f16..05b6f363d 100644
--- a/tests/wpunit/ShippingZoneMutationsTest.php
+++ b/tests/wpunit/ShippingZoneMutationsTest.php
@@ -1,9 +1,9 @@
[
- 'name' => 'Test Shipping Zone',
- 'order' => 0
- ]
- ];
-
- // Execute the request.
- $response = $this->graphql( compact( 'query', 'variables' ) );
-
- // Confirm permissions error.
- $this->assertQueryError( $response );
-
- // Login as admin and re-execute expecting success.
- $this->loginAsShopManager();
- $response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
- $this->expectedObject(
- 'createShippingZone.shippingZone',
- [
- $this->expectedField( 'id', static::NOT_NULL ),
- $this->expectedField( 'name', 'Test Shipping Zone' ),
- $this->expectedField( 'order', 0 ),
- ]
- ),
- ];
-
- // Validate the response.
- $this->assertQuerySuccessful( $response, $expected );
- }
-
- public function testUpdateShippingZoneMutation() {
- // Create a shipping zone.
- $shipping_zone_id = $this->factory->shipping_zone->create(
- [
- 'zone_name' => 'Test Shipping Zone',
- 'zone_order' => 0,
- ]
- );
-
- // Prepare the request.
- $query = 'mutation ($input: UpdateShippingZoneInput!) {
+ // Prepare the variables.
+ $variables = array(
+ 'input' => array(
+ 'name' => 'Test Shipping Zone',
+ 'order' => 0,
+ ),
+ );
+
+ // Execute the request.
+ $response = $this->graphql( compact( 'query', 'variables' ) );
+
+ // Confirm permissions error.
+ $this->assertQueryError( $response );
+
+ // Login as admin and re-execute expecting success.
+ $this->loginAsShopManager();
+ $response = $this->graphql( compact( 'query', 'variables' ) );
+ $expected = array(
+ $this->expectedObject(
+ 'createShippingZone.shippingZone',
+ array(
+ $this->expectedField( 'id', static::NOT_NULL ),
+ $this->expectedField( 'name', 'Test Shipping Zone' ),
+ $this->expectedField( 'order', 0 ),
+ )
+ ),
+ );
+
+ // Validate the response.
+ $this->assertQuerySuccessful( $response, $expected );
+ }
+
+ public function testUpdateShippingZoneMutation() {
+ // Create a shipping zone.
+ $shipping_zone_id = $this->factory->shipping_zone->create(
+ array(
+ 'zone_name' => 'Test Shipping Zone',
+ 'zone_order' => 0,
+ )
+ );
+
+ // Prepare the request.
+ $query = 'mutation ($input: UpdateShippingZoneInput!) {
updateShippingZone(input: $input) {
shippingZone {
id
@@ -66,46 +66,46 @@ public function testUpdateShippingZoneMutation() {
}
}';
- // Prepare the variables.
- $variables = [
- 'input' => [
- 'id' => $shipping_zone_id,
- 'name' => 'Updated Shipping Zone',
- 'order' => 1
- ]
- ];
-
- // Execute the request.
- $response = $this->graphql( compact( 'query', 'variables' ) );
-
- // Confirm permissions error.
- $this->assertQueryError( $response );
-
- // Login as admin and re-execute expecting success.
- $this->loginAsShopManager();
- $response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
- $this->expectedObject(
- 'updateShippingZone.shippingZone',
- [
- $this->expectedField( 'id', $this->toRelayId( 'shipping_zone', $shipping_zone_id ) ),
- $this->expectedField( 'databaseId', $shipping_zone_id ),
- $this->expectedField( 'name', 'Updated Shipping Zone' ),
- $this->expectedField( 'order', 1 ),
- ]
- ),
- ];
-
- // Validate the response.
- $this->assertQuerySuccessful( $response, $expected );
- }
-
- public function testDeleteShippingZoneMutation() {
- // Create a shipping zone.
- $shipping_zone = $this->factory->shipping_zone->create_and_get();
-
- // Prepare the request.
- $query = 'mutation ($input: DeleteShippingZoneInput!) {
+ // Prepare the variables.
+ $variables = array(
+ 'input' => array(
+ 'id' => $shipping_zone_id,
+ 'name' => 'Updated Shipping Zone',
+ 'order' => 1,
+ ),
+ );
+
+ // Execute the request.
+ $response = $this->graphql( compact( 'query', 'variables' ) );
+
+ // Confirm permissions error.
+ $this->assertQueryError( $response );
+
+ // Login as admin and re-execute expecting success.
+ $this->loginAsShopManager();
+ $response = $this->graphql( compact( 'query', 'variables' ) );
+ $expected = array(
+ $this->expectedObject(
+ 'updateShippingZone.shippingZone',
+ array(
+ $this->expectedField( 'id', $this->toRelayId( 'shipping_zone', $shipping_zone_id ) ),
+ $this->expectedField( 'databaseId', $shipping_zone_id ),
+ $this->expectedField( 'name', 'Updated Shipping Zone' ),
+ $this->expectedField( 'order', 1 ),
+ )
+ ),
+ );
+
+ // Validate the response.
+ $this->assertQuerySuccessful( $response, $expected );
+ }
+
+ public function testDeleteShippingZoneMutation() {
+ // Create a shipping zone.
+ $shipping_zone = $this->factory->shipping_zone->create_and_get();
+
+ // Prepare the request.
+ $query = 'mutation ($input: DeleteShippingZoneInput!) {
deleteShippingZone(input: $input) {
shippingZone {
id
@@ -116,44 +116,44 @@ public function testDeleteShippingZoneMutation() {
}
}';
- // Prepare the variables.
- $variables = [
- 'input' => [
- 'id' => $shipping_zone->get_id()
- ]
- ];
-
- // Execute the request.
- $response = $this->graphql( compact( 'query', 'variables' ) );
-
- // Confirm permissions error.
- $this->assertQueryError( $response );
-
- // Login as admin and re-execute expecting success.
- $this->loginAsShopManager();
- $response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
- $this->expectedObject(
- 'deleteShippingZone.shippingZone',
- [
- $this->expectedField( 'id', $this->toRelayId( 'shipping_zone', $shipping_zone->get_id() ) ),
- $this->expectedField( 'databaseId', $shipping_zone->get_id() ),
- $this->expectedField( 'name', $shipping_zone->get_zone_name() ),
- $this->expectedField( 'order', $shipping_zone->get_zone_order() ),
- ]
- ),
- ];
-
- // Validate the response.
- $this->assertQuerySuccessful( $response, $expected );
- }
-
- public function testUpdateShippingZoneLocationsMutation() {
- // Create a shipping zone.
- $shipping_zone_id = $this->factory->shipping_zone->create();
-
- // Prepare the request.
- $query = 'mutation ($input: UpdateShippingZoneLocationsInput!) {
+ // Prepare the variables.
+ $variables = array(
+ 'input' => array(
+ 'id' => $shipping_zone->get_id(),
+ ),
+ );
+
+ // Execute the request.
+ $response = $this->graphql( compact( 'query', 'variables' ) );
+
+ // Confirm permissions error.
+ $this->assertQueryError( $response );
+
+ // Login as admin and re-execute expecting success.
+ $this->loginAsShopManager();
+ $response = $this->graphql( compact( 'query', 'variables' ) );
+ $expected = array(
+ $this->expectedObject(
+ 'deleteShippingZone.shippingZone',
+ array(
+ $this->expectedField( 'id', $this->toRelayId( 'shipping_zone', $shipping_zone->get_id() ) ),
+ $this->expectedField( 'databaseId', $shipping_zone->get_id() ),
+ $this->expectedField( 'name', $shipping_zone->get_zone_name() ),
+ $this->expectedField( 'order', $shipping_zone->get_zone_order() ),
+ )
+ ),
+ );
+
+ // Validate the response.
+ $this->assertQuerySuccessful( $response, $expected );
+ }
+
+ public function testUpdateShippingZoneLocationsMutation() {
+ // Create a shipping zone.
+ $shipping_zone_id = $this->factory->shipping_zone->create();
+
+ // Prepare the request.
+ $query = 'mutation ($input: UpdateShippingZoneLocationsInput!) {
updateShippingZoneLocations(input: $input) {
shippingZone {
id
@@ -169,118 +169,118 @@ public function testUpdateShippingZoneLocationsMutation() {
}
}';
- // Prepare the variables.
- $variables = [
- 'input' => [
- 'zoneId' => $shipping_zone_id,
- 'locations' => [
- [
- 'code' => 'US',
- ],
- [
- 'code' => 'CALIFORNIA',
- 'type' => 'STATE',
- ],
- [
- 'code' => '12345',
- 'type' => 'POSTCODE',
- ],
- [
- 'code' => 'NA',
- 'type' => 'CONTINENT',
- ],
- ]
- ]
- ];
-
- // Execute the request.
- $response = $this->graphql( compact( 'query', 'variables' ) );
-
- // Confirm permissions error.
- $this->assertQueryError( $response );
-
- // Login as admin and re-execute expecting success.
- $this->loginAsShopManager();
- $response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
- $this->expectedObject(
- 'updateShippingZoneLocations.shippingZone',
- [
- $this->expectedField( 'id', $this->toRelayId( 'shipping_zone', $shipping_zone_id ) ),
- $this->expectedObject(
- 'locations.0',
- [
- $this->expectedField( 'code', 'US' ),
- $this->expectedField( 'type', 'COUNTRY' )
- ]
- ),
- $this->expectedObject(
- 'locations.1',
- [
- $this->expectedField( 'code', 'CALIFORNIA' ),
- $this->expectedField( 'type', 'STATE' )
- ]
- ),
- $this->expectedObject(
- 'locations.2',
- [
- $this->expectedField( 'code', '12345' ),
- $this->expectedField( 'type', 'POSTCODE' )
- ]
- ),
- $this->expectedObject(
- 'locations.3',
- [
- $this->expectedField( 'code', 'NA' ),
- $this->expectedField( 'type', 'CONTINENT' )
- ]
- )
- ]
- ),
- $this->expectedObject(
- 'updateShippingZoneLocations.locations.0',
- [
- $this->expectedField( 'code', 'US' ),
- $this->expectedField( 'type', 'COUNTRY' )
- ]
- ),
- $this->expectedObject(
- 'updateShippingZoneLocations.locations.1',
- [
- $this->expectedField( 'code', 'CALIFORNIA' ),
- $this->expectedField( 'type', 'STATE' )
- ]
- ),
- $this->expectedObject(
- 'updateShippingZoneLocations.locations.2',
- [
- $this->expectedField( 'code', '12345' ),
- $this->expectedField( 'type', 'POSTCODE' )
- ]
- ),
- $this->expectedObject(
- 'updateShippingZoneLocations.locations.3',
- [
- $this->expectedField( 'code', 'NA' ),
- $this->expectedField( 'type', 'CONTINENT' )
- ]
- )
- ];
-
- // Validate the response.
- $this->assertQuerySuccessful( $response, $expected );
- }
-
- public function testClearShippingZoneLocationsMutation() {
- // Create a shipping zone.
- $shipping_zone = $this->factory->shipping_zone->create_and_get();
-
- // Add a location to the shipping zone.
- $shipping_zone->add_location( 'US', 'country' );
- $shipping_zone->save();
-
- // Prepare the request.
- $query = 'mutation ($input: ClearShippingZoneLocationsInput!) {
+ // Prepare the variables.
+ $variables = array(
+ 'input' => array(
+ 'zoneId' => $shipping_zone_id,
+ 'locations' => array(
+ array(
+ 'code' => 'US',
+ ),
+ array(
+ 'code' => 'CALIFORNIA',
+ 'type' => 'STATE',
+ ),
+ array(
+ 'code' => '12345',
+ 'type' => 'POSTCODE',
+ ),
+ array(
+ 'code' => 'NA',
+ 'type' => 'CONTINENT',
+ ),
+ ),
+ ),
+ );
+
+ // Execute the request.
+ $response = $this->graphql( compact( 'query', 'variables' ) );
+
+ // Confirm permissions error.
+ $this->assertQueryError( $response );
+
+ // Login as admin and re-execute expecting success.
+ $this->loginAsShopManager();
+ $response = $this->graphql( compact( 'query', 'variables' ) );
+ $expected = array(
+ $this->expectedObject(
+ 'updateShippingZoneLocations.shippingZone',
+ array(
+ $this->expectedField( 'id', $this->toRelayId( 'shipping_zone', $shipping_zone_id ) ),
+ $this->expectedObject(
+ 'locations.0',
+ array(
+ $this->expectedField( 'code', 'US' ),
+ $this->expectedField( 'type', 'COUNTRY' ),
+ )
+ ),
+ $this->expectedObject(
+ 'locations.1',
+ array(
+ $this->expectedField( 'code', 'CALIFORNIA' ),
+ $this->expectedField( 'type', 'STATE' ),
+ )
+ ),
+ $this->expectedObject(
+ 'locations.2',
+ array(
+ $this->expectedField( 'code', '12345' ),
+ $this->expectedField( 'type', 'POSTCODE' ),
+ )
+ ),
+ $this->expectedObject(
+ 'locations.3',
+ array(
+ $this->expectedField( 'code', 'NA' ),
+ $this->expectedField( 'type', 'CONTINENT' ),
+ )
+ ),
+ )
+ ),
+ $this->expectedObject(
+ 'updateShippingZoneLocations.locations.0',
+ array(
+ $this->expectedField( 'code', 'US' ),
+ $this->expectedField( 'type', 'COUNTRY' ),
+ )
+ ),
+ $this->expectedObject(
+ 'updateShippingZoneLocations.locations.1',
+ array(
+ $this->expectedField( 'code', 'CALIFORNIA' ),
+ $this->expectedField( 'type', 'STATE' ),
+ )
+ ),
+ $this->expectedObject(
+ 'updateShippingZoneLocations.locations.2',
+ array(
+ $this->expectedField( 'code', '12345' ),
+ $this->expectedField( 'type', 'POSTCODE' ),
+ )
+ ),
+ $this->expectedObject(
+ 'updateShippingZoneLocations.locations.3',
+ array(
+ $this->expectedField( 'code', 'NA' ),
+ $this->expectedField( 'type', 'CONTINENT' ),
+ )
+ ),
+ );
+
+ // Validate the response.
+ $this->assertQuerySuccessful( $response, $expected );
+ }
+
+ public function testClearShippingZoneLocationsMutation() {
+ // Create a shipping zone.
+ $shipping_zone = $this->factory->shipping_zone->create_and_get();
+
+ // Add a location to the shipping zone.
+ $shipping_zone->add_location( 'US', 'country' );
+ $shipping_zone->save();
+
+ // Prepare the request.
+ $query = 'mutation ($input: ClearShippingZoneLocationsInput!) {
clearShippingZoneLocations(input: $input) {
shippingZone {
id
@@ -295,47 +295,47 @@ public function testClearShippingZoneLocationsMutation() {
}
}';
- // Prepare the variables.
- $variables = [
- 'input' => [ 'zoneId' => $shipping_zone->get_id() ]
- ];
-
- // Execute the request.
- $response = $this->graphql( compact( 'query', 'variables' ) );
-
- // Confirm permissions error.
- $this->assertQueryError( $response );
-
- // Login as admin and re-execute expecting success.
- $this->loginAsShopManager();
- $response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
- $this->expectedObject(
- 'clearShippingZoneLocations.shippingZone',
- [
- $this->expectedField( 'id', $this->toRelayId( 'shipping_zone', $shipping_zone->get_id() ) ),
- $this->expectedField( 'locations', static::IS_FALSY )
- ]
- ),
- $this->expectedObject(
- 'clearShippingZoneLocations.removedLocations.0',
- [
- $this->expectedField( 'code', 'US' ),
- $this->expectedField( 'type', 'COUNTRY' )
- ]
- )
- ];
-
- // Validate the response.
- $this->assertQuerySuccessful( $response, $expected );
- }
-
- public function testAddMethodToShippingZoneMutation() {
- // Create a shipping zone.
- $shipping_zone_id = $this->factory->shipping_zone->create();
-
- // Prepare the request.
- $query = 'mutation ($input: AddMethodToShippingZoneInput!) {
+ // Prepare the variables.
+ $variables = array(
+ 'input' => array( 'zoneId' => $shipping_zone->get_id() ),
+ );
+
+ // Execute the request.
+ $response = $this->graphql( compact( 'query', 'variables' ) );
+
+ // Confirm permissions error.
+ $this->assertQueryError( $response );
+
+ // Login as admin and re-execute expecting success.
+ $this->loginAsShopManager();
+ $response = $this->graphql( compact( 'query', 'variables' ) );
+ $expected = array(
+ $this->expectedObject(
+ 'clearShippingZoneLocations.shippingZone',
+ array(
+ $this->expectedField( 'id', $this->toRelayId( 'shipping_zone', $shipping_zone->get_id() ) ),
+ $this->expectedField( 'locations', static::IS_FALSY ),
+ )
+ ),
+ $this->expectedObject(
+ 'clearShippingZoneLocations.removedLocations.0',
+ array(
+ $this->expectedField( 'code', 'US' ),
+ $this->expectedField( 'type', 'COUNTRY' ),
+ )
+ ),
+ );
+
+ // Validate the response.
+ $this->assertQuerySuccessful( $response, $expected );
+ }
+
+ public function testAddMethodToShippingZoneMutation() {
+ // Create a shipping zone.
+ $shipping_zone_id = $this->factory->shipping_zone->create();
+
+ // Prepare the request.
+ $query = 'mutation ($input: AddMethodToShippingZoneInput!) {
addMethodToShippingZone(input: $input) {
shippingZone {
id
@@ -389,100 +389,100 @@ public function testAddMethodToShippingZoneMutation() {
}
}';
- // Prepare the variables.
- $variables = [
- 'input' => [
- 'zoneId' => $shipping_zone_id,
- 'methodId' => 'flat_rate',
- 'order' => 0,
- 'enabled' => true,
- 'settings' => [
- [
- 'id' => 'cost',
- 'value' => '10'
- ]
- ]
- ]
- ];
-
- // Execute the request.
- $response = $this->graphql( compact( 'query', 'variables' ) );
-
- // Confirm permissions error.
- $this->assertQueryError( $response );
-
- // Login as admin and re-execute expecting success.
- $this->loginAsShopManager();
- $response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
- $this->expectedObject(
- 'addMethodToShippingZone.shippingZone',
- [
- $this->expectedField( 'id', $this->toRelayId( 'shipping_zone', $shipping_zone_id ) ),
- $this->expectedNode(
- 'methods.edges',
- [
- $this->expectedField( 'id', static::NOT_NULL ),
- $this->expectedField( 'instanceId', static::NOT_NULL ),
- $this->expectedField( 'order', 0 ),
- $this->expectedField( 'enabled', true ),
- $this->expectedNode(
- 'settings',
- [
- $this->expectedField( 'id', 'cost' ),
- $this->expectedField( 'value', '10' )
- ]
- ),
- $this->expectedObject(
- 'node',
- [
- $this->expectedField( 'id', $this->toRelayId( 'shipping_method', 'flat_rate' ) ),
- $this->expectedField( 'databaseId', static::NOT_NULL ),
- $this->expectedField( 'title', static::NOT_NULL ),
- ]
- )
- ],
- 0
- ),
- ]
- ),
- $this->expectedObject(
- 'addMethodToShippingZone.method',
- [
- $this->expectedField( 'id', static::NOT_NULL ),
- $this->expectedField( 'instanceId', static::NOT_NULL ),
- $this->expectedField( 'order', 0 ),
- $this->expectedField( 'enabled', true ),
- $this->expectedNode(
- 'settings',
- [
- $this->expectedField( 'id', 'cost' ),
- $this->expectedField( 'value', '10' )
- ]
- ),
- $this->expectedObject(
- 'node',
- [
- $this->expectedField( 'id', $this->toRelayId( 'shipping_method', 'flat_rate' ) ),
- $this->expectedField( 'databaseId', static::NOT_NULL ),
- $this->expectedField( 'title', static::NOT_NULL ),
- ]
- )
- ]
- )
- ];
-
- // Validate the response.
- $this->assertQuerySuccessful( $response, $expected );
- }
-
- public function testUpdateMethodOnShippingZoneMutation() {
- // Create a shipping zone.
- $shipping_zone = $this->factory->shipping_zone->create_and_get();
- $instance_id = $shipping_zone->add_shipping_method( 'flat_rate' );
-
- // Prepare the request.
- $query = 'mutation ($input: UpdateMethodOnShippingZoneInput!) {
+ // Prepare the variables.
+ $variables = array(
+ 'input' => array(
+ 'zoneId' => $shipping_zone_id,
+ 'methodId' => 'flat_rate',
+ 'order' => 0,
+ 'enabled' => true,
+ 'settings' => array(
+ array(
+ 'id' => 'cost',
+ 'value' => '10',
+ ),
+ ),
+ ),
+ );
+
+ // Execute the request.
+ $response = $this->graphql( compact( 'query', 'variables' ) );
+
+ // Confirm permissions error.
+ $this->assertQueryError( $response );
+
+ // Login as admin and re-execute expecting success.
+ $this->loginAsShopManager();
+ $response = $this->graphql( compact( 'query', 'variables' ) );
+ $expected = array(
+ $this->expectedObject(
+ 'addMethodToShippingZone.shippingZone',
+ array(
+ $this->expectedField( 'id', $this->toRelayId( 'shipping_zone', $shipping_zone_id ) ),
+ $this->expectedNode(
+ 'methods.edges',
+ array(
+ $this->expectedField( 'id', static::NOT_NULL ),
+ $this->expectedField( 'instanceId', static::NOT_NULL ),
+ $this->expectedField( 'order', 0 ),
+ $this->expectedField( 'enabled', true ),
+ $this->expectedNode(
+ 'settings',
+ array(
+ $this->expectedField( 'id', 'cost' ),
+ $this->expectedField( 'value', '10' ),
+ )
+ ),
+ $this->expectedObject(
+ 'node',
+ array(
+ $this->expectedField( 'id', $this->toRelayId( 'shipping_method', 'flat_rate' ) ),
+ $this->expectedField( 'databaseId', static::NOT_NULL ),
+ $this->expectedField( 'title', static::NOT_NULL ),
+ )
+ ),
+ ),
+ 0
+ ),
+ )
+ ),
+ $this->expectedObject(
+ 'addMethodToShippingZone.method',
+ array(
+ $this->expectedField( 'id', static::NOT_NULL ),
+ $this->expectedField( 'instanceId', static::NOT_NULL ),
+ $this->expectedField( 'order', 0 ),
+ $this->expectedField( 'enabled', true ),
+ $this->expectedNode(
+ 'settings',
+ array(
+ $this->expectedField( 'id', 'cost' ),
+ $this->expectedField( 'value', '10' ),
+ )
+ ),
+ $this->expectedObject(
+ 'node',
+ array(
+ $this->expectedField( 'id', $this->toRelayId( 'shipping_method', 'flat_rate' ) ),
+ $this->expectedField( 'databaseId', static::NOT_NULL ),
+ $this->expectedField( 'title', static::NOT_NULL ),
+ )
+ ),
+ )
+ ),
+ );
+
+ // Validate the response.
+ $this->assertQuerySuccessful( $response, $expected );
+ }
+
+ public function testUpdateMethodOnShippingZoneMutation() {
+ // Create a shipping zone.
+ $shipping_zone = $this->factory->shipping_zone->create_and_get();
+ $instance_id = $shipping_zone->add_shipping_method( 'flat_rate' );
+
+ // Prepare the request.
+ $query = 'mutation ($input: UpdateMethodOnShippingZoneInput!) {
updateMethodOnShippingZone(input: $input) {
shippingZone {
id
@@ -534,86 +534,86 @@ public function testUpdateMethodOnShippingZoneMutation() {
}
}';
- // Prepare the variables.
- $variables = [
- 'input' => [
- 'zoneId' => $shipping_zone->get_id(),
- 'instanceId' => $instance_id,
- 'settings' => [
- [
- 'id' => 'cost',
- 'value' => '10'
- ]
- ],
- ]
- ];
-
- // Execute the request.
- $response = $this->graphql( compact( 'query', 'variables' ) );
-
- // Confirm permissions error.
- $this->assertQueryError( $response );
-
- // Login as admin and re-execute expecting success.
- $this->loginAsShopManager();
- $response = $this->graphql( compact( 'query', 'variables' ) );
-
- $expected = [
- $this->expectedObject(
- 'updateMethodOnShippingZone.shippingZone',
- [
- $this->expectedField( 'id', $this->toRelayId( 'shipping_zone', $shipping_zone->get_id() ) ),
- $this->expectedNode(
- 'methods.edges',
- [
- $this->expectedField( 'id', $this->toRelayId( 'shipping_zone_method', $instance_id ) ),
- $this->expectedField( 'instanceId', $instance_id ),
- $this->expectedField( 'order', static::NOT_NULL ),
- $this->expectedField( 'enabled', true ),
- $this->expectedNode(
- 'settings',
- [
- $this->expectedField( 'id', 'cost' ),
- $this->expectedField( 'value', '10' )
- ]
- ),
- $this->expectedField( 'node.id', $this->toRelayId( 'shipping_method', 'flat_rate' ) ),
- ],
- 0
- ),
- ]
- ),
- $this->expectedObject(
- 'updateMethodOnShippingZone.method',
- [
- $this->expectedField( 'id', $this->toRelayId( 'shipping_zone_method', $instance_id ) ),
- $this->expectedField( 'instanceId', $instance_id ),
- $this->expectedField( 'order', static::NOT_NULL ),
- $this->expectedField( 'enabled', true ),
- $this->expectedNode(
- 'settings',
- [
- $this->expectedField( 'id', 'cost' ),
- $this->expectedField( 'value', '10' )
- ]
- ),
- $this->expectedField( 'node.id', $this->toRelayId( 'shipping_method', 'flat_rate' ) ),
- ]
- )
- ];
-
- // Validate the response.
- $this->assertQuerySuccessful( $response, $expected );
- }
-
- public function testRemoveMethodFromShippingZoneMutation() {
- // Create a shipping zone and add the shipping method.
- $shipping_zone = $this->factory->shipping_zone->create_and_get();
- $instance_id = $shipping_zone->add_shipping_method( 'flat_rate' );
- $shipping_method = new \WC_Shipping_Flat_Rate( $instance_id );
-
- // Prepare the request.
- $query = 'mutation ($input: RemoveMethodFromShippingZoneInput!) {
+ // Prepare the variables.
+ $variables = array(
+ 'input' => array(
+ 'zoneId' => $shipping_zone->get_id(),
+ 'instanceId' => $instance_id,
+ 'settings' => array(
+ array(
+ 'id' => 'cost',
+ 'value' => '10',
+ ),
+ ),
+ ),
+ );
+
+ // Execute the request.
+ $response = $this->graphql( compact( 'query', 'variables' ) );
+
+ // Confirm permissions error.
+ $this->assertQueryError( $response );
+
+ // Login as admin and re-execute expecting success.
+ $this->loginAsShopManager();
+ $response = $this->graphql( compact( 'query', 'variables' ) );
+
+ $expected = array(
+ $this->expectedObject(
+ 'updateMethodOnShippingZone.shippingZone',
+ array(
+ $this->expectedField( 'id', $this->toRelayId( 'shipping_zone', $shipping_zone->get_id() ) ),
+ $this->expectedNode(
+ 'methods.edges',
+ array(
+ $this->expectedField( 'id', $this->toRelayId( 'shipping_zone_method', $instance_id ) ),
+ $this->expectedField( 'instanceId', $instance_id ),
+ $this->expectedField( 'order', static::NOT_NULL ),
+ $this->expectedField( 'enabled', true ),
+ $this->expectedNode(
+ 'settings',
+ array(
+ $this->expectedField( 'id', 'cost' ),
+ $this->expectedField( 'value', '10' ),
+ )
+ ),
+ $this->expectedField( 'node.id', $this->toRelayId( 'shipping_method', 'flat_rate' ) ),
+ ),
+ 0
+ ),
+ )
+ ),
+ $this->expectedObject(
+ 'updateMethodOnShippingZone.method',
+ array(
+ $this->expectedField( 'id', $this->toRelayId( 'shipping_zone_method', $instance_id ) ),
+ $this->expectedField( 'instanceId', $instance_id ),
+ $this->expectedField( 'order', static::NOT_NULL ),
+ $this->expectedField( 'enabled', true ),
+ $this->expectedNode(
+ 'settings',
+ array(
+ $this->expectedField( 'id', 'cost' ),
+ $this->expectedField( 'value', '10' ),
+ )
+ ),
+ $this->expectedField( 'node.id', $this->toRelayId( 'shipping_method', 'flat_rate' ) ),
+ )
+ ),
+ );
+
+ // Validate the response.
+ $this->assertQuerySuccessful( $response, $expected );
+ }
+
+ public function testRemoveMethodFromShippingZoneMutation() {
+ // Create a shipping zone and add the shipping method.
+ $shipping_zone = $this->factory->shipping_zone->create_and_get();
+ $instance_id = $shipping_zone->add_shipping_method( 'flat_rate' );
+ $shipping_method = new \WC_Shipping_Flat_Rate( $instance_id );
+
+ // Prepare the request.
+ $query = 'mutation ($input: RemoveMethodFromShippingZoneInput!) {
removeMethodFromShippingZone(input: $input) {
shippingZone {
id
@@ -633,44 +633,44 @@ public function testRemoveMethodFromShippingZoneMutation() {
}
}';
- // Prepare the variables.
- $variables = [
- 'input' => [
- 'zoneId' => $shipping_zone->get_id(),
- 'instanceId' => $instance_id
- ]
- ];
-
- // Execute the request.
- $response = $this->graphql( compact( 'query', 'variables' ) );
-
- // Confirm permissions error.
- $this->assertQueryError( $response );
-
- // Login as admin and re-execute expecting success.
- $this->loginAsShopManager();
- $response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
- $this->expectedObject(
- 'removeMethodFromShippingZone.shippingZone',
- [
- $this->expectedField( 'id', $this->toRelayId( 'shipping_zone', $shipping_zone->get_id() ) ),
- $this->expectedField( 'methods.edges', static::IS_FALSY ),
- ]
- ),
- $this->expectedObject(
- 'removeMethodFromShippingZone.removedMethod',
- [
- $this->expectedField( 'enabled', $shipping_method->is_enabled() ),
- $this->expectedNode(
- 'node',
- [ $this->expectedField( 'id', $this->toRelayId( 'shipping_method', $shipping_method->id ) ) ]
- )
- ]
- ),
- ];
-
- // Validate the response.
- $this->assertQuerySuccessful( $response, $expected );
- }
+ // Prepare the variables.
+ $variables = array(
+ 'input' => array(
+ 'zoneId' => $shipping_zone->get_id(),
+ 'instanceId' => $instance_id,
+ ),
+ );
+
+ // Execute the request.
+ $response = $this->graphql( compact( 'query', 'variables' ) );
+
+ // Confirm permissions error.
+ $this->assertQueryError( $response );
+
+ // Login as admin and re-execute expecting success.
+ $this->loginAsShopManager();
+ $response = $this->graphql( compact( 'query', 'variables' ) );
+ $expected = array(
+ $this->expectedObject(
+ 'removeMethodFromShippingZone.shippingZone',
+ array(
+ $this->expectedField( 'id', $this->toRelayId( 'shipping_zone', $shipping_zone->get_id() ) ),
+ $this->expectedField( 'methods.edges', static::IS_FALSY ),
+ )
+ ),
+ $this->expectedObject(
+ 'removeMethodFromShippingZone.removedMethod',
+ array(
+ $this->expectedField( 'enabled', $shipping_method->is_enabled() ),
+ $this->expectedNode(
+ 'node',
+ array( $this->expectedField( 'id', $this->toRelayId( 'shipping_method', $shipping_method->id ) ) )
+ ),
+ )
+ ),
+ );
+
+ // Validate the response.
+ $this->assertQuerySuccessful( $response, $expected );
+ }
}
diff --git a/tests/wpunit/ShippingZoneQueriesTest.php b/tests/wpunit/ShippingZoneQueriesTest.php
index c689e0344..762cdd170 100644
--- a/tests/wpunit/ShippingZoneQueriesTest.php
+++ b/tests/wpunit/ShippingZoneQueriesTest.php
@@ -1,30 +1,29 @@
factory->shipping_zone->create_and_get();
-
- // Add location.
- $shipping_zone->add_location( 'US', 'country' );
- $shipping_zone->save();
-
-
- // Add shipping method.
- $instance_id = $shipping_zone->add_shipping_method( 'flat_rate' );
- $shipping_method = null;
- foreach ( $shipping_zone->get_shipping_methods() as $method ) {
- if ( $method->instance_id === $instance_id ) {
- $shipping_method = $method;
- break;
- }
- }
- $instance_settings = $shipping_method->instance_settings;
- $instance_settings['cost'] = 10.00;
- update_option( $shipping_method->get_instance_option_key(), $instance_settings );
-
- // Prepare the request.
- $query = 'query ($id: ID!) {
+ public function testShippingZoneQuery() {
+ // Create a shipping zone.
+ $shipping_zone = $this->factory->shipping_zone->create_and_get();
+
+ // Add location.
+ $shipping_zone->add_location( 'US', 'country' );
+ $shipping_zone->save();
+
+ // Add shipping method.
+ $instance_id = $shipping_zone->add_shipping_method( 'flat_rate' );
+ $shipping_method = null;
+ foreach ( $shipping_zone->get_shipping_methods() as $method ) {
+ if ( $method->instance_id === $instance_id ) {
+ $shipping_method = $method;
+ break;
+ }
+ }
+ $instance_settings = $shipping_method->instance_settings;
+ $instance_settings['cost'] = 10.00;
+ update_option( $shipping_method->get_instance_option_key(), $instance_settings );
+
+ // Prepare the request.
+ $query = 'query ($id: ID!) {
shippingZone(id: $id) {
id
name
@@ -59,68 +58,68 @@ public function testShippingZoneQuery() {
}
}';
- // Prepare the variables.
- $variables = [ 'id' => $this->toRelayId( 'shipping_zone', $shipping_zone->get_id() ) ];
-
- // Execute the request expecting failure.
- $response = $this->graphql( compact( 'query', 'variables' ) );
- $this->assertQueryError( $response );
+ // Prepare the variables.
+ $variables = array( 'id' => $this->toRelayId( 'shipping_zone', $shipping_zone->get_id() ) );
- // Login as shop manager.
- $this->loginAsShopManager();
+ // Execute the request expecting failure.
+ $response = $this->graphql( compact( 'query', 'variables' ) );
+ $this->assertQueryError( $response );
- // Execute the request expecting success.
- $response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
- $this->expectedObject(
- 'shippingZone',
- [
- $this->expectedField( 'id', $this->toRelayId( 'shipping_zone', $shipping_zone->get_id() ) ),
- $this->expectedField( 'name', $shipping_zone->get_zone_name() ),
- $this->expectedField( 'order', $shipping_zone->get_zone_order() ),
- $this->expectedNode(
- 'locations',
- [
- $this->expectedField( 'code', 'US' ),
- $this->expectedField( 'type', 'COUNTRY' )
- ]
- ),
- $this->expectedNode(
- 'methods.edges',
- [
- $this->expectedField( 'id', $this->toRelayId( 'shipping_zone_method', $instance_id ) ),
- $this->expectedField( 'instanceId', $instance_id ),
- $this->expectedField( 'order', $shipping_method->method_order ),
- $this->expectedField( 'enabled', $shipping_method->is_enabled() ),
- $this->expectedNode(
- 'settings',
- [
- $this->expectedField( 'id', 'cost' ),
- $this->expectedField( 'label', 'Cost' ),
- $this->expectedField( 'description', static::NOT_FALSY ),
- $this->expectedField( 'type', 'TEXT' ),
- $this->expectedField( 'value', '10' ),
- $this->expectedField( 'default', static::IS_NULL ),
- $this->expectedField( 'placeholder', static::IS_NULL ),
- ],
- )
- ],
- 0
- )
- ]
- )
- ];
-
- // Validate the response.
- $this->assertQuerySuccessful( $response, $expected );
- }
-
- public function testShippingZonesQuery() {
- // Create a shipping zones.
- $shipping_zones = $this->factory->shipping_zone->create_many( 3 );
+ // Login as shop manager.
+ $this->loginAsShopManager();
- // Prepare the request.
- $query = 'query {
+ // Execute the request expecting success.
+ $response = $this->graphql( compact( 'query', 'variables' ) );
+ $expected = array(
+ $this->expectedObject(
+ 'shippingZone',
+ array(
+ $this->expectedField( 'id', $this->toRelayId( 'shipping_zone', $shipping_zone->get_id() ) ),
+ $this->expectedField( 'name', $shipping_zone->get_zone_name() ),
+ $this->expectedField( 'order', $shipping_zone->get_zone_order() ),
+ $this->expectedNode(
+ 'locations',
+ array(
+ $this->expectedField( 'code', 'US' ),
+ $this->expectedField( 'type', 'COUNTRY' ),
+ )
+ ),
+ $this->expectedNode(
+ 'methods.edges',
+ array(
+ $this->expectedField( 'id', $this->toRelayId( 'shipping_zone_method', $instance_id ) ),
+ $this->expectedField( 'instanceId', $instance_id ),
+ $this->expectedField( 'order', $shipping_method->method_order ),
+ $this->expectedField( 'enabled', $shipping_method->is_enabled() ),
+ $this->expectedNode(
+ 'settings',
+ array(
+ $this->expectedField( 'id', 'cost' ),
+ $this->expectedField( 'label', 'Cost' ),
+ $this->expectedField( 'description', static::NOT_FALSY ),
+ $this->expectedField( 'type', 'TEXT' ),
+ $this->expectedField( 'value', '10' ),
+ $this->expectedField( 'default', static::IS_NULL ),
+ $this->expectedField( 'placeholder', static::IS_NULL ),
+ ),
+ ),
+ ),
+ 0
+ ),
+ )
+ ),
+ );
+
+ // Validate the response.
+ $this->assertQuerySuccessful( $response, $expected );
+ }
+
+ public function testShippingZonesQuery() {
+ // Create a shipping zones.
+ $shipping_zones = $this->factory->shipping_zone->create_many( 3 );
+
+ // Prepare the request.
+ $query = 'query {
shippingZones {
nodes {
id
@@ -128,41 +127,41 @@ public function testShippingZonesQuery() {
}
}';
- /**
+ /**
* Assertion One
*
* Confirm permission check is working
*/
- $response = $this->graphql( compact( 'query' ) );
- $this->assertQuerySuccessful( $response, [ $this->expectedField( 'shippingZones.nodes', static::IS_FALSY ) ] );
+ $response = $this->graphql( compact( 'query' ) );
+ $this->assertQuerySuccessful( $response, array( $this->expectedField( 'shippingZones.nodes', static::IS_FALSY ) ) );
// Login as shop manager.
$this->loginAsShopManager();
- // Execute the request.
- $response = $this->graphql( compact( 'query' ) );
- $expected = [
- $this->expectedNode(
- 'shippingZones.nodes',
- [
- $this->expectedField( 'id', $this->toRelayId( 'shipping_zone', $shipping_zones[0] ) )
- ]
- ),
- $this->expectedNode(
- 'shippingZones.nodes',
- [
- $this->expectedField( 'id', $this->toRelayId( 'shipping_zone', $shipping_zones[1] ) )
- ]
- ),
- $this->expectedNode(
- 'shippingZones.nodes',
- [
- $this->expectedField( 'id', $this->toRelayId( 'shipping_zone', $shipping_zones[2] ) )
- ]
- )
- ];
-
- // Validate the response.
- $this->assertQuerySuccessful( $response, $expected );
- }
+ // Execute the request.
+ $response = $this->graphql( compact( 'query' ) );
+ $expected = array(
+ $this->expectedNode(
+ 'shippingZones.nodes',
+ array(
+ $this->expectedField( 'id', $this->toRelayId( 'shipping_zone', $shipping_zones[0] ) ),
+ )
+ ),
+ $this->expectedNode(
+ 'shippingZones.nodes',
+ array(
+ $this->expectedField( 'id', $this->toRelayId( 'shipping_zone', $shipping_zones[1] ) ),
+ )
+ ),
+ $this->expectedNode(
+ 'shippingZones.nodes',
+ array(
+ $this->expectedField( 'id', $this->toRelayId( 'shipping_zone', $shipping_zones[2] ) ),
+ )
+ ),
+ );
+
+ // Validate the response.
+ $this->assertQuerySuccessful( $response, $expected );
+ }
}
diff --git a/tests/wpunit/TaxClassMutationsTest.php b/tests/wpunit/TaxClassMutationsTest.php
index a272902ea..730ce4ef1 100644
--- a/tests/wpunit/TaxClassMutationsTest.php
+++ b/tests/wpunit/TaxClassMutationsTest.php
@@ -1,9 +1,9 @@
[
- 'name' => 'Test Tax Class',
- 'slug' => 'test-tax-class'
- ]
- ];
+ // Prepare the variables.
+ $variables = array(
+ 'input' => array(
+ 'name' => 'Test Tax Class',
+ 'slug' => 'test-tax-class',
+ ),
+ );
- // Execute the request expecting failure due to missing permissions.
- $response = $this->graphql( compact( 'query', 'variables' ) );
- $this->assertQueryError( $response );
+ // Execute the request expecting failure due to missing permissions.
+ $response = $this->graphql( compact( 'query', 'variables' ) );
+ $this->assertQueryError( $response );
- // Login as shop manager.
- $this->loginAsShopManager();
+ // Login as shop manager.
+ $this->loginAsShopManager();
- // Execute the request.
- $response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
- $this->expectedObject(
- 'createTaxClass.taxClass',
- [
- $this->expectedField( 'name', 'Test Tax Class' ),
- $this->expectedField( 'slug', 'test-tax-class' )
- ]
- ),
- ];
+ // Execute the request.
+ $response = $this->graphql( compact( 'query', 'variables' ) );
+ $expected = array(
+ $this->expectedObject(
+ 'createTaxClass.taxClass',
+ array(
+ $this->expectedField( 'name', 'Test Tax Class' ),
+ $this->expectedField( 'slug', 'test-tax-class' ),
+ )
+ ),
+ );
- // Validate the response.
- $this->assertQuerySuccessful( $response, $expected );
- }
+ // Validate the response.
+ $this->assertQuerySuccessful( $response, $expected );
+ }
- public function testDeleteTaxClassMutation() {
- // Create a tax class.
- $tax_class = $this->factory->tax_class->create();
+ public function testDeleteTaxClassMutation() {
+ // Create a tax class.
+ $tax_class = $this->factory->tax_class->create();
- // Prepare the request.
- $query = 'mutation ($input: DeleteTaxClassInput!) {
+ // Prepare the request.
+ $query = 'mutation ($input: DeleteTaxClassInput!) {
deleteTaxClass(input: $input) {
taxClass {
name
@@ -57,37 +57,37 @@ public function testDeleteTaxClassMutation() {
}
}';
- // Prepare the variables.
- $variables = [
- 'input' => [
- 'slug' => $tax_class['slug']
- ]
- ];
+ // Prepare the variables.
+ $variables = array(
+ 'input' => array(
+ 'slug' => $tax_class['slug'],
+ ),
+ );
- // Execute the request expecting failure due to missing permissions.
- $response = $this->graphql( compact( 'query', 'variables' ) );
- $this->assertQueryError( $response );
+ // Execute the request expecting failure due to missing permissions.
+ $response = $this->graphql( compact( 'query', 'variables' ) );
+ $this->assertQueryError( $response );
- // Login as shop manager.
- $this->loginAsShopManager();
+ // Login as shop manager.
+ $this->loginAsShopManager();
- // Execute the request.
- $response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
- $this->expectedObject(
- 'deleteTaxClass.taxClass',
- [
- $this->expectedField( 'name', $tax_class['name'] ),
- $this->expectedField( 'slug', $tax_class['slug'] )
- ]
- ),
- ];
+ // Execute the request.
+ $response = $this->graphql( compact( 'query', 'variables' ) );
+ $expected = array(
+ $this->expectedObject(
+ 'deleteTaxClass.taxClass',
+ array(
+ $this->expectedField( 'name', $tax_class['name'] ),
+ $this->expectedField( 'slug', $tax_class['slug'] ),
+ )
+ ),
+ );
- // Validate the response.
- $this->assertQuerySuccessful( $response, $expected );
+ // Validate the response.
+ $this->assertQuerySuccessful( $response, $expected );
- // Ensure the tax class was deleted.
- $tax_class = $this->factory->tax_class->get_object_by_id( $tax_class['slug'] );
- $this->assertNull( $tax_class );
- }
+ // Ensure the tax class was deleted.
+ $tax_class = $this->factory->tax_class->get_object_by_id( $tax_class['slug'] );
+ $this->assertNull( $tax_class );
+ }
}
diff --git a/tests/wpunit/TaxClassQueriesTest.php b/tests/wpunit/TaxClassQueriesTest.php
index ba3740435..304dd88c8 100644
--- a/tests/wpunit/TaxClassQueriesTest.php
+++ b/tests/wpunit/TaxClassQueriesTest.php
@@ -1,12 +1,12 @@
factory->tax_class->create_many( 2 );
+ public function testTaxClassesQuery() {
+ // Create tax classes.
+ $tax_classes = $this->factory->tax_class->create_many( 2 );
- // Prepare the request.
- $query = '{
+ // Prepare the request.
+ $query = '{
taxClasses {
nodes {
name
@@ -14,34 +14,34 @@ public function testTaxClassesQuery() {
}
}
}';
-
- // Execute the request expecting failure due to missing permissions.
- $response = $this->graphql( compact( 'query' ) );
- $this->assertQuerySuccessful( $response, [ $this->expectedField( 'taxClasses.nodes', static::IS_FALSY ) ] );
- // Login as shop manager.
- $this->loginAsShopManager();
+ // Execute the request expecting failure due to missing permissions.
+ $response = $this->graphql( compact( 'query' ) );
+ $this->assertQuerySuccessful( $response, array( $this->expectedField( 'taxClasses.nodes', static::IS_FALSY ) ) );
- // Execute the request.
- $response = $this->graphql( compact( 'query' ) );
- $expected = [
- $this->expectedNode(
- 'taxClasses.nodes',
- [
- $this->expectedField( 'name', $tax_classes[0]['name'] ),
- $this->expectedField( 'slug', $tax_classes[0]['slug'] ),
- ]
- ),
- $this->expectedNode(
- 'taxClasses.nodes',
- [
- $this->expectedField( 'name', $tax_classes[1]['name'] ),
- $this->expectedField( 'slug', $tax_classes[1]['slug'] ),
- ]
- ),
- ];
+ // Login as shop manager.
+ $this->loginAsShopManager();
- // Validate the response.
- $this->assertQuerySuccessful( $response, $expected );
- }
+ // Execute the request.
+ $response = $this->graphql( compact( 'query' ) );
+ $expected = array(
+ $this->expectedNode(
+ 'taxClasses.nodes',
+ array(
+ $this->expectedField( 'name', $tax_classes[0]['name'] ),
+ $this->expectedField( 'slug', $tax_classes[0]['slug'] ),
+ )
+ ),
+ $this->expectedNode(
+ 'taxClasses.nodes',
+ array(
+ $this->expectedField( 'name', $tax_classes[1]['name'] ),
+ $this->expectedField( 'slug', $tax_classes[1]['slug'] ),
+ )
+ ),
+ );
+
+ // Validate the response.
+ $this->assertQuerySuccessful( $response, $expected );
+ }
}
diff --git a/tests/wpunit/TaxRateMutationsTest.php b/tests/wpunit/TaxRateMutationsTest.php
index 99e25165a..44fd33122 100644
--- a/tests/wpunit/TaxRateMutationsTest.php
+++ b/tests/wpunit/TaxRateMutationsTest.php
@@ -3,12 +3,12 @@
use WPGraphQL\Type\WPEnumType;
class TaxRateMutationsTest extends \Tests\WPGraphQL\WooCommerce\TestCase\WooGraphQLTestCase {
- public function testCreateTaxRateMutation() {
- // Create tax class.
- $tax_class = $this->factory->tax_class->create();
+ public function testCreateTaxRateMutation() {
+ // Create tax class.
+ $tax_class = $this->factory->tax_class->create();
- // Prepare the request.
- $query = 'mutation ($input: CreateTaxRateInput!) {
+ // Prepare the request.
+ $query = 'mutation ($input: CreateTaxRateInput!) {
createTaxRate(input: $input) {
taxRate {
id
@@ -28,68 +28,68 @@ class
}
}';
- // Prepare the variables.
- $variables = [
- 'input' => [
- 'rate' => '10',
- 'country' => 'US',
- 'state' => 'CA',
- 'postcodes' => [ '12345', '67890' ],
- 'cities' => [ 'Los Angeles', 'San Francisco' ],
- 'priority' => 1,
- 'compound' => false,
- 'shipping' => false,
- 'order' => 0,
- 'class' => WPEnumType::get_safe_name( $tax_class['slug'] )
- ]
- ];
-
- // Execute the request expecting failure due to missing permissions.
- $response = $this->graphql( compact( 'query', 'variables' ) );
- $this->assertQueryError( $response );
-
- // Login as shop manager.
- $this->loginAsShopManager();
-
- // Execute the request.
- $response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
- $this->expectedObject(
- 'createTaxRate.taxRate',
- [
- $this->expectedField( 'id', self::NOT_NULL ),
- $this->expectedField( 'rate', static::NOT_FALSY ),
- $this->expectedField( 'country', 'US' ),
- $this->expectedField( 'state', 'CA' ),
- $this->expectedField( 'postcode', '67890' ),
- $this->expectedField( 'postcodes.0', '12345' ),
- $this->expectedField( 'postcodes.1', '67890' ),
- $this->expectedField( 'city', 'SAN FRANCISCO' ),
- $this->expectedField( 'cities.0', 'LOS ANGELES' ),
- $this->expectedField( 'cities.1', 'SAN FRANCISCO' ),
- $this->expectedField( 'priority', 1 ),
- $this->expectedField( 'compound', false ),
- $this->expectedField( 'shipping', false ),
- $this->expectedField( 'order', 0 ),
- $this->expectedField( 'class', WPEnumType::get_safe_name( $tax_class['slug'] ) )
- ]
- )
- ];
-
- // Validate the response.
- $this->assertQuerySuccessful( $response, $expected );
- }
-
- public function testUpdateTaxRateMutation() {
- // Create a tax class.
- $old_tax_class = $this->factory->tax_class->create();
- $new_tax_class = $this->factory->tax_class->create();
-
- // Create a tax rate.
- $tax_rate_id = $this->factory->tax_rate->create( [ 'class' => $old_tax_class['slug'] ] );
-
- // Prepare the request.
- $query = 'mutation ($input: UpdateTaxRateInput!) {
+ // Prepare the variables.
+ $variables = array(
+ 'input' => array(
+ 'rate' => '10',
+ 'country' => 'US',
+ 'state' => 'CA',
+ 'postcodes' => array( '12345', '67890' ),
+ 'cities' => array( 'Los Angeles', 'San Francisco' ),
+ 'priority' => 1,
+ 'compound' => false,
+ 'shipping' => false,
+ 'order' => 0,
+ 'class' => WPEnumType::get_safe_name( $tax_class['slug'] ),
+ ),
+ );
+
+ // Execute the request expecting failure due to missing permissions.
+ $response = $this->graphql( compact( 'query', 'variables' ) );
+ $this->assertQueryError( $response );
+
+ // Login as shop manager.
+ $this->loginAsShopManager();
+
+ // Execute the request.
+ $response = $this->graphql( compact( 'query', 'variables' ) );
+ $expected = array(
+ $this->expectedObject(
+ 'createTaxRate.taxRate',
+ array(
+ $this->expectedField( 'id', self::NOT_NULL ),
+ $this->expectedField( 'rate', static::NOT_FALSY ),
+ $this->expectedField( 'country', 'US' ),
+ $this->expectedField( 'state', 'CA' ),
+ $this->expectedField( 'postcode', '67890' ),
+ $this->expectedField( 'postcodes.0', '12345' ),
+ $this->expectedField( 'postcodes.1', '67890' ),
+ $this->expectedField( 'city', 'SAN FRANCISCO' ),
+ $this->expectedField( 'cities.0', 'LOS ANGELES' ),
+ $this->expectedField( 'cities.1', 'SAN FRANCISCO' ),
+ $this->expectedField( 'priority', 1 ),
+ $this->expectedField( 'compound', false ),
+ $this->expectedField( 'shipping', false ),
+ $this->expectedField( 'order', 0 ),
+ $this->expectedField( 'class', WPEnumType::get_safe_name( $tax_class['slug'] ) ),
+ )
+ ),
+ );
+
+ // Validate the response.
+ $this->assertQuerySuccessful( $response, $expected );
+ }
+
+ public function testUpdateTaxRateMutation() {
+ // Create a tax class.
+ $old_tax_class = $this->factory->tax_class->create();
+ $new_tax_class = $this->factory->tax_class->create();
+
+ // Create a tax rate.
+ $tax_rate_id = $this->factory->tax_rate->create( array( 'class' => $old_tax_class['slug'] ) );
+
+ // Prepare the request.
+ $query = 'mutation ($input: UpdateTaxRateInput!) {
updateTaxRate(input: $input) {
taxRate {
id
@@ -107,70 +107,70 @@ class
}
}';
- // Prepare the variables.
- $variables = [
- 'input' => [
- 'id' => $tax_rate_id,
- 'rate' => '20',
- 'country' => 'US',
- 'state' => 'NY',
- 'postcodes' => [ '54321', '09876' ],
- 'cities' => [ 'New York', 'Buffalo' ],
- 'priority' => 2,
- 'compound' => true,
- 'shipping' => true,
- 'order' => 1,
- 'class' => WPEnumType::get_safe_name( $new_tax_class['slug'] )
- ]
- ];
-
- // Execute the request expecting failure due to missing permissions.
- $response = $this->graphql( compact( 'query', 'variables' ) );
- $this->assertQueryError( $response );
-
- // Login as shop manager.
- $this->loginAsShopManager();
-
- // Execute the request.
- $response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
- $this->expectedObject(
- 'updateTaxRate.taxRate',
- [
- $this->expectedField( 'id', $this->toRelayId( 'tax_rate', $tax_rate_id ) ),
- $this->expectedField( 'rate', static::NOT_FALSY ),
- $this->expectedField( 'country', 'US' ),
- $this->expectedField( 'state', 'NY' ),
- $this->expectedField( 'postcodes.0', '54321' ),
- $this->expectedField( 'postcodes.1', '09876' ),
- $this->expectedField( 'cities.0', 'NEW YORK' ),
- $this->expectedField( 'cities.1', 'BUFFALO' ),
- $this->expectedField( 'priority', 2 ),
- $this->expectedField( 'compound', true ),
- $this->expectedField( 'shipping', true ),
- $this->expectedField( 'order', 1 ),
- $this->expectedField( 'class', WPEnumType::get_safe_name( $new_tax_class['slug'] ) ),
- ]
- )
- ];
-
- // Validate the response.
- $this->assertQuerySuccessful( $response, $expected );
- }
-
- public function testDeleteTaxRateMutation() {
- // Create a tax rate.
- $tax_rate = $this->factory->tax_rate->create_and_get(
- [
- 'rate' => '30',
- 'country' => 'US',
- 'state' => 'TX',
- 'class' => 'zero-rate',
- ]
- );
-
- // Prepare the request.
- $query = 'mutation ($input: DeleteTaxRateInput!) {
+ // Prepare the variables.
+ $variables = array(
+ 'input' => array(
+ 'id' => $tax_rate_id,
+ 'rate' => '20',
+ 'country' => 'US',
+ 'state' => 'NY',
+ 'postcodes' => array( '54321', '09876' ),
+ 'cities' => array( 'New York', 'Buffalo' ),
+ 'priority' => 2,
+ 'compound' => true,
+ 'shipping' => true,
+ 'order' => 1,
+ 'class' => WPEnumType::get_safe_name( $new_tax_class['slug'] ),
+ ),
+ );
+
+ // Execute the request expecting failure due to missing permissions.
+ $response = $this->graphql( compact( 'query', 'variables' ) );
+ $this->assertQueryError( $response );
+
+ // Login as shop manager.
+ $this->loginAsShopManager();
+
+ // Execute the request.
+ $response = $this->graphql( compact( 'query', 'variables' ) );
+ $expected = array(
+ $this->expectedObject(
+ 'updateTaxRate.taxRate',
+ array(
+ $this->expectedField( 'id', $this->toRelayId( 'tax_rate', $tax_rate_id ) ),
+ $this->expectedField( 'rate', static::NOT_FALSY ),
+ $this->expectedField( 'country', 'US' ),
+ $this->expectedField( 'state', 'NY' ),
+ $this->expectedField( 'postcodes.0', '54321' ),
+ $this->expectedField( 'postcodes.1', '09876' ),
+ $this->expectedField( 'cities.0', 'NEW YORK' ),
+ $this->expectedField( 'cities.1', 'BUFFALO' ),
+ $this->expectedField( 'priority', 2 ),
+ $this->expectedField( 'compound', true ),
+ $this->expectedField( 'shipping', true ),
+ $this->expectedField( 'order', 1 ),
+ $this->expectedField( 'class', WPEnumType::get_safe_name( $new_tax_class['slug'] ) ),
+ )
+ ),
+ );
+
+ // Validate the response.
+ $this->assertQuerySuccessful( $response, $expected );
+ }
+
+ public function testDeleteTaxRateMutation() {
+ // Create a tax rate.
+ $tax_rate = $this->factory->tax_rate->create_and_get(
+ array(
+ 'rate' => '30',
+ 'country' => 'US',
+ 'state' => 'TX',
+ 'class' => 'zero-rate',
+ )
+ );
+
+ // Prepare the request.
+ $query = 'mutation ($input: DeleteTaxRateInput!) {
deleteTaxRate(input: $input) {
taxRate {
id
@@ -182,40 +182,40 @@ class
}
}';
- // Prepare the variables.
- $variables = [
- 'input' => [
- 'id' => absint( $tax_rate->tax_rate_id ),
- ]
- ];
-
- // Execute the request expecting failure due to missing permissions.
- $response = $this->graphql( compact( 'query', 'variables' ) );
- $this->assertQueryError( $response );
-
- // Login as shop manager.
- $this->loginAsShopManager();
-
- // Execute the request.
- $response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
- $this->expectedObject(
- 'deleteTaxRate.taxRate',
- [
- $this->expectedField( 'id', $this->toRelayId( 'tax_rate', $tax_rate->tax_rate_id ) ),
- $this->expectedField( 'rate', static::NOT_FALSY ),
- $this->expectedField( 'country', 'US' ),
- $this->expectedField( 'state', 'TX' ),
- $this->expectedField( 'class', 'ZERO_RATE' ),
- ]
- )
- ];
-
- // Validate the response.
- $this->assertQuerySuccessful( $response, $expected );
-
- // Ensure the tax rate has been deleted.
- $tax_rate = $this->factory->tax_rate->get_object_by_id( $tax_rate->tax_rate_id );
- $this->assertNull( $tax_rate );
- }
+ // Prepare the variables.
+ $variables = array(
+ 'input' => array(
+ 'id' => absint( $tax_rate->tax_rate_id ),
+ ),
+ );
+
+ // Execute the request expecting failure due to missing permissions.
+ $response = $this->graphql( compact( 'query', 'variables' ) );
+ $this->assertQueryError( $response );
+
+ // Login as shop manager.
+ $this->loginAsShopManager();
+
+ // Execute the request.
+ $response = $this->graphql( compact( 'query', 'variables' ) );
+ $expected = array(
+ $this->expectedObject(
+ 'deleteTaxRate.taxRate',
+ array(
+ $this->expectedField( 'id', $this->toRelayId( 'tax_rate', $tax_rate->tax_rate_id ) ),
+ $this->expectedField( 'rate', static::NOT_FALSY ),
+ $this->expectedField( 'country', 'US' ),
+ $this->expectedField( 'state', 'TX' ),
+ $this->expectedField( 'class', 'ZERO_RATE' ),
+ )
+ ),
+ );
+
+ // Validate the response.
+ $this->assertQuerySuccessful( $response, $expected );
+
+ // Ensure the tax rate has been deleted.
+ $tax_rate = $this->factory->tax_rate->get_object_by_id( $tax_rate->tax_rate_id );
+ $this->assertNull( $tax_rate );
+ }
}
diff --git a/tests/wpunit/TaxRateQueriesTest.php b/tests/wpunit/TaxRateQueriesTest.php
index 53913fa2a..f456ef175 100644
--- a/tests/wpunit/TaxRateQueriesTest.php
+++ b/tests/wpunit/TaxRateQueriesTest.php
@@ -4,7 +4,7 @@ class TaxRateQueriesTest extends \Tests\WPGraphQL\WooCommerce\TestCase\WooGraphQ
public function expectedTaxRateData( $rate_id ) {
$rate = $this->factory->tax_rate->get_object_by_id( $rate_id );
- return [
+ return array(
$this->expectedField( 'taxRate.id', $this->toRelayId( 'tax_rate', $rate_id ) ),
$this->expectedField( 'taxRate.databaseId', absint( $rate->tax_rate_id ) ),
$this->expectedField( 'taxRate.country', ! empty( $rate->tax_rate_country ) ? $rate->tax_rate_country : static::IS_NULL ),
@@ -23,7 +23,7 @@ public function expectedTaxRateData( $rate_id ) {
? WPEnumType::get_safe_name( $rate->tax_rate_class )
: 'STANDARD'
),
- ];
+ );
}
// tests
@@ -51,19 +51,19 @@ class
';
// Execute the request expecting failure due to missing permissions.
- $variables = [ 'id' => $this->toRelayId( 'tax_rate', $rate ) ];
- $response = $this->graphql( compact( 'query', 'variables' ) );
- $this->assertQueryError( $response );
+ $variables = array( 'id' => $this->toRelayId( 'tax_rate', $rate ) );
+ $response = $this->graphql( compact( 'query', 'variables' ) );
+ $this->assertQueryError( $response );
- // Login as shop manager.
- $this->loginAsShopManager();
+ // Login as shop manager.
+ $this->loginAsShopManager();
/**
* Assertion One
*
* Tests query, "id" query arg, and results
*/
- $variables = [ 'id' => $this->toRelayId( 'tax_rate', $rate ) ];
+ $variables = array( 'id' => $this->toRelayId( 'tax_rate', $rate ) );
$response = $this->graphql( compact( 'query', 'variables' ) );
$expected = $this->expectedTaxRateData( $rate );
@@ -74,20 +74,20 @@ class
*
* Tests query, "rateId" query arg, and results
*/
- $variables = [
+ $variables = array(
'id' => $rate,
'idType' => 'DATABASE_ID',
- ];
+ );
$response = $this->graphql( compact( 'query', 'variables' ) );
$this->assertQuerySuccessful( $response, $expected );
}
public function testTaxesQuery() {
- $rates = [
+ $rates = array(
$this->factory->tax_rate->create(),
$this->factory->tax_rate->create(
- [
+ array(
'country' => 'US',
'state' => 'AL',
'city' => 'Montgomery',
@@ -98,10 +98,10 @@ public function testTaxesQuery() {
'compound' => '1',
'shipping' => '1',
'class' => 'reduced-rate',
- ]
+ )
),
$this->factory->tax_rate->create(
- [
+ array(
'country' => 'US',
'state' => 'VA',
'city' => 'Norfolk',
@@ -112,9 +112,9 @@ public function testTaxesQuery() {
'compound' => '1',
'shipping' => '1',
'class' => 'zero-rate',
- ]
+ )
),
- ];
+ );
$query = '
query ( $class: TaxClassEnum, $postCode: String, $postCodeIn: [String] ) {
@@ -128,11 +128,11 @@ class
';
// Execute the request expecting failure due to missing permissions.
- $response = $this->graphql( compact( 'query' ) );
- $this->assertQuerySuccessful( $response, [ $this->expectedField( 'taxRates.nodes', static::IS_FALSY ) ] );
+ $response = $this->graphql( compact( 'query' ) );
+ $this->assertQuerySuccessful( $response, array( $this->expectedField( 'taxRates.nodes', static::IS_FALSY ) ) );
- // Login as shop manager.
- $this->loginAsShopManager();
+ // Login as shop manager.
+ $this->loginAsShopManager();
/**
* Assertion One
@@ -144,9 +144,9 @@ class
function ( $id ) {
return $this->expectedNode(
'taxRates.nodes',
- [
+ array(
$this->expectedField( 'id', $this->toRelayId( 'tax_rate', $id ) ),
- ]
+ )
);
},
$rates
@@ -168,15 +168,15 @@ function ( $id ) {
}
)
);
- $variables = [ 'class' => 'REDUCED_RATE' ];
+ $variables = array( 'class' => 'REDUCED_RATE' );
$response = $this->graphql( compact( 'query', 'variables' ) );
$expected = array_map(
function ( $id ) {
return $this->expectedNode(
'taxRates.nodes',
- [
+ array(
$this->expectedField( 'id', $this->toRelayId( 'tax_rate', $id ) ),
- ]
+ )
);
},
$reduced_tax_rates,
@@ -191,13 +191,13 @@ function ( $id ) {
*
* Tests "postCode" where arg
*/
- $variables = [ 'postCode' => '23451' ];
+ $variables = array( 'postCode' => '23451' );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'taxRates.nodes.0.id', $this->toRelayId( 'tax_rate', $rates[2] ) ),
$this->not()->expectedField( 'taxRates.nodes.#.id', $this->toRelayId( 'tax_rate', $rates[0] ) ),
$this->not()->expectedField( 'taxRates.nodes.#.id', $this->toRelayId( 'tax_rate', $rates[1] ) ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
@@ -206,13 +206,13 @@ function ( $id ) {
*
* Tests "postCodeIn" where arg
*/
- $variables = [ 'postCodeIn' => [ '123456', '23451' ] ];
+ $variables = array( 'postCodeIn' => array( '123456', '23451' ) );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'taxRates.nodes.#.id', $this->toRelayId( 'tax_rate', $rates[1] ) ),
$this->expectedField( 'taxRates.nodes.#.id', $this->toRelayId( 'tax_rate', $rates[2] ) ),
$this->not()->expectedField( 'taxRates.nodes.#.id', $this->toRelayId( 'tax_rate', $rates[0] ) ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
}
@@ -220,7 +220,7 @@ function ( $id ) {
public function testTaxIncludedOptionEffect() {
// Create tax rate.
$this->factory->tax_rate->create(
- [
+ array(
'country' => 'US',
'state' => '',
'rate' => 10,
@@ -229,7 +229,7 @@ public function testTaxIncludedOptionEffect() {
'compound' => '0',
'shipping' => '1',
'class' => '',
- ]
+ )
);
// Set customer address.
@@ -242,10 +242,10 @@ public function testTaxIncludedOptionEffect() {
// Create product to query.
$product_id = $this->factory->product->createSimple(
- [
+ array(
'price' => 10,
'regular_price' => 10,
- ]
+ )
);
$query = '
query( $id: ID! ) {
@@ -257,7 +257,7 @@ public function testTaxIncludedOptionEffect() {
}
}
';
- $variables = [ 'id' => $this->toRelayId( 'post', $product_id ) ];
+ $variables = array( 'id' => $this->toRelayId( 'post', $product_id ) );
/**
* Assertion One
@@ -266,9 +266,9 @@ public function testTaxIncludedOptionEffect() {
*/
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'product.price', '$10.00' ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
@@ -287,9 +287,9 @@ public function testTaxIncludedOptionEffect() {
$this->logData( \wc_prices_include_tax() ? 'included' : 'excluded' );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'product.price', '$11.00' ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
}
diff --git a/tests/wpunit/TransferSessionHandlerTest.php b/tests/wpunit/TransferSessionHandlerTest.php
index 380eb4e35..8ddb78491 100644
--- a/tests/wpunit/TransferSessionHandlerTest.php
+++ b/tests/wpunit/TransferSessionHandlerTest.php
@@ -23,7 +23,7 @@ public function tearDown(): void {
// after
parent::tearDown();
- $_REQUEST = [];
+ $_REQUEST = array();
}
public function testInitSessionCookie() {
diff --git a/tests/wpunit/UnsupportedProductTypeTest.php b/tests/wpunit/UnsupportedProductTypeTest.php
index 700278c64..d4c92f91a 100644
--- a/tests/wpunit/UnsupportedProductTypeTest.php
+++ b/tests/wpunit/UnsupportedProductTypeTest.php
@@ -2,9 +2,9 @@
class UnsupportedProductTypeTest extends \Tests\WPGraphQL\WooCommerce\TestCase\WooGraphQLTestCase {
public function testUnsupportedProductTypeFailsWhenDisabled() {
$product_id = $this->factory->product->createSimple(
- [
+ array(
'product_class' => '\WC_Product_Advanced',
- ]
+ )
);
$query = '
@@ -15,11 +15,11 @@ public function testUnsupportedProductTypeFailsWhenDisabled() {
}
';
- $variables = [ 'id' => $this->toRelayId( 'post', $product_id ) ];
+ $variables = array( 'id' => $this->toRelayId( 'post', $product_id ) );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'post', static::IS_NULL ),
- ];
+ );
$this->assertQueryError( $response, $expected );
}
@@ -27,11 +27,11 @@ public function testUnsupportedProductTypeFailsWhenDisabled() {
public function testUnsupportedProductTypePassesWhenEnabled() {
update_option(
'woographql_settings',
- [ 'enable_unsupported_product_type' => 'on' ]
+ array( 'enable_unsupported_product_type' => 'on' )
);
$product_id = $this->factory->product->createSimple(
- [ 'product_class' => '\WC_Product_Advanced' ]
+ array( 'product_class' => '\WC_Product_Advanced' )
);
$query = '
@@ -43,12 +43,12 @@ public function testUnsupportedProductTypePassesWhenEnabled() {
}
';
- $variables = [ 'id' => $this->toRelayId( 'post', $product_id ) ];
+ $variables = array( 'id' => $this->toRelayId( 'post', $product_id ) );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'product.id', $this->toRelayId( 'post', $product_id ) ),
$this->expectedField( 'product.type', 'UNSUPPORTED' ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
@@ -62,10 +62,10 @@ public function testUnsupportedProductTypePassesWhenEnabled() {
';
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'unsupportedProduct.id', $this->toRelayId( 'post', $product_id ) ),
$this->expectedField( 'unsupportedProduct.type', 'UNSUPPORTED' ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
}
diff --git a/tests/wpunit/VariationAttributeQueriesTest.php b/tests/wpunit/VariationAttributeQueriesTest.php
index 62b04d2f6..51d1bdf3d 100644
--- a/tests/wpunit/VariationAttributeQueriesTest.php
+++ b/tests/wpunit/VariationAttributeQueriesTest.php
@@ -7,29 +7,29 @@ public function expectedAttributes( $id ) {
? $product->get_default_attributes()
: $product->get_attributes();
- $expected = [];
+ $expected = array();
foreach ( $attributes as $name => $value ) {
$term = \get_term_by( 'slug', $value, $name );
$expected_id = base64_encode( $id . '||' . $name . '||' . $value ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode
if ( ! $term instanceof \WP_Term ) {
$expected[] = $this->expectedNode(
'nodes',
- [
+ array(
$this->expectedField( 'id', $expected_id ),
$this->expectedField( 'attributeId', 0 ),
$this->expectedField( 'name', $name ),
$this->expectedField( 'value', $value ),
- ]
+ )
);
} else {
$expected[] = $this->expectedNode(
'nodes',
- [
+ array(
$this->expectedField( 'id', $expected_id ),
$this->expectedField( 'attributeId', $term->term_id ),
$this->expectedField( 'name', $term->taxonomy ),
$this->expectedField( 'value', $term->name ),
- ]
+ )
);
}
}
@@ -41,20 +41,20 @@ public function expectedDefaultAttributes( $id ) {
$product = wc_get_product( $id );
$attributes = $product->get_attributes();
- $expected = [];
+ $expected = array();
foreach ( $attributes as $attribute ) {
$name = $attribute->get_name();
if ( $attribute->is_taxonomy() ) {
- $attribute_values = wc_get_product_terms( $id, $attribute->get_name(), [ 'fields' => 'all' ] );
+ $attribute_values = wc_get_product_terms( $id, $attribute->get_name(), array( 'fields' => 'all' ) );
foreach ( $attribute_values as $attribute_value ) {
$expected[] = $this->expectedNode(
'nodes',
- [
+ array(
$this->expectedField( 'id', base64_encode( $id . '|' . $name . '|' . $attribute_value->name ) ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode
$this->expectedField( 'attributeId', $attribute_value->term_id ),
$this->expectedField( 'name', $name ),
$this->expectedField( 'value', $attribute_value->name ),
- ]
+ )
);
}
} else {
@@ -62,12 +62,12 @@ public function expectedDefaultAttributes( $id ) {
foreach ( $values as $attribute_value ) {
$expected[] = $this->expectedNode(
'nodes',
- [
+ array(
$this->expectedField( 'id', base64_encode( $id . '|' . $name . '|' . $attribute_value ) ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode
$this->expectedField( 'attributeId', 0 ),
$this->expectedField( 'name', $name ),
$this->expectedField( 'value', $attribute_value ),
- ]
+ )
);
}
}
@@ -103,12 +103,12 @@ public function testProductVariationToVariationAttributeQuery() {
*
* Test query and results
*/
- $variables = [ 'id' => $this->toRelayId( 'post', $variation_id ) ];
+ $variables = array( 'id' => $this->toRelayId( 'post', $variation_id ) );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'productVariation.id', $this->toRelayId( 'post', $variation_id ) ),
$this->expectedObject( 'productVariation.attributes', $this->expectedAttributes( $variation_id ) ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
}
@@ -142,27 +142,27 @@ public function testVariableProductToVariationAttributeQuery() {
*
* Test query and results
*/
- $variables = [ 'id' => $this->toRelayId( 'post', $product_id ) ];
+ $variables = array( 'id' => $this->toRelayId( 'post', $product_id ) );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'product.id', $this->toRelayId( 'post', $product_id ) ),
$this->expectedObject( 'product.defaultAttributes', $this->expectedAttributes( $product_id ) ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
}
public function testSimpleProductToVariationAttributeQuery() {
// Create a product w/ default attributes.
- $attribute_data = [
- $this->factory->product->createAttribute( 'size', [ 'small' ] ),
- $this->factory->product->createAttribute( 'color', [ 'red' ] ),
- [
+ $attribute_data = array(
+ $this->factory->product->createAttribute( 'size', array( 'small' ) ),
+ $this->factory->product->createAttribute( 'color', array( 'red' ) ),
+ array(
'attribute_id' => 0,
'attribute_taxonomy' => 'logo',
- 'term_ids' => [ 'Yes' ],
- ],
- ];
+ 'term_ids' => array( 'Yes' ),
+ ),
+ );
$attributes = array_map(
static function ( $data, $index ) {
$attribute = new \WC_Product_Attribute();
@@ -178,14 +178,14 @@ static function ( $data, $index ) {
array_keys( $attribute_data )
);
$product_id = $this->factory->product->createSimple(
- [
+ array(
'attributes' => $attributes,
- 'default_attributes' => [
+ 'default_attributes' => array(
'pa_size' => 'small',
'pa_color' => 'red',
'logo' => 'Yes',
- ],
- ]
+ ),
+ )
);
// Create a query.
@@ -212,12 +212,12 @@ static function ( $data, $index ) {
*
* Test query and results
*/
- $variables = [ 'id' => $this->toRelayId( 'post', $product_id ) ];
+ $variables = array( 'id' => $this->toRelayId( 'post', $product_id ) );
$response = $this->graphql( compact( 'query', 'variables' ) );
- $expected = [
+ $expected = array(
$this->expectedField( 'product.id', $this->toRelayId( 'post', $product_id ) ),
$this->expectedObject( 'product.defaultAttributes', $this->expectedDefaultAttributes( $product_id ) ),
- ];
+ );
$this->assertQuerySuccessful( $response, $expected );
}
diff --git a/tests/wpunit/bootstrap.php b/tests/wpunit/bootstrap.php
index 3bf063e42..f0dcb46fa 100644
--- a/tests/wpunit/bootstrap.php
+++ b/tests/wpunit/bootstrap.php
@@ -79,5 +79,5 @@ function initialize_hpos() {
if ( defined( 'HPOS' ) ) {
\codecept_debug( 'HPOS activated!!!' );
- //add_action( 'woocommerce_init', 'initialize_hpos' );
+ // add_action( 'woocommerce_init', 'initialize_hpos' );
}
diff --git a/vendor-prefixed/firebase/php-jwt/src/BeforeValidException.php b/vendor-prefixed/firebase/php-jwt/src/BeforeValidException.php
index 110dbc845..7912e8a0a 100644
--- a/vendor-prefixed/firebase/php-jwt/src/BeforeValidException.php
+++ b/vendor-prefixed/firebase/php-jwt/src/BeforeValidException.php
@@ -8,17 +8,15 @@
namespace WPGraphQL\WooCommerce\Vendor\Firebase\JWT;
-class BeforeValidException extends \UnexpectedValueException implements JWTExceptionWithPayloadInterface
-{
- private object $payload;
+class BeforeValidException extends \UnexpectedValueException implements JWTExceptionWithPayloadInterface {
- public function setPayload(object $payload): void
- {
- $this->payload = $payload;
- }
+ private object $payload;
- public function getPayload(): object
- {
- return $this->payload;
- }
+ public function setPayload( object $payload ): void {
+ $this->payload = $payload;
+ }
+
+ public function getPayload(): object {
+ return $this->payload;
+ }
}
diff --git a/vendor-prefixed/firebase/php-jwt/src/CachedKeySet.php b/vendor-prefixed/firebase/php-jwt/src/CachedKeySet.php
index c2a2f0e5a..c471c4544 100644
--- a/vendor-prefixed/firebase/php-jwt/src/CachedKeySet.php
+++ b/vendor-prefixed/firebase/php-jwt/src/CachedKeySet.php
@@ -22,259 +22,256 @@
/**
* @implements ArrayAccess
*/
-class CachedKeySet implements ArrayAccess
-{
- /**
- * @var string
- */
- private $jwksUri;
- /**
- * @var ClientInterface
- */
- private $httpClient;
- /**
- * @var RequestFactoryInterface
- */
- private $httpFactory;
- /**
- * @var CacheItemPoolInterface
- */
- private $cache;
- /**
- * @var ?int
- */
- private $expiresAfter;
- /**
- * @var ?CacheItemInterface
- */
- private $cacheItem;
- /**
- * @var array>
- */
- private $keySet;
- /**
- * @var string
- */
- private $cacheKey;
- /**
- * @var string
- */
- private $cacheKeyPrefix = 'jwks';
- /**
- * @var int
- */
- private $maxKeyLength = 64;
- /**
- * @var bool
- */
- private $rateLimit;
- /**
- * @var string
- */
- private $rateLimitCacheKey;
- /**
- * @var int
- */
- private $maxCallsPerMinute = 10;
- /**
- * @var string|null
- */
- private $defaultAlg;
-
- public function __construct(
- string $jwksUri,
- ClientInterface $httpClient,
- RequestFactoryInterface $httpFactory,
- CacheItemPoolInterface $cache,
- ?int $expiresAfter = null,
- bool $rateLimit = false,
- ?string $defaultAlg = null
- ) {
- $this->jwksUri = $jwksUri;
- $this->httpClient = $httpClient;
- $this->httpFactory = $httpFactory;
- $this->cache = $cache;
- $this->expiresAfter = $expiresAfter;
- $this->rateLimit = $rateLimit;
- $this->defaultAlg = $defaultAlg;
- $this->setCacheKeys();
- }
-
- /**
- * @param string $keyId
- * @return Key
- */
- public function offsetGet($keyId): Key
- {
- if (!$this->keyIdExists($keyId)) {
- throw new OutOfBoundsException('Key ID not found');
- }
- return JWK::parseKey($this->keySet[$keyId], $this->defaultAlg);
- }
-
- /**
- * @param string $keyId
- * @return bool
- */
- public function offsetExists($keyId): bool
- {
- return $this->keyIdExists($keyId);
- }
-
- /**
- * @param string $offset
- * @param Key $value
- */
- public function offsetSet($offset, $value): void
- {
- throw new LogicException('Method not implemented');
- }
-
- /**
- * @param string $offset
- */
- public function offsetUnset($offset): void
- {
- throw new LogicException('Method not implemented');
- }
-
- /**
- * @return array
- */
- private function formatJwksForCache(string $jwks): array
- {
- $jwks = json_decode($jwks, true);
-
- if (!isset($jwks['keys'])) {
- throw new UnexpectedValueException('"keys" member must exist in the JWK Set');
- }
-
- if (empty($jwks['keys'])) {
- throw new InvalidArgumentException('JWK Set did not contain any keys');
- }
-
- $keys = [];
- foreach ($jwks['keys'] as $k => $v) {
- $kid = isset($v['kid']) ? $v['kid'] : $k;
- $keys[(string) $kid] = $v;
- }
-
- return $keys;
- }
-
- private function keyIdExists(string $keyId): bool
- {
- if (null === $this->keySet) {
- $item = $this->getCacheItem();
- // Try to load keys from cache
- if ($item->isHit()) {
- // item found! retrieve it
- $this->keySet = $item->get();
- // If the cached item is a string, the JWKS response was cached (previous behavior).
- // Parse this into expected format array instead.
- if (\is_string($this->keySet)) {
- $this->keySet = $this->formatJwksForCache($this->keySet);
- }
- }
- }
-
- if (!isset($this->keySet[$keyId])) {
- if ($this->rateLimitExceeded()) {
- return false;
- }
- $request = $this->httpFactory->createRequest('GET', $this->jwksUri);
- $jwksResponse = $this->httpClient->sendRequest($request);
- if ($jwksResponse->getStatusCode() !== 200) {
- throw new UnexpectedValueException(
- \sprintf('HTTP Error: %d %s for URI "%s"',
- $jwksResponse->getStatusCode(),
- $jwksResponse->getReasonPhrase(),
- $this->jwksUri,
- ),
- $jwksResponse->getStatusCode()
- );
- }
- $this->keySet = $this->formatJwksForCache((string) $jwksResponse->getBody());
-
- if (!isset($this->keySet[$keyId])) {
- return false;
- }
-
- $item = $this->getCacheItem();
- $item->set($this->keySet);
- if ($this->expiresAfter) {
- $item->expiresAfter($this->expiresAfter);
- }
- $this->cache->save($item);
- }
-
- return true;
- }
-
- private function rateLimitExceeded(): bool
- {
- if (!$this->rateLimit) {
- return false;
- }
-
- $cacheItem = $this->cache->getItem($this->rateLimitCacheKey);
-
- $cacheItemData = [];
- if ($cacheItem->isHit() && \is_array($data = $cacheItem->get())) {
- $cacheItemData = $data;
- }
-
- $callsPerMinute = $cacheItemData['callsPerMinute'] ?? 0;
- $expiry = $cacheItemData['expiry'] ?? new \DateTime('+60 seconds', new \DateTimeZone('UTC'));
-
- if (++$callsPerMinute > $this->maxCallsPerMinute) {
- return true;
- }
-
- $cacheItem->set(['expiry' => $expiry, 'callsPerMinute' => $callsPerMinute]);
- $cacheItem->expiresAt($expiry);
- $this->cache->save($cacheItem);
- return false;
- }
-
- private function getCacheItem(): CacheItemInterface
- {
- if (\is_null($this->cacheItem)) {
- $this->cacheItem = $this->cache->getItem($this->cacheKey);
- }
-
- return $this->cacheItem;
- }
-
- private function setCacheKeys(): void
- {
- if (empty($this->jwksUri)) {
- throw new RuntimeException('JWKS URI is empty');
- }
-
- // ensure we do not have illegal characters
- $key = preg_replace('|[^a-zA-Z0-9_\.!]|', '', $this->jwksUri);
-
- // add prefix
- $key = $this->cacheKeyPrefix . $key;
-
- // Hash keys if they exceed $maxKeyLength of 64
- if (\strlen($key) > $this->maxKeyLength) {
- $key = substr(hash('sha256', $key), 0, $this->maxKeyLength);
- }
-
- $this->cacheKey = $key;
-
- if ($this->rateLimit) {
- // add prefix
- $rateLimitKey = $this->cacheKeyPrefix . 'ratelimit' . $key;
-
- // Hash keys if they exceed $maxKeyLength of 64
- if (\strlen($rateLimitKey) > $this->maxKeyLength) {
- $rateLimitKey = substr(hash('sha256', $rateLimitKey), 0, $this->maxKeyLength);
- }
-
- $this->rateLimitCacheKey = $rateLimitKey;
- }
- }
+class CachedKeySet implements ArrayAccess {
+
+ /**
+ * @var string
+ */
+ private $jwksUri;
+ /**
+ * @var ClientInterface
+ */
+ private $httpClient;
+ /**
+ * @var RequestFactoryInterface
+ */
+ private $httpFactory;
+ /**
+ * @var CacheItemPoolInterface
+ */
+ private $cache;
+ /**
+ * @var ?int
+ */
+ private $expiresAfter;
+ /**
+ * @var ?CacheItemInterface
+ */
+ private $cacheItem;
+ /**
+ * @var array>
+ */
+ private $keySet;
+ /**
+ * @var string
+ */
+ private $cacheKey;
+ /**
+ * @var string
+ */
+ private $cacheKeyPrefix = 'jwks';
+ /**
+ * @var int
+ */
+ private $maxKeyLength = 64;
+ /**
+ * @var bool
+ */
+ private $rateLimit;
+ /**
+ * @var string
+ */
+ private $rateLimitCacheKey;
+ /**
+ * @var int
+ */
+ private $maxCallsPerMinute = 10;
+ /**
+ * @var string|null
+ */
+ private $defaultAlg;
+
+ public function __construct(
+ string $jwksUri,
+ ClientInterface $httpClient,
+ RequestFactoryInterface $httpFactory,
+ CacheItemPoolInterface $cache,
+ ?int $expiresAfter = null,
+ bool $rateLimit = false,
+ ?string $defaultAlg = null
+ ) {
+ $this->jwksUri = $jwksUri;
+ $this->httpClient = $httpClient;
+ $this->httpFactory = $httpFactory;
+ $this->cache = $cache;
+ $this->expiresAfter = $expiresAfter;
+ $this->rateLimit = $rateLimit;
+ $this->defaultAlg = $defaultAlg;
+ $this->setCacheKeys();
+ }
+
+ /**
+ * @param string $keyId
+ * @return Key
+ */
+ public function offsetGet( $keyId ): Key {
+ if ( ! $this->keyIdExists( $keyId ) ) {
+ throw new OutOfBoundsException( 'Key ID not found' );
+ }
+ return JWK::parseKey( $this->keySet[ $keyId ], $this->defaultAlg );
+ }
+
+ /**
+ * @param string $keyId
+ * @return bool
+ */
+ public function offsetExists( $keyId ): bool {
+ return $this->keyIdExists( $keyId );
+ }
+
+ /**
+ * @param string $offset
+ * @param Key $value
+ */
+ public function offsetSet( $offset, $value ): void {
+ throw new LogicException( 'Method not implemented' );
+ }
+
+ /**
+ * @param string $offset
+ */
+ public function offsetUnset( $offset ): void {
+ throw new LogicException( 'Method not implemented' );
+ }
+
+ /**
+ * @return array
+ */
+ private function formatJwksForCache( string $jwks ): array {
+ $jwks = json_decode( $jwks, true );
+
+ if ( ! isset( $jwks['keys'] ) ) {
+ throw new UnexpectedValueException( '"keys" member must exist in the JWK Set' );
+ }
+
+ if ( empty( $jwks['keys'] ) ) {
+ throw new InvalidArgumentException( 'JWK Set did not contain any keys' );
+ }
+
+ $keys = array();
+ foreach ( $jwks['keys'] as $k => $v ) {
+ $kid = isset( $v['kid'] ) ? $v['kid'] : $k;
+ $keys[ (string) $kid ] = $v;
+ }
+
+ return $keys;
+ }
+
+ private function keyIdExists( string $keyId ): bool {
+ if ( null === $this->keySet ) {
+ $item = $this->getCacheItem();
+ // Try to load keys from cache
+ if ( $item->isHit() ) {
+ // item found! retrieve it
+ $this->keySet = $item->get();
+ // If the cached item is a string, the JWKS response was cached (previous behavior).
+ // Parse this into expected format array instead.
+ if ( \is_string( $this->keySet ) ) {
+ $this->keySet = $this->formatJwksForCache( $this->keySet );
+ }
+ }
+ }
+
+ if ( ! isset( $this->keySet[ $keyId ] ) ) {
+ if ( $this->rateLimitExceeded() ) {
+ return false;
+ }
+ $request = $this->httpFactory->createRequest( 'GET', $this->jwksUri );
+ $jwksResponse = $this->httpClient->sendRequest( $request );
+ if ( $jwksResponse->getStatusCode() !== 200 ) {
+ throw new UnexpectedValueException(
+ \sprintf(
+ 'HTTP Error: %d %s for URI "%s"',
+ $jwksResponse->getStatusCode(),
+ $jwksResponse->getReasonPhrase(),
+ $this->jwksUri,
+ ),
+ $jwksResponse->getStatusCode()
+ );
+ }
+ $this->keySet = $this->formatJwksForCache( (string) $jwksResponse->getBody() );
+
+ if ( ! isset( $this->keySet[ $keyId ] ) ) {
+ return false;
+ }
+
+ $item = $this->getCacheItem();
+ $item->set( $this->keySet );
+ if ( $this->expiresAfter ) {
+ $item->expiresAfter( $this->expiresAfter );
+ }
+ $this->cache->save( $item );
+ }
+
+ return true;
+ }
+
+ private function rateLimitExceeded(): bool {
+ if ( ! $this->rateLimit ) {
+ return false;
+ }
+
+ $cacheItem = $this->cache->getItem( $this->rateLimitCacheKey );
+
+ $cacheItemData = array();
+ if ( $cacheItem->isHit() && \is_array( $data = $cacheItem->get() ) ) {
+ $cacheItemData = $data;
+ }
+
+ $callsPerMinute = $cacheItemData['callsPerMinute'] ?? 0;
+ $expiry = $cacheItemData['expiry'] ?? new \DateTime( '+60 seconds', new \DateTimeZone( 'UTC' ) );
+
+ if ( ++$callsPerMinute > $this->maxCallsPerMinute ) {
+ return true;
+ }
+
+ $cacheItem->set(
+ array(
+ 'expiry' => $expiry,
+ 'callsPerMinute' => $callsPerMinute,
+ )
+ );
+ $cacheItem->expiresAt( $expiry );
+ $this->cache->save( $cacheItem );
+ return false;
+ }
+
+ private function getCacheItem(): CacheItemInterface {
+ if ( \is_null( $this->cacheItem ) ) {
+ $this->cacheItem = $this->cache->getItem( $this->cacheKey );
+ }
+
+ return $this->cacheItem;
+ }
+
+ private function setCacheKeys(): void {
+ if ( empty( $this->jwksUri ) ) {
+ throw new RuntimeException( 'JWKS URI is empty' );
+ }
+
+ // ensure we do not have illegal characters
+ $key = preg_replace( '|[^a-zA-Z0-9_\.!]|', '', $this->jwksUri );
+
+ // add prefix
+ $key = $this->cacheKeyPrefix . $key;
+
+ // Hash keys if they exceed $maxKeyLength of 64
+ if ( \strlen( $key ) > $this->maxKeyLength ) {
+ $key = substr( hash( 'sha256', $key ), 0, $this->maxKeyLength );
+ }
+
+ $this->cacheKey = $key;
+
+ if ( $this->rateLimit ) {
+ // add prefix
+ $rateLimitKey = $this->cacheKeyPrefix . 'ratelimit' . $key;
+
+ // Hash keys if they exceed $maxKeyLength of 64
+ if ( \strlen( $rateLimitKey ) > $this->maxKeyLength ) {
+ $rateLimitKey = substr( hash( 'sha256', $rateLimitKey ), 0, $this->maxKeyLength );
+ }
+
+ $this->rateLimitCacheKey = $rateLimitKey;
+ }
+ }
}
diff --git a/vendor-prefixed/firebase/php-jwt/src/ExpiredException.php b/vendor-prefixed/firebase/php-jwt/src/ExpiredException.php
index aad64d76a..f2e43d1b1 100644
--- a/vendor-prefixed/firebase/php-jwt/src/ExpiredException.php
+++ b/vendor-prefixed/firebase/php-jwt/src/ExpiredException.php
@@ -8,17 +8,15 @@
namespace WPGraphQL\WooCommerce\Vendor\Firebase\JWT;
-class ExpiredException extends \UnexpectedValueException implements JWTExceptionWithPayloadInterface
-{
- private object $payload;
+class ExpiredException extends \UnexpectedValueException implements JWTExceptionWithPayloadInterface {
- public function setPayload(object $payload): void
- {
- $this->payload = $payload;
- }
+ private object $payload;
- public function getPayload(): object
- {
- return $this->payload;
- }
+ public function setPayload( object $payload ): void {
+ $this->payload = $payload;
+ }
+
+ public function getPayload(): object {
+ return $this->payload;
+ }
}
diff --git a/vendor-prefixed/firebase/php-jwt/src/JWK.php b/vendor-prefixed/firebase/php-jwt/src/JWK.php
index c6674c428..9d5beb3ac 100644
--- a/vendor-prefixed/firebase/php-jwt/src/JWK.php
+++ b/vendor-prefixed/firebase/php-jwt/src/JWK.php
@@ -24,338 +24,332 @@
* @license http://opensource.org/licenses/BSD-3-Clause 3-clause BSD
* @link https://github.com/firebase/php-jwt
*/
-class JWK
-{
- private const OID = '1.2.840.10045.2.1';
- private const ASN1_OBJECT_IDENTIFIER = 0x06;
- private const ASN1_SEQUENCE = 0x10; // also defined in JWT
- private const ASN1_BIT_STRING = 0x03;
- private const EC_CURVES = [
- 'P-256' => '1.2.840.10045.3.1.7', // Len: 64
- 'secp256k1' => '1.3.132.0.10', // Len: 64
- 'P-384' => '1.3.132.0.34', // Len: 96
- // 'P-521' => '1.3.132.0.35', // Len: 132 (not supported)
- ];
-
- // For keys with "kty" equal to "OKP" (Octet Key Pair), the "crv" parameter must contain the key subtype.
- // This library supports the following subtypes:
- private const OKP_SUBTYPES = [
- 'Ed25519' => true, // RFC 8037
- ];
-
- /**
- * Parse a set of JWK keys
- *
- * @param array $jwks The JSON Web Key Set as an associative array
- * @param string $defaultAlg The algorithm for the Key object if "alg" is not set in the
- * JSON Web Key Set
- *
- * @return array An associative array of key IDs (kid) to Key objects
- *
- * @throws InvalidArgumentException Provided JWK Set is empty
- * @throws UnexpectedValueException Provided JWK Set was invalid
- * @throws DomainException OpenSSL failure
- *
- * @uses parseKey
- */
- public static function parseKeySet(array $jwks, ?string $defaultAlg = null): array
- {
- $keys = [];
-
- if (!isset($jwks['keys'])) {
- throw new UnexpectedValueException('"keys" member must exist in the JWK Set');
- }
-
- if (empty($jwks['keys'])) {
- throw new InvalidArgumentException('JWK Set did not contain any keys');
- }
-
- foreach ($jwks['keys'] as $k => $v) {
- $kid = isset($v['kid']) ? $v['kid'] : $k;
- if ($key = self::parseKey($v, $defaultAlg)) {
- $keys[(string) $kid] = $key;
- }
- }
-
- if (0 === \count($keys)) {
- throw new UnexpectedValueException('No supported algorithms found in JWK Set');
- }
-
- return $keys;
- }
-
- /**
- * Parse a JWK key
- *
- * @param array $jwk An individual JWK
- * @param string $defaultAlg The algorithm for the Key object if "alg" is not set in the
- * JSON Web Key Set
- *
- * @return Key The key object for the JWK
- *
- * @throws InvalidArgumentException Provided JWK is empty
- * @throws UnexpectedValueException Provided JWK was invalid
- * @throws DomainException OpenSSL failure
- *
- * @uses createPemFromModulusAndExponent
- */
- public static function parseKey(array $jwk, ?string $defaultAlg = null): ?Key
- {
- if (empty($jwk)) {
- throw new InvalidArgumentException('JWK must not be empty');
- }
-
- if (!isset($jwk['kty'])) {
- throw new UnexpectedValueException('JWK must contain a "kty" parameter');
- }
-
- if (!isset($jwk['alg'])) {
- if (\is_null($defaultAlg)) {
- // The "alg" parameter is optional in a KTY, but an algorithm is required
- // for parsing in this library. Use the $defaultAlg parameter when parsing the
- // key set in order to prevent this error.
- // @see https://datatracker.ietf.org/doc/html/rfc7517#section-4.4
- throw new UnexpectedValueException('JWK must contain an "alg" parameter');
- }
- $jwk['alg'] = $defaultAlg;
- }
-
- switch ($jwk['kty']) {
- case 'RSA':
- if (!empty($jwk['d'])) {
- throw new UnexpectedValueException('RSA private keys are not supported');
- }
- if (!isset($jwk['n']) || !isset($jwk['e'])) {
- throw new UnexpectedValueException('RSA keys must contain values for both "n" and "e"');
- }
-
- $pem = self::createPemFromModulusAndExponent($jwk['n'], $jwk['e']);
- $publicKey = \openssl_pkey_get_public($pem);
- if (false === $publicKey) {
- throw new DomainException(
- 'OpenSSL error: ' . \openssl_error_string()
- );
- }
- return new Key($publicKey, $jwk['alg']);
- case 'EC':
- if (isset($jwk['d'])) {
- // The key is actually a private key
- throw new UnexpectedValueException('Key data must be for a public key');
- }
-
- if (empty($jwk['crv'])) {
- throw new UnexpectedValueException('crv not set');
- }
-
- if (!isset(self::EC_CURVES[$jwk['crv']])) {
- throw new DomainException('Unrecognised or unsupported EC curve');
- }
-
- if (empty($jwk['x']) || empty($jwk['y'])) {
- throw new UnexpectedValueException('x and y not set');
- }
-
- $publicKey = self::createPemFromCrvAndXYCoordinates($jwk['crv'], $jwk['x'], $jwk['y']);
- return new Key($publicKey, $jwk['alg']);
- case 'OKP':
- if (isset($jwk['d'])) {
- // The key is actually a private key
- throw new UnexpectedValueException('Key data must be for a public key');
- }
-
- if (!isset($jwk['crv'])) {
- throw new UnexpectedValueException('crv not set');
- }
-
- if (empty(self::OKP_SUBTYPES[$jwk['crv']])) {
- throw new DomainException('Unrecognised or unsupported OKP key subtype');
- }
-
- if (empty($jwk['x'])) {
- throw new UnexpectedValueException('x not set');
- }
-
- // This library works internally with EdDSA keys (Ed25519) encoded in standard base64.
- $publicKey = JWT::convertBase64urlToBase64($jwk['x']);
- return new Key($publicKey, $jwk['alg']);
- case 'oct':
- if (!isset($jwk['k'])) {
- throw new UnexpectedValueException('k not set');
- }
-
- return new Key(JWT::urlsafeB64Decode($jwk['k']), $jwk['alg']);
- default:
- break;
- }
-
- return null;
- }
-
- /**
- * Converts the EC JWK values to pem format.
- *
- * @param string $crv The EC curve (only P-256 & P-384 is supported)
- * @param string $x The EC x-coordinate
- * @param string $y The EC y-coordinate
- *
- * @return string
- */
- private static function createPemFromCrvAndXYCoordinates(string $crv, string $x, string $y): string
- {
- $pem =
- self::encodeDER(
- self::ASN1_SEQUENCE,
- self::encodeDER(
- self::ASN1_SEQUENCE,
- self::encodeDER(
- self::ASN1_OBJECT_IDENTIFIER,
- self::encodeOID(self::OID)
- )
- . self::encodeDER(
- self::ASN1_OBJECT_IDENTIFIER,
- self::encodeOID(self::EC_CURVES[$crv])
- )
- ) .
- self::encodeDER(
- self::ASN1_BIT_STRING,
- \chr(0x00) . \chr(0x04)
- . JWT::urlsafeB64Decode($x)
- . JWT::urlsafeB64Decode($y)
- )
- );
-
- return \sprintf(
- "-----BEGIN PUBLIC KEY-----\n%s\n-----END PUBLIC KEY-----\n",
- wordwrap(base64_encode($pem), 64, "\n", true)
- );
- }
-
- /**
- * Create a public key represented in PEM format from RSA modulus and exponent information
- *
- * @param string $n The RSA modulus encoded in Base64
- * @param string $e The RSA exponent encoded in Base64
- *
- * @return string The RSA public key represented in PEM format
- *
- * @uses encodeLength
- */
- private static function createPemFromModulusAndExponent(
- string $n,
- string $e
- ): string {
- $mod = JWT::urlsafeB64Decode($n);
- $exp = JWT::urlsafeB64Decode($e);
-
- $modulus = \pack('Ca*a*', 2, self::encodeLength(\strlen($mod)), $mod);
- $publicExponent = \pack('Ca*a*', 2, self::encodeLength(\strlen($exp)), $exp);
-
- $rsaPublicKey = \pack(
- 'Ca*a*a*',
- 48,
- self::encodeLength(\strlen($modulus) + \strlen($publicExponent)),
- $modulus,
- $publicExponent
- );
-
- // sequence(oid(1.2.840.113549.1.1.1), null)) = rsaEncryption.
- $rsaOID = \pack('H*', '300d06092a864886f70d0101010500'); // hex version of MA0GCSqGSIb3DQEBAQUA
- $rsaPublicKey = \chr(0) . $rsaPublicKey;
- $rsaPublicKey = \chr(3) . self::encodeLength(\strlen($rsaPublicKey)) . $rsaPublicKey;
-
- $rsaPublicKey = \pack(
- 'Ca*a*',
- 48,
- self::encodeLength(\strlen($rsaOID . $rsaPublicKey)),
- $rsaOID . $rsaPublicKey
- );
-
- return "-----BEGIN PUBLIC KEY-----\r\n" .
- \chunk_split(\base64_encode($rsaPublicKey), 64) .
- '-----END PUBLIC KEY-----';
- }
-
- /**
- * DER-encode the length
- *
- * DER supports lengths up to (2**8)**127, however, we'll only support lengths up to (2**8)**4. See
- * {@link http://itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf#p=13 X.690 paragraph 8.1.3} for more information.
- *
- * @param int $length
- * @return string
- */
- private static function encodeLength(int $length): string
- {
- if ($length <= 0x7F) {
- return \chr($length);
- }
-
- $temp = \ltrim(\pack('N', $length), \chr(0));
-
- return \pack('Ca*', 0x80 | \strlen($temp), $temp);
- }
-
- /**
- * Encodes a value into a DER object.
- * Also defined in Firebase\JWT\JWT
- *
- * @param int $type DER tag
- * @param string $value the value to encode
- * @return string the encoded object
- */
- private static function encodeDER(int $type, string $value): string
- {
- $tag_header = 0;
- if ($type === self::ASN1_SEQUENCE) {
- $tag_header |= 0x20;
- }
-
- // Type
- $der = \chr($tag_header | $type);
-
- // Length
- $der .= \chr(\strlen($value));
-
- return $der . $value;
- }
-
- /**
- * Encodes a string into a DER-encoded OID.
- *
- * @param string $oid the OID string
- * @return string the binary DER-encoded OID
- */
- private static function encodeOID(string $oid): string
- {
- $octets = explode('.', $oid);
-
- // Get the first octet
- $first = (int) array_shift($octets);
- $second = (int) array_shift($octets);
- $oid = \chr($first * 40 + $second);
-
- // Iterate over subsequent octets
- foreach ($octets as $octet) {
- if ($octet == 0) {
- $oid .= \chr(0x00);
- continue;
- }
- $bin = '';
-
- while ($octet) {
- $bin .= \chr(0x80 | ($octet & 0x7f));
- $octet >>= 7;
- }
- $bin[0] = $bin[0] & \chr(0x7f);
-
- // Convert to big endian if necessary
- if (pack('V', 65534) == pack('L', 65534)) {
- $oid .= strrev($bin);
- } else {
- $oid .= $bin;
- }
- }
-
- return $oid;
- }
+class JWK {
+
+ private const OID = '1.2.840.10045.2.1';
+ private const ASN1_OBJECT_IDENTIFIER = 0x06;
+ private const ASN1_SEQUENCE = 0x10; // also defined in JWT
+ private const ASN1_BIT_STRING = 0x03;
+ private const EC_CURVES = array(
+ 'P-256' => '1.2.840.10045.3.1.7', // Len: 64
+ 'secp256k1' => '1.3.132.0.10', // Len: 64
+ 'P-384' => '1.3.132.0.34', // Len: 96
+ // 'P-521' => '1.3.132.0.35', // Len: 132 (not supported)
+ );
+
+ // For keys with "kty" equal to "OKP" (Octet Key Pair), the "crv" parameter must contain the key subtype.
+ // This library supports the following subtypes:
+ private const OKP_SUBTYPES = array(
+ 'Ed25519' => true, // RFC 8037
+ );
+
+ /**
+ * Parse a set of JWK keys
+ *
+ * @param array $jwks The JSON Web Key Set as an associative array
+ * @param string $defaultAlg The algorithm for the Key object if "alg" is not set in the
+ * JSON Web Key Set
+ *
+ * @return array An associative array of key IDs (kid) to Key objects
+ *
+ * @throws InvalidArgumentException Provided JWK Set is empty
+ * @throws UnexpectedValueException Provided JWK Set was invalid
+ * @throws DomainException OpenSSL failure
+ *
+ * @uses parseKey
+ */
+ public static function parseKeySet( array $jwks, ?string $defaultAlg = null ): array {
+ $keys = array();
+
+ if ( ! isset( $jwks['keys'] ) ) {
+ throw new UnexpectedValueException( '"keys" member must exist in the JWK Set' );
+ }
+
+ if ( empty( $jwks['keys'] ) ) {
+ throw new InvalidArgumentException( 'JWK Set did not contain any keys' );
+ }
+
+ foreach ( $jwks['keys'] as $k => $v ) {
+ $kid = isset( $v['kid'] ) ? $v['kid'] : $k;
+ if ( $key = self::parseKey( $v, $defaultAlg ) ) {
+ $keys[ (string) $kid ] = $key;
+ }
+ }
+
+ if ( 0 === \count( $keys ) ) {
+ throw new UnexpectedValueException( 'No supported algorithms found in JWK Set' );
+ }
+
+ return $keys;
+ }
+
+ /**
+ * Parse a JWK key
+ *
+ * @param array $jwk An individual JWK
+ * @param string $defaultAlg The algorithm for the Key object if "alg" is not set in the
+ * JSON Web Key Set
+ *
+ * @return Key The key object for the JWK
+ *
+ * @throws InvalidArgumentException Provided JWK is empty
+ * @throws UnexpectedValueException Provided JWK was invalid
+ * @throws DomainException OpenSSL failure
+ *
+ * @uses createPemFromModulusAndExponent
+ */
+ public static function parseKey( array $jwk, ?string $defaultAlg = null ): ?Key {
+ if ( empty( $jwk ) ) {
+ throw new InvalidArgumentException( 'JWK must not be empty' );
+ }
+
+ if ( ! isset( $jwk['kty'] ) ) {
+ throw new UnexpectedValueException( 'JWK must contain a "kty" parameter' );
+ }
+
+ if ( ! isset( $jwk['alg'] ) ) {
+ if ( \is_null( $defaultAlg ) ) {
+ // The "alg" parameter is optional in a KTY, but an algorithm is required
+ // for parsing in this library. Use the $defaultAlg parameter when parsing the
+ // key set in order to prevent this error.
+ // @see https://datatracker.ietf.org/doc/html/rfc7517#section-4.4
+ throw new UnexpectedValueException( 'JWK must contain an "alg" parameter' );
+ }
+ $jwk['alg'] = $defaultAlg;
+ }
+
+ switch ( $jwk['kty'] ) {
+ case 'RSA':
+ if ( ! empty( $jwk['d'] ) ) {
+ throw new UnexpectedValueException( 'RSA private keys are not supported' );
+ }
+ if ( ! isset( $jwk['n'] ) || ! isset( $jwk['e'] ) ) {
+ throw new UnexpectedValueException( 'RSA keys must contain values for both "n" and "e"' );
+ }
+
+ $pem = self::createPemFromModulusAndExponent( $jwk['n'], $jwk['e'] );
+ $publicKey = \openssl_pkey_get_public( $pem );
+ if ( false === $publicKey ) {
+ throw new DomainException(
+ 'OpenSSL error: ' . \openssl_error_string()
+ );
+ }
+ return new Key( $publicKey, $jwk['alg'] );
+ case 'EC':
+ if ( isset( $jwk['d'] ) ) {
+ // The key is actually a private key
+ throw new UnexpectedValueException( 'Key data must be for a public key' );
+ }
+
+ if ( empty( $jwk['crv'] ) ) {
+ throw new UnexpectedValueException( 'crv not set' );
+ }
+
+ if ( ! isset( self::EC_CURVES[ $jwk['crv'] ] ) ) {
+ throw new DomainException( 'Unrecognised or unsupported EC curve' );
+ }
+
+ if ( empty( $jwk['x'] ) || empty( $jwk['y'] ) ) {
+ throw new UnexpectedValueException( 'x and y not set' );
+ }
+
+ $publicKey = self::createPemFromCrvAndXYCoordinates( $jwk['crv'], $jwk['x'], $jwk['y'] );
+ return new Key( $publicKey, $jwk['alg'] );
+ case 'OKP':
+ if ( isset( $jwk['d'] ) ) {
+ // The key is actually a private key
+ throw new UnexpectedValueException( 'Key data must be for a public key' );
+ }
+
+ if ( ! isset( $jwk['crv'] ) ) {
+ throw new UnexpectedValueException( 'crv not set' );
+ }
+
+ if ( empty( self::OKP_SUBTYPES[ $jwk['crv'] ] ) ) {
+ throw new DomainException( 'Unrecognised or unsupported OKP key subtype' );
+ }
+
+ if ( empty( $jwk['x'] ) ) {
+ throw new UnexpectedValueException( 'x not set' );
+ }
+
+ // This library works internally with EdDSA keys (Ed25519) encoded in standard base64.
+ $publicKey = JWT::convertBase64urlToBase64( $jwk['x'] );
+ return new Key( $publicKey, $jwk['alg'] );
+ case 'oct':
+ if ( ! isset( $jwk['k'] ) ) {
+ throw new UnexpectedValueException( 'k not set' );
+ }
+
+ return new Key( JWT::urlsafeB64Decode( $jwk['k'] ), $jwk['alg'] );
+ default:
+ break;
+ }
+
+ return null;
+ }
+
+ /**
+ * Converts the EC JWK values to pem format.
+ *
+ * @param string $crv The EC curve (only P-256 & P-384 is supported)
+ * @param string $x The EC x-coordinate
+ * @param string $y The EC y-coordinate
+ *
+ * @return string
+ */
+ private static function createPemFromCrvAndXYCoordinates( string $crv, string $x, string $y ): string {
+ $pem =
+ self::encodeDER(
+ self::ASN1_SEQUENCE,
+ self::encodeDER(
+ self::ASN1_SEQUENCE,
+ self::encodeDER(
+ self::ASN1_OBJECT_IDENTIFIER,
+ self::encodeOID( self::OID )
+ )
+ . self::encodeDER(
+ self::ASN1_OBJECT_IDENTIFIER,
+ self::encodeOID( self::EC_CURVES[ $crv ] )
+ )
+ ) .
+ self::encodeDER(
+ self::ASN1_BIT_STRING,
+ \chr( 0x00 ) . \chr( 0x04 )
+ . JWT::urlsafeB64Decode( $x )
+ . JWT::urlsafeB64Decode( $y )
+ )
+ );
+
+ return \sprintf(
+ "-----BEGIN PUBLIC KEY-----\n%s\n-----END PUBLIC KEY-----\n",
+ wordwrap( base64_encode( $pem ), 64, "\n", true )
+ );
+ }
+
+ /**
+ * Create a public key represented in PEM format from RSA modulus and exponent information
+ *
+ * @param string $n The RSA modulus encoded in Base64
+ * @param string $e The RSA exponent encoded in Base64
+ *
+ * @return string The RSA public key represented in PEM format
+ *
+ * @uses encodeLength
+ */
+ private static function createPemFromModulusAndExponent(
+ string $n,
+ string $e
+ ): string {
+ $mod = JWT::urlsafeB64Decode( $n );
+ $exp = JWT::urlsafeB64Decode( $e );
+
+ $modulus = \pack( 'Ca*a*', 2, self::encodeLength( \strlen( $mod ) ), $mod );
+ $publicExponent = \pack( 'Ca*a*', 2, self::encodeLength( \strlen( $exp ) ), $exp );
+
+ $rsaPublicKey = \pack(
+ 'Ca*a*a*',
+ 48,
+ self::encodeLength( \strlen( $modulus ) + \strlen( $publicExponent ) ),
+ $modulus,
+ $publicExponent
+ );
+
+ // sequence(oid(1.2.840.113549.1.1.1), null)) = rsaEncryption.
+ $rsaOID = \pack( 'H*', '300d06092a864886f70d0101010500' ); // hex version of MA0GCSqGSIb3DQEBAQUA
+ $rsaPublicKey = \chr( 0 ) . $rsaPublicKey;
+ $rsaPublicKey = \chr( 3 ) . self::encodeLength( \strlen( $rsaPublicKey ) ) . $rsaPublicKey;
+
+ $rsaPublicKey = \pack(
+ 'Ca*a*',
+ 48,
+ self::encodeLength( \strlen( $rsaOID . $rsaPublicKey ) ),
+ $rsaOID . $rsaPublicKey
+ );
+
+ return "-----BEGIN PUBLIC KEY-----\r\n" .
+ \chunk_split( \base64_encode( $rsaPublicKey ), 64 ) .
+ '-----END PUBLIC KEY-----';
+ }
+
+ /**
+ * DER-encode the length
+ *
+ * DER supports lengths up to (2**8)**127, however, we'll only support lengths up to (2**8)**4. See
+ * {@link http://itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf#p=13 X.690 paragraph 8.1.3} for more information.
+ *
+ * @param int $length
+ * @return string
+ */
+ private static function encodeLength( int $length ): string {
+ if ( $length <= 0x7F ) {
+ return \chr( $length );
+ }
+
+ $temp = \ltrim( \pack( 'N', $length ), \chr( 0 ) );
+
+ return \pack( 'Ca*', 0x80 | \strlen( $temp ), $temp );
+ }
+
+ /**
+ * Encodes a value into a DER object.
+ * Also defined in Firebase\JWT\JWT
+ *
+ * @param int $type DER tag
+ * @param string $value the value to encode
+ * @return string the encoded object
+ */
+ private static function encodeDER( int $type, string $value ): string {
+ $tag_header = 0;
+ if ( $type === self::ASN1_SEQUENCE ) {
+ $tag_header |= 0x20;
+ }
+
+ // Type
+ $der = \chr( $tag_header | $type );
+
+ // Length
+ $der .= \chr( \strlen( $value ) );
+
+ return $der . $value;
+ }
+
+ /**
+ * Encodes a string into a DER-encoded OID.
+ *
+ * @param string $oid the OID string
+ * @return string the binary DER-encoded OID
+ */
+ private static function encodeOID( string $oid ): string {
+ $octets = explode( '.', $oid );
+
+ // Get the first octet
+ $first = (int) array_shift( $octets );
+ $second = (int) array_shift( $octets );
+ $oid = \chr( $first * 40 + $second );
+
+ // Iterate over subsequent octets
+ foreach ( $octets as $octet ) {
+ if ( $octet == 0 ) {
+ $oid .= \chr( 0x00 );
+ continue;
+ }
+ $bin = '';
+
+ while ( $octet ) {
+ $bin .= \chr( 0x80 | ( $octet & 0x7f ) );
+ $octet >>= 7;
+ }
+ $bin[0] = $bin[0] & \chr( 0x7f );
+
+ // Convert to big endian if necessary
+ if ( pack( 'V', 65534 ) == pack( 'L', 65534 ) ) {
+ $oid .= strrev( $bin );
+ } else {
+ $oid .= $bin;
+ }
+ }
+
+ return $oid;
+ }
}
diff --git a/vendor-prefixed/firebase/php-jwt/src/JWT.php b/vendor-prefixed/firebase/php-jwt/src/JWT.php
index fd868c0c1..17a144ed6 100644
--- a/vendor-prefixed/firebase/php-jwt/src/JWT.php
+++ b/vendor-prefixed/firebase/php-jwt/src/JWT.php
@@ -31,643 +31,631 @@
* @license http://opensource.org/licenses/BSD-3-Clause 3-clause BSD
* @link https://github.com/firebase/php-jwt
*/
-class JWT
-{
- private const ASN1_INTEGER = 0x02;
- private const ASN1_SEQUENCE = 0x10;
- private const ASN1_BIT_STRING = 0x03;
-
- /**
- * When checking nbf, iat or expiration times,
- * we want to provide some extra leeway time to
- * account for clock skew.
- *
- * @var int
- */
- public static $leeway = 0;
-
- /**
- * Allow the current timestamp to be specified.
- * Useful for fixing a value within unit testing.
- * Will default to PHP time() value if null.
- *
- * @var ?int
- */
- public static $timestamp = null;
-
- /**
- * @var array
- */
- public static $supported_algs = [
- 'ES384' => ['openssl', 'SHA384'],
- 'ES256' => ['openssl', 'SHA256'],
- 'ES256K' => ['openssl', 'SHA256'],
- 'HS256' => ['hash_hmac', 'SHA256'],
- 'HS384' => ['hash_hmac', 'SHA384'],
- 'HS512' => ['hash_hmac', 'SHA512'],
- 'RS256' => ['openssl', 'SHA256'],
- 'RS384' => ['openssl', 'SHA384'],
- 'RS512' => ['openssl', 'SHA512'],
- 'EdDSA' => ['sodium_crypto', 'EdDSA'],
- ];
-
- /**
- * Decodes a JWT string into a PHP object.
- *
- * @param string $jwt The JWT
- * @param Key|ArrayAccess|array $keyOrKeyArray The Key or associative array of key IDs
- * (kid) to Key objects.
- * If the algorithm used is asymmetric, this is
- * the public key.
- * Each Key object contains an algorithm and
- * matching key.
- * Supported algorithms are 'ES384','ES256',
- * 'HS256', 'HS384', 'HS512', 'RS256', 'RS384'
- * and 'RS512'.
- * @param stdClass $headers Optional. Populates stdClass with headers.
- *
- * @return stdClass The JWT's payload as a PHP object
- *
- * @throws InvalidArgumentException Provided key/key-array was empty or malformed
- * @throws DomainException Provided JWT is malformed
- * @throws UnexpectedValueException Provided JWT was invalid
- * @throws SignatureInvalidException Provided JWT was invalid because the signature verification failed
- * @throws BeforeValidException Provided JWT is trying to be used before it's eligible as defined by 'nbf'
- * @throws BeforeValidException Provided JWT is trying to be used before it's been created as defined by 'iat'
- * @throws ExpiredException Provided JWT has since expired, as defined by the 'exp' claim
- *
- * @uses jsonDecode
- * @uses urlsafeB64Decode
- */
- public static function decode(
- string $jwt,
- $keyOrKeyArray,
- ?stdClass &$headers = null
- ): stdClass {
- // Validate JWT
- $timestamp = \is_null(static::$timestamp) ? \time() : static::$timestamp;
-
- if (empty($keyOrKeyArray)) {
- throw new InvalidArgumentException('Key may not be empty');
- }
- $tks = \explode('.', $jwt);
- if (\count($tks) !== 3) {
- throw new UnexpectedValueException('Wrong number of segments');
- }
- list($headb64, $bodyb64, $cryptob64) = $tks;
- $headerRaw = static::urlsafeB64Decode($headb64);
- if (null === ($header = static::jsonDecode($headerRaw))) {
- throw new UnexpectedValueException('Invalid header encoding');
- }
- if ($headers !== null) {
- $headers = $header;
- }
- $payloadRaw = static::urlsafeB64Decode($bodyb64);
- if (null === ($payload = static::jsonDecode($payloadRaw))) {
- throw new UnexpectedValueException('Invalid claims encoding');
- }
- if (\is_array($payload)) {
- // prevent PHP Fatal Error in edge-cases when payload is empty array
- $payload = (object) $payload;
- }
- if (!$payload instanceof stdClass) {
- throw new UnexpectedValueException('Payload must be a JSON object');
- }
- $sig = static::urlsafeB64Decode($cryptob64);
- if (empty($header->alg)) {
- throw new UnexpectedValueException('Empty algorithm');
- }
- if (empty(static::$supported_algs[$header->alg])) {
- throw new UnexpectedValueException('Algorithm not supported');
- }
-
- $key = self::getKey($keyOrKeyArray, property_exists($header, 'kid') ? $header->kid : null);
-
- // Check the algorithm
- if (!self::constantTimeEquals($key->getAlgorithm(), $header->alg)) {
- // See issue #351
- throw new UnexpectedValueException('Incorrect key for this algorithm');
- }
- if (\in_array($header->alg, ['ES256', 'ES256K', 'ES384'], true)) {
- // OpenSSL expects an ASN.1 DER sequence for ES256/ES256K/ES384 signatures
- $sig = self::signatureToDER($sig);
- }
- if (!self::verify("{$headb64}.{$bodyb64}", $sig, $key->getKeyMaterial(), $header->alg)) {
- throw new SignatureInvalidException('Signature verification failed');
- }
-
- // Check the nbf if it is defined. This is the time that the
- // token can actually be used. If it's not yet that time, abort.
- if (isset($payload->nbf) && floor($payload->nbf) > ($timestamp + static::$leeway)) {
- $ex = new BeforeValidException(
- 'Cannot handle token with nbf prior to ' . \date(DateTime::ISO8601, (int) $payload->nbf)
- );
- $ex->setPayload($payload);
- throw $ex;
- }
-
- // Check that this token has been created before 'now'. This prevents
- // using tokens that have been created for later use (and haven't
- // correctly used the nbf claim).
- if (!isset($payload->nbf) && isset($payload->iat) && floor($payload->iat) > ($timestamp + static::$leeway)) {
- $ex = new BeforeValidException(
- 'Cannot handle token with iat prior to ' . \date(DateTime::ISO8601, (int) $payload->iat)
- );
- $ex->setPayload($payload);
- throw $ex;
- }
-
- // Check if this token has expired.
- if (isset($payload->exp) && ($timestamp - static::$leeway) >= $payload->exp) {
- $ex = new ExpiredException('Expired token');
- $ex->setPayload($payload);
- throw $ex;
- }
-
- return $payload;
- }
-
- /**
- * Converts and signs a PHP array into a JWT string.
- *
- * @param array $payload PHP array
- * @param string|resource|OpenSSLAsymmetricKey|OpenSSLCertificate $key The secret key.
- * @param string $alg Supported algorithms are 'ES384','ES256', 'ES256K', 'HS256',
- * 'HS384', 'HS512', 'RS256', 'RS384', and 'RS512'
- * @param string $keyId
- * @param array $head An array with header elements to attach
- *
- * @return string A signed JWT
- *
- * @uses jsonEncode
- * @uses urlsafeB64Encode
- */
- public static function encode(
- array $payload,
- $key,
- string $alg,
- ?string $keyId = null,
- ?array $head = null
- ): string {
- $header = ['typ' => 'JWT'];
- if (isset($head)) {
- $header = \array_merge($header, $head);
- }
- $header['alg'] = $alg;
- if ($keyId !== null) {
- $header['kid'] = $keyId;
- }
- $segments = [];
- $segments[] = static::urlsafeB64Encode((string) static::jsonEncode($header));
- $segments[] = static::urlsafeB64Encode((string) static::jsonEncode($payload));
- $signing_input = \implode('.', $segments);
-
- $signature = static::sign($signing_input, $key, $alg);
- $segments[] = static::urlsafeB64Encode($signature);
-
- return \implode('.', $segments);
- }
-
- /**
- * Sign a string with a given key and algorithm.
- *
- * @param string $msg The message to sign
- * @param string|resource|OpenSSLAsymmetricKey|OpenSSLCertificate $key The secret key.
- * @param string $alg Supported algorithms are 'EdDSA', 'ES384', 'ES256', 'ES256K', 'HS256',
- * 'HS384', 'HS512', 'RS256', 'RS384', and 'RS512'
- *
- * @return string An encrypted message
- *
- * @throws DomainException Unsupported algorithm or bad key was specified
- */
- public static function sign(
- string $msg,
- $key,
- string $alg
- ): string {
- if (empty(static::$supported_algs[$alg])) {
- throw new DomainException('Algorithm not supported');
- }
- list($function, $algorithm) = static::$supported_algs[$alg];
- switch ($function) {
- case 'hash_hmac':
- if (!\is_string($key)) {
- throw new InvalidArgumentException('key must be a string when using hmac');
- }
- return \hash_hmac($algorithm, $msg, $key, true);
- case 'openssl':
- $signature = '';
- if (!\is_resource($key) && !openssl_pkey_get_private($key)) {
- throw new DomainException('OpenSSL unable to validate key');
- }
- $success = \openssl_sign($msg, $signature, $key, $algorithm); // @phpstan-ignore-line
- if (!$success) {
- throw new DomainException('OpenSSL unable to sign data');
- }
- if ($alg === 'ES256' || $alg === 'ES256K') {
- $signature = self::signatureFromDER($signature, 256);
- } elseif ($alg === 'ES384') {
- $signature = self::signatureFromDER($signature, 384);
- }
- return $signature;
- case 'sodium_crypto':
- if (!\function_exists('sodium_crypto_sign_detached')) {
- throw new DomainException('libsodium is not available');
- }
- if (!\is_string($key)) {
- throw new InvalidArgumentException('key must be a string when using EdDSA');
- }
- try {
- // The last non-empty line is used as the key.
- $lines = array_filter(explode("\n", $key));
- $key = base64_decode((string) end($lines));
- if (\strlen($key) === 0) {
- throw new DomainException('Key cannot be empty string');
- }
- return sodium_crypto_sign_detached($msg, $key);
- } catch (Exception $e) {
- throw new DomainException($e->getMessage(), 0, $e);
- }
- }
-
- throw new DomainException('Algorithm not supported');
- }
-
- /**
- * Verify a signature with the message, key and method. Not all methods
- * are symmetric, so we must have a separate verify and sign method.
- *
- * @param string $msg The original message (header and body)
- * @param string $signature The original signature
- * @param string|resource|OpenSSLAsymmetricKey|OpenSSLCertificate $keyMaterial For Ed*, ES*, HS*, a string key works. for RS*, must be an instance of OpenSSLAsymmetricKey
- * @param string $alg The algorithm
- *
- * @return bool
- *
- * @throws DomainException Invalid Algorithm, bad key, or OpenSSL failure
- */
- private static function verify(
- string $msg,
- string $signature,
- $keyMaterial,
- string $alg
- ): bool {
- if (empty(static::$supported_algs[$alg])) {
- throw new DomainException('Algorithm not supported');
- }
-
- list($function, $algorithm) = static::$supported_algs[$alg];
- switch ($function) {
- case 'openssl':
- $success = \openssl_verify($msg, $signature, $keyMaterial, $algorithm); // @phpstan-ignore-line
- if ($success === 1) {
- return true;
- }
- if ($success === 0) {
- return false;
- }
- // returns 1 on success, 0 on failure, -1 on error.
- throw new DomainException(
- 'OpenSSL error: ' . \openssl_error_string()
- );
- case 'sodium_crypto':
- if (!\function_exists('sodium_crypto_sign_verify_detached')) {
- throw new DomainException('libsodium is not available');
- }
- if (!\is_string($keyMaterial)) {
- throw new InvalidArgumentException('key must be a string when using EdDSA');
- }
- try {
- // The last non-empty line is used as the key.
- $lines = array_filter(explode("\n", $keyMaterial));
- $key = base64_decode((string) end($lines));
- if (\strlen($key) === 0) {
- throw new DomainException('Key cannot be empty string');
- }
- if (\strlen($signature) === 0) {
- throw new DomainException('Signature cannot be empty string');
- }
- return sodium_crypto_sign_verify_detached($signature, $msg, $key);
- } catch (Exception $e) {
- throw new DomainException($e->getMessage(), 0, $e);
- }
- case 'hash_hmac':
- default:
- if (!\is_string($keyMaterial)) {
- throw new InvalidArgumentException('key must be a string when using hmac');
- }
- $hash = \hash_hmac($algorithm, $msg, $keyMaterial, true);
- return self::constantTimeEquals($hash, $signature);
- }
- }
-
- /**
- * Decode a JSON string into a PHP object.
- *
- * @param string $input JSON string
- *
- * @return mixed The decoded JSON string
- *
- * @throws DomainException Provided string was invalid JSON
- */
- public static function jsonDecode(string $input)
- {
- $obj = \json_decode($input, false, 512, JSON_BIGINT_AS_STRING);
-
- if ($errno = \json_last_error()) {
- self::handleJsonError($errno);
- } elseif ($obj === null && $input !== 'null') {
- throw new DomainException('Null result with non-null input');
- }
- return $obj;
- }
-
- /**
- * Encode a PHP array into a JSON string.
- *
- * @param array $input A PHP array
- *
- * @return string JSON representation of the PHP array
- *
- * @throws DomainException Provided object could not be encoded to valid JSON
- */
- public static function jsonEncode(array $input): string
- {
- $json = \json_encode($input, \JSON_UNESCAPED_SLASHES);
- if ($errno = \json_last_error()) {
- self::handleJsonError($errno);
- } elseif ($json === 'null') {
- throw new DomainException('Null result with non-null input');
- }
- if ($json === false) {
- throw new DomainException('Provided object could not be encoded to valid JSON');
- }
- return $json;
- }
-
- /**
- * Decode a string with URL-safe Base64.
- *
- * @param string $input A Base64 encoded string
- *
- * @return string A decoded string
- *
- * @throws InvalidArgumentException invalid base64 characters
- */
- public static function urlsafeB64Decode(string $input): string
- {
- return \base64_decode(self::convertBase64UrlToBase64($input));
- }
-
- /**
- * Convert a string in the base64url (URL-safe Base64) encoding to standard base64.
- *
- * @param string $input A Base64 encoded string with URL-safe characters (-_ and no padding)
- *
- * @return string A Base64 encoded string with standard characters (+/) and padding (=), when
- * needed.
- *
- * @see https://www.rfc-editor.org/rfc/rfc4648
- */
- public static function convertBase64UrlToBase64(string $input): string
- {
- $remainder = \strlen($input) % 4;
- if ($remainder) {
- $padlen = 4 - $remainder;
- $input .= \str_repeat('=', $padlen);
- }
- return \strtr($input, '-_', '+/');
- }
-
- /**
- * Encode a string with URL-safe Base64.
- *
- * @param string $input The string you want encoded
- *
- * @return string The base64 encode of what you passed in
- */
- public static function urlsafeB64Encode(string $input): string
- {
- return \str_replace('=', '', \strtr(\base64_encode($input), '+/', '-_'));
- }
-
-
- /**
- * Determine if an algorithm has been provided for each Key
- *
- * @param Key|ArrayAccess|array $keyOrKeyArray
- * @param string|null $kid
- *
- * @throws UnexpectedValueException
- *
- * @return Key
- */
- private static function getKey(
- $keyOrKeyArray,
- ?string $kid
- ): Key {
- if ($keyOrKeyArray instanceof Key) {
- return $keyOrKeyArray;
- }
-
- if (empty($kid) && $kid !== '0') {
- throw new UnexpectedValueException('"kid" empty, unable to lookup correct key');
- }
-
- if ($keyOrKeyArray instanceof CachedKeySet) {
- // Skip "isset" check, as this will automatically refresh if not set
- return $keyOrKeyArray[$kid];
- }
-
- if (!isset($keyOrKeyArray[$kid])) {
- throw new UnexpectedValueException('"kid" invalid, unable to lookup correct key');
- }
-
- return $keyOrKeyArray[$kid];
- }
-
- /**
- * @param string $left The string of known length to compare against
- * @param string $right The user-supplied string
- * @return bool
- */
- public static function constantTimeEquals(string $left, string $right): bool
- {
- if (\function_exists('hash_equals')) {
- return \hash_equals($left, $right);
- }
- $len = \min(self::safeStrlen($left), self::safeStrlen($right));
-
- $status = 0;
- for ($i = 0; $i < $len; $i++) {
- $status |= (\ord($left[$i]) ^ \ord($right[$i]));
- }
- $status |= (self::safeStrlen($left) ^ self::safeStrlen($right));
-
- return ($status === 0);
- }
-
- /**
- * Helper method to create a JSON error.
- *
- * @param int $errno An error number from json_last_error()
- *
- * @throws DomainException
- *
- * @return void
- */
- private static function handleJsonError(int $errno): void
- {
- $messages = [
- JSON_ERROR_DEPTH => 'Maximum stack depth exceeded',
- JSON_ERROR_STATE_MISMATCH => 'Invalid or malformed JSON',
- JSON_ERROR_CTRL_CHAR => 'Unexpected control character found',
- JSON_ERROR_SYNTAX => 'Syntax error, malformed JSON',
- JSON_ERROR_UTF8 => 'Malformed UTF-8 characters' //PHP >= 5.3.3
- ];
- throw new DomainException(
- isset($messages[$errno])
- ? $messages[$errno]
- : 'Unknown JSON error: ' . $errno
- );
- }
-
- /**
- * Get the number of bytes in cryptographic strings.
- *
- * @param string $str
- *
- * @return int
- */
- private static function safeStrlen(string $str): int
- {
- if (\function_exists('mb_strlen')) {
- return \mb_strlen($str, '8bit');
- }
- return \strlen($str);
- }
-
- /**
- * Convert an ECDSA signature to an ASN.1 DER sequence
- *
- * @param string $sig The ECDSA signature to convert
- * @return string The encoded DER object
- */
- private static function signatureToDER(string $sig): string
- {
- // Separate the signature into r-value and s-value
- $length = max(1, (int) (\strlen($sig) / 2));
- list($r, $s) = \str_split($sig, $length);
-
- // Trim leading zeros
- $r = \ltrim($r, "\x00");
- $s = \ltrim($s, "\x00");
-
- // Convert r-value and s-value from unsigned big-endian integers to
- // signed two's complement
- if (\ord($r[0]) > 0x7f) {
- $r = "\x00" . $r;
- }
- if (\ord($s[0]) > 0x7f) {
- $s = "\x00" . $s;
- }
-
- return self::encodeDER(
- self::ASN1_SEQUENCE,
- self::encodeDER(self::ASN1_INTEGER, $r) .
- self::encodeDER(self::ASN1_INTEGER, $s)
- );
- }
-
- /**
- * Encodes a value into a DER object.
- *
- * @param int $type DER tag
- * @param string $value the value to encode
- *
- * @return string the encoded object
- */
- private static function encodeDER(int $type, string $value): string
- {
- $tag_header = 0;
- if ($type === self::ASN1_SEQUENCE) {
- $tag_header |= 0x20;
- }
-
- // Type
- $der = \chr($tag_header | $type);
-
- // Length
- $der .= \chr(\strlen($value));
-
- return $der . $value;
- }
-
- /**
- * Encodes signature from a DER object.
- *
- * @param string $der binary signature in DER format
- * @param int $keySize the number of bits in the key
- *
- * @return string the signature
- */
- private static function signatureFromDER(string $der, int $keySize): string
- {
- // OpenSSL returns the ECDSA signatures as a binary ASN.1 DER SEQUENCE
- list($offset, $_) = self::readDER($der);
- list($offset, $r) = self::readDER($der, $offset);
- list($offset, $s) = self::readDER($der, $offset);
-
- // Convert r-value and s-value from signed two's compliment to unsigned
- // big-endian integers
- $r = \ltrim($r, "\x00");
- $s = \ltrim($s, "\x00");
-
- // Pad out r and s so that they are $keySize bits long
- $r = \str_pad($r, $keySize / 8, "\x00", STR_PAD_LEFT);
- $s = \str_pad($s, $keySize / 8, "\x00", STR_PAD_LEFT);
-
- return $r . $s;
- }
-
- /**
- * Reads binary DER-encoded data and decodes into a single object
- *
- * @param string $der the binary data in DER format
- * @param int $offset the offset of the data stream containing the object
- * to decode
- *
- * @return array{int, string|null} the new offset and the decoded object
- */
- private static function readDER(string $der, int $offset = 0): array
- {
- $pos = $offset;
- $size = \strlen($der);
- $constructed = (\ord($der[$pos]) >> 5) & 0x01;
- $type = \ord($der[$pos++]) & 0x1f;
-
- // Length
- $len = \ord($der[$pos++]);
- if ($len & 0x80) {
- $n = $len & 0x1f;
- $len = 0;
- while ($n-- && $pos < $size) {
- $len = ($len << 8) | \ord($der[$pos++]);
- }
- }
-
- // Value
- if ($type === self::ASN1_BIT_STRING) {
- $pos++; // Skip the first contents octet (padding indicator)
- $data = \substr($der, $pos, $len - 1);
- $pos += $len - 1;
- } elseif (!$constructed) {
- $data = \substr($der, $pos, $len);
- $pos += $len;
- } else {
- $data = null;
- }
-
- return [$pos, $data];
- }
+class JWT {
+
+ private const ASN1_INTEGER = 0x02;
+ private const ASN1_SEQUENCE = 0x10;
+ private const ASN1_BIT_STRING = 0x03;
+
+ /**
+ * When checking nbf, iat or expiration times,
+ * we want to provide some extra leeway time to
+ * account for clock skew.
+ *
+ * @var int
+ */
+ public static $leeway = 0;
+
+ /**
+ * Allow the current timestamp to be specified.
+ * Useful for fixing a value within unit testing.
+ * Will default to PHP time() value if null.
+ *
+ * @var ?int
+ */
+ public static $timestamp = null;
+
+ /**
+ * @var array
+ */
+ public static $supported_algs = array(
+ 'ES384' => array( 'openssl', 'SHA384' ),
+ 'ES256' => array( 'openssl', 'SHA256' ),
+ 'ES256K' => array( 'openssl', 'SHA256' ),
+ 'HS256' => array( 'hash_hmac', 'SHA256' ),
+ 'HS384' => array( 'hash_hmac', 'SHA384' ),
+ 'HS512' => array( 'hash_hmac', 'SHA512' ),
+ 'RS256' => array( 'openssl', 'SHA256' ),
+ 'RS384' => array( 'openssl', 'SHA384' ),
+ 'RS512' => array( 'openssl', 'SHA512' ),
+ 'EdDSA' => array( 'sodium_crypto', 'EdDSA' ),
+ );
+
+ /**
+ * Decodes a JWT string into a PHP object.
+ *
+ * @param string $jwt The JWT
+ * @param Key|ArrayAccess|array $keyOrKeyArray The Key or associative array of key IDs
+ * (kid) to Key objects.
+ * If the algorithm used is asymmetric, this is
+ * the public key.
+ * Each Key object contains an algorithm and
+ * matching key.
+ * Supported algorithms are 'ES384','ES256',
+ * 'HS256', 'HS384', 'HS512', 'RS256', 'RS384'
+ * and 'RS512'.
+ * @param stdClass $headers Optional. Populates stdClass with headers.
+ *
+ * @return stdClass The JWT's payload as a PHP object
+ *
+ * @throws InvalidArgumentException Provided key/key-array was empty or malformed
+ * @throws DomainException Provided JWT is malformed
+ * @throws UnexpectedValueException Provided JWT was invalid
+ * @throws SignatureInvalidException Provided JWT was invalid because the signature verification failed
+ * @throws BeforeValidException Provided JWT is trying to be used before it's eligible as defined by 'nbf'
+ * @throws BeforeValidException Provided JWT is trying to be used before it's been created as defined by 'iat'
+ * @throws ExpiredException Provided JWT has since expired, as defined by the 'exp' claim
+ *
+ * @uses jsonDecode
+ * @uses urlsafeB64Decode
+ */
+ public static function decode(
+ string $jwt,
+ $keyOrKeyArray,
+ ?stdClass &$headers = null
+ ): stdClass {
+ // Validate JWT
+ $timestamp = \is_null( static::$timestamp ) ? \time() : static::$timestamp;
+
+ if ( empty( $keyOrKeyArray ) ) {
+ throw new InvalidArgumentException( 'Key may not be empty' );
+ }
+ $tks = \explode( '.', $jwt );
+ if ( \count( $tks ) !== 3 ) {
+ throw new UnexpectedValueException( 'Wrong number of segments' );
+ }
+ list($headb64, $bodyb64, $cryptob64) = $tks;
+ $headerRaw = static::urlsafeB64Decode( $headb64 );
+ if ( null === ( $header = static::jsonDecode( $headerRaw ) ) ) {
+ throw new UnexpectedValueException( 'Invalid header encoding' );
+ }
+ if ( $headers !== null ) {
+ $headers = $header;
+ }
+ $payloadRaw = static::urlsafeB64Decode( $bodyb64 );
+ if ( null === ( $payload = static::jsonDecode( $payloadRaw ) ) ) {
+ throw new UnexpectedValueException( 'Invalid claims encoding' );
+ }
+ if ( \is_array( $payload ) ) {
+ // prevent PHP Fatal Error in edge-cases when payload is empty array
+ $payload = (object) $payload;
+ }
+ if ( ! $payload instanceof stdClass ) {
+ throw new UnexpectedValueException( 'Payload must be a JSON object' );
+ }
+ $sig = static::urlsafeB64Decode( $cryptob64 );
+ if ( empty( $header->alg ) ) {
+ throw new UnexpectedValueException( 'Empty algorithm' );
+ }
+ if ( empty( static::$supported_algs[ $header->alg ] ) ) {
+ throw new UnexpectedValueException( 'Algorithm not supported' );
+ }
+
+ $key = self::getKey( $keyOrKeyArray, property_exists( $header, 'kid' ) ? $header->kid : null );
+
+ // Check the algorithm
+ if ( ! self::constantTimeEquals( $key->getAlgorithm(), $header->alg ) ) {
+ // See issue #351
+ throw new UnexpectedValueException( 'Incorrect key for this algorithm' );
+ }
+ if ( \in_array( $header->alg, array( 'ES256', 'ES256K', 'ES384' ), true ) ) {
+ // OpenSSL expects an ASN.1 DER sequence for ES256/ES256K/ES384 signatures
+ $sig = self::signatureToDER( $sig );
+ }
+ if ( ! self::verify( "{$headb64}.{$bodyb64}", $sig, $key->getKeyMaterial(), $header->alg ) ) {
+ throw new SignatureInvalidException( 'Signature verification failed' );
+ }
+
+ // Check the nbf if it is defined. This is the time that the
+ // token can actually be used. If it's not yet that time, abort.
+ if ( isset( $payload->nbf ) && floor( $payload->nbf ) > ( $timestamp + static::$leeway ) ) {
+ $ex = new BeforeValidException(
+ 'Cannot handle token with nbf prior to ' . \date( DateTime::ISO8601, (int) $payload->nbf )
+ );
+ $ex->setPayload( $payload );
+ throw $ex;
+ }
+
+ // Check that this token has been created before 'now'. This prevents
+ // using tokens that have been created for later use (and haven't
+ // correctly used the nbf claim).
+ if ( ! isset( $payload->nbf ) && isset( $payload->iat ) && floor( $payload->iat ) > ( $timestamp + static::$leeway ) ) {
+ $ex = new BeforeValidException(
+ 'Cannot handle token with iat prior to ' . \date( DateTime::ISO8601, (int) $payload->iat )
+ );
+ $ex->setPayload( $payload );
+ throw $ex;
+ }
+
+ // Check if this token has expired.
+ if ( isset( $payload->exp ) && ( $timestamp - static::$leeway ) >= $payload->exp ) {
+ $ex = new ExpiredException( 'Expired token' );
+ $ex->setPayload( $payload );
+ throw $ex;
+ }
+
+ return $payload;
+ }
+
+ /**
+ * Converts and signs a PHP array into a JWT string.
+ *
+ * @param array $payload PHP array
+ * @param string|resource|OpenSSLAsymmetricKey|OpenSSLCertificate $key The secret key.
+ * @param string $alg Supported algorithms are 'ES384','ES256', 'ES256K', 'HS256',
+ * 'HS384', 'HS512', 'RS256', 'RS384', and 'RS512'
+ * @param string $keyId
+ * @param array $head An array with header elements to attach
+ *
+ * @return string A signed JWT
+ *
+ * @uses jsonEncode
+ * @uses urlsafeB64Encode
+ */
+ public static function encode(
+ array $payload,
+ $key,
+ string $alg,
+ ?string $keyId = null,
+ ?array $head = null
+ ): string {
+ $header = array( 'typ' => 'JWT' );
+ if ( isset( $head ) ) {
+ $header = \array_merge( $header, $head );
+ }
+ $header['alg'] = $alg;
+ if ( $keyId !== null ) {
+ $header['kid'] = $keyId;
+ }
+ $segments = array();
+ $segments[] = static::urlsafeB64Encode( (string) static::jsonEncode( $header ) );
+ $segments[] = static::urlsafeB64Encode( (string) static::jsonEncode( $payload ) );
+ $signing_input = \implode( '.', $segments );
+
+ $signature = static::sign( $signing_input, $key, $alg );
+ $segments[] = static::urlsafeB64Encode( $signature );
+
+ return \implode( '.', $segments );
+ }
+
+ /**
+ * Sign a string with a given key and algorithm.
+ *
+ * @param string $msg The message to sign
+ * @param string|resource|OpenSSLAsymmetricKey|OpenSSLCertificate $key The secret key.
+ * @param string $alg Supported algorithms are 'EdDSA', 'ES384', 'ES256', 'ES256K', 'HS256',
+ * 'HS384', 'HS512', 'RS256', 'RS384', and 'RS512'
+ *
+ * @return string An encrypted message
+ *
+ * @throws DomainException Unsupported algorithm or bad key was specified
+ */
+ public static function sign(
+ string $msg,
+ $key,
+ string $alg
+ ): string {
+ if ( empty( static::$supported_algs[ $alg ] ) ) {
+ throw new DomainException( 'Algorithm not supported' );
+ }
+ list($function, $algorithm) = static::$supported_algs[ $alg ];
+ switch ( $function ) {
+ case 'hash_hmac':
+ if ( ! \is_string( $key ) ) {
+ throw new InvalidArgumentException( 'key must be a string when using hmac' );
+ }
+ return \hash_hmac( $algorithm, $msg, $key, true );
+ case 'openssl':
+ $signature = '';
+ if ( ! \is_resource( $key ) && ! openssl_pkey_get_private( $key ) ) {
+ throw new DomainException( 'OpenSSL unable to validate key' );
+ }
+ $success = \openssl_sign( $msg, $signature, $key, $algorithm ); // @phpstan-ignore-line
+ if ( ! $success ) {
+ throw new DomainException( 'OpenSSL unable to sign data' );
+ }
+ if ( $alg === 'ES256' || $alg === 'ES256K' ) {
+ $signature = self::signatureFromDER( $signature, 256 );
+ } elseif ( $alg === 'ES384' ) {
+ $signature = self::signatureFromDER( $signature, 384 );
+ }
+ return $signature;
+ case 'sodium_crypto':
+ if ( ! \function_exists( 'sodium_crypto_sign_detached' ) ) {
+ throw new DomainException( 'libsodium is not available' );
+ }
+ if ( ! \is_string( $key ) ) {
+ throw new InvalidArgumentException( 'key must be a string when using EdDSA' );
+ }
+ try {
+ // The last non-empty line is used as the key.
+ $lines = array_filter( explode( "\n", $key ) );
+ $key = base64_decode( (string) end( $lines ) );
+ if ( \strlen( $key ) === 0 ) {
+ throw new DomainException( 'Key cannot be empty string' );
+ }
+ return sodium_crypto_sign_detached( $msg, $key );
+ } catch ( Exception $e ) {
+ throw new DomainException( $e->getMessage(), 0, $e );
+ }
+ }
+
+ throw new DomainException( 'Algorithm not supported' );
+ }
+
+ /**
+ * Verify a signature with the message, key and method. Not all methods
+ * are symmetric, so we must have a separate verify and sign method.
+ *
+ * @param string $msg The original message (header and body)
+ * @param string $signature The original signature
+ * @param string|resource|OpenSSLAsymmetricKey|OpenSSLCertificate $keyMaterial For Ed*, ES*, HS*, a string key works. for RS*, must be an instance of OpenSSLAsymmetricKey
+ * @param string $alg The algorithm
+ *
+ * @return bool
+ *
+ * @throws DomainException Invalid Algorithm, bad key, or OpenSSL failure
+ */
+ private static function verify(
+ string $msg,
+ string $signature,
+ $keyMaterial,
+ string $alg
+ ): bool {
+ if ( empty( static::$supported_algs[ $alg ] ) ) {
+ throw new DomainException( 'Algorithm not supported' );
+ }
+
+ list($function, $algorithm) = static::$supported_algs[ $alg ];
+ switch ( $function ) {
+ case 'openssl':
+ $success = \openssl_verify( $msg, $signature, $keyMaterial, $algorithm ); // @phpstan-ignore-line
+ if ( $success === 1 ) {
+ return true;
+ }
+ if ( $success === 0 ) {
+ return false;
+ }
+ // returns 1 on success, 0 on failure, -1 on error.
+ throw new DomainException(
+ 'OpenSSL error: ' . \openssl_error_string()
+ );
+ case 'sodium_crypto':
+ if ( ! \function_exists( 'sodium_crypto_sign_verify_detached' ) ) {
+ throw new DomainException( 'libsodium is not available' );
+ }
+ if ( ! \is_string( $keyMaterial ) ) {
+ throw new InvalidArgumentException( 'key must be a string when using EdDSA' );
+ }
+ try {
+ // The last non-empty line is used as the key.
+ $lines = array_filter( explode( "\n", $keyMaterial ) );
+ $key = base64_decode( (string) end( $lines ) );
+ if ( \strlen( $key ) === 0 ) {
+ throw new DomainException( 'Key cannot be empty string' );
+ }
+ if ( \strlen( $signature ) === 0 ) {
+ throw new DomainException( 'Signature cannot be empty string' );
+ }
+ return sodium_crypto_sign_verify_detached( $signature, $msg, $key );
+ } catch ( Exception $e ) {
+ throw new DomainException( $e->getMessage(), 0, $e );
+ }
+ case 'hash_hmac':
+ default:
+ if ( ! \is_string( $keyMaterial ) ) {
+ throw new InvalidArgumentException( 'key must be a string when using hmac' );
+ }
+ $hash = \hash_hmac( $algorithm, $msg, $keyMaterial, true );
+ return self::constantTimeEquals( $hash, $signature );
+ }
+ }
+
+ /**
+ * Decode a JSON string into a PHP object.
+ *
+ * @param string $input JSON string
+ *
+ * @return mixed The decoded JSON string
+ *
+ * @throws DomainException Provided string was invalid JSON
+ */
+ public static function jsonDecode( string $input ) {
+ $obj = \json_decode( $input, false, 512, JSON_BIGINT_AS_STRING );
+
+ if ( $errno = \json_last_error() ) {
+ self::handleJsonError( $errno );
+ } elseif ( $obj === null && $input !== 'null' ) {
+ throw new DomainException( 'Null result with non-null input' );
+ }
+ return $obj;
+ }
+
+ /**
+ * Encode a PHP array into a JSON string.
+ *
+ * @param array $input A PHP array
+ *
+ * @return string JSON representation of the PHP array
+ *
+ * @throws DomainException Provided object could not be encoded to valid JSON
+ */
+ public static function jsonEncode( array $input ): string {
+ $json = \json_encode( $input, \JSON_UNESCAPED_SLASHES );
+ if ( $errno = \json_last_error() ) {
+ self::handleJsonError( $errno );
+ } elseif ( $json === 'null' ) {
+ throw new DomainException( 'Null result with non-null input' );
+ }
+ if ( $json === false ) {
+ throw new DomainException( 'Provided object could not be encoded to valid JSON' );
+ }
+ return $json;
+ }
+
+ /**
+ * Decode a string with URL-safe Base64.
+ *
+ * @param string $input A Base64 encoded string
+ *
+ * @return string A decoded string
+ *
+ * @throws InvalidArgumentException invalid base64 characters
+ */
+ public static function urlsafeB64Decode( string $input ): string {
+ return \base64_decode( self::convertBase64UrlToBase64( $input ) );
+ }
+
+ /**
+ * Convert a string in the base64url (URL-safe Base64) encoding to standard base64.
+ *
+ * @param string $input A Base64 encoded string with URL-safe characters (-_ and no padding)
+ *
+ * @return string A Base64 encoded string with standard characters (+/) and padding (=), when
+ * needed.
+ *
+ * @see https://www.rfc-editor.org/rfc/rfc4648
+ */
+ public static function convertBase64UrlToBase64( string $input ): string {
+ $remainder = \strlen( $input ) % 4;
+ if ( $remainder ) {
+ $padlen = 4 - $remainder;
+ $input .= \str_repeat( '=', $padlen );
+ }
+ return \strtr( $input, '-_', '+/' );
+ }
+
+ /**
+ * Encode a string with URL-safe Base64.
+ *
+ * @param string $input The string you want encoded
+ *
+ * @return string The base64 encode of what you passed in
+ */
+ public static function urlsafeB64Encode( string $input ): string {
+ return \str_replace( '=', '', \strtr( \base64_encode( $input ), '+/', '-_' ) );
+ }
+
+
+ /**
+ * Determine if an algorithm has been provided for each Key
+ *
+ * @param Key|ArrayAccess|array $keyOrKeyArray
+ * @param string|null $kid
+ *
+ * @throws UnexpectedValueException
+ *
+ * @return Key
+ */
+ private static function getKey(
+ $keyOrKeyArray,
+ ?string $kid
+ ): Key {
+ if ( $keyOrKeyArray instanceof Key ) {
+ return $keyOrKeyArray;
+ }
+
+ if ( empty( $kid ) && $kid !== '0' ) {
+ throw new UnexpectedValueException( '"kid" empty, unable to lookup correct key' );
+ }
+
+ if ( $keyOrKeyArray instanceof CachedKeySet ) {
+ // Skip "isset" check, as this will automatically refresh if not set
+ return $keyOrKeyArray[ $kid ];
+ }
+
+ if ( ! isset( $keyOrKeyArray[ $kid ] ) ) {
+ throw new UnexpectedValueException( '"kid" invalid, unable to lookup correct key' );
+ }
+
+ return $keyOrKeyArray[ $kid ];
+ }
+
+ /**
+ * @param string $left The string of known length to compare against
+ * @param string $right The user-supplied string
+ * @return bool
+ */
+ public static function constantTimeEquals( string $left, string $right ): bool {
+ if ( \function_exists( 'hash_equals' ) ) {
+ return \hash_equals( $left, $right );
+ }
+ $len = \min( self::safeStrlen( $left ), self::safeStrlen( $right ) );
+
+ $status = 0;
+ for ( $i = 0; $i < $len; $i++ ) {
+ $status |= ( \ord( $left[ $i ] ) ^ \ord( $right[ $i ] ) );
+ }
+ $status |= ( self::safeStrlen( $left ) ^ self::safeStrlen( $right ) );
+
+ return ( $status === 0 );
+ }
+
+ /**
+ * Helper method to create a JSON error.
+ *
+ * @param int $errno An error number from json_last_error()
+ *
+ * @throws DomainException
+ *
+ * @return void
+ */
+ private static function handleJsonError( int $errno ): void {
+ $messages = array(
+ JSON_ERROR_DEPTH => 'Maximum stack depth exceeded',
+ JSON_ERROR_STATE_MISMATCH => 'Invalid or malformed JSON',
+ JSON_ERROR_CTRL_CHAR => 'Unexpected control character found',
+ JSON_ERROR_SYNTAX => 'Syntax error, malformed JSON',
+ JSON_ERROR_UTF8 => 'Malformed UTF-8 characters', // PHP >= 5.3.3
+ );
+ throw new DomainException(
+ isset( $messages[ $errno ] )
+ ? $messages[ $errno ]
+ : 'Unknown JSON error: ' . $errno
+ );
+ }
+
+ /**
+ * Get the number of bytes in cryptographic strings.
+ *
+ * @param string $str
+ *
+ * @return int
+ */
+ private static function safeStrlen( string $str ): int {
+ if ( \function_exists( 'mb_strlen' ) ) {
+ return \mb_strlen( $str, '8bit' );
+ }
+ return \strlen( $str );
+ }
+
+ /**
+ * Convert an ECDSA signature to an ASN.1 DER sequence
+ *
+ * @param string $sig The ECDSA signature to convert
+ * @return string The encoded DER object
+ */
+ private static function signatureToDER( string $sig ): string {
+ // Separate the signature into r-value and s-value
+ $length = max( 1, (int) ( \strlen( $sig ) / 2 ) );
+ list($r, $s) = \str_split( $sig, $length );
+
+ // Trim leading zeros
+ $r = \ltrim( $r, "\x00" );
+ $s = \ltrim( $s, "\x00" );
+
+ // Convert r-value and s-value from unsigned big-endian integers to
+ // signed two's complement
+ if ( \ord( $r[0] ) > 0x7f ) {
+ $r = "\x00" . $r;
+ }
+ if ( \ord( $s[0] ) > 0x7f ) {
+ $s = "\x00" . $s;
+ }
+
+ return self::encodeDER(
+ self::ASN1_SEQUENCE,
+ self::encodeDER( self::ASN1_INTEGER, $r ) .
+ self::encodeDER( self::ASN1_INTEGER, $s )
+ );
+ }
+
+ /**
+ * Encodes a value into a DER object.
+ *
+ * @param int $type DER tag
+ * @param string $value the value to encode
+ *
+ * @return string the encoded object
+ */
+ private static function encodeDER( int $type, string $value ): string {
+ $tag_header = 0;
+ if ( $type === self::ASN1_SEQUENCE ) {
+ $tag_header |= 0x20;
+ }
+
+ // Type
+ $der = \chr( $tag_header | $type );
+
+ // Length
+ $der .= \chr( \strlen( $value ) );
+
+ return $der . $value;
+ }
+
+ /**
+ * Encodes signature from a DER object.
+ *
+ * @param string $der binary signature in DER format
+ * @param int $keySize the number of bits in the key
+ *
+ * @return string the signature
+ */
+ private static function signatureFromDER( string $der, int $keySize ): string {
+ // OpenSSL returns the ECDSA signatures as a binary ASN.1 DER SEQUENCE
+ list($offset, $_) = self::readDER( $der );
+ list($offset, $r) = self::readDER( $der, $offset );
+ list($offset, $s) = self::readDER( $der, $offset );
+
+ // Convert r-value and s-value from signed two's compliment to unsigned
+ // big-endian integers
+ $r = \ltrim( $r, "\x00" );
+ $s = \ltrim( $s, "\x00" );
+
+ // Pad out r and s so that they are $keySize bits long
+ $r = \str_pad( $r, $keySize / 8, "\x00", STR_PAD_LEFT );
+ $s = \str_pad( $s, $keySize / 8, "\x00", STR_PAD_LEFT );
+
+ return $r . $s;
+ }
+
+ /**
+ * Reads binary DER-encoded data and decodes into a single object
+ *
+ * @param string $der the binary data in DER format
+ * @param int $offset the offset of the data stream containing the object
+ * to decode
+ *
+ * @return array{int, string|null} the new offset and the decoded object
+ */
+ private static function readDER( string $der, int $offset = 0 ): array {
+ $pos = $offset;
+ $size = \strlen( $der );
+ $constructed = ( \ord( $der[ $pos ] ) >> 5 ) & 0x01;
+ $type = \ord( $der[ $pos++ ] ) & 0x1f;
+
+ // Length
+ $len = \ord( $der[ $pos++ ] );
+ if ( $len & 0x80 ) {
+ $n = $len & 0x1f;
+ $len = 0;
+ while ( $n-- && $pos < $size ) {
+ $len = ( $len << 8 ) | \ord( $der[ $pos++ ] );
+ }
+ }
+
+ // Value
+ if ( $type === self::ASN1_BIT_STRING ) {
+ ++$pos; // Skip the first contents octet (padding indicator)
+ $data = \substr( $der, $pos, $len - 1 );
+ $pos += $len - 1;
+ } elseif ( ! $constructed ) {
+ $data = \substr( $der, $pos, $len );
+ $pos += $len;
+ } else {
+ $data = null;
+ }
+
+ return array( $pos, $data );
+ }
}
diff --git a/vendor-prefixed/firebase/php-jwt/src/JWTExceptionWithPayloadInterface.php b/vendor-prefixed/firebase/php-jwt/src/JWTExceptionWithPayloadInterface.php
index 6c4392bbf..02c41d57d 100644
--- a/vendor-prefixed/firebase/php-jwt/src/JWTExceptionWithPayloadInterface.php
+++ b/vendor-prefixed/firebase/php-jwt/src/JWTExceptionWithPayloadInterface.php
@@ -7,20 +7,20 @@
*/
namespace WPGraphQL\WooCommerce\Vendor\Firebase\JWT;
-interface JWTExceptionWithPayloadInterface
-{
- /**
- * Get the payload that caused this exception.
- *
- * @return object
- */
- public function getPayload(): object;
+interface JWTExceptionWithPayloadInterface {
- /**
- * Get the payload that caused this exception.
- *
- * @param object $payload
- * @return void
- */
- public function setPayload(object $payload): void;
+ /**
+ * Get the payload that caused this exception.
+ *
+ * @return object
+ */
+ public function getPayload(): object;
+
+ /**
+ * Get the payload that caused this exception.
+ *
+ * @param object $payload
+ * @return void
+ */
+ public function setPayload( object $payload ): void;
}
diff --git a/vendor-prefixed/firebase/php-jwt/src/Key.php b/vendor-prefixed/firebase/php-jwt/src/Key.php
index 366f16ccf..fce9c4a21 100644
--- a/vendor-prefixed/firebase/php-jwt/src/Key.php
+++ b/vendor-prefixed/firebase/php-jwt/src/Key.php
@@ -13,49 +13,47 @@
use OpenSSLCertificate;
use TypeError;
-class Key
-{
- /**
- * @param string|resource|OpenSSLAsymmetricKey|OpenSSLCertificate $keyMaterial
- * @param string $algorithm
- */
- public function __construct(
- private $keyMaterial,
- private string $algorithm
- ) {
- if (
- !\is_string($keyMaterial)
- && !$keyMaterial instanceof OpenSSLAsymmetricKey
- && !$keyMaterial instanceof OpenSSLCertificate
- && !\is_resource($keyMaterial)
- ) {
- throw new TypeError('Key material must be a string, resource, or OpenSSLAsymmetricKey');
- }
-
- if (empty($keyMaterial)) {
- throw new InvalidArgumentException('Key material must not be empty');
- }
-
- if (empty($algorithm)) {
- throw new InvalidArgumentException('Algorithm must not be empty');
- }
- }
-
- /**
- * Return the algorithm valid for this key
- *
- * @return string
- */
- public function getAlgorithm(): string
- {
- return $this->algorithm;
- }
-
- /**
- * @return string|resource|OpenSSLAsymmetricKey|OpenSSLCertificate
- */
- public function getKeyMaterial()
- {
- return $this->keyMaterial;
- }
+class Key {
+
+ /**
+ * @param string|resource|OpenSSLAsymmetricKey|OpenSSLCertificate $keyMaterial
+ * @param string $algorithm
+ */
+ public function __construct(
+ private $keyMaterial,
+ private string $algorithm
+ ) {
+ if (
+ ! \is_string( $keyMaterial )
+ && ! $keyMaterial instanceof OpenSSLAsymmetricKey
+ && ! $keyMaterial instanceof OpenSSLCertificate
+ && ! \is_resource( $keyMaterial )
+ ) {
+ throw new TypeError( 'Key material must be a string, resource, or OpenSSLAsymmetricKey' );
+ }
+
+ if ( empty( $keyMaterial ) ) {
+ throw new InvalidArgumentException( 'Key material must not be empty' );
+ }
+
+ if ( empty( $algorithm ) ) {
+ throw new InvalidArgumentException( 'Algorithm must not be empty' );
+ }
+ }
+
+ /**
+ * Return the algorithm valid for this key
+ *
+ * @return string
+ */
+ public function getAlgorithm(): string {
+ return $this->algorithm;
+ }
+
+ /**
+ * @return string|resource|OpenSSLAsymmetricKey|OpenSSLCertificate
+ */
+ public function getKeyMaterial() {
+ return $this->keyMaterial;
+ }
}
diff --git a/vendor-prefixed/firebase/php-jwt/src/SignatureInvalidException.php b/vendor-prefixed/firebase/php-jwt/src/SignatureInvalidException.php
index 487ec9713..c9c132c89 100644
--- a/vendor-prefixed/firebase/php-jwt/src/SignatureInvalidException.php
+++ b/vendor-prefixed/firebase/php-jwt/src/SignatureInvalidException.php
@@ -8,6 +8,6 @@
namespace WPGraphQL\WooCommerce\Vendor\Firebase\JWT;
-class SignatureInvalidException extends \UnexpectedValueException
-{
+class SignatureInvalidException extends \UnexpectedValueException {
+
}
diff --git a/wp-graphql-woocommerce.php b/wp-graphql-woocommerce.php
index 998d97d4d..5789500d1 100644
--- a/wp-graphql-woocommerce.php
+++ b/wp-graphql-woocommerce.php
@@ -101,7 +101,7 @@ function plugin_file_url( $filepath ) {
*
* @return array
*/
-function dependencies_not_ready( &$deps = [] ) {
+function dependencies_not_ready( &$deps = array() ) {
if ( ! class_exists( '\WPGraphQL' ) ) {
$deps[] = 'WPGraphQL';
}
@@ -119,7 +119,7 @@ function dependencies_not_ready( &$deps = [] ) {
*/
function init() {
// We define this now and pass it as a reference.
- $not_ready = [];
+ $not_ready = array();
if ( empty( dependencies_not_ready( $not_ready ) ) ) {
require_once get_includes_directory() . 'class-wp-graphql-woocommerce.php';