Files
wp-graphql-woocommerce/tests/wpunit/ProtectedRouterTest.php
T
Geoffrey K TaylorandGitHub ba13b2ec0a feat: Authorizing URLs implemented and tested. (#745)
* feat: Authorizing URLs implemented and tested.

* feat: More woographql_*_nonce functions implemented.

* chore: linting changes made.

* chore: linting changes made.

* fix: woographql_*_ functions tested.

* chore: WPCS compliance met.

* devops: lint-code script updated to PHP v8.0

* chore: WPCS compliance met

* devops: TransferSessionHandlerTest & QLSessionHandlerTest updated

* devops: codeclimate.yml added.

* chore: Linter compliance met

* devops: Harmonizing WordPress doc written and Settings doc updated.

* chore: Typo fixed in docs.

* fix: General bugfixes and improvements related to Auth URLs

* devops: More docs.

* chore: Linter compliance met

* chore: small change made to docs.
2023-05-22 13:43:10 -04:00

55 lines
2.3 KiB
PHP

<?php
class ProtectedRouterTest extends \Tests\WPGraphQL\WooCommerce\TestCase\WooGraphQLTestCase {
public function testRouteEndpoint() {
/**
* Test that the default route is set to "graphql"
*/
$this->assertEquals( 'transfer-session', apply_filters( 'woographql_authorizing_url_endpoint', \WPGraphQL\WooCommerce\Utils\Protected_Router::$route ) );
}
/**
* Test to make sure that the rewrite rules properly include the graphql route
*/
public function testGraphQLRewriteRule() {
global $wp_rewrite;
$route = apply_filters( 'woographql_authorizing_url_endpoint', \WPGraphQL\WooCommerce\Utils\Protected_Router::$route );
$this->assertArrayHasKey( $route . '/?$', $wp_rewrite->extra_rules_top );
}
public function testAddQueryVar() {
$query_vars = [];
$router = \WPGraphQL\WooCommerce\Utils\Protected_Router::instance();
$actual = $router->add_query_var( $query_vars );
$this->assertEquals( $actual, [ apply_filters( 'woographql_authorizing_url_endpoint', \WPGraphQL\WooCommerce\Utils\Protected_Router::$route ) ] );
}
public function testGetNonceNames() {
$router = \WPGraphQL\WooCommerce\Utils\Protected_Router::instance();
$this->assertEquals(
[
'cart_url' => '_wc_cart',
'checkout_url' => '_wc_checkout',
'add_payment_method_url' => '_wc_payment',
],
$router->get_nonce_names()
);
}
public function testGetNoncePrefix() {
$router = \WPGraphQL\WooCommerce\Utils\Protected_Router::instance();
$this->assertEquals( 'load-cart_', $router->get_nonce_prefix( 'cart_url' ) );
$this->assertEquals( 'load-checkout_', $router->get_nonce_prefix( 'checkout_url' ) );
$this->assertEquals( 'load-account_', $router->get_nonce_prefix( 'add_payment_method_url' ) );
$this->assertEquals( null, $router->get_nonce_prefix( 'invalid' ) );
}
public function testGetTargetEndpoint() {
$router = \WPGraphQL\WooCommerce\Utils\Protected_Router::instance();
$this->assertEquals( wc_get_endpoint_url( 'cart' ), $router->get_target_endpoint( 'cart_url' ) );
$this->assertEquals( wc_get_endpoint_url( 'checkout' ), $router->get_target_endpoint( 'checkout_url' ) );
$this->assertEquals( wc_get_account_endpoint_url( 'add-payment-method' ), $router->get_target_endpoint( 'add_payment_method_url' ) );
$this->assertEquals( null, $router->get_nonce_prefix( 'invalid' ) );
}
}