2020-01-28 13:56:58 -05:00
|
|
|
<?php
|
|
|
|
|
|
2024-10-29 11:54:06 -04:00
|
|
|
class IntrospectionQueryTest extends \Tests\WPGraphQL\WooCommerce\TestCase\WooGraphQLTestCase {
|
2022-02-04 15:00:44 -05:00
|
|
|
public function setUp(): void {
|
|
|
|
|
// before
|
2020-10-13 15:01:44 -04:00
|
|
|
parent::setUp();
|
2020-01-28 13:56:58 -05:00
|
|
|
|
2020-10-13 15:01:44 -04:00
|
|
|
$settings = get_option( 'graphql_general_settings' );
|
2020-10-14 20:33:55 -04:00
|
|
|
if ( ! $settings ) {
|
2022-08-26 14:53:36 -04:00
|
|
|
$settings = [];
|
2020-10-14 20:33:55 -04:00
|
|
|
}
|
2020-10-13 15:01:44 -04:00
|
|
|
$settings['public_introspection_enabled'] = 'on';
|
|
|
|
|
update_option( 'graphql_general_settings', $settings );
|
2021-08-11 14:26:09 -04:00
|
|
|
\WPGraphQL::clear_schema();
|
2022-02-04 15:00:44 -05:00
|
|
|
}
|
2020-01-28 13:56:58 -05:00
|
|
|
|
2022-02-04 15:00:44 -05:00
|
|
|
// Validate schema.
|
|
|
|
|
public function testSchema() {
|
|
|
|
|
try {
|
2024-10-29 11:54:06 -04:00
|
|
|
new \WPGraphQL\Request();
|
|
|
|
|
|
|
|
|
|
$schema = WPGraphQL::get_schema();
|
|
|
|
|
$schema->assertValid();
|
2020-01-28 13:56:58 -05:00
|
|
|
|
2022-02-04 15:00:44 -05:00
|
|
|
// Assert true upon success.
|
2024-10-29 11:54:06 -04:00
|
|
|
$this->assertTrue( true, 'Schema is valid.' );
|
2022-02-04 15:00:44 -05:00
|
|
|
} catch ( \GraphQL\Error\InvariantViolation $e ) {
|
|
|
|
|
// use --debug flag to view.
|
2024-10-29 11:54:06 -04:00
|
|
|
$this->logData( $e->getMessage() );
|
2020-01-28 13:56:58 -05:00
|
|
|
|
2022-02-04 15:00:44 -05:00
|
|
|
// Fail upon throwing
|
2024-10-29 11:54:06 -04:00
|
|
|
$this->assertTrue( false, $e->getMessage() );
|
2022-02-04 15:00:44 -05:00
|
|
|
}
|
|
|
|
|
}
|
2020-01-28 13:56:58 -05:00
|
|
|
|
2022-02-04 15:00:44 -05:00
|
|
|
// Test introspection query.
|
|
|
|
|
public function testIntrospectionQuery() {
|
|
|
|
|
$query = \GraphQL\Type\Introspection::getIntrospectionQuery();
|
2026-03-20 13:31:13 -04:00
|
|
|
$results = $this->graphql( compact( 'query' ) );
|
2020-06-19 18:44:21 -04:00
|
|
|
|
2026-03-20 13:31:13 -04:00
|
|
|
$this->assertQuerySuccessful( $results, [] );
|
2022-02-04 15:00:44 -05:00
|
|
|
}
|
2020-06-19 18:44:21 -04:00
|
|
|
}
|