Files
wp-graphql-woocommerce/tests/wpunit/TaxClassQueriesTest.php
Geoff TaylorandGitHub f686e743b0 feat: Queries and mutations for shipping zones, tax classes, and tax rates. (#856)
* fix: General bugfixes and improvements

* devops: New mutations and types tested and compliance with Linter and PHPStan

* chore: hooks added to the mutation resolvers

* feat: permission checks added

* chore: Linter and compliance met

* chore: Linter and compliance met
2024-05-17 00:03:10 -04:00

48 lines
1.5 KiB
PHP

<?php
class TaxClassQueriesTest extends \Tests\WPGraphQL\WooCommerce\TestCase\WooGraphQLTestCase {
public function testTaxClassesQuery() {
// Create tax classes.
$tax_classes = $this->factory->tax_class->create_many( 2 );
// Prepare the request.
$query = '{
taxClasses {
nodes {
name
slug
}
}
}';
// Execute the request expecting failure due to missing permissions.
$response = $this->graphql( compact( 'query' ) );
$this->assertQuerySuccessful( $response, [ $this->expectedField( 'taxClasses.nodes', self::IS_FALSY ) ] );
// Login as shop manager.
$this->loginAsShopManager();
// Execute the request.
$response = $this->graphql( compact( 'query' ) );
$expected = [
$this->expectedNode(
'taxClasses.nodes',
[
$this->expectedField( 'name', $tax_classes[0]['name'] ),
$this->expectedField( 'slug', $tax_classes[0]['slug'] ),
]
),
$this->expectedNode(
'taxClasses.nodes',
[
$this->expectedField( 'name', $tax_classes[1]['name'] ),
$this->expectedField( 'slug', $tax_classes[1]['slug'] ),
]
),
];
// Validate the response.
$this->assertQuerySuccessful( $response, $expected );
}
}