Misc cleanup of descriptions and some error strings.
This commit is contained in:
parent
35f0d77e7d
commit
57fd38c1a8
|
@ -29,6 +29,7 @@ class WC_Rest_Settings_Controller extends WC_REST_Controller {
|
|||
|
||||
/**
|
||||
* Register routes.
|
||||
*
|
||||
* @since 2.7.0
|
||||
*/
|
||||
public function register_routes() {
|
||||
|
@ -101,6 +102,7 @@ class WC_Rest_Settings_Controller extends WC_REST_Controller {
|
|||
/**
|
||||
* Prepare a report sales object for serialization.
|
||||
*
|
||||
* @since 2.7.0
|
||||
* @param array $item Group object.
|
||||
* @param WP_REST_Request $request Request object.
|
||||
* @return WP_REST_Response $response Response data.
|
||||
|
@ -194,14 +196,14 @@ class WC_Rest_Settings_Controller extends WC_REST_Controller {
|
|||
),
|
||||
),
|
||||
'label' => array(
|
||||
'description' => __( 'A human readable label. This is a translated string that can be used in interfaces.', 'woocommerce' ),
|
||||
'description' => __( 'A human readable translation wrapped label. Meant to be used in interfaces.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'arg_options' => array(
|
||||
'sanitize_callback' => 'sanitize_text_field',
|
||||
),
|
||||
),
|
||||
'description' => array(
|
||||
'description' => __( 'A human readable description. This is a translated string that can be used in interfaces.', 'woocommerce' ),
|
||||
'description' => __( 'A human readable translation wrapped description. Meant to be used in interfaces', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'arg_options' => array(
|
||||
'sanitize_callback' => 'sanitize_text_field',
|
||||
|
|
|
@ -29,6 +29,7 @@ class WC_Rest_Settings_Options_Controller extends WC_REST_Controller {
|
|||
|
||||
/**
|
||||
* Register routes.
|
||||
*
|
||||
* @since 2.7.0
|
||||
*/
|
||||
public function register_routes() {
|
||||
|
@ -69,6 +70,7 @@ class WC_Rest_Settings_Options_Controller extends WC_REST_Controller {
|
|||
|
||||
/**
|
||||
* Return a single setting.
|
||||
*
|
||||
* @since 2.7.0
|
||||
* @param WP_REST_Request $request
|
||||
* @return WP_Error|WP_REST_Response
|
||||
|
@ -87,6 +89,7 @@ class WC_Rest_Settings_Options_Controller extends WC_REST_Controller {
|
|||
|
||||
/**
|
||||
* Return all settings in a group.
|
||||
*
|
||||
* @since 2.7.0
|
||||
* @param WP_REST_Request $request
|
||||
* @return WP_Error|WP_REST_Response
|
||||
|
@ -112,19 +115,19 @@ class WC_Rest_Settings_Options_Controller extends WC_REST_Controller {
|
|||
/**
|
||||
* Get all settings in a group.
|
||||
*
|
||||
* @since 2.7.0
|
||||
* @param string $group_id Group ID.
|
||||
*
|
||||
* @return array|WP_Error
|
||||
*/
|
||||
public function get_group_settings( $group_id ) {
|
||||
if ( empty( $group_id ) ) {
|
||||
return new WP_Error( 'rest_setting_setting_invalid', __( 'Invalid setting.', 'woocommerce' ), array( 'status' => 404 ) );
|
||||
return new WP_Error( 'rest_setting_setting_group_invalid', __( 'Invalid setting group.', 'woocommerce' ), array( 'status' => 404 ) );
|
||||
}
|
||||
|
||||
$settings = apply_filters( 'woocommerce_settings-' . $group_id, array() );
|
||||
|
||||
if ( empty( $settings ) ) {
|
||||
return new WP_Error( 'rest_setting_setting_invalid', __( 'Invalid setting.', 'woocommerce' ), array( 'status' => 404 ) );
|
||||
return new WP_Error( 'rest_setting_setting_group_invalid', __( 'Invalid setting group.', 'woocommerce' ), array( 'status' => 404 ) );
|
||||
}
|
||||
|
||||
$filtered_settings = array();
|
||||
|
@ -143,9 +146,9 @@ class WC_Rest_Settings_Options_Controller extends WC_REST_Controller {
|
|||
/**
|
||||
* Get setting data.
|
||||
*
|
||||
* @since 2.7.0
|
||||
* @param string $group_id Group ID.
|
||||
* @param string $setting_id Setting ID.
|
||||
*
|
||||
* @return stdClass|WP_Error
|
||||
*/
|
||||
public function get_setting( $group_id, $setting_id ) {
|
||||
|
@ -177,6 +180,7 @@ class WC_Rest_Settings_Options_Controller extends WC_REST_Controller {
|
|||
/**
|
||||
* Bulk create, update and delete items.
|
||||
*
|
||||
* @since 2.7.0
|
||||
* @param WP_REST_Request $request Full details about the request.
|
||||
* @return array Of WP_Error or WP_REST_Response.
|
||||
*/
|
||||
|
@ -202,6 +206,7 @@ class WC_Rest_Settings_Options_Controller extends WC_REST_Controller {
|
|||
|
||||
/**
|
||||
* Update a single setting in a group.
|
||||
|
||||
* @since 2.7.0
|
||||
* @param WP_REST_Request $request
|
||||
* @return WP_Error|WP_REST_Response
|
||||
|
@ -226,6 +231,7 @@ class WC_Rest_Settings_Options_Controller extends WC_REST_Controller {
|
|||
/**
|
||||
* Prepare a single setting object for response.
|
||||
*
|
||||
* @since 2.7.0
|
||||
* @param object $item Setting object.
|
||||
* @param WP_REST_Request $request Request object.
|
||||
* @return WP_REST_Response $response Response data.
|
||||
|
@ -248,6 +254,7 @@ class WC_Rest_Settings_Options_Controller extends WC_REST_Controller {
|
|||
/**
|
||||
* Prepare links for the request.
|
||||
*
|
||||
* @since 2.7.0
|
||||
* @param string $setting_id Setting ID.
|
||||
* @param string $group_id Group ID.
|
||||
* @return array Links for the given setting.
|
||||
|
@ -366,14 +373,14 @@ class WC_Rest_Settings_Options_Controller extends WC_REST_Controller {
|
|||
),
|
||||
),
|
||||
'label' => array(
|
||||
'description' => __( 'A human readable label. This is a translated string that can be used in interfaces.', 'woocommerce' ),
|
||||
'description' => __( 'A human readable translation wrapped label. Meant to be used in interfaces.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'arg_options' => array(
|
||||
'sanitize_callback' => 'sanitize_text_field',
|
||||
),
|
||||
),
|
||||
'description' => array(
|
||||
'description' => __( 'A human readable description. This is a translated string that can be used in interfaces.', 'woocommerce' ),
|
||||
'description' => __( 'A human readable translation wrapped description. Meant to be used in interfaces.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'arg_options' => array(
|
||||
'sanitize_callback' => 'sanitize_text_field',
|
||||
|
|
|
@ -9,7 +9,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
*
|
||||
* @version 2.7.0
|
||||
* @since 2.7.0
|
||||
* @package WooCommerce/Classes
|
||||
* @package WooCommerce/Classes
|
||||
* @category Class
|
||||
*/
|
||||
class WC_Register_Legacy_Settings {
|
||||
|
@ -19,6 +19,7 @@ class WC_Register_Legacy_Settings {
|
|||
|
||||
/**
|
||||
* Hooks into the settings API and starts registering our settings registered via legacy hooks/filters.
|
||||
*
|
||||
* @since 2.7.0
|
||||
*/
|
||||
public function __construct( $page ) {
|
||||
|
@ -29,6 +30,7 @@ class WC_Register_Legacy_Settings {
|
|||
|
||||
/**
|
||||
* Registers a setting group.
|
||||
*
|
||||
* @since 2.7.0
|
||||
* @param array $group
|
||||
* @return array
|
||||
|
@ -43,6 +45,7 @@ class WC_Register_Legacy_Settings {
|
|||
|
||||
/**
|
||||
* Registers the actual settings to the group they came from.
|
||||
*
|
||||
* @since 2.7.0
|
||||
* @param array $settings Existing registered settings
|
||||
* @return array
|
||||
|
@ -67,10 +70,10 @@ class WC_Register_Legacy_Settings {
|
|||
|
||||
/**
|
||||
* Convert a "legacy" setting (WC_Settings_Page::get_settings()) into the format expected
|
||||
* for the REST API Settings Controller
|
||||
* for the REST API Settings Controller.
|
||||
*
|
||||
* @since 2.7.0
|
||||
* @param $legacy_setting Settings array, as produced by a subclass of WC_Settings_Page.
|
||||
*
|
||||
* @return array|bool Boolean false if legacy setting has no ID, Array of converted new setting otherwise.
|
||||
*/
|
||||
public function new_setting_from_legacy( $legacy_setting ) {
|
||||
|
|
|
@ -9,6 +9,7 @@ class WC_Helper_Settings {
|
|||
|
||||
/**
|
||||
* Hooks in some dummy data for testing the settings REST API.
|
||||
*
|
||||
* @since 2.7.0
|
||||
*/
|
||||
public static function register() {
|
||||
|
@ -18,6 +19,7 @@ class WC_Helper_Settings {
|
|||
|
||||
/**
|
||||
* Registers some example setting groups, including invalid ones that should not show up in JSON responses.
|
||||
*
|
||||
* @since 2.7.0
|
||||
* @param array $groups
|
||||
* @return array
|
||||
|
@ -47,6 +49,7 @@ class WC_Helper_Settings {
|
|||
|
||||
/**
|
||||
* Registers some example settings.
|
||||
*
|
||||
* @since 2.7.0
|
||||
* @param array $settings
|
||||
* @return array
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Settings API Tests
|
||||
* Settings API Tests.
|
||||
*
|
||||
* @package WooCommerce\Tests\API
|
||||
* @since 2.7.0
|
||||
*/
|
||||
|
@ -35,6 +36,7 @@ class Settings extends WC_Unit_Test_Case {
|
|||
|
||||
/**
|
||||
* Test route registration.
|
||||
*
|
||||
* @since 2.7.0
|
||||
*/
|
||||
public function test_register_routes() {
|
||||
|
@ -46,6 +48,7 @@ class Settings extends WC_Unit_Test_Case {
|
|||
|
||||
/**
|
||||
* Test getting all groups.
|
||||
*
|
||||
* @since 2.7.0
|
||||
*/
|
||||
public function test_get_groups() {
|
||||
|
@ -91,6 +94,7 @@ class Settings extends WC_Unit_Test_Case {
|
|||
|
||||
/**
|
||||
* Test /settings without valid permissions/creds.
|
||||
*
|
||||
* @since 2.7.0
|
||||
*/
|
||||
public function test_get_groups_without_permission() {
|
||||
|
@ -102,6 +106,7 @@ class Settings extends WC_Unit_Test_Case {
|
|||
|
||||
/**
|
||||
* Test /settings without valid permissions/creds.
|
||||
*
|
||||
* @since 2.7.0
|
||||
* @covers WC_Rest_Settings_Controller::get_items
|
||||
*/
|
||||
|
@ -118,6 +123,7 @@ class Settings extends WC_Unit_Test_Case {
|
|||
|
||||
/**
|
||||
* Test groups schema.
|
||||
*
|
||||
* @since 2.7.0
|
||||
*/
|
||||
public function test_get_group_schema() {
|
||||
|
@ -135,6 +141,7 @@ class Settings extends WC_Unit_Test_Case {
|
|||
|
||||
/**
|
||||
* Test settings schema.
|
||||
*
|
||||
* @since 2.7.0
|
||||
*/
|
||||
public function test_get_setting_schema() {
|
||||
|
@ -155,6 +162,7 @@ class Settings extends WC_Unit_Test_Case {
|
|||
|
||||
/**
|
||||
* Test getting a single group.
|
||||
*
|
||||
* @since 2.7.0
|
||||
*/
|
||||
public function test_get_group() {
|
||||
|
@ -210,6 +218,7 @@ class Settings extends WC_Unit_Test_Case {
|
|||
|
||||
/**
|
||||
* Test getting a single group without permission.
|
||||
*
|
||||
* @since 2.7.0
|
||||
*/
|
||||
public function test_get_group_without_permission() {
|
||||
|
@ -221,6 +230,7 @@ class Settings extends WC_Unit_Test_Case {
|
|||
|
||||
/**
|
||||
* Test updating a single setting.
|
||||
*
|
||||
* @since 2.7.0
|
||||
*/
|
||||
public function test_update_setting() {
|
||||
|
@ -290,6 +300,7 @@ class Settings extends WC_Unit_Test_Case {
|
|||
|
||||
/**
|
||||
* Test updating multiple settings at once.
|
||||
*
|
||||
* @since 2.7.0
|
||||
*/
|
||||
public function test_update_settings() {
|
||||
|
@ -345,6 +356,7 @@ class Settings extends WC_Unit_Test_Case {
|
|||
|
||||
/**
|
||||
* Test getting a single setting.
|
||||
*
|
||||
* @since 2.7.0
|
||||
*/
|
||||
public function test_get_setting() {
|
||||
|
@ -376,6 +388,7 @@ class Settings extends WC_Unit_Test_Case {
|
|||
|
||||
/**
|
||||
* Test getting a single setting without valid user permissions.
|
||||
*
|
||||
* @since 2.7.0
|
||||
*/
|
||||
public function test_get_setting_without_permission() {
|
||||
|
@ -387,6 +400,8 @@ class Settings extends WC_Unit_Test_Case {
|
|||
|
||||
/**
|
||||
* Tests the GET single setting route handler receiving an empty setting ID.
|
||||
*
|
||||
* @since 2.7.0
|
||||
*/
|
||||
public function test_get_setting_empty_setting_id() {
|
||||
$result = $this->endpoint->get_setting( 'test', '' );
|
||||
|
@ -396,6 +411,8 @@ class Settings extends WC_Unit_Test_Case {
|
|||
|
||||
/**
|
||||
* Tests the GET single setting route handler receiving an invalid setting ID.
|
||||
*
|
||||
* @since 2.7.0
|
||||
*/
|
||||
public function test_get_setting_invalid_setting_id() {
|
||||
$result = $this->endpoint->get_setting( 'test', 'invalid' );
|
||||
|
@ -405,6 +422,8 @@ class Settings extends WC_Unit_Test_Case {
|
|||
|
||||
/**
|
||||
* Tests the GET single setting route handler encountering an invalid setting type.
|
||||
*
|
||||
* @since 2.7.0
|
||||
*/
|
||||
public function test_get_setting_invalid_setting_type() {
|
||||
$controller = $this->getMock( 'WC_Rest_Settings_Options_Controller', array( 'get_group_settings', 'is_setting_type_valid' ) );
|
||||
|
@ -426,6 +445,7 @@ class Settings extends WC_Unit_Test_Case {
|
|||
|
||||
/**
|
||||
* Test updating a single setting without valid user permissions.
|
||||
*
|
||||
* @since 2.7.0
|
||||
*/
|
||||
public function test_update_setting_without_permission() {
|
||||
|
@ -442,6 +462,7 @@ class Settings extends WC_Unit_Test_Case {
|
|||
|
||||
/**
|
||||
* Test updating multiple settings without valid user permissions.
|
||||
*
|
||||
* @since 2.7.0
|
||||
*/
|
||||
public function test_update_settings_without_permission() {
|
||||
|
@ -462,6 +483,7 @@ class Settings extends WC_Unit_Test_Case {
|
|||
|
||||
/**
|
||||
* Test updating a bad setting ID.
|
||||
*
|
||||
* @since 2.7.0
|
||||
* @covers WC_Rest_Settings_Options_Controller::update_item
|
||||
*/
|
||||
|
@ -478,6 +500,7 @@ class Settings extends WC_Unit_Test_Case {
|
|||
|
||||
/**
|
||||
* Tests our classic setting registration to make sure settings added for WP-Admin are available over the API.
|
||||
*
|
||||
* @since 2.7.0
|
||||
*/
|
||||
public function test_classic_settings() {
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
/**
|
||||
* Settings API Tests
|
||||
*
|
||||
* @package WooCommerce\Tests\Settings
|
||||
* @since 2.7.0
|
||||
*/
|
||||
|
@ -34,16 +35,18 @@ class WC_Tests_Register_Legacy_Settings extends WC_Unit_Test_Case {
|
|||
}
|
||||
|
||||
/**
|
||||
* @since 2.7.0
|
||||
* @covers WC_Register_Legacy_Settings::__construct
|
||||
*/
|
||||
public function test_constructor() {
|
||||
$legacy_settings = new WC_Register_Legacy_Settings( $this->page );
|
||||
|
||||
|
||||
$this->assertEquals( has_filter( 'woocommerce_settings_groups', array( $legacy_settings, 'register_legacy_group' ) ), 10 );
|
||||
$this->assertEquals( has_filter( 'woocommerce_settings-' . $this->page->get_id(), array( $legacy_settings, 'register_legacy_settings' ) ), 10 );
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.7.0
|
||||
* @covers WC_Register_Legacy_Settings::register_legacy_group
|
||||
*/
|
||||
public function test_register_legacy_group() {
|
||||
|
@ -66,6 +69,9 @@ class WC_Tests_Register_Legacy_Settings extends WC_Unit_Test_Case {
|
|||
$this->assertEquals( $expected, $actual );
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.7.0
|
||||
*/
|
||||
public function new_setting_from_legacy_provider() {
|
||||
return array(
|
||||
// No "id" case
|
||||
|
@ -145,6 +151,7 @@ class WC_Tests_Register_Legacy_Settings extends WC_Unit_Test_Case {
|
|||
}
|
||||
|
||||
/**
|
||||
* @since 2.7.0
|
||||
* @dataProvider new_setting_from_legacy_provider
|
||||
* @covers WC_Register_Legacy_Settings::new_setting_from_legacy
|
||||
*/
|
||||
|
@ -157,6 +164,7 @@ class WC_Tests_Register_Legacy_Settings extends WC_Unit_Test_Case {
|
|||
}
|
||||
|
||||
/**
|
||||
* @since 2.7.0
|
||||
* @covers WC_Register_Legacy_Settings::register_legacy_settings
|
||||
*/
|
||||
public function test_register_legacy_settings_one_section() {
|
||||
|
@ -180,6 +188,7 @@ class WC_Tests_Register_Legacy_Settings extends WC_Unit_Test_Case {
|
|||
}
|
||||
|
||||
/**
|
||||
* @since 2.7.0
|
||||
* @covers WC_Register_Legacy_Settings::register_legacy_settings
|
||||
*/
|
||||
public function test_register_legacy_settings() {
|
||||
|
@ -227,4 +236,4 @@ class WC_Tests_Register_Legacy_Settings extends WC_Unit_Test_Case {
|
|||
|
||||
$this->assertEquals( $expected, $actual );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue