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.
This commit is contained in:
Christopher Allford 2021-05-21 10:36:13 -07:00
parent 514068982a
commit 070954c888
19 changed files with 59 additions and 517 deletions

View File

@ -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',

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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;
}
/**

View File

@ -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,
);

View File

@ -1,31 +0,0 @@
<?php
/**
* ThemeManagementServiceProvider class file.
*/
namespace Automattic\WooCommerce\Internal\DependencyManagement\ServiceProviders;
use Automattic\WooCommerce\Internal\ThemeSupport;
use Automattic\WooCommerce\Internal\DependencyManagement\AbstractServiceProvider;
/**
* Service provider for the classes in the Automattic\WooCommerce\ThemeManagement namespace.
*/
class ThemeManagementServiceProvider extends AbstractServiceProvider {
/**
* The classes/interfaces that are serviced by this service provider.
*
* @var array
*/
protected $provides = array(
ThemeSupport::class,
);
/**
* Register the classes.
*/
public function register() {
$this->share_with_auto_arguments( ThemeSupport::class );
}
}

View File

@ -1,118 +0,0 @@
<?php
/**
* ThemeSupport class file.
*
* @package Automattic\WooCommerce\ThemeManagement
*/
namespace Automattic\WooCommerce\Internal;
use Automattic\WooCommerce\Proxies\LegacyProxy;
use Automattic\WooCommerce\Utilities\ArrayUtil;
/**
* Provides methods for theme support.
*/
class ThemeSupport {
const DEFAULTS_KEY = '_defaults';
/**
* The instance of LegacyProxy to use.
*
* @var LegacyProxy
*/
private $legacy_proxy;
/**
* ThemeSupport constructor.
*
* @internal
* @param LegacyProxy $legacy_proxy The instance of LegacyProxy to use.
*/
final public function init( LegacyProxy $legacy_proxy ) {
$this->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;
}
}

View File

@ -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 ) ) {

View File

@ -1,59 +0,0 @@
<?php
/**
* Tests for WC_Shop_Customizer
*/
use Automattic\WooCommerce\Internal\ThemeSupport;
require_once ABSPATH . WPINC . '/class-wp-customize-manager.php';
require_once ABSPATH . WPINC . '/class-wp-customize-control.php';
/**
* Tests for WC_Shop_Customizer
*/
class WC_Shop_Customizer_Test extends WC_Unit_Test_Case {
/**
* Runs before each test of the class.
*/
public function setUp() {
remove_theme_support( 'woocommerce' );
}
/**
* @testdox add_sections should add controls for image size settings only if these sizes haven't been explicitly declared as theme support (not counting default declarations).
*
* @testWith ["single_image_width", true, false]
* ["single_image_width", false, true]
* ["thumbnail_image_width", true, false]
* ["thumbnail_image_width", false, true]
*
* @param string $option_name The option name to test, either 'single_image_width' or 'thumbnail_image_width'.
* @param bool $add_explicit_theme_support True to test when theme support is added explicitly (not as a default value).
* @param bool $expected_to_have_added_customization True to expect the customization to have been added, false to expect it no to have been added.
*/
public function test_add_sections_should_add_image_controls_only_if_no_theme_support_for_image_sizes_is_defined( $option_name, $add_explicit_theme_support, $expected_to_have_added_customization ) {
$customize_manager = $this->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 ) );
}
}

View File

@ -1,254 +0,0 @@
<?php
/**
* Tests for ThemeSupport
*
* @package Automattic\WooCommerce\Tests\ThemeSupport
*/
namespace Automattic\WooCommerce\Tests\ThemeManagement;
use Automattic\WooCommerce\Internal\ThemeSupport;
/**
* Tests for ThemeSupport
*/
class ThemeSupportTest extends \WC_Unit_Test_Case {
/**
* The system under test.
*
* @var ThemeSupport
*/
private $sut;
/**
* Runs before each test.
*/
public function setUp() {
$this->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 ) );
}
}