2016-06-14 01:58:45 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* REST API Functions.
|
|
|
|
* @package WooCommerce\Tests\API
|
|
|
|
* @since 2.6.0
|
|
|
|
*/
|
|
|
|
class WC_Tests_API_Functions extends WC_Unit_Test_Case {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test wc_rest_prepare_date_response().
|
|
|
|
*
|
|
|
|
* @since 2.6.0
|
|
|
|
*/
|
|
|
|
public function test_wc_rest_prepare_date_response() {
|
|
|
|
$this->assertEquals( '2016-06-06T06:06:06', wc_rest_prepare_date_response( '2016-06-06 06:06:06' ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test wc_rest_upload_image_from_url().
|
|
|
|
*
|
|
|
|
* @since 2.6.0
|
|
|
|
*/
|
|
|
|
public function test_wc_rest_upload_image_from_url() {
|
|
|
|
// Only test the error, no need to upload images.
|
|
|
|
$this->assertIsWPError( wc_rest_upload_image_from_url( 'thing' ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test wc_rest_set_uploaded_image_as_attachment().
|
|
|
|
*
|
|
|
|
* @since 2.6.0
|
|
|
|
*/
|
|
|
|
public function test_wc_rest_set_uploaded_image_as_attachment() {
|
|
|
|
$this->assertInternalType( 'int', wc_rest_set_uploaded_image_as_attachment( array( 'file' => '', 'url' => '' ) ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test wc_rest_validate_reports_request_arg().
|
|
|
|
*
|
|
|
|
* @since 2.6.0
|
|
|
|
*/
|
|
|
|
public function test_wc_rest_validate_reports_request_arg() {
|
2017-02-09 20:21:52 +00:00
|
|
|
$request = new WP_REST_Request( 'GET', '/wc/v2/foo', array(
|
2016-06-14 01:58:45 +00:00
|
|
|
'args' => array(
|
|
|
|
'date' => array(
|
|
|
|
'type' => 'string',
|
|
|
|
'format' => 'date',
|
|
|
|
),
|
|
|
|
),
|
|
|
|
) );
|
|
|
|
|
|
|
|
// Success.
|
|
|
|
$this->assertTrue( wc_rest_validate_reports_request_arg( '2016-06-06', $request, 'date' ) );
|
|
|
|
|
|
|
|
// Error.
|
|
|
|
$error = wc_rest_validate_reports_request_arg( 'foo', $request, 'date' );
|
|
|
|
$this->assertEquals( 'The date you provided is invalid.', $error->get_error_message() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test wc_rest_urlencode_rfc3986().
|
|
|
|
*
|
|
|
|
* @since 2.6.0
|
|
|
|
*/
|
|
|
|
public function test_wc_rest_urlencode_rfc3986() {
|
2017-06-06 20:43:40 +00:00
|
|
|
$this->assertEquals( 'https%3A%2F%2Fwoocommerce.com%2F', wc_rest_urlencode_rfc3986( 'https://woocommerce.com/' ) );
|
2016-06-14 01:58:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test wc_rest_check_post_permissions().
|
|
|
|
*
|
|
|
|
* @since 2.6.0
|
|
|
|
*/
|
|
|
|
public function test_wc_rest_check_post_permissions() {
|
2017-07-13 04:06:38 +00:00
|
|
|
$this->assertFalse( wc_rest_check_post_permissions( 'shop_order' ) );
|
2016-06-14 01:58:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test wc_rest_check_user_permissions().
|
|
|
|
*
|
|
|
|
* @since 2.6.0
|
|
|
|
*/
|
|
|
|
public function test_wc_rest_check_user_permissions() {
|
2017-07-13 04:06:38 +00:00
|
|
|
$this->assertFalse( wc_rest_check_user_permissions() );
|
2016-06-14 01:58:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test wc_rest_check_product_term_permissions().
|
|
|
|
*
|
|
|
|
* @since 2.6.0
|
|
|
|
*/
|
|
|
|
public function test_wc_rest_check_product_term_permissions() {
|
2017-07-13 04:06:38 +00:00
|
|
|
$this->assertFalse( wc_rest_check_product_term_permissions( 'product_cat' ) );
|
2016-06-14 01:58:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test wc_rest_check_manager_permissions().
|
|
|
|
*
|
|
|
|
* @since 2.6.0
|
|
|
|
*/
|
|
|
|
public function test_wc_rest_check_manager_permissions() {
|
2017-07-13 04:06:38 +00:00
|
|
|
$this->assertFalse( wc_rest_check_manager_permissions( 'reports' ) );
|
2016-06-14 01:58:45 +00:00
|
|
|
}
|
|
|
|
}
|