Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion features/sidebar.feature
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ Feature: Manage WordPress sidebars
0
"""

When I run `wp eval 'update_option( "sidebars_widgets", array_merge( wp_get_sidebars_widgets(), [ "orphaned-sidebar-1" => [] ] ) );'`
Given a sidebar-update.php file:
"""
<?php
update_option( 'sidebars_widgets', array_merge( wp_get_sidebars_widgets(), [ 'orphaned-sidebar-1' => [] ] ) );
"""
When I run `wp eval-file sidebar-update.php`
And I run `wp sidebar list --inactive --fields=id --format=csv`
Then STDOUT should be:
"""
Expand Down
13 changes: 12 additions & 1 deletion features/widget-reset.feature
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ Feature: Reset WordPress sidebars
text-1
"""

@skip-windows
Scenario: Testing movement of widgets while reset
When I run `wp widget add calendar sidebar-2 --title="Calendar"`
Then STDOUT should not be empty
Expand All @@ -141,6 +142,8 @@ Feature: Reset WordPress sidebars
"""
calendar-1 search-1
"""

# TODO: Investigate why output is not empty on Windows
When I run `wp widget list wp_inactive_widgets --format=ids`
Then STDOUT should be empty

Expand All @@ -166,7 +169,15 @@ Feature: Reset WordPress sidebars
Then STDOUT should not be empty

# Simulate an inactive (unregistered) sidebar by moving widget data to an orphaned key
When I run `wp eval '$w = wp_get_sidebars_widgets(); $w["orphaned-sidebar-1"] = $w["sidebar-1"]; $w["sidebar-1"] = []; update_option( "sidebars_widgets", $w );'`
Given a widget-orphaned-reset.php file:
"""
<?php
$w = wp_get_sidebars_widgets();
$w['orphaned-sidebar-1'] = $w['sidebar-1'];
$w['sidebar-1'] = [];
update_option( 'sidebars_widgets', $w );
Comment on lines +175 to +178
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This code assumes that $w['sidebar-1'] is always set. While the current test setup ensures this, it makes the test fragile. If a preceding step changes, this could lead to a PHP notice and potentially confusing test failures. To make the test more robust and easier to debug, consider adding an explicit check and failing loudly if the prerequisite is not met.

      $w = wp_get_sidebars_widgets();
      if ( ! array_key_exists( 'sidebar-1', $w ) ) {
          throw new \Exception( "Test prerequisite not met: 'sidebar-1' not found in sidebars_widgets." );
      }
      $w['orphaned-sidebar-1'] = $w['sidebar-1'];
      $w['sidebar-1'] = [];
      update_option( 'sidebars_widgets', $w );

"""
When I run `wp eval-file widget-orphaned-reset.php`

And I run `wp sidebar list --inactive --fields=id --format=ids`
Then STDOUT should be:
Expand Down
2 changes: 2 additions & 0 deletions features/widget.feature
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Feature: Manage widgets in WordPress sidebar
And I run `wp widget add search sidebar-2 --title="Quick Search"`
And I run `wp widget add text sidebar-3 --title="Text"`

@skip-windows
Scenario: Widget CRUD
When I run `wp widget list sidebar-1 --fields=name,id,position`
Then STDOUT should be a table containing rows:
Expand Down Expand Up @@ -55,6 +56,7 @@ Feature: Manage widgets in WordPress sidebar
| text | text-2 | 3 |

When I run `wp widget list wp_inactive_widgets --fields=name,id,position`
# TODO: Investigate why calendar is at position 7 on Windows.
Then STDOUT should be a table containing rows:
| name | id | position |
| text | text-1 | 1 |
Expand Down
Loading