Skip to content

Commit

Permalink
Assign supported_features.hpos value if not defined
Browse files Browse the repository at this point in the history
  • Loading branch information
nmolham-godaddy committed Oct 9, 2024
1 parent 08bcc84 commit f3c9a7e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
24 changes: 19 additions & 5 deletions tests/unit/PluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,28 +104,42 @@ public function testCanMaybeHandleBackwardsCompatibleArgs(array $inputArgs, arra
public function providerCanMaybeHandleBackwardsCompatibleArgs(): Generator
{
yield 'no HPOS args' => [
'inputArgs' => [],
'inputArgs' => [],
'outputArgs' => [],
];

yield 'old HPOS args, no support' => [
'inputArgs' => [
'inputArgs' => [
'supports_hpos' => false,
],
'outputArgs' => [
'supported_features' => [
'hpos' => false,
'hpos' => false,
],
],
];

yield 'old HPOS args, has support' => [
'inputArgs' => [
'inputArgs' => [
'supports_hpos' => true,
],
'outputArgs' => [
'supported_features' => [
'hpos' => true,
'hpos' => true,
],
],
];

yield 'old HPOS args and new HPOS args' => [
'inputArgs' => [
'supports_hpos' => true,
'supported_features' => [
'hpos' => false,
],
],
'outputArgs' => [
'supported_features' => [
'hpos' => false,
],
],
];
Expand Down
14 changes: 9 additions & 5 deletions woocommerce/class-sv-wc-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,15 @@ public function __construct( string $id, string $version, array $args = [] ) {
protected function maybeHandleBackwardsCompatibleArgs(array $args): array
{
// handle format change for HPOS declaration
if (
array_key_exists('supports_hpos', $args) &&
! isset($args['supported_features']['hpos'])
) {
$args['supported_features']['hpos'] = $args['supports_hpos'];
if (array_key_exists('supports_hpos', $args)) {
// make sure `supported_features` initialized
if (! array_key_exists('supported_features', $args)) {
$args['supported_features'] = [];
}

// Assign `supported_features.hpos` value if not already assigned
$args['supported_features']['hpos'] = $args['supported_features']['hpos'] ?? $args['supports_hpos'];

unset($args['supports_hpos']);
}

Expand Down

0 comments on commit f3c9a7e

Please sign in to comment.