Skip to content

Commit 06037f3

Browse files
Restore Site_Option_Command and User_Session_Command
These commands need to be included in this repo because of registry race conditions
1 parent 48d0f0c commit 06037f3

File tree

6 files changed

+685
-1
lines changed

6 files changed

+685
-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-3728-entity-command
40+
- composer require wp-cli/wp-cli:dev-3728-entity-command-2
4141
- composer install
4242
- bash bin/install-package-tests.sh
4343

entity-command.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@
2626
WP_CLI::add_command( 'post term', 'Post_Term_Command' );
2727
WP_CLI::add_command( 'post-type', 'Post_Type_Command' );
2828
WP_CLI::add_command( 'site', 'Site_Command' );
29+
WP_CLI::add_command( 'site option', 'Site_Option_Command', array(
30+
'before_invoke' => function() {
31+
if ( !is_multisite() ) {
32+
WP_CLI::error( 'This is not a multisite install.' );
33+
}
34+
}
35+
) );
2936
WP_CLI::add_command( 'taxonomy', 'Taxonomy_Command' );
3037
WP_CLI::add_command( 'term', 'Term_Command' );
3138
WP_CLI::add_command( 'term meta', 'Term_Meta_Command', array(
@@ -37,4 +44,12 @@
3744
);
3845
WP_CLI::add_command( 'user', 'User_Command' );
3946
WP_CLI::add_command( 'user meta', 'User_Meta_Command' );
47+
WP_CLI::add_command( 'user session', 'User_Session_Command', array(
48+
'before_invoke' => function() {
49+
if ( \WP_CLI\Utils\wp_version_compare( '4.0', '<' ) ) {
50+
WP_CLI::error( "Requires WordPress 4.0 or greater." );
51+
}
52+
})
53+
);
54+
4055
WP_CLI::add_command( 'user term', 'User_Term_Command' );

features/site-option.feature

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
Feature: Manage WordPress site options
2+
3+
Scenario: Site Option CRUD
4+
Given a WP multisite install
5+
6+
# String values
7+
When I run `wp site option add str_opt 'bar'`
8+
Then STDOUT should not be empty
9+
10+
When I run `wp site option get str_opt`
11+
Then STDOUT should be:
12+
"""
13+
bar
14+
"""
15+
16+
When I run `wp site option list`
17+
Then STDOUT should not be empty
18+
19+
When I run `wp site option list`
20+
Then STDOUT should contain:
21+
"""
22+
str_opt bar
23+
"""
24+
25+
When I run `wp site option list --search='str_o*'`
26+
Then STDOUT should be a table containing rows:
27+
| meta_key | meta_value |
28+
| str_opt | bar |
29+
30+
When I run `wp site option list --search='str_o*' --format=total_bytes`
31+
Then STDOUT should be:
32+
"""
33+
3
34+
"""
35+
36+
When I run `wp site option list`
37+
Then STDOUT should contain:
38+
"""
39+
admin_user_id 1
40+
"""
41+
42+
When I run `wp site option delete str_opt`
43+
Then STDOUT should not be empty
44+
45+
When I run `wp site option list`
46+
Then STDOUT should not contain:
47+
"""
48+
str_opt bar
49+
"""
50+
51+
When I try `wp site option get str_opt`
52+
Then the return code should be 1
53+
54+
# Integer values
55+
When I run `wp site option update admin_user_id 2`
56+
Then STDOUT should not be empty
57+
58+
When I run `wp site option get admin_user_id`
59+
Then STDOUT should be:
60+
"""
61+
2
62+
"""
63+
64+
When I run `wp site option update admin_user_id 1`
65+
Then STDOUT should contain:
66+
"""
67+
Success: Updated 'admin_user_id' site option.
68+
"""
69+
70+
When I run the previous command again
71+
Then STDOUT should contain:
72+
"""
73+
Success: Value passed for 'admin_user_id' site option is unchanged.
74+
"""
75+
76+
When I run `wp site option get admin_user_id`
77+
Then STDOUT should be:
78+
"""
79+
1
80+
"""
81+
82+
# JSON values
83+
When I run `wp site option set json_opt '[ 1, 2 ]' --format=json`
84+
Then STDOUT should not be empty
85+
86+
When I run the previous command again
87+
Then STDOUT should not be empty
88+
89+
When I run `wp site option get json_opt --format=json`
90+
Then STDOUT should be:
91+
"""
92+
[1,2]
93+
"""
94+
95+
# Reading from files
96+
Given a value.json file:
97+
"""
98+
{
99+
"foo": "bar",
100+
"list": [1, 2, 3]
101+
}
102+
"""
103+
When I run `wp site option set foo --format=json < value.json`
104+
And I run `wp site option get foo --format=json`
105+
Then STDOUT should be JSON containing:
106+
"""
107+
{
108+
"foo": "bar",
109+
"list": [1, 2, 3]
110+
}
111+
"""
112+
113+
Scenario: Error on single install
114+
Given a WP install
115+
116+
When I try `wp site option get str_opt`
117+
Then STDERR should be:
118+
"""
119+
Error: This is not a multisite install.
120+
"""
121+
122+
When I try `wp site option add str_opt 'bar'`
123+
Then STDERR should be:
124+
"""
125+
Error: This is not a multisite install.
126+
"""
127+
128+
Scenario: Filter options by `--site_id`
129+
Given a WP multisite install
130+
131+
When I run `wp db query "INSERT INTO wp_sitemeta (site_id,meta_key,meta_value) VALUES (2,'wp_cli_test_option','foobar');"`
132+
Then the return code should be 0
133+
134+
When I run `wp site option list`
135+
Then STDOUT should contain:
136+
"""
137+
wp_cli_test_option
138+
"""
139+
And STDERR should be empty
140+
141+
When I run `wp site option list --site_id=1`
142+
Then STDOUT should not contain:
143+
"""
144+
wp_cli_test_option
145+
"""
146+
And STDERR should be empty
147+
148+
When I run `wp site option list --site_id=2`
149+
Then STDOUT should contain:
150+
"""
151+
wp_cli_test_option
152+
"""
153+
And STDERR should be empty

features/user-session.feature

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
Feature: Manage user session
2+
3+
Background:
4+
Given a WP install
5+
6+
@require-wp-4.0
7+
Scenario: Destroy user sessions
8+
When I run `wp eval 'wp_set_current_user(1);'`
9+
And I run `wp eval 'wp_set_auth_cookie(1);'`
10+
And I run `wp eval 'wp_set_current_user(1);'`
11+
And I run `wp eval 'wp_set_auth_cookie(1);'`
12+
And I run `wp user session list admin --format=count`
13+
Then STDOUT should be:
14+
"""
15+
2
16+
"""
17+
18+
When I run `wp user session destroy admin`
19+
Then STDOUT should be:
20+
"""
21+
Success: Destroyed session. 1 remaining.
22+
"""
23+
24+
When I run `wp user session list admin --format=count`
25+
Then STDOUT should be:
26+
"""
27+
1
28+
"""
29+
30+
When I run `wp user session destroy admin --all`
31+
Then STDOUT should be:
32+
"""
33+
Success: Destroyed all sessions.
34+
"""
35+
36+
And I run `wp user session list admin --format=count`
37+
Then STDOUT should be:
38+
"""
39+
0
40+
"""

0 commit comments

Comments
 (0)