|
| 1 | +Feature: Prune unused taxonomy terms |
| 2 | + |
| 3 | + Background: |
| 4 | + Given a WP install |
| 5 | + |
| 6 | + Scenario: Prune terms with no published posts |
| 7 | + When I run `wp term create post_tag 'Unused Tag' --slug=unused-tag --porcelain` |
| 8 | + Then STDOUT should be a number |
| 9 | + And save STDOUT as {TERM_ID} |
| 10 | + |
| 11 | + When I run `wp term prune post_tag` |
| 12 | + Then STDOUT should contain: |
| 13 | + """ |
| 14 | + Deleted post_tag {TERM_ID}. |
| 15 | + """ |
| 16 | + And STDOUT should contain: |
| 17 | + """ |
| 18 | + Success: |
| 19 | + """ |
| 20 | + And the return code should be 0 |
| 21 | + |
| 22 | + When I try `wp term get post_tag {TERM_ID}` |
| 23 | + Then STDERR should contain: |
| 24 | + """ |
| 25 | + Error: Term doesn't exist. |
| 26 | + """ |
| 27 | + |
| 28 | + Scenario: Does not prune terms with more than one published post |
| 29 | + When I run `wp term create post_tag 'Popular Tag' --slug=popular-tag --porcelain` |
| 30 | + Then STDOUT should be a number |
| 31 | + And save STDOUT as {TERM_ID} |
| 32 | + |
| 33 | + When I run `wp post create --post_title='Post 1' --post_status=publish --porcelain` |
| 34 | + Then STDOUT should be a number |
| 35 | + And save STDOUT as {POST_ID_1} |
| 36 | + |
| 37 | + When I run `wp post create --post_title='Post 2' --post_status=publish --porcelain` |
| 38 | + Then STDOUT should be a number |
| 39 | + And save STDOUT as {POST_ID_2} |
| 40 | + |
| 41 | + When I run `wp post term set {POST_ID_1} post_tag {TERM_ID} --by=id` |
| 42 | + Then STDOUT should not be empty |
| 43 | + |
| 44 | + When I run `wp post term set {POST_ID_2} post_tag {TERM_ID} --by=id` |
| 45 | + Then STDOUT should not be empty |
| 46 | + |
| 47 | + When I run `wp term prune post_tag` |
| 48 | + Then STDOUT should not contain: |
| 49 | + """ |
| 50 | + Deleted post_tag {TERM_ID}. |
| 51 | + """ |
| 52 | + |
| 53 | + When I run `wp term get post_tag {TERM_ID} --field=name` |
| 54 | + Then STDOUT should be: |
| 55 | + """ |
| 56 | + Popular Tag |
| 57 | + """ |
| 58 | + |
| 59 | + Scenario: Prune terms with exactly one published post |
| 60 | + When I run `wp term create post_tag 'Single Post Tag' --slug=single-post-tag --porcelain` |
| 61 | + Then STDOUT should be a number |
| 62 | + And save STDOUT as {TERM_ID} |
| 63 | + |
| 64 | + When I run `wp post create --post_title='Post 1' --post_status=publish --porcelain` |
| 65 | + Then STDOUT should be a number |
| 66 | + And save STDOUT as {POST_ID} |
| 67 | + |
| 68 | + When I run `wp post term set {POST_ID} post_tag {TERM_ID} --by=id` |
| 69 | + Then STDOUT should not be empty |
| 70 | + |
| 71 | + When I run `wp term prune post_tag` |
| 72 | + Then STDOUT should contain: |
| 73 | + """ |
| 74 | + Deleted post_tag {TERM_ID}. |
| 75 | + """ |
| 76 | + And the return code should be 0 |
| 77 | + |
| 78 | + When I try `wp term get post_tag {TERM_ID}` |
| 79 | + Then STDERR should contain: |
| 80 | + """ |
| 81 | + Error: Term doesn't exist. |
| 82 | + """ |
| 83 | + |
| 84 | + Scenario: Dry run previews terms without deleting them |
| 85 | + When I run `wp term create post_tag 'Unused Tag' --slug=unused-tag --porcelain` |
| 86 | + Then STDOUT should be a number |
| 87 | + And save STDOUT as {TERM_ID} |
| 88 | + |
| 89 | + When I run `wp term prune post_tag --dry-run` |
| 90 | + Then STDOUT should contain: |
| 91 | + """ |
| 92 | + Would delete post_tag {TERM_ID}. |
| 93 | + """ |
| 94 | + And STDOUT should contain: |
| 95 | + """ |
| 96 | + Success: |
| 97 | + """ |
| 98 | + And the return code should be 0 |
| 99 | + |
| 100 | + When I run `wp term get post_tag {TERM_ID} --field=name` |
| 101 | + Then STDOUT should be: |
| 102 | + """ |
| 103 | + Unused Tag |
| 104 | + """ |
| 105 | + |
| 106 | + Scenario: Prune with an invalid taxonomy |
| 107 | + When I try `wp term prune nonexistent_taxonomy` |
| 108 | + Then STDERR should be: |
| 109 | + """ |
| 110 | + Error: Taxonomy nonexistent_taxonomy doesn't exist. |
| 111 | + """ |
| 112 | + And the return code should be 1 |
| 113 | + |
| 114 | + Scenario: Prune multiple taxonomies at once |
| 115 | + # Assign an extra post to the default Uncategorized category so its count |
| 116 | + # exceeds the prune threshold and it won't interfere with the test. |
| 117 | + When I run `wp post create --post_title='Extra Post' --post_status=publish --post_category=1 --porcelain` |
| 118 | + Then STDOUT should be a number |
| 119 | + |
| 120 | + When I run `wp term create post_tag 'Unused Tag' --slug=unused-tag --porcelain` |
| 121 | + Then STDOUT should be a number |
| 122 | + And save STDOUT as {TAG_TERM_ID} |
| 123 | + |
| 124 | + When I run `wp term create category 'Unused Category' --slug=unused-category --porcelain` |
| 125 | + Then STDOUT should be a number |
| 126 | + And save STDOUT as {CAT_TERM_ID} |
| 127 | + |
| 128 | + When I run `wp term prune post_tag category` |
| 129 | + Then STDOUT should contain: |
| 130 | + """ |
| 131 | + Deleted post_tag {TAG_TERM_ID}. |
| 132 | + """ |
| 133 | + And STDOUT should contain: |
| 134 | + """ |
| 135 | + Deleted category {CAT_TERM_ID}. |
| 136 | + """ |
| 137 | + And the return code should be 0 |
0 commit comments