You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: features/search-replace.feature
+69Lines changed: 69 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -1637,3 +1637,72 @@ Feature: Do global search/replace
1637
1637
"""
1638
1638
Table is read-only
1639
1639
"""
1640
+
1641
+
@require-mysql
1642
+
Scenario: Search and replace handles JSON-encoded URLs in custom tables
1643
+
Given a WP install
1644
+
And I run `wp db query "CREATE TABLE wp_json_test ( id int(11) unsigned NOT NULL AUTO_INCREMENT, meta TEXT, PRIMARY KEY (id) ) ENGINE=InnoDB;"`
1645
+
And I run `wp db query "INSERT INTO wp_json_test (meta) VALUES ('{\"confirmations\":{\"1\":{\"url\":\"https:\\/\\/oldsite.com\\/confirmation-page\",\"type\":\"redirect\"}}}');"`
1646
+
1647
+
When I run `wp search-replace 'https://oldsite.com''https://newsite.com' wp_json_test`
1648
+
Then STDOUT should be a table containing rows:
1649
+
| Table | Column | Replacements | Type |
1650
+
| wp_json_test | meta | 1 | PHP |
1651
+
1652
+
When I run `wp db query "SELECT meta FROM wp_json_test WHERE id = 1" --skip-column-names`
1653
+
Then STDOUT should contain:
1654
+
"""
1655
+
https:\/\/newsite.com\/confirmation-page
1656
+
"""
1657
+
And STDOUT should not contain:
1658
+
"""
1659
+
https:\/\/oldsite.com
1660
+
"""
1661
+
1662
+
@require-mysql
1663
+
Scenario: Search and replace handles nested JSON (JSON within serialized data)
1664
+
Given a WP install
1665
+
And a setup-nested-json.php file:
1666
+
"""
1667
+
<?php
1668
+
$data = array(
1669
+
'config' => json_encode( array(
1670
+
'url' => 'https://oldsite.com/page',
1671
+
'name' => 'Test',
1672
+
) ),
1673
+
);
1674
+
update_option( 'nested_json_test', $data );
1675
+
"""
1676
+
And I run `wp eval-file setup-nested-json.php`
1677
+
1678
+
When I run `wp search-replace 'https://oldsite.com''https://newsite.com' wp_options --include-columns=option_value`
1679
+
Then STDOUT should be a table containing rows:
1680
+
| Table | Column | Replacements | Type |
1681
+
| wp_options | option_value | 1 | PHP |
1682
+
1683
+
When I run `wp option get nested_json_test --format=json`
1684
+
Then STDOUT should contain:
1685
+
"""
1686
+
newsite.com
1687
+
"""
1688
+
And STDOUT should not contain:
1689
+
"""
1690
+
oldsite.com
1691
+
"""
1692
+
1693
+
@require-mysql
1694
+
Scenario: Search and replace detects JSON columns for PHP mode automatically
1695
+
Given a WP install
1696
+
And I run `wp db query "CREATE TABLE wp_json_detect ( id int(11) unsigned NOT NULL AUTO_INCREMENT, data TEXT, PRIMARY KEY (id) ) ENGINE=InnoDB;"`
1697
+
And I run `wp db query "INSERT INTO wp_json_detect (data) VALUES ('{\"site_url\":\"https:\\/\\/old.example.com\\/path\"}');"`
1698
+
1699
+
When I run `wp search-replace 'https://old.example.com''https://new.example.com' wp_json_detect`
1700
+
Then STDOUT should be a table containing rows:
1701
+
| Table | Column | Replacements | Type |
1702
+
| wp_json_detect | data | 1 | PHP |
1703
+
1704
+
When I run `wp db query "SELECT data FROM wp_json_detect WHERE id = 1" --skip-column-names`
0 commit comments