Skip to content

Commit

Permalink
Merge pull request #8 from wp-cli/option-command
Browse files Browse the repository at this point in the history
Add `wp option` from wp-cli/wp-cli
  • Loading branch information
schlessera authored Apr 18, 2017
2 parents 91e54a7 + 21a85a2 commit e1c6586
Show file tree
Hide file tree
Showing 5 changed files with 672 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ before_install:
- phpenv config-rm xdebug.ini

install:
- composer require wp-cli/wp-cli:dev-master
- composer require wp-cli/wp-cli:dev-3728-option-command
- composer install
- bash bin/install-package-tests.sh

Expand Down
1 change: 1 addition & 0 deletions entity-command.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
}
}
) );
WP_CLI::add_command( 'option', 'Option_Command' );
WP_CLI::add_command( 'post', 'Post_Command' );
WP_CLI::add_command( 'post meta', 'Post_Meta_Command' );
WP_CLI::add_command( 'post term', 'Post_Term_Command' );
Expand Down
66 changes: 66 additions & 0 deletions features/option-list.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
Feature: List WordPress options

Scenario: Using the `--transients` flag
Given a WP install
And I run `wp transient set wp_transient_flag wp_transient_flag`

When I run `wp option list --no-transients`
Then STDOUT should not contain:
"""
wp_transient_flag
"""
And STDOUT should not contain:
"""
_transient
"""
And STDOUT should contain:
"""
siteurl
"""

When I run `wp option list --transients`
Then STDOUT should contain:
"""
wp_transient_flag
"""
And STDOUT should contain:
"""
_transient
"""
And STDOUT should not contain:
"""
siteurl
"""

Scenario: List option with exclude pattern
Given a WP install

When I run `wp option add sample_test_field_one sample_test_field_value_one`
And I run `wp option add sample_test_field_two sample_test_field_value_two`
And I run `wp option list --search="sample_test_field_*" --format=csv`
Then STDOUT should be:
"""
option_name,option_value
sample_test_field_one,sample_test_field_value_one
sample_test_field_two,sample_test_field_value_two
"""

When I run `wp option list --search="sample_test_field_*" --exclude="*field_one" --format=csv`
Then STDOUT should be:
"""
option_name,option_value
sample_test_field_two,sample_test_field_value_two
"""

When I run `wp option list`
Then STDOUT should contain:
"""
sample_test_field_one
"""

When I run `wp option list --exclude="sample_test_field_one"`
Then STDOUT should not contain:
"""
sample_test_field_one
"""

218 changes: 218 additions & 0 deletions features/option.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
Feature: Manage WordPress options

Scenario: Option CRUD
Given a WP install

# String values
When I run `wp option add str_opt 'bar'`
Then STDOUT should not be empty

When I run `wp option get str_opt`
Then STDOUT should be:
"""
bar
"""

When I run `wp option list`
Then STDOUT should not be empty

When I run `wp option list`
Then STDOUT should contain:
"""
str_opt bar
"""

When I run `wp option list --autoload=off`
Then STDOUT should not contain:
"""
str_opt bar
"""

When I run `wp option list --search='str_o*'`
Then STDOUT should be a table containing rows:
| option_name | option_value |
| str_opt | bar |

When I run `wp option list --search='str_o*' --format=total_bytes`
Then STDOUT should be:
"""
3
"""

When I run `wp option list`
Then STDOUT should contain:
"""
home http://example.com
"""

When I run `wp option add auto_opt --autoload=no 'bar'`
Then STDOUT should not be empty

When I run `wp option list --search='auto_opt' --autoload`
Then STDOUT should not be empty

When I run `wp option list | grep -q "str_opt"`
Then the return code should be 0

When I run `wp option delete str_opt`
Then STDOUT should not be empty

When I run `wp option list`
Then STDOUT should not contain:
"""
str_opt bar
"""

When I try `wp option get str_opt`
Then the return code should be 1

