Fix PHP CodeSniffer issues (https://github.com/woocommerce/woocommerce-blocks/pull/215)
This commit is contained in:
parent
1ea12ca2ff
commit
c6d071cebf
|
@ -5,6 +5,7 @@
|
|||
<!-- Exclude paths -->
|
||||
<exclude-pattern>*/node_modules/*</exclude-pattern>
|
||||
<exclude-pattern>*/vendor/*</exclude-pattern>
|
||||
<exclude-pattern>languages/woo-gutenberg-products-block.php</exclude-pattern>
|
||||
|
||||
<!-- Configs -->
|
||||
<config name="minimum_supported_wp_version" value="4.7" />
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
<?php
|
||||
/**
|
||||
* @package WooCommerce\Tests\API
|
||||
*/
|
||||
|
||||
/**
|
||||
* Product Controller "extras" REST API Test
|
||||
*
|
||||
* @package WooCommerce\Tests\API
|
||||
* @since 1.2.0
|
||||
*/
|
||||
class WC_Tests_API_Products_Controller extends WC_REST_Unit_Test_Case {
|
||||
|
@ -22,7 +25,7 @@ class WC_Tests_API_Products_Controller extends WC_REST_Unit_Test_Case {
|
|||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->user = $this->factory->user->create(
|
||||
$this->user = $this->factory->user->create(
|
||||
array(
|
||||
'role' => 'author',
|
||||
)
|
||||
|
@ -32,7 +35,7 @@ class WC_Tests_API_Products_Controller extends WC_REST_Unit_Test_Case {
|
|||
'role' => 'contributor',
|
||||
)
|
||||
);
|
||||
$this->subscriber = $this->factory->user->create(
|
||||
$this->subscriber = $this->factory->user->create(
|
||||
array(
|
||||
'role' => 'subscriber',
|
||||
)
|
||||
|
@ -60,7 +63,7 @@ class WC_Tests_API_Products_Controller extends WC_REST_Unit_Test_Case {
|
|||
wp_set_current_user( $this->user );
|
||||
WC_Helper_Product::create_external_product();
|
||||
sleep( 1 ); // So both products have different timestamps.
|
||||
$product = WC_Helper_Product::create_simple_product();
|
||||
$product = WC_Helper_Product::create_simple_product();
|
||||
$response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc-pb/v3/products' ) );
|
||||
$products = $response->get_data();
|
||||
|
||||
|
@ -108,10 +111,12 @@ class WC_Tests_API_Products_Controller extends WC_REST_Unit_Test_Case {
|
|||
sleep( 1 ); // So both products have different timestamps.
|
||||
$product = WC_Helper_Product::create_simple_product( false ); // Prevent saving, since we save here.
|
||||
// Customize the price, otherwise both are 10.
|
||||
$product->set_props( array(
|
||||
'regular_price' => 15,
|
||||
'price' => 15,
|
||||
) );
|
||||
$product->set_props(
|
||||
array(
|
||||
'regular_price' => 15,
|
||||
'price' => 15,
|
||||
)
|
||||
);
|
||||
$product->save();
|
||||
|
||||
$request = new WP_REST_Request( 'GET', '/wc-pb/v3/products' );
|
||||
|
@ -123,7 +128,7 @@ class WC_Tests_API_Products_Controller extends WC_REST_Unit_Test_Case {
|
|||
$this->assertEquals( 200, $response->get_status() );
|
||||
$this->assertEquals( 2, count( $products ) );
|
||||
|
||||
// The external product should be first, then the simple product
|
||||
// The external product should be first, then the simple product.
|
||||
$this->assertEquals( 'Dummy External Product', $products[0]['name'] );
|
||||
$this->assertEquals( 'Dummy Product', $products[1]['name'] );
|
||||
$this->assertEquals( '10', $products[0]['price'] );
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPUnit bootstrap file
|
||||
*
|
||||
* @package WooCommerce\Blocks
|
||||
*/
|
||||
|
||||
$_tests_dir = getenv( 'WP_TESTS_DIR' );
|
||||
|
@ -30,7 +32,9 @@ function wc_dir() {
|
|||
* Install wc admin.
|
||||
*/
|
||||
function wgpb_admin_install() {
|
||||
// Clean existing install first.L_DATA', true );
|
||||
// Clean existing install first.
|
||||
define( 'WP_UNINSTALL_PLUGIN', true );
|
||||
define( 'WC_REMOVE_ALL_DATA', true );
|
||||
|
||||
// Initialize the WC API extensions.
|
||||
require_once dirname( dirname( __FILE__ ) ) . '/woocommerce-gutenberg-products-block.php';
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
* Text Domain: woo-gutenberg-products-block
|
||||
* WC requires at least: 3.3
|
||||
* WC tested up to: 3.5
|
||||
*
|
||||
* @package WooCommerce\Blocks
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || die();
|
||||
|
@ -41,7 +43,7 @@ add_action( 'woocommerce_loaded', 'wgpb_initialize' );
|
|||
*/
|
||||
function wgpb_plugins_notice() {
|
||||
echo '<div class="error"><p>';
|
||||
echo __( 'WooCommerce Product Blocks development mode requires files to be built. From the plugin directory, run <code>npm install</code> to install dependencies, <code>npm run build</code> to build the files or <code>npm start</code> to build the files and watch for changes.', 'woo-gutenberg-products-block' );
|
||||
esc_html_e( 'WooCommerce Product Blocks development mode requires files to be built. From the plugin directory, run <code>npm install</code> to install dependencies, <code>npm run build</code> to build the files or <code>npm start</code> to build the files and watch for changes.', 'woo-gutenberg-products-block' );
|
||||
echo '</p></div>';
|
||||
}
|
||||
|
||||
|
@ -49,10 +51,13 @@ function wgpb_plugins_notice() {
|
|||
* Register the Products block and its scripts.
|
||||
*/
|
||||
function wgpb_register_products_block() {
|
||||
register_block_type( 'woocommerce/products', array(
|
||||
'editor_script' => 'woocommerce-products-block-editor',
|
||||
'editor_style' => 'woocommerce-products-block-editor',
|
||||
) );
|
||||
register_block_type(
|
||||
'woocommerce/products',
|
||||
array(
|
||||
'editor_script' => 'woocommerce-products-block-editor',
|
||||
'editor_style' => 'woocommerce-products-block-editor',
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -100,12 +105,12 @@ function wgpb_extra_gutenberg_scripts() {
|
|||
);
|
||||
|
||||
$product_block_data = array(
|
||||
'min_columns' => wc_get_theme_support( 'product_grid::min_columns', 1 ),
|
||||
'max_columns' => wc_get_theme_support( 'product_grid::max_columns', 6 ),
|
||||
'min_columns' => wc_get_theme_support( 'product_grid::min_columns', 1 ),
|
||||
'max_columns' => wc_get_theme_support( 'product_grid::max_columns', 6 ),
|
||||
'default_columns' => wc_get_default_products_per_row(),
|
||||
'min_rows' => wc_get_theme_support( 'product_grid::min_rows', 1 ),
|
||||
'max_rows' => wc_get_theme_support( 'product_grid::max_rows', 6 ),
|
||||
'default_rows' => wc_get_default_product_rows_per_page(),
|
||||
'min_rows' => wc_get_theme_support( 'product_grid::min_rows', 1 ),
|
||||
'max_rows' => wc_get_theme_support( 'product_grid::max_rows', 6 ),
|
||||
'default_rows' => wc_get_default_product_rows_per_page(),
|
||||
);
|
||||
wp_localize_script( 'woocommerce-products-block-editor', 'wc_product_block_data', $product_block_data );
|
||||
|
||||
|
@ -139,21 +144,21 @@ function wgpb_print_script_settings() {
|
|||
|
||||
// Settings and variables can be passed here for access in the app.
|
||||
$settings = array(
|
||||
'adminUrl' => admin_url(),
|
||||
'wcAssetUrl' => plugins_url( 'assets/', WC_PLUGIN_FILE ),
|
||||
'siteLocale' => esc_attr( get_bloginfo( 'language' ) ),
|
||||
'currency' => array(
|
||||
'adminUrl' => admin_url(),
|
||||
'wcAssetUrl' => plugins_url( 'assets/', WC_PLUGIN_FILE ),
|
||||
'siteLocale' => esc_attr( get_bloginfo( 'language' ) ),
|
||||
'currency' => array(
|
||||
'code' => $code,
|
||||
'precision' => wc_get_price_decimals(),
|
||||
'symbol' => get_woocommerce_currency_symbol( $code ),
|
||||
),
|
||||
'date' => array(
|
||||
'date' => array(
|
||||
'dow' => get_option( 'start_of_week', 0 ),
|
||||
),
|
||||
);
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
var wcSettings = <?php echo json_encode( $settings ); ?>;
|
||||
var wcSettings = <?php echo wp_json_encode( $settings ); ?>;
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
@ -186,8 +191,8 @@ function wgpb_register_api_routes() {
|
|||
*
|
||||
* @todo Remove this function when merging into core because it won't be necessary.
|
||||
*
|
||||
* @param array $args WP_Query args.
|
||||
* @param array $attributes Shortcode attributes.
|
||||
* @param array $args WP_Query args.
|
||||
* @param array $attributes Shortcode attributes.
|
||||
* @param string $type Type of shortcode currently processing.
|
||||
*/
|
||||
function wgpb_extra_shortcode_features( $args, $attributes, $type ) {
|
||||
|
@ -201,7 +206,7 @@ function wgpb_extra_shortcode_features( $args, $attributes, $type ) {
|
|||
$field = 'slug';
|
||||
|
||||
if ( empty( $args['tax_query'] ) ) {
|
||||
$args['tax_query'] = array();
|
||||
$args['tax_query'] = array(); // WPCS: slow query ok.
|
||||
}
|
||||
|
||||
// Unset old category tax query.
|
||||
|
@ -230,7 +235,7 @@ function wgpb_extra_shortcode_features( $args, $attributes, $type ) {
|
|||
$field = 'slug';
|
||||
|
||||
if ( empty( $args['tax_query'] ) ) {
|
||||
$args['tax_query'] = array();
|
||||
$args['tax_query'] = array(); // WPCS: slow query ok.
|
||||
}
|
||||
|
||||
// Unset old attribute tax query.
|
||||
|
|
Loading…
Reference in New Issue