Skip to content

Commit bbe0a40

Browse files
committed
test: add tests for edge cases in --replace-keys
1 parent 377328f commit bbe0a40

1 file changed

Lines changed: 71 additions & 0 deletions

File tree

features/search-replace.feature

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,77 @@ Feature: Do global search/replace
328328
"""
329329
{"sr-key-new":"value"}
330330
"""
331+
332+
Scenario: Search and replace nested serialized array keys with --replace-keys
333+
Given a WP install
334+
And a setup-nested-serialized-array-key.php file:
335+
"""
336+
<?php
337+
update_option(
338+
'replace_nested_key_option',
339+
array(
340+
'outer' => array(
341+
'sr-key-old' => 'value',
342+
),
343+
)
344+
);
345+
"""
346+
And I run `wp eval-file setup-nested-serialized-array-key.php`
347+
348+
When I run `wp search-replace sr-key-old sr-key-new --replace-keys --dry-run`
349+
Then STDOUT should be a table containing rows:
350+
| Table | Column | Replacements | Type |
351+
| wp_options | option_value | 1 | PHP |
352+
353+
When I run `wp search-replace sr-key-old sr-key-new --replace-keys`
354+
And I run `wp option get replace_nested_key_option --format=json`
355+
Then STDOUT should be JSON containing:
356+
"""
357+
{"outer":{"sr-key-new":"value"}}
358+
"""
359+
360+
Scenario: Search and replace key and value with --replace-keys
361+
Given a WP install
362+
And a setup-key-and-value-option.php file:
363+
"""
364+
<?php
365+
update_option( 'replace_key_and_value_option', array( 'sr-key-old' => 'sr-key-old' ) );
366+
"""
367+
And I run `wp eval-file setup-key-and-value-option.php`
368+
369+
When I run `wp search-replace sr-key-old sr-key-new --replace-keys --dry-run`
370+
Then STDOUT should be a table containing rows:
371+
| Table | Column | Replacements | Type |
372+
| wp_options | option_value | 1 | PHP |
373+
374+
When I run `wp search-replace sr-key-old sr-key-new --replace-keys`
375+
And I run `wp option get replace_key_and_value_option --format=json`
376+
Then STDOUT should be JSON containing:
377+
"""
378+
{"sr-key-new":"sr-key-new"}
379+
"""
380+
381+
Scenario: Search and replace colliding serialized array keys with --replace-keys
382+
Given a WP install
383+
And a setup-colliding-keys-option.php file:
384+
"""
385+
<?php
386+
update_option(
387+
'replace_colliding_keys_option',
388+
array(
389+
'sr-key-old' => 'from-old',
390+
'sr-key-new' => 'existing',
391+
)
392+
);
393+
"""
394+
And I run `wp eval-file setup-colliding-keys-option.php`
395+
396+
When I run `wp search-replace sr-key-old sr-key-new --replace-keys`
397+
And I run `wp option get replace_colliding_keys_option --format=json`
398+
Then STDOUT should be JSON containing:
399+
"""
400+
{"sr-key-new":"from-old"}
401+
"""
331402
@require-mysql
332403
Scenario: Search and replace with quoted strings
333404
Given a WP install

0 commit comments

Comments
 (0)