From 070954c8882123e698c34b847fc8401be71ff013 Mon Sep 17 00:00:00 2001 From: Christopher Allford <6451942+ObliviousHarmony@users.noreply.github.com> Date: Fri, 21 May 2021 10:36:13 -0700 Subject: [PATCH] Revert #28187 The default functionality within the `ThemeSupport` class has an unintended side-effect of breaking the existing default functionality within the `wc_get_theme_support()` function. Since the default set in the support class is prioritized over the one given to `ThemeSupport::get_option()`, the WordPress options set in the Customizer are never used for images. --- .../customizer/class-wc-shop-customizer.php | 19 +- .../theme-support/class-wc-twenty-eleven.php | 5 +- .../theme-support/class-wc-twenty-fifteen.php | 5 +- .../class-wc-twenty-fourteen.php | 5 +- .../class-wc-twenty-nineteen.php | 4 +- .../class-wc-twenty-seventeen.php | 4 +- .../theme-support/class-wc-twenty-sixteen.php | 5 +- .../theme-support/class-wc-twenty-ten.php | 5 +- .../class-wc-twenty-thirteen.php | 5 +- .../theme-support/class-wc-twenty-twelve.php | 5 +- .../class-wc-twenty-twenty-one.php | 4 +- .../theme-support/class-wc-twenty-twenty.php | 4 +- includes/wc-core-functions.php | 34 ++- src/Container.php | 2 - .../ThemeManagementServiceProvider.php | 31 --- src/Internal/ThemeSupport.php | 118 -------- tests/legacy/bootstrap.php | 8 +- .../class-wc-shop-customizer-test.php | 59 ---- .../php/src/ThemeSupport/ThemeSupportTest.php | 254 ------------------ 19 files changed, 59 insertions(+), 517 deletions(-) delete mode 100644 src/Internal/DependencyManagement/ServiceProviders/ThemeManagementServiceProvider.php delete mode 100644 src/Internal/ThemeSupport.php delete mode 100644 tests/php/includes/customizer/class-wc-shop-customizer-test.php delete mode 100644 tests/php/src/ThemeSupport/ThemeSupportTest.php diff --git a/includes/customizer/class-wc-shop-customizer.php b/includes/customizer/class-wc-shop-customizer.php index bf86e7f9e55..2170ff6d210 100644 --- a/includes/customizer/class-wc-shop-customizer.php +++ b/includes/customizer/class-wc-shop-customizer.php @@ -6,8 +6,6 @@ * @package WooCommerce */ -use Automattic\WooCommerce\Internal\ThemeSupport; - defined( 'ABSPATH' ) || exit; /** @@ -15,19 +13,10 @@ defined( 'ABSPATH' ) || exit; */ class WC_Shop_Customizer { - /** - * Holds the instance of ThemeSupport to use. - * - * @var ThemeSupport $theme_support The instance of ThemeSupport to use. - */ - private $theme_support; - /** * Constructor. */ public function __construct() { - $this->theme_support = wc_get_container()->get( ThemeSupport::class ); - add_action( 'customize_register', array( $this, 'add_sections' ) ); add_action( 'customize_controls_print_styles', array( $this, 'add_styles' ) ); add_action( 'customize_controls_print_scripts', array( $this, 'add_scripts' ), 30 ); @@ -556,11 +545,11 @@ class WC_Shop_Customizer { ) ); - if ( ! $this->theme_support->has_option( 'single_image_width', false ) ) { + if ( ! wc_get_theme_support( 'single_image_width' ) ) { $wp_customize->add_setting( 'woocommerce_single_image_width', array( - 'default' => $this->theme_support->get_option( 'single_image_width', 600 ), + 'default' => 600, 'type' => 'option', 'capability' => 'manage_woocommerce', 'sanitize_callback' => 'absint', @@ -584,11 +573,11 @@ class WC_Shop_Customizer { ); } - if ( ! $this->theme_support->has_option( 'thumbnail_image_width', false ) ) { + if ( ! wc_get_theme_support( 'thumbnail_image_width' ) ) { $wp_customize->add_setting( 'woocommerce_thumbnail_image_width', array( - 'default' => $this->theme_support->get_option( 'thumbnail_image_width', 300 ), + 'default' => 300, 'type' => 'option', 'capability' => 'manage_woocommerce', 'sanitize_callback' => 'absint', diff --git a/includes/theme-support/class-wc-twenty-eleven.php b/includes/theme-support/class-wc-twenty-eleven.php index db598f78907..fb06a7a84dc 100644 --- a/includes/theme-support/class-wc-twenty-eleven.php +++ b/includes/theme-support/class-wc-twenty-eleven.php @@ -6,8 +6,6 @@ * @package WooCommerce\Classes */ -use Automattic\WooCommerce\Internal\ThemeSupport; - defined( 'ABSPATH' ) || exit; /** @@ -31,7 +29,8 @@ class WC_Twenty_Eleven { add_theme_support( 'wc-product-gallery-zoom' ); add_theme_support( 'wc-product-gallery-lightbox' ); add_theme_support( 'wc-product-gallery-slider' ); - wc_get_container()->get( ThemeSupport::class )->add_default_options( + add_theme_support( + 'woocommerce', array( 'thumbnail_image_width' => 150, 'single_image_width' => 300, diff --git a/includes/theme-support/class-wc-twenty-fifteen.php b/includes/theme-support/class-wc-twenty-fifteen.php index a3a194c7579..83e1930cf93 100644 --- a/includes/theme-support/class-wc-twenty-fifteen.php +++ b/includes/theme-support/class-wc-twenty-fifteen.php @@ -7,8 +7,6 @@ * @package WooCommerce\Classes */ -use Automattic\WooCommerce\Internal\ThemeSupport; - defined( 'ABSPATH' ) || exit; /** @@ -32,7 +30,8 @@ class WC_Twenty_Fifteen { add_theme_support( 'wc-product-gallery-zoom' ); add_theme_support( 'wc-product-gallery-lightbox' ); add_theme_support( 'wc-product-gallery-slider' ); - wc_get_container()->get( ThemeSupport::class )->add_default_options( + add_theme_support( + 'woocommerce', array( 'thumbnail_image_width' => 200, 'single_image_width' => 350, diff --git a/includes/theme-support/class-wc-twenty-fourteen.php b/includes/theme-support/class-wc-twenty-fourteen.php index b8f5cf09a6b..ce04395299d 100644 --- a/includes/theme-support/class-wc-twenty-fourteen.php +++ b/includes/theme-support/class-wc-twenty-fourteen.php @@ -7,8 +7,6 @@ * @package WooCommerce\Classes */ -use Automattic\WooCommerce\Internal\ThemeSupport; - defined( 'ABSPATH' ) || exit; /** @@ -32,7 +30,8 @@ class WC_Twenty_Fourteen { add_theme_support( 'wc-product-gallery-zoom' ); add_theme_support( 'wc-product-gallery-lightbox' ); add_theme_support( 'wc-product-gallery-slider' ); - wc_get_container()->get( ThemeSupport::class )->add_default_options( + add_theme_support( + 'woocommerce', array( 'thumbnail_image_width' => 150, 'single_image_width' => 300, diff --git a/includes/theme-support/class-wc-twenty-nineteen.php b/includes/theme-support/class-wc-twenty-nineteen.php index 5419ade5b0a..9d1f44cc64c 100644 --- a/includes/theme-support/class-wc-twenty-nineteen.php +++ b/includes/theme-support/class-wc-twenty-nineteen.php @@ -7,7 +7,6 @@ */ use Automattic\Jetpack\Constants; -use Automattic\WooCommerce\Internal\ThemeSupport; defined( 'ABSPATH' ) || exit; @@ -38,7 +37,8 @@ class WC_Twenty_Nineteen { add_theme_support( 'wc-product-gallery-zoom' ); add_theme_support( 'wc-product-gallery-lightbox' ); add_theme_support( 'wc-product-gallery-slider' ); - wc_get_container()->get( ThemeSupport::class )->add_default_options( + add_theme_support( + 'woocommerce', array( 'thumbnail_image_width' => 300, 'single_image_width' => 450, diff --git a/includes/theme-support/class-wc-twenty-seventeen.php b/includes/theme-support/class-wc-twenty-seventeen.php index 661121063a5..2093d2200e7 100644 --- a/includes/theme-support/class-wc-twenty-seventeen.php +++ b/includes/theme-support/class-wc-twenty-seventeen.php @@ -7,7 +7,6 @@ */ use Automattic\Jetpack\Constants; -use Automattic\WooCommerce\Internal\ThemeSupport; defined( 'ABSPATH' ) || exit; @@ -31,7 +30,8 @@ class WC_Twenty_Seventeen { add_theme_support( 'wc-product-gallery-zoom' ); add_theme_support( 'wc-product-gallery-lightbox' ); add_theme_support( 'wc-product-gallery-slider' ); - wc_get_container()->get( ThemeSupport::class )->add_default_options( + add_theme_support( + 'woocommerce', array( 'thumbnail_image_width' => 250, 'single_image_width' => 350, diff --git a/includes/theme-support/class-wc-twenty-sixteen.php b/includes/theme-support/class-wc-twenty-sixteen.php index f78fbb634f5..c9681fa5e98 100644 --- a/includes/theme-support/class-wc-twenty-sixteen.php +++ b/includes/theme-support/class-wc-twenty-sixteen.php @@ -6,8 +6,6 @@ * @package WooCommerce\Classes */ -use Automattic\WooCommerce\Internal\ThemeSupport; - defined( 'ABSPATH' ) || exit; /** @@ -31,7 +29,8 @@ class WC_Twenty_Sixteen { add_theme_support( 'wc-product-gallery-zoom' ); add_theme_support( 'wc-product-gallery-lightbox' ); add_theme_support( 'wc-product-gallery-slider' ); - wc_get_container()->get( ThemeSupport::class )->add_default_options( + add_theme_support( + 'woocommerce', array( 'thumbnail_image_width' => 250, 'single_image_width' => 400, diff --git a/includes/theme-support/class-wc-twenty-ten.php b/includes/theme-support/class-wc-twenty-ten.php index 4988aea16a4..8a9262e6191 100644 --- a/includes/theme-support/class-wc-twenty-ten.php +++ b/includes/theme-support/class-wc-twenty-ten.php @@ -6,8 +6,6 @@ * @package WooCommerce\Classes */ -use Automattic\WooCommerce\Internal\ThemeSupport; - defined( 'ABSPATH' ) || exit; /** @@ -31,7 +29,8 @@ class WC_Twenty_Ten { add_theme_support( 'wc-product-gallery-zoom' ); add_theme_support( 'wc-product-gallery-lightbox' ); add_theme_support( 'wc-product-gallery-slider' ); - wc_get_container()->get( ThemeSupport::class )->add_default_options( + add_theme_support( + 'woocommerce', array( 'thumbnail_image_width' => 200, 'single_image_width' => 300, diff --git a/includes/theme-support/class-wc-twenty-thirteen.php b/includes/theme-support/class-wc-twenty-thirteen.php index 527fa176ee0..4e80b3e27c6 100644 --- a/includes/theme-support/class-wc-twenty-thirteen.php +++ b/includes/theme-support/class-wc-twenty-thirteen.php @@ -7,8 +7,6 @@ * @package WooCommerce\Classes */ -use Automattic\WooCommerce\Internal\ThemeSupport; - defined( 'ABSPATH' ) || exit; /** @@ -32,7 +30,8 @@ class WC_Twenty_Thirteen { add_theme_support( 'wc-product-gallery-zoom' ); add_theme_support( 'wc-product-gallery-lightbox' ); add_theme_support( 'wc-product-gallery-slider' ); - wc_get_container()->get( ThemeSupport::class )->add_default_options( + add_theme_support( + 'woocommerce', array( 'thumbnail_image_width' => 200, 'single_image_width' => 300, diff --git a/includes/theme-support/class-wc-twenty-twelve.php b/includes/theme-support/class-wc-twenty-twelve.php index 3815ac4c26d..116dabea432 100644 --- a/includes/theme-support/class-wc-twenty-twelve.php +++ b/includes/theme-support/class-wc-twenty-twelve.php @@ -7,8 +7,6 @@ * @package WooCommerce\Classes */ -use Automattic\WooCommerce\Internal\ThemeSupport; - defined( 'ABSPATH' ) || exit; /** @@ -32,7 +30,8 @@ class WC_Twenty_Twelve { add_theme_support( 'wc-product-gallery-zoom' ); add_theme_support( 'wc-product-gallery-lightbox' ); add_theme_support( 'wc-product-gallery-slider' ); - wc_get_container()->get( ThemeSupport::class )->add_default_options( + add_theme_support( + 'woocommerce', array( 'thumbnail_image_width' => 200, 'single_image_width' => 300, diff --git a/includes/theme-support/class-wc-twenty-twenty-one.php b/includes/theme-support/class-wc-twenty-twenty-one.php index 7707c05ecd5..6b568ae0e2d 100644 --- a/includes/theme-support/class-wc-twenty-twenty-one.php +++ b/includes/theme-support/class-wc-twenty-twenty-one.php @@ -7,7 +7,6 @@ */ use Automattic\Jetpack\Constants; -use Automattic\WooCommerce\Internal\ThemeSupport; defined( 'ABSPATH' ) || exit; @@ -38,7 +37,8 @@ class WC_Twenty_Twenty_One { add_theme_support( 'wc-product-gallery-zoom' ); add_theme_support( 'wc-product-gallery-lightbox' ); add_theme_support( 'wc-product-gallery-slider' ); - wc_get_container()->get( ThemeSupport::class )->add_default_options( + add_theme_support( + 'woocommerce', array( 'thumbnail_image_width' => 450, 'single_image_width' => 600, diff --git a/includes/theme-support/class-wc-twenty-twenty.php b/includes/theme-support/class-wc-twenty-twenty.php index 862376f9eda..47296f639ab 100644 --- a/includes/theme-support/class-wc-twenty-twenty.php +++ b/includes/theme-support/class-wc-twenty-twenty.php @@ -7,7 +7,6 @@ */ use Automattic\Jetpack\Constants; -use Automattic\WooCommerce\Internal\ThemeSupport; defined( 'ABSPATH' ) || exit; @@ -38,7 +37,8 @@ class WC_Twenty_Twenty { add_theme_support( 'wc-product-gallery-zoom' ); add_theme_support( 'wc-product-gallery-lightbox' ); add_theme_support( 'wc-product-gallery-slider' ); - wc_get_container()->get( ThemeSupport::class )->add_default_options( + add_theme_support( + 'woocommerce', array( 'thumbnail_image_width' => 450, 'single_image_width' => 600, diff --git a/includes/wc-core-functions.php b/includes/wc-core-functions.php index 3ffb94d5d6e..d0298871e68 100644 --- a/includes/wc-core-functions.php +++ b/includes/wc-core-functions.php @@ -9,7 +9,6 @@ */ use Automattic\Jetpack\Constants; -use Automattic\WooCommerce\Internal\ThemeSupport; use Automattic\WooCommerce\Utilities\NumberUtil; if ( ! defined( 'ABSPATH' ) ) { @@ -880,7 +879,38 @@ function wc_mail( $to, $subject, $message, $headers = "Content-Type: text/html\r * @return mixed Value of prop(s). */ function wc_get_theme_support( $prop = '', $default = null ) { - return wc_get_container()->get( ThemeSupport::class )->get_option( $prop, $default ); + $theme_support = get_theme_support( 'woocommerce' ); + $theme_support = is_array( $theme_support ) ? $theme_support[0] : false; + + if ( ! $theme_support ) { + return $default; + } + + if ( $prop ) { + $prop_stack = explode( '::', $prop ); + $prop_key = array_shift( $prop_stack ); + + if ( isset( $theme_support[ $prop_key ] ) ) { + $value = $theme_support[ $prop_key ]; + + if ( count( $prop_stack ) ) { + foreach ( $prop_stack as $prop_key ) { + if ( is_array( $value ) && isset( $value[ $prop_key ] ) ) { + $value = $value[ $prop_key ]; + } else { + $value = $default; + break; + } + } + } + } else { + $value = $default; + } + + return $value; + } + + return $theme_support; } /** diff --git a/src/Container.php b/src/Container.php index cb6b61fe96f..b0b99b94e14 100644 --- a/src/Container.php +++ b/src/Container.php @@ -10,7 +10,6 @@ use Automattic\WooCommerce\Internal\DependencyManagement\ServiceProviders\Downlo use Automattic\WooCommerce\Internal\DependencyManagement\ServiceProviders\AssignDefaultCategoryServiceProvider; use Automattic\WooCommerce\Internal\DependencyManagement\ServiceProviders\ProductAttributesLookupServiceProvider; use Automattic\WooCommerce\Internal\DependencyManagement\ServiceProviders\ProxiesServiceProvider; -use Automattic\WooCommerce\Internal\DependencyManagement\ServiceProviders\ThemeManagementServiceProvider; use Automattic\WooCommerce\Internal\DependencyManagement\ServiceProviders\RestockRefundedItemsAdjusterServiceProvider; /** @@ -41,7 +40,6 @@ final class Container implements \Psr\Container\ContainerInterface { DownloadPermissionsAdjusterServiceProvider::class, ProductAttributesLookupServiceProvider::class, ProxiesServiceProvider::class, - ThemeManagementServiceProvider::class, RestockRefundedItemsAdjusterServiceProvider::class, ); diff --git a/src/Internal/DependencyManagement/ServiceProviders/ThemeManagementServiceProvider.php b/src/Internal/DependencyManagement/ServiceProviders/ThemeManagementServiceProvider.php deleted file mode 100644 index 7216b04271b..00000000000 --- a/src/Internal/DependencyManagement/ServiceProviders/ThemeManagementServiceProvider.php +++ /dev/null @@ -1,31 +0,0 @@ -share_with_auto_arguments( ThemeSupport::class ); - } -} diff --git a/src/Internal/ThemeSupport.php b/src/Internal/ThemeSupport.php deleted file mode 100644 index 46e627eb137..00000000000 --- a/src/Internal/ThemeSupport.php +++ /dev/null @@ -1,118 +0,0 @@ -legacy_proxy = $legacy_proxy; - } - - /** - * Adds theme support options for the current theme. - * - * @param array $options The options to be added. - */ - public function add_options( $options ) { - $this->legacy_proxy->call_function( 'add_theme_support', 'woocommerce', $options ); - } - - /** - * Adds default theme support options for the current theme. - * - * @param array $options The options to be added. - */ - public function add_default_options( $options ) { - $default_options = $this->get_option( self::DEFAULTS_KEY, array() ); - $default_options = array_merge( $default_options, $options ); - $this->add_options( array( self::DEFAULTS_KEY => $default_options ) ); - } - - /** - * Gets "theme support" options from the current theme, if set. - * - * @param string $option_name Option name, possibly nested (key::subkey), to get specific value. Blank to get all the existing options as an array. - * @param mixed $default_value Value to return if the specified option doesn't exist. - * @return mixed The retrieved option or the default value. - */ - public function get_option( $option_name = '', $default_value = null ) { - $theme_support_options = $this->get_all_options(); - - if ( ! $theme_support_options ) { - return $default_value; - } - - if ( $option_name ) { - $value = ArrayUtil::get_nested_value( $theme_support_options, $option_name ); - if ( is_null( $value ) ) { - $value = ArrayUtil::get_nested_value( $theme_support_options, self::DEFAULTS_KEY . '::' . $option_name, $default_value ); - } - return $value; - } - - return $theme_support_options; - } - - /** - * Checks whether a given theme support option has been defined. - * - * @param string $option_name The (possibly nested) name of the option to check. - * @param bool $include_defaults True to include the default values in the check, false otherwise. - * - * @return bool True if the specified theme support option has been defined, false otherwise. - */ - public function has_option( $option_name, $include_defaults = true ) { - $theme_support_options = $this->get_all_options(); - - if ( ! $theme_support_options ) { - return false; - } - - $value = ArrayUtil::get_nested_value( $theme_support_options, $option_name ); - if ( ! is_null( $value ) ) { - return true; - } - - if ( ! $include_defaults ) { - return false; - } - $value = ArrayUtil::get_nested_value( $theme_support_options, self::DEFAULTS_KEY . '::' . $option_name ); - return ! is_null( $value ); - } - - /** - * Get all the defined theme support options for the 'woocommerce' feature. - * - * @return array An array with all the theme support options defined for the 'woocommerce' feature, or false if nothing has been defined for that feature. - */ - private function get_all_options() { - $theme_support = $this->legacy_proxy->call_function( 'get_theme_support', 'woocommerce' ); - return is_array( $theme_support ) ? $theme_support[0] : false; - } -} diff --git a/tests/legacy/bootstrap.php b/tests/legacy/bootstrap.php index 62d93d87254..fd8bfb96dce 100644 --- a/tests/legacy/bootstrap.php +++ b/tests/legacy/bootstrap.php @@ -103,13 +103,7 @@ class WC_Unit_Tests_Bootstrap { * @throws Exception Error when initializing one of the hacks. */ private function initialize_code_hacker() { - $wp_dir = getenv( 'WP_TESTS_WP_DIR' ) ? getenv( 'WP_TESTS_WP_DIR' ) : sys_get_temp_dir() . '/wordpress'; - CodeHacker::initialize( - array( - $this->plugin_dir . '/includes/', - $wp_dir . '/wp-includes/class-wp-customize-manager.php', - ) - ); + CodeHacker::initialize( array( __DIR__ . '/../../includes/' ) ); $replaceable_functions = include_once __DIR__ . '/mockable-functions.php'; if ( ! empty( $replaceable_functions ) ) { diff --git a/tests/php/includes/customizer/class-wc-shop-customizer-test.php b/tests/php/includes/customizer/class-wc-shop-customizer-test.php deleted file mode 100644 index 0dc8057ccc9..00000000000 --- a/tests/php/includes/customizer/class-wc-shop-customizer-test.php +++ /dev/null @@ -1,59 +0,0 @@ -createMock( WP_Customize_Manager::class ); - $added_settings = array(); - $added_controls = array(); - - $add_setting_callback = function( $id, $args = array() ) use ( &$added_settings ) { - array_push( $added_settings, $id ); - }; - $add_control_callback = function( $id, $args = array() ) use ( &$added_controls ) { - array_push( $added_controls, $id ); - }; - $customize_manager->method( 'add_setting' )->will( $this->returnCallback( $add_setting_callback ) ); - $customize_manager->method( 'add_control' )->will( $this->returnCallback( $add_control_callback ) ); - - $theme_support = $this->get_instance_of( ThemeSupport::class ); - $add_support_method = $add_explicit_theme_support ? 'add_options' : 'add_default_options'; - $theme_support->$add_support_method( array( $option_name => 1234 ) ); - - $sut = $this->get_legacy_instance_of( WC_Shop_Customizer::class ); - $sut->add_sections( $customize_manager ); - - $this->assertEquals( $expected_to_have_added_customization, in_array( 'woocommerce_' . $option_name, $added_settings, true ) ); - $this->assertEquals( $expected_to_have_added_customization, in_array( 'woocommerce_' . $option_name, $added_controls, true ) ); - } -} diff --git a/tests/php/src/ThemeSupport/ThemeSupportTest.php b/tests/php/src/ThemeSupport/ThemeSupportTest.php deleted file mode 100644 index 0add81a3415..00000000000 --- a/tests/php/src/ThemeSupport/ThemeSupportTest.php +++ /dev/null @@ -1,254 +0,0 @@ -sut = $this->get_instance_of( ThemeSupport::class ); - remove_theme_support( 'woocommerce' ); - } - - /** - * @testdox add_options should add the supplied options under the 'woocommerce' feature. - */ - public function test_add_options() { - $actual_added_feature = null; - $actual_added_options = null; - - $this->register_legacy_proxy_function_mocks( - array( - 'add_theme_support' => function( $feature, ...$args ) use ( &$actual_added_feature, &$actual_added_options ) { - $actual_added_feature = $feature; - $actual_added_options = $args; - }, - ) - ); - - $options = array( 'foo' => 'bar' ); - $this->sut->add_options( $options ); - - $this->assertEquals( 'woocommerce', $actual_added_feature ); - $this->assertEquals( $options, $actual_added_options[0] ); - - $this->reset_legacy_proxy_mocks(); - - $this->sut->add_options( $options ); - - $actual_retrieved_options = get_theme_support( 'woocommerce' )[0]; - $this->assertEquals( $options, $actual_retrieved_options ); - } - - /** - * @testdox add_default_options should add the supplied options under the 'woocommerce' feature on a '_defaults' key. - */ - public function test_2_add_default_options() { - $actual_added_options = array(); - - $this->register_legacy_proxy_function_mocks( - array( - 'add_theme_support' => function( $feature, ...$args ) use ( &$actual_added_options ) { - array_push( $actual_added_options, $args ); - }, - ) - ); - - $this->sut->add_default_options( array( 'foo' => 'bar' ) ); - $this->sut->add_default_options( array( 'fizz' => 'buzz' ) ); - - $expected_added_options = array( - array( - array( - ThemeSupport::DEFAULTS_KEY => - array( - 'foo' => 'bar', - ), - ), - ), - array( - array( - ThemeSupport::DEFAULTS_KEY => - array( - 'fizz' => 'buzz', - ), - ), - ), - ); - - $this->assertEquals( $expected_added_options, $actual_added_options ); - - $this->reset_legacy_proxy_mocks(); - - $this->sut->add_default_options( array( 'foo' => 'bar' ) ); - $this->sut->add_default_options( array( 'fizz' => 'buzz' ) ); - - $actual_retrieved_options = get_theme_support( 'woocommerce' )[0]; - $expected_retrieved_options = array( - ThemeSupport::DEFAULTS_KEY => array( - 'foo' => 'bar', - 'fizz' => 'buzz', - ), - ); - $this->assertEquals( $expected_retrieved_options, $actual_retrieved_options ); - } - - /** - * @testdox add_default_options should add the supplied options under the 'woocommerce' feature on a '_defaults' key. - */ - public function test_add_default_options() { - $this->sut->add_default_options( array( 'foo' => 'bar' ) ); - $this->sut->add_default_options( array( 'fizz' => 'buzz' ) ); - - $actual = get_theme_support( 'woocommerce' )[0]; - $expected = array( - ThemeSupport::DEFAULTS_KEY => array( - 'foo' => 'bar', - 'fizz' => 'buzz', - ), - ); - $this->assertEquals( $expected, $actual ); - } - - /** - * @testdox get_option should return all the options under the 'woocommerce' feature when invoked with blank option name. - */ - public function test_get_option_with_no_option_name() { - $options = array( 'foo' => 'bar' ); - $this->sut->add_options( $options ); - - $actual = $this->sut->get_option(); - $this->assertEquals( $options, $actual ); - } - - /** - * @testdox get_option should return null if no 'woocommerce' feature exists and no default value is supplied. - */ - public function test_get_option_with_no_option_name_when_no_options_exist_and_no_default_value_supplied() { - $actual = $this->sut->get_option(); - $this->assertNull( $actual ); - } - - /** - * @testdox get_option should return the supplied default value if no 'woocommerce' feature exists. - */ - public function test_get_option_with_no_option_name_when_no_options_exist_and_default_value_supplied() { - $actual = $this->sut->get_option( '', 'DEFAULT' ); - $this->assertEquals( 'DEFAULT', $actual ); - } - - /** - * @testdox get_theme_support should return the value of the requested option if it exists. - */ - public function test_get_theme_support_with_option_name() { - $options = array( 'foo' => array( 'bar' => 'fizz' ) ); - $this->sut->add_options( $options ); - - $actual = $this->sut->get_option( 'foo::bar' ); - $this->assertEquals( 'fizz', $actual ); - } - - /** - * @testdox get_option should return null if the requested option doesn't exist and no default value is supplied. - */ - public function test_get_option_with_option_name_when_option_does_not_exist_and_no_default_value_supplied() { - $options = array( 'foo' => array( 'bar' => 'fizz' ) ); - $this->sut->add_options( $options ); - - $actual = $this->sut->get_option( 'buzz' ); - $this->assertNull( $actual ); - } - - /** - * @testdox get_option should return the supplied default value if the requested option doesn't exist. - */ - public function test_get_option_with_option_name_when_option_does_not_exist_and_default_value_supplied() { - $options = array( 'foo' => array( 'bar' => 'fizz' ) ); - $this->sut->add_options( $options ); - - $actual = $this->sut->get_option( 'buzz', 'DEFAULT' ); - $this->assertEquals( 'DEFAULT', $actual ); - } - - /** - * @testdox get_option should return the value of the requested option if it has been defined as a default. - */ - public function test_get_option_with_option_name_and_option_defined_as_default() { - $options = array( 'foo' => array( 'bar' => 'fizz' ) ); - $this->sut->add_default_options( $options ); - - $actual = $this->sut->get_option( 'foo::bar' ); - $this->assertEquals( 'fizz', $actual ); - } - - /** - * @testdox has_option should return false if no 'woocommerce' feature exists. - * - * @testWith [true] - * [false] - * - * @param bool $include_defaults Whether to include defaults in the search or not. - */ - public function test_has_option_when_no_woocommerce_feature_is_defined( $include_defaults ) { - $this->assertFalse( $this->sut->has_option( 'foo::bar', $include_defaults ) ); - } - - /** - * @testdox has_option should return false if the specified option has not been defined. - * - * @testWith [true] - * [false] - * - * @param bool $include_defaults Whether to include defaults in the search or not. - */ - public function test_has_option_when_option_is_not_defined( $include_defaults ) { - $this->sut->add_options( array( 'foo' => 'bar' ) ); - $this->assertFalse( $this->sut->has_option( 'fizz::buzz', $include_defaults ) ); - } - - /** - * @testdox has_option should return true if the specified option has been defined. - * - * @testWith [true] - * [false] - * - * @param bool $include_defaults Whether to include defaults in the search or not. - */ - public function test_has_option_when_option_is_defined( $include_defaults ) { - $this->sut->add_options( array( 'foo' => 'bar' ) ); - $this->assertTrue( $this->sut->has_option( 'foo', $include_defaults ) ); - } - - /** - * @testdox If an option has been defined as a default, has_theme_support should return true if $include_defaults is passed as true, should return false otherwise. - * - * @testWith [true, true] - * [false, false] - * - * @param bool $include_defaults Whether to include defaults in the search or not. - * @param bool $expected_result The expected return value from the tested method. - */ - public function test_has_option_when_option_is_defined_as_default( $include_defaults, $expected_result ) { - $this->sut->add_default_options( array( 'foo' => 'bar' ) ); - $this->assertEquals( $expected_result, $this->sut->has_option( 'foo', $include_defaults ) ); - } -}