Files

100 lines
2.3 KiB
PHP
Raw Permalink Normal View History

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