2019-03-14 23:55:34 -04:00
|
|
|
<?php
|
|
|
|
|
|
2019-04-14 01:59:03 -04:00
|
|
|
use GraphQLRelay\Relay;
|
|
|
|
|
|
2024-05-17 00:03:10 -04:00
|
|
|
class ShippingMethodQueriesTest extends \Tests\WPGraphQL\WooCommerce\TestCase\WooGraphQLTestCase {
|
2019-03-14 23:55:34 -04:00
|
|
|
|
2019-04-14 01:59:03 -04:00
|
|
|
public function testShippingMethodQueryAndArgs() {
|
2024-05-17 00:03:10 -04:00
|
|
|
$id = Relay::toGlobalId( 'shipping_method', 'flat_rate' );
|
2019-04-14 01:59:03 -04:00
|
|
|
|
|
|
|
|
$query = '
|
2020-01-25 12:36:47 -05:00
|
|
|
query( $id: ID!, $idType: ShippingMethodIdTypeEnum ) {
|
|
|
|
|
shippingMethod( id: $id, idType: $idType ) {
|
2019-04-14 01:59:03 -04:00
|
|
|
id
|
2020-09-16 16:32:14 -04:00
|
|
|
databaseId
|
2019-04-14 01:59:03 -04:00
|
|
|
title
|
|
|
|
|
description
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Assertion One
|
2020-09-16 16:32:14 -04:00
|
|
|
*
|
2024-05-17 00:03:10 -04:00
|
|
|
* Confirm permission check is working
|
2019-04-14 01:59:03 -04:00
|
|
|
*/
|
2024-05-17 00:03:10 -04:00
|
|
|
$variables = [ 'id' => $id ];
|
|
|
|
|
$response = $this->graphql( compact( 'query', 'variables' ) );
|
2019-04-14 01:59:03 -04:00
|
|
|
|
2024-05-17 00:03:10 -04:00
|
|
|
$this->assertQueryError( $response );
|
2019-04-14 01:59:03 -04:00
|
|
|
|
2024-05-17 00:03:10 -04:00
|
|
|
// Login as shop manager.
|
|
|
|
|
$this->loginAsShopManager();
|
2019-04-14 01:59:03 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Assertion Two
|
2020-09-16 16:32:14 -04:00
|
|
|
*
|
2024-05-17 00:03:10 -04:00
|
|
|
* Test "ID" ID type.
|
|
|
|
|
*/
|
|
|
|
|
$variables = [ 'id' => $id ];
|
|
|
|
|
$response = $this->graphql( compact( 'query', 'variables' ) );
|
|
|
|
|
$expected = [
|
|
|
|
|
$this->expectedField( 'shippingMethod.id', $id ),
|
|
|
|
|
$this->expectedField( 'shippingMethod.databaseId', 'flat_rate' ),
|
|
|
|
|
$this->expectedField( 'shippingMethod.title', self::NOT_NULL ),
|
|
|
|
|
$this->expectedField( 'shippingMethod.description', self::NOT_NULL ),
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$this->assertQuerySuccessful( $response, $expected );
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Assertion Three
|
|
|
|
|
*
|
2022-02-04 15:00:44 -05:00
|
|
|
* Test "DATABASE_ID" ID type.
|
2019-04-14 01:59:03 -04:00
|
|
|
*/
|
2024-05-17 00:03:10 -04:00
|
|
|
$variables = [ 'id' => 'flat_rate', 'idType' => 'DATABASE_ID' ];
|
|
|
|
|
$response = $this->graphql( compact( 'query', 'variables' ) );
|
2019-04-14 01:59:03 -04:00
|
|
|
|
2024-05-17 00:03:10 -04:00
|
|
|
$this->assertQuerySuccessful( $response, $expected );
|
2019-04-14 01:59:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testShippingMethodsQuery() {
|
|
|
|
|
$query = '
|
2024-05-17 00:03:10 -04:00
|
|
|
query {
|
2019-04-14 01:59:03 -04:00
|
|
|
shippingMethods {
|
|
|
|
|
nodes {
|
|
|
|
|
id
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
';
|
|
|
|
|
|
2024-05-17 00:03:10 -04:00
|
|
|
/**
|
|
|
|
|
* Assertion One
|
|
|
|
|
*
|
|
|
|
|
* Confirm permission check is working
|
|
|
|
|
*/
|
|
|
|
|
$response = $this->graphql( compact( 'query' ) );
|
|
|
|
|
$this->assertQuerySuccessful( $response, [ $this->expectedField( 'shippingMethods.nodes', self::IS_FALSY ) ] );
|
|
|
|
|
|
|
|
|
|
// Login as shop manager.
|
|
|
|
|
$this->loginAsShopManager();
|
|
|
|
|
|
2019-04-14 01:59:03 -04:00
|
|
|
/**
|
|
|
|
|
* Assertion One
|
2020-09-16 16:32:14 -04:00
|
|
|
*
|
2022-02-04 15:00:44 -05:00
|
|
|
* Tests query
|
2019-04-14 01:59:03 -04:00
|
|
|
*/
|
2024-05-17 00:03:10 -04:00
|
|
|
$response = $this->graphql( compact( 'query' ) );
|
|
|
|
|
$expected = array_map(
|
|
|
|
|
function( $method ) {
|
|
|
|
|
return $this->expectedField( 'shippingMethods.nodes.#.id', $this->toRelayId( 'shipping_method', $method->id ) );
|
|
|
|
|
},
|
|
|
|
|
array_values( WC_Shipping::instance()->get_shipping_methods() )
|
|
|
|
|
);
|
|
|
|
|
|
2019-04-14 01:59:03 -04:00
|
|
|
|
2024-05-17 00:03:10 -04:00
|
|
|
$this->assertQuerySuccessful( $response, $expected );
|
2019-04-14 01:59:03 -04:00
|
|
|
}
|
2019-03-21 21:43:24 -04:00
|
|
|
}
|