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
Scenario: Search and replace handles JSON-encoded URLs in post content
243
+
Given a WP install
244
+
245
+
When I run `wp post create --post_content='{"src":"http:\/\/example.com\/wp-content\/uploads\/fonts\/test.woff2","fontWeight":"400"}' --post_status=publish --porcelain`
246
+
Then save STDOUT as {POST_ID}
247
+
248
+
When I run `wp post get {POST_ID} --field=post_content`
249
+
Then STDOUT should contain:
250
+
"""
251
+
http:\/\/example.com
252
+
"""
253
+
254
+
When I run `wp search-replace 'http://example.com''http://newdomain.com' wp_posts --include-columns=post_content`
255
+
Then STDOUT should be a table containing rows:
256
+
| Table | Column | Replacements | Type |
257
+
| wp_posts | post_content | 1 | SQL |
258
+
259
+
When I run `wp post get {POST_ID} --field=post_content`
260
+
Then STDOUT should contain:
261
+
"""
262
+
http:\/\/newdomain.com
263
+
"""
264
+
And STDOUT should not contain:
265
+
"""
266
+
http:\/\/example.com
267
+
"""
268
+
269
+
When I run `wp search-replace 'http://newdomain.com''http://example.com' wp_posts --include-columns=post_content --precise`
270
+
Then STDOUT should be a table containing rows:
271
+
| Table | Column | Replacements | Type |
272
+
| wp_posts | post_content | 1 | PHP |
273
+
274
+
When I run `wp post get {POST_ID} --field=post_content`
275
+
Then STDOUT should contain:
276
+
"""
277
+
http:\/\/example.com
278
+
"""
279
+
241
280
@require-mysql
242
281
Scenario: Search and replace with quoted strings
243
282
Given a WP install
@@ -1392,3 +1431,145 @@ Feature: Do global search/replace
1392
1431
"""
1393
1432
Success: Made 0 replacements.
1394
1433
"""
1434
+
1435
+
@require-mysql
1436
+
Scenario: Search/replace strings starting with hyphens using --old and --new flags
1437
+
Given a WP install
1438
+
And I run `wp post create --post_title="Test Post" --post_content="This is --old-content and more text" --porcelain`
1439
+
Then save STDOUT as {POST_ID}
1440
+
1441
+
When I run `wp search-replace --old='--old-content' --new='--new-content'`
1442
+
Then STDOUT should contain:
1443
+
"""
1444
+
wp_posts
1445
+
"""
1446
+
And the return code should be 0
1447
+
1448
+
When I run `wp post get {POST_ID} --field=post_content`
1449
+
Then STDOUT should contain:
1450
+
"""
1451
+
--new-content
1452
+
"""
1453
+
And STDOUT should not contain:
1454
+
"""
1455
+
--old-content
1456
+
"""
1457
+
1458
+
@require-mysql
1459
+
Scenario: Error when neither positional args nor flags provided
1460
+
Given a WP install
1461
+
1462
+
When I try `wp search-replace`
1463
+
Then STDERR should contain:
1464
+
"""
1465
+
Please provide both <old> and <new> arguments
1466
+
"""
1467
+
And STDERR should contain:
1468
+
"""
1469
+
--old
1470
+
"""
1471
+
And STDERR should contain:
1472
+
"""
1473
+
--new
1474
+
"""
1475
+
And the return code should be 1
1476
+
1477
+
@require-mysql
1478
+
Scenario: Error when only --old flag provided without --new
1479
+
Given a WP install
1480
+
1481
+
When I try `wp search-replace --old='test-value'`
1482
+
Then STDERR should contain:
1483
+
"""
1484
+
Please provide the <new> argument
1485
+
"""
1486
+
And the return code should be 1
1487
+
1488
+
@require-mysql
1489
+
Scenario: Error when only --new flag provided without --old
1490
+
Given a WP install
1491
+
1492
+
When I try `wp search-replace --new='test-value'`
1493
+
Then STDERR should contain:
1494
+
"""
1495
+
Please provide the <old> argument
1496
+
"""
1497
+
And the return code should be 1
1498
+
1499
+
@require-mysql
1500
+
Scenario: Error when both flags and positional arguments provided
1501
+
Given a WP install
1502
+
1503
+
When I try `wp search-replace --old='flag-old' --new='flag-new''positional-arg'`
1504
+
Then STDERR should contain:
1505
+
"""
1506
+
Cannot use both positional arguments and --old/--new flags
1507
+
"""
1508
+
And the return code should be 1
1509
+
1510
+
@require-mysql
1511
+
Scenario: Error when empty string provided via --old flag
1512
+
Given a WP install
1513
+
1514
+
When I try `wp search-replace --old='' --new='replacement'`
1515
+
Then STDERR should contain:
1516
+
"""
1517
+
Please provide the <old> argument
1518
+
"""
1519
+
And the return code should be 1
1520
+
1521
+
@require-mysql
1522
+
Scenario: No error when empty string provided via --new flag
1523
+
Given a WP install
1524
+
1525
+
When I try `wp search-replace --old='search' --new=''`
1526
+
Then STDERR should not contain:
1527
+
"""
1528
+
Please provide the <new> argument
1529
+
"""
1530
+
1531
+
@require-mysql
1532
+
Scenario: Search/replace string starting with single hyphen works with positional args
1533
+
Given a WP install
1534
+
And I run `wp post create --post_title="Test Post" --post_content="This is -single-hyphen content" --porcelain`
1535
+
Then save STDOUT as {POST_ID}
1536
+
1537
+
When I run `wp search-replace '-single-hyphen''-replaced-hyphen'`
1538
+
Then STDOUT should contain:
1539
+
"""
1540
+
wp_posts
1541
+
"""
1542
+
And the return code should be 0
1543
+
1544
+
When I run `wp post get {POST_ID} --field=post_content`
1545
+
Then STDOUT should contain:
1546
+
"""
1547
+
-replaced-hyphen
1548
+
"""
1549
+
And STDOUT should not contain:
1550
+
"""
1551
+
-single-hyphen
1552
+
"""
1553
+
1554
+
@require-mysql
1555
+
Scenario: Allow mixing one flag with one positional argument
1556
+
Given a WP install
1557
+
And I run `wp post create --post_title="Test Post" --post_content="This is --old-content text" --porcelain`
1558
+
Then save STDOUT as {POST_ID}
1559
+
1560
+
When I run `wp search-replace --old='--old-content''new-content'`
1561
+
Then STDOUT should contain:
1562
+
"""
1563
+
wp_posts
1564
+
"""
1565
+
And the return code should be 0
1566
+
1567
+
When I run `wp post get {POST_ID} --field=post_content`
0 commit comments