@@ -996,6 +996,10 @@ Feature: Export content.
996996 Then STDOUT should be a number
997997 And save STDOUT as {EXPORT_CATEGORY_ID}
998998
999+ When I run `wp term create category National --parent={EXPORT_CATEGORY_ID} --porcelain`
1000+ Then STDOUT should be a number
1001+ And save STDOUT as {EXPORT_SUBCATEGORY_ID}
1002+
9991003 When I run `wp term create post_tag Tech --description="Technology-related" --porcelain`
10001004 Then STDOUT should be a number
10011005 And save STDOUT as {EXPORT_TAG_ID}
@@ -1028,6 +1032,10 @@ Feature: Export content.
10281032 """
10291033 <wp:term_id>{EXPORT_CATEGORY_ID}</wp:term_id>
10301034 """
1035+ And the {EXPORT_FILE} file should contain:
1036+ """
1037+ <wp:category_parent>news</wp:category_parent>
1038+ """
10311039 And the {EXPORT_FILE} file should contain:
10321040 """
10331041 <wp:cat_name><![CDATA[News]]></wp:cat_name>
@@ -1104,6 +1112,20 @@ Feature: Export content.
11041112 """
11051113 News
11061114 """
1115+ And STDOUT should contain:
1116+ """
1117+ National
1118+ """
1119+
1120+ When I run `wp term get category news --by=slug --field=id`
1121+ Then STDOUT should be a number
1122+ And save STDOUT as {IMPORT_CATEGORY_ID}
1123+
1124+ When I run `wp term get category national --by=slug --field=parent`
1125+ Then STDOUT should be:
1126+ """
1127+ {IMPORT_CATEGORY_ID}
1128+ """
11071129
11081130 When I run `wp term list post_tag`
11091131 Then STDOUT should contain:
@@ -1148,3 +1170,69 @@ Feature: Export content.
11481170 """
11491171 Test User
11501172 """
1173+
1174+ @require-wp-5.2
1175+ Scenario : Allow export to proceed when orphaned terms are found
1176+ Given a WP install
1177+ And I run `wp term create category orphan --parent=1`
1178+ And I run `wp term create category parent`
1179+ And I run `wp term create category child --parent=3`
1180+ And I run `wp term create post_tag atag`
1181+ And I run `wp term create post_tag btag`
1182+ And I run `wp term create post_tag ctag`
1183+ And I run `wp db query "DELETE FROM wp_terms WHERE term_id = 1" `
1184+
1185+ When I run `wp export --allow_orphan_terms`
1186+ Then save STDOUT 'Writing to file %s' as {EXPORT_FILE}
1187+ And the {EXPORT_FILE} file should contain:
1188+ """
1189+ <wp:category_nicename>orphan</wp:category_nicename>
1190+ """
1191+ And the {EXPORT_FILE} file should contain:
1192+ """
1193+ <wp:tag_slug>atag</wp:tag_slug>
1194+ """
1195+
1196+ When I run `wp site empty --yes`
1197+ And I run `wp plugin install wordpress-importer --activate`
1198+ And I run `wp import {EXPORT_FILE} --authors=skip`
1199+ Then STDOUT should contain:
1200+ """
1201+ Success:
1202+ """
1203+
1204+ When I run `wp term get post_tag atag --by=slug --field=id`
1205+ Then STDOUT should be a number
1206+
1207+ When I run `wp term get post_tag btag --by=slug --field=id`
1208+ Then STDOUT should be a number
1209+
1210+ When I run `wp term get post_tag ctag --by=slug --field=id`
1211+ Then STDOUT should be a number
1212+
1213+ When I run `wp term get category parent --by=slug --field=id`
1214+ Then STDOUT should be a number
1215+ And save STDOUT as {EXPORT_CATEGORY_PARENT_ID}
1216+
1217+ When I run `wp term get category child --by=slug --field=parent`
1218+ Then STDOUT should be:
1219+ """
1220+ {EXPORT_CATEGORY_PARENT_ID}
1221+ """
1222+
1223+ When I run `wp term get category orphan --by=slug --field=parent`
1224+ Then STDOUT should be:
1225+ """
1226+ 0
1227+ """
1228+
1229+ Scenario : Throw exception when orphaned terms are found
1230+ Given a WP install
1231+ And I run `wp term create category orphan --parent=1`
1232+ And I run `wp db query "DELETE FROM wp_terms WHERE term_id = 1" `
1233+
1234+ When I try `wp export`
1235+ Then STDERR should contain:
1236+ """
1237+ Error: Term is missing a parent
1238+ """
0 commit comments