@@ -98,4 +98,122 @@ public function get_expected_block_fragment_response() {
9898 ];
9999 }
100100
101+ /**
102+ * @see: https://github.com/wp-graphql/wpgraphql-acf/issues/184
103+ * @see: https://github.com/wp-graphql/wpgraphql-acf/issues/151
104+ * @return void
105+ */
106+ public function testCloneGroupFieldResolvesDataAsExpected () {
107+
108+ // if ACF PRO is not active, skip the test
109+ if ( ! defined ( 'ACF_PRO ' ) ) {
110+ $ this ->markTestSkipped ( 'ACF Pro is not active so this test will not run. ' );
111+ }
112+
113+ $ field_key = $ this ->register_acf_field ([
114+ 'key ' => 'field_65df9360bebef ' ,
115+ 'label ' => 'My Text Field ' ,
116+ 'name ' => 'my_text_field ' ,
117+ 'type ' => 'text ' ,
118+ 'show_in_graphql ' => 1 ,
119+ 'graphql_field_name ' => 'myTextField ' ,
120+ 'graphql_non_null ' => 0 ,
121+ ], [
122+ 'key ' => 'group_65df9360afcb0 ' ,
123+ 'graphql_field_name ' => 'myCollectionOfFieldTypes ' ,
124+ 'show_in_graphql ' => 1 ,
125+ 'map_graphql_types_from_location_rules ' => 0 ,
126+ 'graphql_types ' => '' ,
127+ 'location ' => [
128+ [
129+ [
130+ 'param ' => 'post_type ' ,
131+ 'operator ' => '== ' ,
132+ 'value ' => 'post ' ,
133+ ],
134+ ],
135+ ],
136+ 'active ' => true ,
137+ ]);
138+
139+
140+ $ cloned_field_key = $ this ->register_acf_field ([
141+ 'label ' => 'My Group Field ' ,
142+ 'name ' => 'my_group_field ' ,
143+ 'show_in_graphql ' => 1 ,
144+ 'type ' => 'group ' ,
145+ 'graphql_field_name ' => 'myGroupField ' ,
146+ 'graphql_non_null ' => 0 ,
147+ 'sub_fields ' => [
148+ [
149+ 'key ' => 'field_65e1ff262ce23 ' ,
150+ 'label ' => 'Clone of My Collection of Field Types (no prefix) ' ,
151+ 'name ' => 'clone_of_my_collection_of_field_types_no_prefix ' ,
152+ 'type ' => 'clone ' ,
153+ 'graphql_field_name ' => 'cloneOfMyCollectionOfFieldTypesNoPrefix ' ,
154+ 'clone ' => [
155+ 'group_65df9360afcb0 '
156+ ],
157+ 'prefix_name ' => 0 ,
158+ ]
159+ ]
160+ ], [
161+ 'key ' => 'group_65e1feb751e7d ' ,
162+ 'title ' => 'My Group with Clone ' ,
163+ 'location ' => [
164+ [
165+ [
166+ 'param ' => 'page_template ' ,
167+ 'operator ' => '== ' ,
168+ 'value ' => 'default ' ,
169+ ],
170+ ],
171+ ],
172+ 'graphql_field_name ' => 'myGroupWithClone ' ,
173+ 'show_in_graphql ' => 1 ,
174+ 'graphql_types ' => [ 'DefaultTemplate ' ],
175+ 'active ' => true ,
176+ ]);
177+
178+ $ query = '
179+ query NewQuery($id:ID!) {
180+ page(id: $id, idType: DATABASE_ID) {
181+ databaseId
182+ template {
183+ ... on DefaultTemplate {
184+ myGroupWithClone {
185+ myGroupField {
186+ myTextField
187+ }
188+ }
189+ }
190+ }
191+ }
192+ }
193+ ' ;
194+
195+ // save text value to the cloned field's meta key
196+ $ expected_text_value = 'text field value... ' ;
197+ update_field ( 'my_group_field_my_text_field ' , $ expected_text_value , $ this ->published_page ->ID );
198+
199+ $ actual = $ this ->graphql ([
200+ 'query ' => $ query ,
201+ 'variables ' => [
202+ 'id ' => $ this ->published_page ->ID ,
203+ ]
204+ ]);
205+
206+
207+
208+ codecept_debug ( [
209+ '$actual ' => $ actual ,
210+ ]);
211+
212+ self ::assertQuerySuccessful ( $ actual , [
213+ $ this ->expectedField ( 'page.databaseId ' , $ this ->published_page ->ID ),
214+ $ this ->expectedField ( 'page.template.myGroupWithClone.myGroupField.myTextField ' , $ expected_text_value ),
215+ ]);
216+
217+ }
218+
101219}
0 commit comments