From acc8de086a3d559fcb362e38c62aa27a380dfb73 Mon Sep 17 00:00:00 2001 From: ernilambar Date: Thu, 26 May 2016 14:51:57 +0545 Subject: [PATCH 1/4] Accept multiple term IDs in term url --- php/commands/term.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/php/commands/term.php b/php/commands/term.php index c92fb8b263..9a275fb2ae 100644 --- a/php/commands/term.php +++ b/php/commands/term.php @@ -409,11 +409,14 @@ public function generate( $args, $assoc_args ) { * wp term url post_tag 123 324 */ public function url( $args ) { - $term_link = get_term_link( (int)$args[1], $args[0] ); - if ( $term_link && ! is_wp_error( $term_link ) ) { - WP_CLI::line( $term_link ); - } else { - WP_CLI::error( "Invalid term." ); + $term_ids = array_slice( $args, 1 ); + foreach ( $term_ids as $term_id ) { + $term_link = get_term_link( (int)$term_id, $args[0] ); + if ( $term_link && ! is_wp_error( $term_link ) ) { + WP_CLI::line( $term_link ); + } else { + WP_CLI::warning( sprintf( "Invalid term %d.", $term_id ) ); + } } } From 5c5d624ddc08d7794a332bcbfa85e9100539ea1c Mon Sep 17 00:00:00 2001 From: ernilambar Date: Thu, 26 May 2016 14:55:22 +0545 Subject: [PATCH 2/4] Use string placeholder for error message in term url --- php/commands/term.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/commands/term.php b/php/commands/term.php index 9a275fb2ae..8df6543672 100644 --- a/php/commands/term.php +++ b/php/commands/term.php @@ -415,7 +415,7 @@ public function url( $args ) { if ( $term_link && ! is_wp_error( $term_link ) ) { WP_CLI::line( $term_link ); } else { - WP_CLI::warning( sprintf( "Invalid term %d.", $term_id ) ); + WP_CLI::warning( sprintf( "Invalid term %s.", $term_id ) ); } } } From 32df792a12752165ee13b03cf01c8b45241eeea6 Mon Sep 17 00:00:00 2001 From: ernilambar Date: Thu, 26 May 2016 17:28:32 +0545 Subject: [PATCH 3/4] Add tests for term url --- features/term.feature | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/features/term.feature b/features/term.feature index 91781bdb90..61b598328e 100644 --- a/features/term.feature +++ b/features/term.feature @@ -92,3 +92,22 @@ Feature: Manage WordPress terms """ My Test Category """ + + Scenario: Fetch term url + When I run `wp term create category "First Category" --porcelain` + And save STDOUT as {TERM_ID_1} + And I run `wp term create category "Second Category" --porcelain` + And save STDOUT as {TERM_ID_2} + + When I run `wp term url category {TERM_ID_1}` + Then STDOUT should be: + """ + http://localhost:8001/category/first-category + """ + + When I run `wp term url category {TERM_ID_1} {TERM_ID_2}` + Then STDOUT should be: + """ + http://localhost:8001/category/first-category + http://localhost:8001/category/second-category + """ From 43d312fc3ebd5cb464664e2979841eab4f977c07 Mon Sep 17 00:00:00 2001 From: Nilambar Sharma Date: Sat, 28 May 2016 07:21:03 +0545 Subject: [PATCH 4/4] fix strange test issue in term url --- features/term.feature | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/features/term.feature b/features/term.feature index 61b598328e..d2e45f1ea3 100644 --- a/features/term.feature +++ b/features/term.feature @@ -95,19 +95,19 @@ Feature: Manage WordPress terms Scenario: Fetch term url When I run `wp term create category "First Category" --porcelain` - And save STDOUT as {TERM_ID_1} + And save STDOUT as {TERM_ID} And I run `wp term create category "Second Category" --porcelain` - And save STDOUT as {TERM_ID_2} + And save STDOUT as {SECOND_TERM_ID} - When I run `wp term url category {TERM_ID_1}` + When I run `wp term url category {TERM_ID}` Then STDOUT should be: """ - http://localhost:8001/category/first-category + http://example.com/?cat=2 """ - When I run `wp term url category {TERM_ID_1} {TERM_ID_2}` + When I run `wp term url category {TERM_ID} {SECOND_TERM_ID}` Then STDOUT should be: """ - http://localhost:8001/category/first-category - http://localhost:8001/category/second-category + http://example.com/?cat=2 + http://example.com/?cat=3 """