-
Notifications
You must be signed in to change notification settings - Fork 94
Expand file tree
/
Copy pathterm-migrate.feature
More file actions
152 lines (120 loc) · 5.15 KB
/
term-migrate.feature
File metadata and controls
152 lines (120 loc) · 5.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
Feature: Migrate term custom fields
@require-wp-4.4
Scenario: Migrate an existing term by slug
Given a WP install
When I run `wp term create category apple`
Then STDOUT should not be empty
When I run `wp post create --post_title='Test post' --porcelain`
Then STDOUT should be a number
And save STDOUT as {POST_ID}
When I run `wp post term set {POST_ID} category apple`
Then STDOUT should not be empty
When I run `wp term migrate apple --by=slug --from=category --to=post_tag`
Then STDOUT should be:
"""
Term 'apple' assigned to post {POST_ID}.
Term 'apple' migrated.
Old instance of term 'apple' removed from its original taxonomy.
Success: Migrated the term 'apple' from taxonomy 'category' to taxonomy 'post_tag' for 1 post.
"""
@require-wp-4.4
Scenario: Migrate an existing term by ID
Given a WP install
When I run `wp term create category apple --porcelain`
Then STDOUT should be a number
And save STDOUT as {TERM_ID}
When I run `wp post create --post_title='Test post' --porcelain`
Then STDOUT should be a number
And save STDOUT as {POST_ID}
When I run `wp post term set {POST_ID} category {TERM_ID}`
Then STDOUT should not be empty
When I run `wp term migrate {TERM_ID} --by=slug --from=category --to=post_tag`
Then STDOUT should be:
"""
Term '{TERM_ID}' assigned to post {POST_ID}.
Term '{TERM_ID}' migrated.
Old instance of term '{TERM_ID}' removed from its original taxonomy.
Success: Migrated the term '{TERM_ID}' from taxonomy 'category' to taxonomy 'post_tag' for 1 post.
"""
@require-wp-4.4
Scenario: Migrate a term in multiple posts
Given a WP install
When I run `wp term create category orange`
Then STDOUT should not be empty
When I run `wp post create --post_title='Test post' --porcelain`
Then STDOUT should be a number
And save STDOUT as {POST_ID}
When I run `wp post term set {POST_ID} category orange`
Then STDOUT should not be empty
When I run `wp post create --post_title='Test post 2' --porcelain`
Then STDOUT should be a number
And save STDOUT as {POST_ID_2}
When I run `wp post term set {POST_ID_2} category orange`
Then STDOUT should not be empty
When I run `wp term migrate orange --by=slug --from=category --to=post_tag`
Then STDOUT should be:
"""
Term 'orange' assigned to post {POST_ID}.
Term 'orange' assigned to post {POST_ID_2}.
Term 'orange' migrated.
Old instance of term 'orange' removed from its original taxonomy.
Success: Migrated the term 'orange' from taxonomy 'category' to taxonomy 'post_tag' for 2 posts.
"""
@require-wp-4.4
Scenario: Try to migrate a term that does not exist
Given a WP install
When I try `wp term migrate peach --by=slug --from=category --to=post_tag`
Then STDERR should be:
"""
Error: Taxonomy term 'peach' for taxonomy 'category' doesn't exist.
"""
@require-wp-4.4
Scenario: Migrate a term when posts have been migrated to a different post type that supports the destination taxonomy
Given a WP install
And a wp-content/mu-plugins/test-migrate.php file:
"""
<?php
// Plugin Name: Test Migrate
add_action( 'init', function() {
register_post_type( 'news', [ 'public' => true ] );
register_taxonomy( 'topic', 'news', [ 'public' => true ] );
} );
"""
When I run `wp term create category grape`
Then STDOUT should not be empty
When I run `wp post create --post_title='Test post' --post_type=post --porcelain`
Then STDOUT should be a number
And save STDOUT as {POST_ID}
When I run `wp post term set {POST_ID} category grape`
Then STDOUT should not be empty
When I run `wp post update {POST_ID} --post_type=news`
Then STDOUT should not be empty
When I run `wp term migrate grape --by=slug --from=category --to=topic`
Then STDOUT should be:
"""
Term 'grape' assigned to post {POST_ID}.
Term 'grape' migrated.
Old instance of term 'grape' removed from its original taxonomy.
Success: Migrated the term 'grape' from taxonomy 'category' to taxonomy 'topic' for 1 post.
"""
@require-wp-4.4
Scenario: Migrate a term warns when post type is not registered with destination taxonomy
Given a WP install
When I run `wp term create category grape`
Then STDOUT should not be empty
When I run `wp post create --post_title='Test post' --post_type=post --porcelain`
Then STDOUT should be a number
And save STDOUT as {POST_ID}
When I run `wp post term set {POST_ID} category grape`
Then STDOUT should not be empty
When I run `wp post update {POST_ID} --post_type=page`
Then STDOUT should not be empty
When I try `wp term migrate grape --by=slug --from=category --to=post_tag`
Then STDERR should contain:
"""
Warning: Term 'grape' not assigned to post {POST_ID}. Post type 'page' is not registered with taxonomy 'post_tag'.
"""
And STDOUT should contain:
"""
Success: Migrated the term 'grape' from taxonomy 'category' to taxonomy 'post_tag' for 0 posts.
"""