Skip to content

Commit f816458

Browse files
committed
adding tests
1 parent 3cedb9e commit f816458

File tree

2 files changed

+70
-5
lines changed

2 files changed

+70
-5
lines changed

features/term-migrate.feature

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
Feature: Manage term custom fields
2+
3+
@require-wp-4.4
4+
Scenario: Migrate a term that exist
5+
Given a WP install
6+
7+
When I run `wp term create category apple`
8+
Then STDOUT should not be empty
9+
10+
When I run `wp post create --post_title='Test post' --porcelain`
11+
Then STDOUT should be a number
12+
And save STDOUT as {POST_ID}
13+
14+
When I run `wp post term set {POST_ID} category apple`
15+
Then STDOUT should not be empty
16+
17+
When I run `wp term migrate apple --by=slug --from=category --to=post_tag`
18+
Then STDOUT should be:
19+
"""
20+
Term 'apple' assigned to post 4.
21+
Term 'apple' migrated!
22+
Old instance of term 'apple' removed from its original taxonomy.
23+
Success: Migrated the term 'apple' from taxonomy 'category' to taxonomy 'post_tag' for 1 post
24+
"""
25+
26+
Scenario: Migrate a term in multiple posts
27+
Given a WP install
28+
29+
When I run `wp term create category orange`
30+
Then STDOUT should not be empty
31+
32+
When I run `wp post create --post_title='Test post' --porcelain`
33+
Then STDOUT should be a number
34+
And save STDOUT as {POST_ID}
35+
36+
When I run `wp post term set {POST_ID} category orange`
37+
Then STDOUT should not be empty
38+
39+
When I run `wp post create --post_title='Test post 2' --porcelain`
40+
Then STDOUT should be a number
41+
And save STDOUT as {POST_ID}
42+
43+
When I run `wp post term set {POST_ID} category orange`
44+
Then STDOUT should not be empty
45+
46+
When I run `wp term migrate orange --by=slug --from=category --to=post_tag`
47+
Then STDOUT should be:
48+
"""
49+
Term 'orange' assigned to post 4.
50+
Term 'orange' assigned to post 5.
51+
Term 'orange' migrated!
52+
Old instance of term 'orange' removed from its original taxonomy.
53+
Success: Migrated the term 'orange' from taxonomy 'category' to taxonomy 'post_tag' for 2 posts
54+
"""
55+
56+
@require-wp-4.4
57+
Scenario: Migrate a term that not exist
58+
Given a WP install
59+
60+
When I run `wp term migrate peach --by=slug --from=category --to=post_tag`
61+
Then STDERR should be:
62+
"""
63+
Error: Taxonomy term `peach` for taxonomy `category` doesn't exist.
64+
"""

src/Term_Command.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -663,8 +663,9 @@ public function recount( $args ) {
663663
*
664664
* # Migrate a category's term (video) to tag taxonomy.
665665
* $ wp term migrate 9190 --from=category --to=post_tag
666-
* Post 219060 assigned to new term!
667-
* Success: Migration of `9190` term for 1 posts
666+
* Term '9190' migrated!
667+
* Old instance of term '9190' removed from its original taxonomy.
668+
* Success: Migrated the term '9190' from taxonomy 'category' to taxonomy 'post_tag' for 1 posts
668669
*/
669670
public function migrate( $args, $assoc_args ) {
670671
$clean_term_cache = $values = array();
@@ -713,10 +714,10 @@ public function migrate( $args, $assoc_args ) {
713714
WP_CLI::error( "On deleting the term, " . $del->get_error_message() );
714715
}
715716

716-
WP_CLI::log( "Old instance of term '{$term->slug} removed from its original taxonomy." );
717-
$post_count = count( $posts );
717+
WP_CLI::log( "Old instance of term '{$term->slug}' removed from its original taxonomy." );
718+
$post_count = count( $post_ids );
718719
$post_plural = WP_CLI\Utils\pluralize( 'post', $post_count );
719-
WP_CLI::success( "Migrated the term '{$term->slug}' from taxonomy '{original_taxonomy}' to taxonomy '{destination_taxonomy}' for {$post_count} {$post_plural}" );
720+
WP_CLI::success( "Migrated the term '{$term->slug}' from taxonomy '{$original_taxonomy->name}' to taxonomy '{$destination_taxonomy}' for {$post_count} {$post_plural}" );
720721
}
721722

722723
private function maybe_make_child() {

0 commit comments

Comments
 (0)