Skip to content

Commit e1c6586

Browse files
authored
Merge pull request #8 from wp-cli/option-command
Add `wp option` from wp-cli/wp-cli
2 parents 91e54a7 + 21a85a2 commit e1c6586

File tree

5 files changed

+672
-1
lines changed

5 files changed

+672
-1
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ before_install:
3737
- phpenv config-rm xdebug.ini
3838

3939
install:
40-
- composer require wp-cli/wp-cli:dev-master
40+
- composer require wp-cli/wp-cli:dev-3728-option-command
4141
- composer install
4242
- bash bin/install-package-tests.sh
4343

entity-command.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
}
2222
}
2323
) );
24+
WP_CLI::add_command( 'option', 'Option_Command' );
2425
WP_CLI::add_command( 'post', 'Post_Command' );
2526
WP_CLI::add_command( 'post meta', 'Post_Meta_Command' );
2627
WP_CLI::add_command( 'post term', 'Post_Term_Command' );

features/option-list.feature

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
Feature: List WordPress options
2+
3+
Scenario: Using the `--transients` flag
4+
Given a WP install
5+
And I run `wp transient set wp_transient_flag wp_transient_flag`
6+
7+
When I run `wp option list --no-transients`
8+
Then STDOUT should not contain:
9+
"""
10+
wp_transient_flag
11+
"""
12+
And STDOUT should not contain:
13+
"""
14+
_transient
15+
"""
16+
And STDOUT should contain:
17+
"""
18+
siteurl
19+
"""
20+
21+
When I run `wp option list --transients`
22+
Then STDOUT should contain:
23+
"""
24+
wp_transient_flag
25+
"""
26+
And STDOUT should contain:
27+
"""
28+
_transient
29+
"""
30+
And STDOUT should not contain:
31+
"""
32+
siteurl
33+
"""
34+
35+
Scenario: List option with exclude pattern
36+
Given a WP install
37+
38+
When I run `wp option add sample_test_field_one sample_test_field_value_one`
39+
And I run `wp option add sample_test_field_two sample_test_field_value_two`
40+
And I run `wp option list --search="sample_test_field_*" --format=csv`
41+
Then STDOUT should be:
42+
"""
43+
option_name,option_value
44+
sample_test_field_one,sample_test_field_value_one
45+
sample_test_field_two,sample_test_field_value_two
46+
"""
47+
48+
When I run `wp option list --search="sample_test_field_*" --exclude="*field_one" --format=csv`
49+
Then STDOUT should be:
50+
"""
51+
option_name,option_value
52+
sample_test_field_two,sample_test_field_value_two
53+
"""
54+
55+
When I run `wp option list`
56+
Then STDOUT should contain:
57+
"""
58+
sample_test_field_one
59+
"""
60+
61+
When I run `wp option list --exclude="sample_test_field_one"`
62+
Then STDOUT should not contain:
63+
"""
64+
sample_test_field_one
65+
"""
66+

