2024-02-28 23:47:15 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
defined( 'ABSPATH' ) || exit;
|
|
|
|
|
2024-03-19 14:15:05 +00:00
|
|
|
use Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\RuleEvaluator;
|
2024-02-28 23:47:15 +00:00
|
|
|
|
|
|
|
register_woocommerce_admin_test_helper_rest_route(
|
|
|
|
'/remote-spec-validator/validate',
|
|
|
|
'wca_test_helper_validate_remote_spec',
|
|
|
|
array(
|
|
|
|
'methods' => 'POST',
|
2024-05-16 22:25:59 +00:00
|
|
|
'args' => array(
|
2024-02-28 23:47:15 +00:00
|
|
|
'spec' => array(
|
|
|
|
'description' => 'The remote spec to validate.',
|
|
|
|
'type' => 'string',
|
|
|
|
'required' => true,
|
|
|
|
'sanitize_callback' => 'sanitize_text_field',
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
2024-05-16 22:25:59 +00:00
|
|
|
* Test the spec.
|
|
|
|
*
|
2024-02-28 23:47:15 +00:00
|
|
|
* @param WP_REST_Request $request The full request data.
|
|
|
|
*/
|
|
|
|
function wca_test_helper_validate_remote_spec( $request ) {
|
2024-05-16 22:25:59 +00:00
|
|
|
$spec = json_decode( $request->get_param( 'spec' ) );
|
2024-02-28 23:47:15 +00:00
|
|
|
$rule_evaluator = new RuleEvaluator();
|
2024-05-16 22:25:59 +00:00
|
|
|
$result = array(
|
2024-02-28 23:47:15 +00:00
|
|
|
'valid' => $rule_evaluator->evaluate( $spec ),
|
2024-05-16 22:25:59 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
return new WP_REST_Response( $result, 200 );
|
2024-02-28 23:47:15 +00:00
|
|
|
}
|