@@ -109,6 +109,62 @@ public function getQuery() {
109109 ' ;
110110 }
111111
112+ public function testConnectedTermsConnectionReturnsTermNodesOfExpectedTaxonomies () {
113+ $ term_one_id = self ::factory ()->term ->create (
114+ [
115+ 'taxonomy ' => 'category ' ,
116+ 'name ' => 'Term One ' ,
117+ ]
118+ );
119+
120+ $ term_two_id = self ::factory ()->term ->create (
121+ [
122+ 'taxonomy ' => 'post_tag ' ,
123+ 'name ' => 'Term Two ' ,
124+ ]
125+ );
126+
127+ $ query = '
128+ query GetConnectedTerms {
129+ taxonomies {
130+ nodes {
131+ name
132+ connectedTerms {
133+ nodes {
134+ __typename
135+ databaseId
136+ name
137+ uri
138+ }
139+ }
140+ }
141+ }
142+ }
143+ ' ;
144+
145+ $ actual = $ this ->graphql ([
146+ 'query ' => $ query
147+ ]);
148+
149+ // codecept_debug( [ '$actual' => $actual ]);
150+ $ this ->assertArrayNotHasKey ( 'errors ' , $ actual );
151+
152+ // map over the connected terms nodes and assert that all of them are category
153+ $ connected_categories = $ actual ['data ' ]['taxonomies ' ]['nodes ' ][0 ]['connectedTerms ' ]['nodes ' ];
154+ foreach ( $ connected_categories as $ connected_category ) {
155+ $ this ->assertEquals ( 'Category ' , $ connected_category ['__typename ' ] );
156+ }
157+
158+ // map over the connected terms nodes and assert that all of them are tags
159+ $ connected_tags = $ actual ['data ' ]['taxonomies ' ]['nodes ' ][1 ]['connectedTerms ' ]['nodes ' ];
160+ foreach ( $ connected_tags as $ connected_tag ) {
161+ $ this ->assertEquals ( 'Tag ' , $ connected_tag ['__typename ' ] );
162+ }
163+
164+ wp_delete_term ( $ term_one_id , 'category ' );
165+ wp_delete_term ( $ term_two_id , 'post_tag ' );
166+ }
167+
112168 public function testForwardPagination () {
113169 $ query = $ this ->getQuery ();
114170 $ wp_query = new WP_Term_Query ();
@@ -945,4 +1001,5 @@ public function testPaginateTermsWithDuplicateNamesAndOrderbyName() {
9451001
9461002 wp_delete_term ( $ parent_category , 'category ' );
9471003 }
1004+
9481005}
0 commit comments