features/option.feature

Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
Feature: Manage WordPress options
2+
3+
Scenario: Option CRUD
4+
Given a WP install
5+
6+
# String values
7+
When I run `wp option add str_opt 'bar'`
8+
Then STDOUT should not be empty
9+
10+
When I run `wp option get str_opt`
11+
Then STDOUT should be:
12+
"""
13+
bar
14+
"""
15+
16+
When I run `wp option list`
17+
Then STDOUT should not be empty
18+
19+
When I run `wp option list`
20+
Then STDOUT should contain:
21+
"""
22+
str_opt bar
23+
"""
24+
25+
When I run `wp option list --autoload=off`
26+
Then STDOUT should not contain:
27+
"""
28+
str_opt bar
29+
"""
30+
31+
When I run `wp option list --search='str_o*'`
32+
Then STDOUT should be a table containing rows:
33+
| option_name | option_value |
34+
| str_opt | bar |
35+
36+
When I run `wp option list --search='str_o*' --format=total_bytes`
37+
Then STDOUT should be:
38+
"""
39+
3
40+
"""
41+
42+
When I run `wp option list`
43+
Then STDOUT should contain:
44+
"""
45+
home http://example.com
46+
"""
47+
48+
When I run `wp option add auto_opt --autoload=no 'bar'`
49+
Then STDOUT should not be empty
50+
51+
When I run `wp option list --search='auto_opt' --autoload`
52+
Then STDOUT should not be empty
53+
54+
When I run `wp option list | grep -q "str_opt"`
55+
Then the return code should be 0
56+
57+
When I run `wp option delete str_opt`
58+
Then STDOUT should not be empty
59+
60+
When I run `wp option list`
61+
Then STDOUT should not contain:
62+
"""
63+
str_opt bar
64+
"""
65+
66+
When I try `wp option get str_opt`
67+
Then the return code should be 1
68+
69+
# Integer values
70+
When I run `wp option update blog_public 1`
71+
Then STDOUT should not be empty
72+
73+
When I run `wp option update blog_public 0`
74+
Then STDOUT should contain:
75+
"""
76+
Success: Updated 'blog_public' option.
77+
"""
78+
79+
When I run the previous command again
80+
Then STDOUT should contain:
81+
"""
82+
Success: Value passed for 'blog_public' option is unchanged.
83+
"""
84+
85+
When I run `wp option get blog_public`
86+
Then STDOUT should be:
87+
"""
88+
0
89+
"""
90+
91+
92+
# JSON values
93+
When I run `wp option set json_opt '[ 1, 2 ]' --format=json`
94+
Then STDOUT should not be empty
95+
96+
When I run the previous command again
97+
Then STDOUT should not be empty
98+
99+
When I run `wp option get json_opt --format=json`
100+
Then STDOUT should be:
101+
"""
102+
[1,2]
103+
"""
104+
105+
106+
# Reading from files
107+
Given a value.json file:
108+
"""
109+
{
110+
"foo": "bar",
111+
"list": [1, 2, 3]
112+
}
113+
"""
114+
When I run `wp option set foo --format=json < value.json`
115+
And I run `wp option get foo --format=json`
116+
Then STDOUT should be JSON containing:
117+
"""
118+
{
119+
"foo": "bar",
120+
"list": [1, 2, 3]
121+
}
122+
"""
123+
124+
@require-wp-4.2
125+
Scenario: Update autoload value for custom option
126+
Given a WP install
127+
And I run `wp option add hello world --autoload=no`
128+
129+
When I run `wp option update hello universe`
130+
Then STDOUT should not be empty
131+
132+
When I run `wp option list --search='hello' --fields=option_name,option_value,autoload`
133+
Then STDOUT should be a table containing rows:
134+
| option_name | option_value | autoload |
135+
| hello | universe | no |
136+
137+
When I run `wp option update hello island --autoload=yes`
138+
Then STDOUT should not be empty
139+
140+
When I run `wp option list --search='hello' --fields=option_name,option_value,autoload`
141+
Then STDOUT should be a table containing rows:
142+
| option_name | option_value | autoload |
143+
| hello | island | yes |
144+
145+
@require-wp-4.2
146+
Scenario: Managed autoloaded options
147+
Given a WP install
148+
149+
When I run `wp option add wp_autoload_1 enabled --autoload=yes`
150+
Then STDOUT should be:
151+
"""
152+
Success: Added 'wp_autoload_1' option.
153+
"""
154+
And STDERR should be empty
155+
156+
When I run `wp option add wp_autoload_2 implicit`
157+
Then STDOUT should be:
158+
"""
159+
Success: Added 'wp_autoload_2' option.
160+
"""
161+
And STDERR should be empty
162+
163+
When I run `wp option add wp_autoload_3 disabled --autoload=no`
164+
Then STDOUT should be:
165+
"""
166+
Success: Added 'wp_autoload_3' option.
167+
"""
168+
And STDERR should be empty
169+
170+
When I run `wp option list --search='wp_autoload*' --fields=option_name,option_value,autoload`
171+
Then STDOUT should be a table containing rows:
172+
| option_name | option_value | autoload |
173+
| wp_autoload_1 | enabled | yes |
174+
| wp_autoload_2 | implicit | yes |
175+
| wp_autoload_3 | disabled | no |
176+
177+
When I run `wp option update wp_autoload_1 disabled --autoload=no`
178+
Then STDOUT should be:
179+
"""
180+
Success: Updated 'wp_autoload_1' option.
181+
"""
182+
And STDERR should be empty
183+
184+
When I run `wp option update wp_autoload_2 implicit2`
185+
Then STDOUT should be:
186+
"""
187+
Success: Updated 'wp_autoload_2' option.
188+
"""
189+
And STDERR should be empty
190+
191+
When I run `wp option update wp_autoload_3 enabled --autoload=yes`
192+
Then STDOUT should be:
193+
"""
194+
Success: Updated 'wp_autoload_3' option.
195+
"""
196+
And STDERR should be empty
197+
198+
When I run `wp option list --search='wp_autoload*' --fields=option_name,option_value,autoload`
199+
Then STDOUT should be a table containing rows:
200+
| option_name | option_value | autoload |
201+
| wp_autoload_1 | disabled | no |
202+
| wp_autoload_2 | implicit2 | yes |
203+
| wp_autoload_3 | enabled | yes |
204+
205+
Scenario: Extra removetrailingslash sanitization for whitelisted options
206+
Given a WP install
207+
208+
When I run `wp option update home 'http://localhost/'`
209+
Then STDOUT should be:
210+
"""
211+
Success: Updated 'home' option.
212+
"""
213+
214+
When I run `wp option update home 'http://localhost/'`
215+
Then STDOUT should be:
216+
"""
217+
Success: Value passed for 'home' option is unchanged.
218+
"""

0 commit comments

Comments
 (0)