-
Notifications
You must be signed in to change notification settings - Fork 94
Expand file tree
/
Copy pathterm-prune.feature
More file actions
137 lines (113 loc) · 4.09 KB
/
term-prune.feature
File metadata and controls
137 lines (113 loc) · 4.09 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
Feature: Prune unused taxonomy terms
Background:
Given a WP install
Scenario: Prune terms with no published posts
When I run `wp term create post_tag 'Unused Tag' --slug=unused-tag --porcelain`
Then STDOUT should be a number
And save STDOUT as {TERM_ID}
When I run `wp term prune post_tag`
Then STDOUT should contain:
"""
Deleted post_tag {TERM_ID}.
"""
And STDOUT should contain:
"""
Success:
"""
And the return code should be 0
When I try `wp term get post_tag {TERM_ID}`
Then STDERR should contain:
"""
Error: Term doesn't exist.
"""
Scenario: Does not prune terms with more than one published post
When I run `wp term create post_tag 'Popular Tag' --slug=popular-tag --porcelain`
Then STDOUT should be a number
And save STDOUT as {TERM_ID}
When I run `wp post create --post_title='Post 1' --post_status=publish --porcelain`
Then STDOUT should be a number
And save STDOUT as {POST_ID_1}
When I run `wp post create --post_title='Post 2' --post_status=publish --porcelain`
Then STDOUT should be a number
And save STDOUT as {POST_ID_2}
When I run `wp post term set {POST_ID_1} post_tag {TERM_ID} --by=id`
Then STDOUT should not be empty
When I run `wp post term set {POST_ID_2} post_tag {TERM_ID} --by=id`
Then STDOUT should not be empty
When I run `wp term prune post_tag`
Then STDOUT should not contain:
"""
Deleted post_tag {TERM_ID}.
"""
When I run `wp term get post_tag {TERM_ID} --field=name`
Then STDOUT should be:
"""
Popular Tag
"""
Scenario: Prune terms with exactly one published post
When I run `wp term create post_tag 'Single Post Tag' --slug=single-post-tag --porcelain`
Then STDOUT should be a number
And save STDOUT as {TERM_ID}
When I run `wp post create --post_title='Post 1' --post_status=publish --porcelain`
Then STDOUT should be a number
And save STDOUT as {POST_ID}
When I run `wp post term set {POST_ID} post_tag {TERM_ID} --by=id`
Then STDOUT should not be empty
When I run `wp term prune post_tag`
Then STDOUT should contain:
"""
Deleted post_tag {TERM_ID}.
"""
And the return code should be 0
When I try `wp term get post_tag {TERM_ID}`
Then STDERR should contain:
"""
Error: Term doesn't exist.
"""
Scenario: Dry run previews terms without deleting them
When I run `wp term create post_tag 'Unused Tag' --slug=unused-tag --porcelain`
Then STDOUT should be a number
And save STDOUT as {TERM_ID}
When I run `wp term prune post_tag --dry-run`
Then STDOUT should contain:
"""
Would delete post_tag {TERM_ID}.
"""
And STDOUT should contain:
"""
Success:
"""
And the return code should be 0
When I run `wp term get post_tag {TERM_ID} --field=name`
Then STDOUT should be:
"""
Unused Tag
"""
Scenario: Prune with an invalid taxonomy
When I try `wp term prune nonexistent_taxonomy`
Then STDERR should be:
"""
Error: Taxonomy nonexistent_taxonomy doesn't exist.
"""
And the return code should be 1
Scenario: Prune multiple taxonomies at once
# Assign an extra post to the default Uncategorized category so its count
# exceeds the prune threshold and it won't interfere with the test.
When I run `wp post create --post_title='Extra Post' --post_status=publish --post_category=1 --porcelain`
Then STDOUT should be a number
When I run `wp term create post_tag 'Unused Tag' --slug=unused-tag --porcelain`
Then STDOUT should be a number
And save STDOUT as {TAG_TERM_ID}
When I run `wp term create category 'Unused Category' --slug=unused-category --porcelain`
Then STDOUT should be a number
And save STDOUT as {CAT_TERM_ID}
When I run `wp term prune post_tag category`
Then STDOUT should contain:
"""
Deleted post_tag {TAG_TERM_ID}.
"""
And STDOUT should contain:
"""
Deleted category {CAT_TERM_ID}.
"""
And the return code should be 0