# Integer values
When I run `wp option update blog_public 1`
Then STDOUT should not be empty

When I run `wp option update blog_public 0`
Then STDOUT should contain:
"""
Success: Updated 'blog_public' option.
"""

When I run the previous command again
Then STDOUT should contain:
"""
Success: Value passed for 'blog_public' option is unchanged.
"""

When I run `wp option get blog_public`
Then STDOUT should be:
"""
0
"""


# JSON values
When I run `wp option set json_opt '[ 1, 2 ]' --format=json`
Then STDOUT should not be empty

When I run the previous command again
Then STDOUT should not be empty

When I run `wp option get json_opt --format=json`
Then STDOUT should be:
"""
[1,2]
"""


# Reading from files
Given a value.json file:
"""
{
"foo": "bar",
"list": [1, 2, 3]
}
"""
When I run `wp option set foo --format=json < value.json`
And I run `wp option get foo --format=json`
Then STDOUT should be JSON containing:
"""
{
"foo": "bar",
"list": [1, 2, 3]
}
"""
@require-wp-4.2
Scenario: Update autoload value for custom option
Given a WP install
And I run `wp option add hello world --autoload=no`
When I run `wp option update hello universe`
Then STDOUT should not be empty
When I run `wp option list --search='hello' --fields=option_name,option_value,autoload`
Then STDOUT should be a table containing rows:
| option_name | option_value | autoload |
| hello | universe | no |
When I run `wp option update hello island --autoload=yes`
Then STDOUT should not be empty
When I run `wp option list --search='hello' --fields=option_name,option_value,autoload`
Then STDOUT should be a table containing rows:
| option_name | option_value | autoload |
| hello | island | yes |
@require-wp-4.2
Scenario: Managed autoloaded options
Given a WP install
When I run `wp option add wp_autoload_1 enabled --autoload=yes`
Then STDOUT should be:
"""
Success: Added 'wp_autoload_1' option.
"""
And STDERR should be empty
When I run `wp option add wp_autoload_2 implicit`
Then STDOUT should be:
"""
Success: Added 'wp_autoload_2' option.
"""
And STDERR should be empty
When I run `wp option add wp_autoload_3 disabled --autoload=no`
Then STDOUT should be:
"""
Success: Added 'wp_autoload_3' option.
"""
And STDERR should be empty
When I run `wp option list --search='wp_autoload*' --fields=option_name,option_value,autoload`
Then STDOUT should be a table containing rows:
| option_name | option_value | autoload |
| wp_autoload_1 | enabled | yes |
| wp_autoload_2 | implicit | yes |
| wp_autoload_3 | disabled | no |
When I run `wp option update wp_autoload_1 disabled --autoload=no`
Then STDOUT should be:
"""
Success: Updated 'wp_autoload_1' option.
"""
And STDERR should be empty
When I run `wp option update wp_autoload_2 implicit2`
Then STDOUT should be:
"""
Success: Updated 'wp_autoload_2' option.
"""
And STDERR should be empty
When I run `wp option update wp_autoload_3 enabled --autoload=yes`
Then STDOUT should be:
"""
Success: Updated 'wp_autoload_3' option.
"""
And STDERR should be empty
When I run `wp option list --search='wp_autoload*' --fields=option_name,option_value,autoload`
Then STDOUT should be a table containing rows:
| option_name | option_value | autoload |
| wp_autoload_1 | disabled | no |
| wp_autoload_2 | implicit2 | yes |
| wp_autoload_3 | enabled | yes |
Scenario: Extra removetrailingslash sanitization for whitelisted options
Given a WP install
When I run `wp option update home 'http://localhost/'`
Then STDOUT should be:
"""
Success: Updated 'home' option.
"""
When I run `wp option update home 'http://localhost/'`
Then STDOUT should be:
"""
Success: Value passed for 'home' option is unchanged.
"""
Loading

0 comments on commit e1c6586

Please sign in to comment.