44
55final class CorePostTermsTest extends PluginTestCase {
66
7+ /**
8+ * The URI of the post created for the test.
9+ *
10+ * @var string
11+ */
12+ public $ post_uri ;
13+
714 /**
815 * The ID of the post created for the test.
916 *
@@ -16,12 +23,15 @@ public function setUp(): void {
1623
1724 $ this ->post_id = wp_insert_post (
1825 [
19- 'post_title ' => 'Test Post ' ,
26+ 'post_title ' => 'Test Terms ' ,
27+ 'post_name ' => 'test-terms ' ,
2028 'post_content ' => '' ,
2129 'post_status ' => 'publish ' ,
2230 ]
2331 );
2432
33+ $ this ->post_uri = get_permalink ($ this ->post_id );
34+
2535 \WPGraphQL::clear_schema ();
2636 }
2737
@@ -33,24 +43,35 @@ public function tearDown(): void {
3343 }
3444
3545 /**
36- * Get the GraphQL query for the CorePostTerms block.
46+ * Get the updated GraphQL query for the CorePostTerms block.
3747 */
3848 public function query (): string {
3949 return '
40- query TestPostTerms($id: ID!) {
41- post(id: $id, idType: DATABASE_ID) {
42- databaseId
43- editorBlocks {
44- __typename
45- ... on CorePostTerms {
46- prefix
47- suffix
48- taxonomySlug
49- terms {
50- __typename
51- nodes {
52- id
53- name
50+ query TestPostTerms($uri: String! = "test-terms") {
51+ nodeByUri(uri: $uri) {
52+ id
53+ uri
54+ ... on NodeWithPostEditorBlocks {
55+ editorBlocks {
56+ __typename
57+ ... on CorePostTerms {
58+ prefix
59+ suffix
60+ taxonomy {
61+ __typename
62+ node {
63+ __typename
64+ id
65+ name
66+ }
67+ }
68+ terms {
69+ __typename
70+ nodes {
71+ __typename
72+ id
73+ name
74+ }
5475 }
5576 }
5677 }
@@ -61,7 +82,7 @@ public function query(): string {
6182 }
6283
6384 /**
64- * Test that the CorePostTerms block retrieves attributes and terms correctly.
85+ * Test that the CorePostTerms block retrieves attributes, taxonomy, and terms correctly.
6586 */
6687 public function test_retrieve_core_post_terms (): void {
6788 $ block_content = '<!-- wp:post-terms {"prefix":"Before","suffix":"After","term":"category"} /--> ' ;
@@ -73,13 +94,12 @@ public function test_retrieve_core_post_terms(): void {
7394 ]
7495 );
7596
76- $ variables = [ 'id ' => $ this -> post_id ];
97+ $ variables = [ 'uri ' => ' test-terms ' ];
7798 $ query = $ this ->query ();
7899 $ actual = graphql (compact ('query ' , 'variables ' ));
79100
80- $ node = $ actual ['data ' ]['post ' ];
101+ $ node = $ actual ['data ' ]['nodeByUri ' ];
81102
82- $ this ->assertEquals ($ this ->post_id , $ node ['databaseId ' ]);
83103 $ this ->assertArrayHasKey ('editorBlocks ' , $ node );
84104 $ this ->assertCount (1 , $ node ['editorBlocks ' ]);
85105
@@ -88,12 +108,25 @@ public function test_retrieve_core_post_terms(): void {
88108 $ this ->assertEquals ('CorePostTerms ' , $ block ['__typename ' ]);
89109 $ this ->assertEquals ('Before ' , $ block ['prefix ' ]);
90110 $ this ->assertEquals ('After ' , $ block ['suffix ' ]);
91- $ this ->assertEquals ('category ' , $ block ['taxonomySlug ' ]);
111+
112+ $ this ->assertArrayHasKey ('taxonomy ' , $ block );
113+ $ this ->assertArrayHasKey ('node ' , $ block ['taxonomy ' ]);
114+ $ this ->assertArrayHasKey ('__typename ' , $ block ['taxonomy ' ]['node ' ]);
115+ $ this ->assertArrayHasKey ('id ' , $ block ['taxonomy ' ]['node ' ]);
116+ $ this ->assertArrayHasKey ('name ' , $ block ['taxonomy ' ]['node ' ]);
92117
93118 $ this ->assertArrayHasKey ('terms ' , $ block );
94119 $ this ->assertArrayHasKey ('nodes ' , $ block ['terms ' ]);
95120 $ this ->assertIsArray ($ block ['terms ' ]['nodes ' ]);
96-
97121 $ this ->assertEquals ('CorePostTermsToTermNodeConnection ' , $ block ['terms ' ]['__typename ' ]);
122+ $ this ->assertEquals ('Category ' , $ block ['terms ' ]['nodes ' ][0 ]['__typename ' ]);
123+
124+ $ this ->assertArrayHasKey ('taxonomy ' , $ block );
125+ $ this ->assertArrayHasKey ('node ' , $ block ['taxonomy ' ]);
126+ $ this ->assertIsArray ($ block ['taxonomy ' ]['node ' ]);
127+ $ this ->assertEquals ('CorePostTermsToTaxonomyConnectionEdge ' , $ block ['taxonomy ' ]['__typename ' ]);
128+ $ this ->assertEquals ('category ' , $ block ['taxonomy ' ]['node ' ]['name ' ]);
129+
130+
98131 }
99132}
0 commit comments