2019-03-14 23:55:34 -04:00
|
|
|
<?php
|
|
|
|
|
|
2019-04-14 01:59:03 -04:00
|
|
|
use GraphQLRelay\Relay;
|
|
|
|
|
|
2019-03-21 21:43:24 -04:00
|
|
|
class ShippingMethodQueriesTest extends \Codeception\TestCase\WPTestCase {
|
2019-04-14 01:59:03 -04:00
|
|
|
private $shop_manager;
|
|
|
|
|
private $customer;
|
|
|
|
|
private $method;
|
|
|
|
|
private $helper;
|
2019-03-14 23:55:34 -04:00
|
|
|
|
2019-03-21 21:43:24 -04:00
|
|
|
public function setUp() {
|
|
|
|
|
parent::setUp();
|
2019-03-14 23:55:34 -04:00
|
|
|
|
2019-04-14 01:59:03 -04:00
|
|
|
$this->shop_manager = $this->factory->user->create( array( 'role' => 'shop_manager' ) );
|
|
|
|
|
$this->customer = $this->factory->user->create( array( 'role' => 'customer' ) );
|
|
|
|
|
$this->helper = $this->getModule('\Helper\Wpunit')->shipping_method();
|
|
|
|
|
$this->method = 'flat_rate';
|
2019-03-21 21:43:24 -04:00
|
|
|
}
|
2019-03-14 23:55:34 -04:00
|
|
|
|
2019-03-21 21:43:24 -04:00
|
|
|
public function tearDown() {
|
|
|
|
|
// your tear down methods here
|
|
|
|
|
// then
|
|
|
|
|
parent::tearDown();
|
|
|
|
|
}
|
2019-03-14 23:55:34 -04:00
|
|
|
|
2019-03-21 21:43:24 -04:00
|
|
|
// tests
|
2019-04-14 01:59:03 -04:00
|
|
|
public function testShippingMethodQueryAndArgs() {
|
|
|
|
|
$id = Relay::toGlobalId( 'shipping_method', $this->method );
|
|
|
|
|
|
|
|
|
|
$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
|
|
|
*
|
2020-01-25 12:36:47 -05:00
|
|
|
* test "ID" ID type.
|
2019-04-14 01:59:03 -04:00
|
|
|
*/
|
2020-01-25 12:36:47 -05:00
|
|
|
$variables = array(
|
|
|
|
|
'id' => $id,
|
|
|
|
|
'idType' => 'ID',
|
|
|
|
|
);
|
|
|
|
|
$actual = graphql(
|
|
|
|
|
array(
|
|
|
|
|
'query' => $query,
|
|
|
|
|
'variables' => $variables,
|
|
|
|
|
)
|
|
|
|
|
);
|
2019-04-14 01:59:03 -04:00
|
|
|
$expected = array( 'data' => array( 'shippingMethod' => $this->helper->print_query( $this->method ) ) );
|
|
|
|
|
|
|
|
|
|
// use --debug flag to view.
|
|
|
|
|
codecept_debug( $actual );
|
|
|
|
|
|
2019-11-13 18:53:31 -05:00
|
|
|
$this->assertEquals( $expected, $actual );
|
2019-04-14 01:59:03 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Assertion Two
|
2020-09-16 16:32:14 -04:00
|
|
|
*
|
2020-01-25 12:36:47 -05:00
|
|
|
* test "DATABASE_ID" ID type.
|
2019-04-14 01:59:03 -04:00
|
|
|
*/
|
2020-01-25 12:36:47 -05:00
|
|
|
$variables = array(
|
|
|
|
|
'id' => $this->method,
|
|
|
|
|
'idType' => 'DATABASE_ID',
|
|
|
|
|
);
|
|
|
|
|
$actual = graphql(
|
|
|
|
|
array(
|
|
|
|
|
'query' => $query,
|
|
|
|
|
'variables' => $variables,
|
|
|
|
|
)
|
|
|
|
|
);
|
2019-04-14 01:59:03 -04:00
|
|
|
$expected = array( 'data' => array( 'shippingMethod' => $this->helper->print_query( $this->method ) ) );
|
|
|
|
|
|
|
|
|
|
// use --debug flag to view.
|
|
|
|
|
codecept_debug( $actual );
|
|
|
|
|
|
2019-11-13 18:53:31 -05:00
|
|
|
$this->assertEquals( $expected, $actual );
|
2019-04-14 01:59:03 -04:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testShippingMethodsQuery() {
|
2019-04-17 14:18:35 -04:00
|
|
|
$wc_shipping = WC_Shipping::instance();
|
2020-09-16 16:32:14 -04:00
|
|
|
$methods = array_values(
|
2019-04-17 14:18:35 -04:00
|
|
|
array_map(
|
|
|
|
|
function( $method ) {
|
|
|
|
|
return array( 'id' => Relay::toGlobalId( 'shipping_method', $method->id ) );
|
|
|
|
|
},
|
|
|
|
|
$wc_shipping->get_shipping_methods()
|
|
|
|
|
)
|
2019-04-14 01:59:03 -04:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$query = '
|
|
|
|
|
query shippingMethodsQuery {
|
|
|
|
|
shippingMethods {
|
|
|
|
|
nodes {
|
|
|
|
|
id
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Assertion One
|
2020-09-16 16:32:14 -04:00
|
|
|
*
|
2019-04-14 01:59:03 -04:00
|
|
|
* tests query
|
|
|
|
|
*/
|
|
|
|
|
$actual = do_graphql_request( $query, 'shippingMethodQuery' );
|
2019-04-17 14:18:35 -04:00
|
|
|
$expected = array( 'data' => array( 'shippingMethods' => array( 'nodes' => $methods ) ) );
|
2019-04-14 01:59:03 -04:00
|
|
|
|
|
|
|
|
// use --debug flag to view.
|
|
|
|
|
codecept_debug( $actual );
|
|
|
|
|
|
2019-11-13 18:53:31 -05:00
|
|
|
$this->assertEquals( $expected, $actual );
|
2019-04-14 01:59:03 -04:00
|
|
|
}
|
2019-03-21 21:43:24 -04:00
|
|
|
}
|