woocommerce/plugins/woocommerce-admin/tests/api/products.php

63 lines
1.3 KiB
PHP

<?php
/**
* Products REST API Test
*
* @package WooCommerce Admin\Tests\API
*/
/**
* WC Tests API Products
*/
class WC_Tests_API_Products extends WC_REST_Unit_Test_Case {
/**
* Endpoints.
*
* @var string
*/
protected $endpoint = '/wc/v4/products';
/**
* Setup test data. Called before every test.
*/
public function setUp() {
parent::setUp();
$this->user = $this->factory->user->create(
array(
'role' => 'administrator',
)
);
}
/**
* Test product schema contains embed fields.
*/
public function test_product_schema() {
wp_set_current_user( $this->user );
$product = WC_Helper_Product::create_simple_product();
$request = new WP_REST_Request( 'OPTIONS', '/wc/v4/products/' . $product->get_id() );
$response = $this->server->dispatch( $request );
$data = $response->get_data();
$properties = $data['schema']['properties'];
$properties_to_embed = array(
'id',
'name',
'slug',
'permalink',
'images',
'description',
'short_description',
);
foreach ( $properties as $property_key => $property ) {
if ( in_array( $property_key, $properties_to_embed ) ) {
$this->assertEquals( array( 'view', 'edit', 'embed' ), $property['context'] );
}
}
$product->delete( true );
}
}