Files
wp-graphql-woocommerce/tests/wpunit/VariationAttributeQueriesTest.php
T
a7714d0cd2 Updates to be compatible with WPGraphQL v1.6.1 (#537)
* fix: Huge refactor across schema and unit tests

* - add shipping_method loader in class-core-schema-filters.php

* - Update class-wc-db-loader.php to respect the new SHIPPING_METHOD loader with a `load_shipping_method_from_id()` function

* - Convert Shipping_Method_Connection_Resolver to extend AbstractConnectionResolver

* - Replace resolver for Shipping Methods connection. Remove use of `resolveNode` and replace the resolver with the new connection class `get_connection()` call

* chore: Factory class refactored.

* - update the function that registers Product Types to the Schema to use the value from the `get_enabled_product_types()` as the Type name and the key as the fieldName

* chore: PaymentGatewayQueriesTest refactored.

* chore: WPCS compliance met

* chore: Syntax error fixed.

Co-authored-by: Jason Bahl <jasonbahl@mac.com>
2021-08-11 14:26:09 -04:00

113 lines
3.4 KiB
PHP

<?php
class VariationAttributeQueriesTest extends \Codeception\TestCase\WPTestCase {
private $shop_manager;
private $customer;
private $product_id;
private $variation_id;
public function setUp(): void {
// before
parent::setUp();
$this->shop_manager = $this->factory->user->create( array( 'role' => 'shop_manager' ) );
$this->customer = $this->factory->user->create( array( 'role' => 'customer' ) );
$this->product = $this->getModule('\Helper\Wpunit')->product();
$this->variation = $this->getModule('\Helper\Wpunit')->product_variation();
$ids = $this->variation->create( $this->product->create_variable() );
$this->product_id = $ids['product'];
$this->variation_id = $ids['variations'][0];
\WPGraphQL::clear_schema();
}
public function tearDown(): void {
// your tear down methods here
// then
parent::tearDown();
}
// tests
public function testProductVariationToVariationAttributeQuery() {
$query = '
query fromVariationQuery( $id: ID! ) {
productVariation( id: $id ) {
id
attributes {
nodes {
id
attributeId
name
value
}
}
}
}
';
/**
* Assertion One
*
* test query and results
*/
$variables = array( 'id' => $this->variation->to_relay_id( $this->variation_id ) );
$actual = graphql( array( 'query' => $query, 'variables' => $variables ) );
$expected = array(
'data' => array(
'productVariation' => array(
'id' => $this->variation->to_relay_id( $this->variation_id ),
'attributes' => $this->variation->print_attributes( $this->variation_id ),
),
),
);
// use --debug flag to view.
codecept_debug( $actual );
$this->assertEquals( $expected, $actual );
}
public function testProductToVariationAttributeQuery() {
$query = '
query ( $id: ID! ) {
product( id: $id ) {
... on VariableProduct {
id
defaultAttributes {
nodes {
id
attributeId
name
value
}
}
}
}
}
';
/**
* Assertion One
*
* test query and results
*/
$variables = array( 'id' => $this->product->to_relay_id( $this->product_id ) );
$actual = graphql( array( 'query' => $query, 'variables' => $variables ) );
$expected = array(
'data' => array(
'product' => array(
'id' => $this->product->to_relay_id( $this->product_id ),
'defaultAttributes' => $this->variation->print_attributes( $this->product_id, 'PRODUCT' ),
),
),
);
// use --debug flag to view.
codecept_debug( $actual );
$this->assertEquals( $expected, $actual );
}
}