woocommerce/tests/framework/helpers/class-wc-helper-settings.php

78 lines
1.9 KiB
PHP
Raw Normal View History

2016-03-07 21:46:40 +00:00
<?php
/**
* Class WC_Helper_Settings.
*
* This helper class should ONLY be used for unit tests!
*/
class WC_Helper_Settings {
/**
* Hooks in some dummy data for testing the settings REST API.
*
2016-03-07 21:46:40 +00:00
* @since 2.7.0
*/
public static function register() {
add_filter( 'woocommerce_settings_groups', array( 'WC_Helper_Settings', 'register_groups' ) );
2016-03-28 19:04:26 +00:00
add_filter( 'woocommerce_settings-test', array( 'WC_Helper_Settings', 'register_test_settings' ) );
2016-03-07 21:46:40 +00:00
}
/**
* Registers some example setting groups, including invalid ones that should not show up in JSON responses.
*
2016-03-07 21:46:40 +00:00
* @since 2.7.0
* @param array $groups
2016-03-07 21:46:40 +00:00
* @return array
*/
public static function register_groups( $groups ) {
$groups[] = array(
2016-03-07 21:46:40 +00:00
'id' => 'test',
'bad' => 'value',
'label' => 'Test extension',
'description' => 'My awesome test settings.',
'option_key' => '',
2016-03-07 21:46:40 +00:00
);
$groups[] = array(
'id' => 'sub-test',
'parent_id' => 'test',
'label' => 'Sub test',
'description' => '',
'option_key' => '',
);
$groups[] = array(
2016-03-07 21:46:40 +00:00
'id' => 'coupon-data',
'label' => 'Coupon data',
'option_key' => '',
2016-03-07 21:46:40 +00:00
);
$groups[] = array(
2016-03-07 21:46:40 +00:00
'id' => 'invalid',
'option_key' => '',
2016-03-07 21:46:40 +00:00
);
return $groups;
2016-03-07 21:46:40 +00:00
}
/**
* Registers some example settings.
*
* @since 2.7.0
* @param array $settings
* @return array
*/
public static function register_test_settings( $settings ) {
$settings[] = array(
'id' => 'woocommerce_shop_page_display',
'label' => 'Shop page display',
'description' => 'This controls what is shown on the product archive.',
'default' => '',
'type' => 'select',
'options' => array(
'' => 'Show products',
'subcategories' => 'Show categories &amp; subcategories',
'both' => 'Show both',
),
'option_key' => 'woocommerce_shop_page_display',
);
return $settings;
}
2016-03-07 21:46:40 +00:00
}