diff --git a/features/site.feature b/features/site.feature index c944642a6..804e6ccbc 100644 --- a/features/site.feature +++ b/features/site.feature @@ -936,3 +936,108 @@ Feature: Manage sites in a multisite installation """ 1 """ + + Scenario: Filter the site list by columns of the sites table + Given a WP multisite install + + When I run `wp site create --slug=first --porcelain` + Then STDOUT should be a number + And save STDOUT as {FIRST_ID} + + When I run `wp site create --slug=second --porcelain` + Then STDOUT should be a number + And save STDOUT as {SECOND_ID} + + # Give the two new sites contrasting statuses, so each filter below has + # something to discriminate on and cannot pass by matching every site. + When I run `wp site archive {FIRST_ID}` + Then STDOUT should contain: + """ + Success: + """ + + When I run `wp site private {SECOND_ID}` + Then STDOUT should contain: + """ + Success: + """ + + When I run `wp site spam {SECOND_ID}` + Then STDOUT should contain: + """ + Success: + """ + + When I run `wp site list --format=count` + Then STDOUT should be: + """ + 3 + """ + + When I run `wp site list --archived=1 --field=blog_id` + Then STDOUT should be: + """ + {FIRST_ID} + """ + + When I run `wp site list --archived=0 --format=count` + Then STDOUT should be: + """ + 2 + """ + + When I run `wp site list --public=0 --field=blog_id` + Then STDOUT should be: + """ + {SECOND_ID} + """ + + When I run `wp site list --public=1 --format=count` + Then STDOUT should be: + """ + 2 + """ + + When I run `wp site list --spam=1 --field=blog_id` + Then STDOUT should be: + """ + {SECOND_ID} + """ + + When I run `wp site list --spam=0 --format=count` + Then STDOUT should be: + """ + 2 + """ + + When I run `wp site list --deleted=0 --format=count` + Then STDOUT should be: + """ + 3 + """ + + When I run `wp site list --blog_id={FIRST_ID} --field=blog_id` + Then STDOUT should be: + """ + {FIRST_ID} + """ + + # site_id is the ID of the network the site belongs to, not the site's own ID. + When I run `wp site list --site_id=1 --format=count` + Then STDOUT should be: + """ + 3 + """ + + When I run `wp site list --site_id=2 --format=count` + Then STDOUT should be: + """ + 0 + """ + + # --network is an alias for site_id and takes precedence over it. + When I run `wp site list --site_id=2 --network=1 --format=count` + Then STDOUT should be: + """ + 3 + """ diff --git a/features/user-application-password.feature b/features/user-application-password.feature index 507b7ee28..c2779900b 100644 --- a/features/user-application-password.feature +++ b/features/user-application-password.feature @@ -315,3 +315,93 @@ Feature: Manage user custom fields """ true """ + + @require-wp-5.6 + Scenario: Filter application passwords by field + Given a WP install + + When I run `wp user application-password create 1 myapp --app-id=abc123 --porcelain` + Then STDOUT should not be empty + + When I run `wp user application-password create 1 otherapp --porcelain` + Then STDOUT should not be empty + + When I run `wp user application-password list 1 --format=count` + Then STDOUT should be: + """ + 2 + """ + + When I run `wp user application-password list 1 --app_id=abc123 --field=name` + Then STDOUT should be: + """ + myapp + """ + + When I run `wp user application-password list 1 --app-id=abc123 --field=name` + Then STDOUT should be: + """ + myapp + """ + + When I run `wp user application-password list 1 --name=otherapp --field=name` + Then STDOUT should be: + """ + otherapp + """ + + When I run `wp user application-password list 1 --name=myapp --field=uuid` + Then STDOUT should not be empty + And save STDOUT as {UUID} + + When I run `wp user application-password list 1 --uuid={UUID} --field=name` + Then STDOUT should be: + """ + myapp + """ + + When I run `wp user application-password list 1 --app_id=nosuchapp --format=count` + Then STDOUT should be: + """ + 0 + """ + + # 'created' and 'last_used' are integers in core but strings on the command + # line, so these only match if the comparison normalizes them. + When I run `wp user application-password list 1 --name=myapp --field=created` + Then STDOUT should not be empty + And save STDOUT as {CREATED} + + When I run `wp user application-password list 1 --created={CREATED} --field=name` + Then STDOUT should contain: + """ + myapp + """ + + When I run `wp user application-password list 1 --created=1 --format=count` + Then STDOUT should be: + """ + 0 + """ + + When I run `wp user application-password record-usage 1 {UUID}` + Then STDOUT should contain: + """ + Success: + """ + + When I run `wp user application-password list 1 --name=myapp --field=last_used` + Then STDOUT should not be empty + And save STDOUT as {LAST_USED} + + When I run `wp user application-password list 1 --last_used={LAST_USED} --field=name` + Then STDOUT should be: + """ + myapp + """ + + When I run `wp user application-password list 1 --last-used={LAST_USED} --field=name` + Then STDOUT should be: + """ + myapp + """ diff --git a/src/Site_Command.php b/src/Site_Command.php index f7735435a..a109b76e6 100644 --- a/src/Site_Command.php +++ b/src/Site_Command.php @@ -1001,6 +1001,40 @@ private function get_network( $network_id ) { * [--site-path=] * : Filter by path. Avoids conflict with the global `--path` parameter. * + * [--blog_id=] + * : Filter by site ID. + * + * [--site_id=] + * : Filter by the ID of the network the site belongs to. `--network` is an + * alias for this, and takes precedence when both are given. + * + * [--domain=] + * : Filter by domain. + * + * [--registered=] + * : Filter by the date the site was registered. + * + * [--last_updated=] + * : Filter by the date the site was last updated. + * + * [--public=] + * : Filter by whether the site is public. Accepts 1 or 0. + * + * [--archived=] + * : Filter by whether the site is archived. Accepts 1 or 0. + * + * [--mature=] + * : Filter by whether the site is flagged as mature. Accepts 1 or 0. + * + * [--spam=] + * : Filter by whether the site is flagged as spam. Accepts 1 or 0. + * + * [--deleted=] + * : Filter by whether the site is flagged as deleted. Accepts 1 or 0. + * + * [--lang_id=] + * : Filter by language ID. + * * [--field=] * : Prints the value of a single field for each site. * diff --git a/src/User_Application_Password_Command.php b/src/User_Application_Password_Command.php index 0dffef714..0281fee5d 100644 --- a/src/User_Application_Password_Command.php +++ b/src/User_Application_Password_Command.php @@ -81,6 +81,29 @@ final class User_Application_Password_Command { * [--=] * : Filter the list by a specific field. * + * [--uuid=] + * : Filter by the universally unique ID of the application password. + * + * [--app_id=] + * : Filter by the application ID. `--app-id` is also accepted. + * + * [--name=] + * : Filter by the name of the application password. + * + * [--password=] + * : Filter by the hashed password. + * + * [--created=] + * : Filter by the Unix timestamp the application password was created at. + * + * [--last_used=] + * : Filter by the Unix timestamp the application password was last used at. + * `--last-used` is also accepted. + * + * [--last_ip=] + * : Filter by the IP address the application password was last used from. + * `--last-ip` is also accepted. + * * [--field=] * : Prints the value of a single field for each application password. * @@ -186,10 +209,18 @@ static function ( $a, $b ) use ( $orderby, $order ) { $value = Utils\get_flag_value( $assoc_args, $field ); + // 'created' and 'last_used' come back from core as integers, while an + // argument always arrives as a string, so compare them as strings. + $filter_value = is_scalar( $value ) ? (string) $value : ''; + $application_passwords = array_filter( $application_passwords, - static function ( $application_password ) use ( $field, $value ) { - return $application_password[ $field ] === $value; + static function ( $application_password ) use ( $field, $filter_value ) { + $item_value = isset( $application_password[ $field ] ) && is_scalar( $application_password[ $field ] ) + ? (string) $application_password[ $field ] + : ''; + + return $item_value === $filter_value; } ); }