Skip to content

Commit

Permalink
Restore Site_Option_Command and User_Session_Command
Browse files Browse the repository at this point in the history
These commands need to be included in this repo because of registry race
conditions
  • Loading branch information
danielbachhuber committed Apr 4, 2017
1 parent 48d0f0c commit 06037f3
Show file tree
Hide file tree
Showing 6 changed files with 685 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-3728-entity-command
- composer require wp-cli/wp-cli:dev-3728-entity-command-2
- composer install
- bash bin/install-package-tests.sh

Expand Down
15 changes: 15 additions & 0 deletions entity-command.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@
WP_CLI::add_command( 'post term', 'Post_Term_Command' );
WP_CLI::add_command( 'post-type', 'Post_Type_Command' );
WP_CLI::add_command( 'site', 'Site_Command' );
WP_CLI::add_command( 'site option', 'Site_Option_Command', array(
'before_invoke' => function() {
if ( !is_multisite() ) {
WP_CLI::error( 'This is not a multisite install.' );
}
}
) );
WP_CLI::add_command( 'taxonomy', 'Taxonomy_Command' );
WP_CLI::add_command( 'term', 'Term_Command' );
WP_CLI::add_command( 'term meta', 'Term_Meta_Command', array(
Expand All @@ -37,4 +44,12 @@
);
WP_CLI::add_command( 'user', 'User_Command' );
WP_CLI::add_command( 'user meta', 'User_Meta_Command' );
WP_CLI::add_command( 'user session', 'User_Session_Command', array(
'before_invoke' => function() {
if ( \WP_CLI\Utils\wp_version_compare( '4.0', '<' ) ) {
WP_CLI::error( "Requires WordPress 4.0 or greater." );
}
})
);

WP_CLI::add_command( 'user term', 'User_Term_Command' );
153 changes: 153 additions & 0 deletions features/site-option.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
Feature: Manage WordPress site options

Scenario: Site Option CRUD
Given a WP multisite install

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

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

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

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

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

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

When I run `wp site option list`
Then STDOUT should contain:
"""
admin_user_id 1
"""

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

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

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

# Integer values
When I run `wp site option update admin_user_id 2`
Then STDOUT should not be empty

When I run `wp site option get admin_user_id`
Then STDOUT should be:
"""
2
"""

When I run `wp site option update admin_user_id 1`
Then STDOUT should contain:
"""
Success: Updated 'admin_user_id' site option.
"""

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

When I run `wp site option get admin_user_id`
Then STDOUT should be:
"""
1
"""

# JSON values
When I run `wp site 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 site 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 site option set foo --format=json < value.json`
And I run `wp site option get foo --format=json`
Then STDOUT should be JSON containing:
"""
{
"foo": "bar",
"list": [1, 2, 3]
}
"""
Scenario: Error on single install
Given a WP install
When I try `wp site option get str_opt`
Then STDERR should be:
"""
Error: This is not a multisite install.
"""
When I try `wp site option add str_opt 'bar'`
Then STDERR should be:
"""
Error: This is not a multisite install.
"""
Scenario: Filter options by `--site_id`
Given a WP multisite install
When I run `wp db query "INSERT INTO wp_sitemeta (site_id,meta_key,meta_value) VALUES (2,'wp_cli_test_option','foobar');"`
Then the return code should be 0
When I run `wp site option list`
Then STDOUT should contain:
"""
wp_cli_test_option
"""
And STDERR should be empty
When I run `wp site option list --site_id=1`
Then STDOUT should not contain:
"""
wp_cli_test_option
"""
And STDERR should be empty
When I run `wp site option list --site_id=2`
Then STDOUT should contain:
"""
wp_cli_test_option
"""
And STDERR should be empty
40 changes: 40 additions & 0 deletions features/user-session.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
Feature: Manage user session

Background:
Given a WP install

@require-wp-4.0
Scenario: Destroy user sessions
When I run `wp eval 'wp_set_current_user(1);'`
And I run `wp eval 'wp_set_auth_cookie(1);'`
And I run `wp eval 'wp_set_current_user(1);'`
And I run `wp eval 'wp_set_auth_cookie(1);'`
And I run `wp user session list admin --format=count`
Then STDOUT should be:
"""
2
"""

When I run `wp user session destroy admin`
Then STDOUT should be:
"""
Success: Destroyed session. 1 remaining.
"""

When I run `wp user session list admin --format=count`
Then STDOUT should be:
"""
1
"""

When I run `wp user session destroy admin --all`
Then STDOUT should be:
"""
Success: Destroyed all sessions.
"""

And I run `wp user session list admin --format=count`
Then STDOUT should be:
"""
0
"""
Loading

0 comments on commit 06037f3

Please sign in to comment.