diff --git a/tests/_support/TestCase/WooGraphQLTestCase.php b/tests/_support/TestCase/WooGraphQLTestCase.php index 2d92f86d..d03c2c71 100644 --- a/tests/_support/TestCase/WooGraphQLTestCase.php +++ b/tests/_support/TestCase/WooGraphQLTestCase.php @@ -115,7 +115,13 @@ protected function logout() { * * @return mixed */ - protected function maybe( $possible, $default = static::IS_NULL ) { + protected function maybe( $possible, $custom_default = null ) { + if ( null === $custom_default ) { + $default = static::IS_NULL; + } else { + $default = $custom_default; + } + if ( is_array( $possible ) && 2 === count( $possible ) ) { list( $possible, $decorated ) = $possible; } else { diff --git a/tests/wpunit/ProductsQueriesTest.php b/tests/wpunit/ProductsQueriesTest.php index 5d1ec287..235e726f 100644 --- a/tests/wpunit/ProductsQueriesTest.php +++ b/tests/wpunit/ProductsQueriesTest.php @@ -292,7 +292,7 @@ public function testProductsQueryAndWhereArgs() { function ( $product_id ) { return $this->expectedNode( 'products.nodes', - [ $this->expectedField( 'id', $this->toRelayId( 'product', $product_id ) ) ] + [ $this->expectedField( 'id', $this->toRelayId( 'post', $product_id ) ) ] ); }, $product_ids @@ -445,12 +445,12 @@ static function ( $node, $index ) use ( $product_ids ) { $expected = [ $this->expectedNode( 'products.nodes', - [ $this->expectedField( 'id', $this->toRelayId( 'product', $product_ids[0] ) ) ], + [ $this->expectedField( 'id', $this->toRelayId( 'post', $product_ids[0] ) ) ], 0 ), $this->expectedNode( 'products.nodes', - [ $this->expectedField( 'id', $this->toRelayId( 'product', $product_ids[1] ) ) ], + [ $this->expectedField( 'id', $this->toRelayId( 'post', $product_ids[1] ) ) ], 4 ), ]; @@ -598,7 +598,7 @@ static function ( $node, $index ) use ( $product_ids, $category_4, $category_3 ) $expected = [ $this->expectedNode( 'products.nodes', - [ $this->expectedField( 'id', $this->toRelayId( 'product', $product_ids[0] ) ) ] + [ $this->expectedField( 'id', $this->toRelayId( 'post', $product_ids[0] ) ) ] ), ]; $this->assertQuerySuccessful( $response, $expected ); @@ -627,7 +627,7 @@ static function ( $node, $index ) use ( $product_ids, $category_4, $category_3 ) $expected = [ $this->not()->expectedNode( 'products.nodes', - [ $this->expectedField( 'id', $this->toRelayId( 'product', $product_ids[0] ) ) ] + [ $this->expectedField( 'id', $this->toRelayId( 'post', $product_ids[0] ) ) ] ), ]; $this->assertQuerySuccessful( $response, $expected ); @@ -652,7 +652,7 @@ static function ( $node, $index ) use ( $product_ids, $category_4, $category_3 ) $expected = [ $this->not()->expectedNode( 'products.nodes', - [ $this->expectedField( 'id', $this->toRelayId( 'product', $product_ids[4] ) ) ] + [ $this->expectedField( 'id', $this->toRelayId( 'post', $product_ids[4] ) ) ] ), ]; $this->assertQuerySuccessful( $response, $expected ); @@ -662,7 +662,7 @@ static function ( $node, $index ) use ( $product_ids, $category_4, $category_3 ) $expected = [ $this->expectedNode( 'products.nodes', - [ $this->expectedField( 'id', $this->toRelayId( 'product', $product_ids[4] ) ) ], + [ $this->expectedField( 'id', $this->toRelayId( 'post', $product_ids[4] ) ) ], 0 ), ]; @@ -675,7 +675,7 @@ public function testVariationsQueryAndWhereArgs() { $this->factory->product->createVariable() ); $variation_id = $products['variations'][0]; - $id = $this->toRelayId( 'product', $products['product'] ); + $id = $this->toRelayId( 'post', $products['product'] ); $product = wc_get_product( $products['product'] ); $variations = $products['variations']; $prices = $product->get_variation_prices( true ); @@ -718,9 +718,9 @@ public function testVariationsQueryAndWhereArgs() { $variables = [ 'id' => $id ]; $response = $this->graphql( compact( 'query', 'variables' ) ); $expected = [ - $this->expectedField( 'product.variations.nodes.#.id', $this->toRelayId( 'product_variation', $variations[0] ) ), - $this->expectedField( 'product.variations.nodes.#.id', $this->toRelayId( 'product_variation', $variations[1] ) ), - $this->expectedField( 'product.variations.nodes.#.id', $this->toRelayId( 'product_variation', $variations[2] ) ), + $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] ) ), $this->expectedField( 'product.price', \wc_graphql_price( current( $prices['price'] ) ) @@ -751,9 +751,9 @@ public function testVariationsQueryAndWhereArgs() { ]; $response = $this->graphql( compact( 'query', 'variables' ) ); $expected = [ - $this->not()->expectedField( 'product.variations.nodes.#.id', $this->toRelayId( 'product_variation', $variations[0] ) ), - $this->expectedField( 'product.variations.nodes.#.id', $this->toRelayId( 'product_variation', $variations[1] ) ), - $this->expectedField( 'product.variations.nodes.#.id', $this->toRelayId( 'product_variation', $variations[2] ) ), + $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 ); @@ -810,14 +810,14 @@ public function testProductsOrderbyArg() { $this->expectedNode( 'products.nodes', [ - $this->expectedField( 'id', $this->toRelayId( 'product', $products[0] ) ) + $this->expectedField( 'id', $this->toRelayId( 'post', $products[0] ) ) ], 0 ), $this->expectedNode( 'products.nodes', [ - $this->expectedField( 'id', $this->toRelayId( 'product', $products[1] ) ) + $this->expectedField( 'id', $this->toRelayId( 'post', $products[1] ) ) ], 1 ), @@ -848,14 +848,14 @@ public function testProductsOrderbyArg() { $this->expectedNode( 'products.nodes', [ - $this->expectedField( 'id', $this->toRelayId( 'product', $products[2] ) ) + $this->expectedField( 'id', $this->toRelayId( 'post', $products[2] ) ) ], 0 ), $this->expectedNode( 'products.nodes', [ - $this->expectedField( 'id', $this->toRelayId( 'product', $products[3] ) ) + $this->expectedField( 'id', $this->toRelayId( 'post', $products[3] ) ) ], 1 ), @@ -883,14 +883,14 @@ public function testProductsOrderbyArg() { $this->expectedNode( 'products.nodes', [ - $this->expectedField( 'id', $this->toRelayId( 'product', $products[0] ) ) + $this->expectedField( 'id', $this->toRelayId( 'post', $products[0] ) ) ], 0 ), $this->expectedNode( 'products.nodes', [ - $this->expectedField( 'id', $this->toRelayId( 'product', $products[1] ) ) + $this->expectedField( 'id', $this->toRelayId( 'post', $products[1] ) ) ], 1 ), @@ -919,14 +919,14 @@ public function testProductsOrderbyArg() { $this->expectedNode( 'products.nodes', [ - $this->expectedField( 'id', $this->toRelayId( 'product', $products[2] ) ) + $this->expectedField( 'id', $this->toRelayId( 'post', $products[2] ) ) ], 0 ), $this->expectedNode( 'products.nodes', [ - $this->expectedField( 'id', $this->toRelayId( 'product', $products[3] ) ) + $this->expectedField( 'id', $this->toRelayId( 'post', $products[3] ) ) ], 1 ), @@ -953,14 +953,14 @@ public function testProductsOrderbyArg() { $this->expectedNode( 'products.nodes', [ - $this->expectedField( 'id', $this->toRelayId( 'product', $products[0] ) ) + $this->expectedField( 'id', $this->toRelayId( 'post', $products[0] ) ) ], 0 ), $this->expectedNode( 'products.nodes', [ - $this->expectedField( 'id', $this->toRelayId( 'product', $products[1] ) ) + $this->expectedField( 'id', $this->toRelayId( 'post', $products[1] ) ) ], 1 ), @@ -989,14 +989,14 @@ public function testProductsOrderbyArg() { $this->expectedNode( 'products.nodes', [ - $this->expectedField( 'id', $this->toRelayId( 'product', $products[4] ) ) + $this->expectedField( 'id', $this->toRelayId( 'post', $products[4] ) ) ], 0 ), $this->expectedNode( 'products.nodes', [ - $this->expectedField( 'id', $this->toRelayId( 'product', $products[2] ) ) + $this->expectedField( 'id', $this->toRelayId( 'post', $products[2] ) ) ], 1 ), @@ -1045,7 +1045,7 @@ public function testProductsSearchArg() { $this->expectedNode( 'products.nodes', [ - $this->expectedField( 'id', $this->toRelayId( 'product', $products[1] ) ) + $this->expectedField( 'id', $this->toRelayId( 'post', $products[1] ) ) ], 0 ), @@ -1066,7 +1066,7 @@ public function testProductsSearchArg() { $this->expectedNode( 'products.nodes', [ - $this->expectedField( 'id', $this->toRelayId( 'product', $products[1] ) ) + $this->expectedField( 'id', $this->toRelayId( 'post', $products[1] ) ) ], 0 ),