22
33class OptionsPageTest extends \Tests \WPGraphQL \Acf \WPUnit \WPGraphQLAcfTestCase {
44
5-
65 public function setUp ():void {
6+
77 if ( ! function_exists ( 'acf_add_options_page ' ) ) {
88 $ this ->markTestSkipped ( 'ACF Options Pages are not available in this test environment ' );
99 }
@@ -15,13 +15,14 @@ public function tearDown(): void {
1515 parent ::tearDown ();
1616 }
1717
18- public function registerOptionsPage ( $ title = 'My Options Page ' , $ config = [] ) {
1918
2019
20+ public function registerOptionsPage ( $ config = [] ) {
21+
2122 // register options page
2223 acf_add_options_page (
2324 array_merge ( [
24- 'page_title ' => $ title ,
25+ 'page_title ' => ' My Options Page ' ,
2526 'menu_title ' => __ ( 'My Options Page ' ),
2627 'menu_slug ' => 'my-options-page ' ,
2728 'capability ' => 'edit_posts ' ,
@@ -40,7 +41,7 @@ public function testAcfOptionsPageIsQueryableInSchema() {
4041 // Save a value to the ACF Option Field
4142 // see: https://www.advancedcustomfields.com/resources/update_field/#update-a-value-from-different-objects
4243 if ( function_exists ( 'update_field ' ) ) {
43- update_field ( 'text ' , $ expected_value , 'option ' );
44+ update_field ( 'text ' , $ expected_value , 'options ' );
4445 }
4546
4647 $ this ->register_acf_field ( [], [
@@ -103,7 +104,7 @@ public function testAcfOptionsPageIsQueryableInSchema() {
103104 */
104105 public function testOptionsPageNotInSchemaIfShowInGraphqlIsFalse () {
105106
106- acf_add_options_page (
107+ $ this -> registerOptionsPage (
107108 [
108109 'page_title ' => 'ShowInGraphQLFalse ' ,
109110 'menu_title ' => __ ( 'Show in GraphQL False ' ),
@@ -175,24 +176,44 @@ public function testOptionsPageNotInSchemaIfShowInGraphqlIsFalse() {
175176
176177 // - options page shows with different name if "graphql_field_name" is set
177178 public function testOptionsPageRespectsGraphqlFieldName () {
178- acf_add_options_page (
179+
180+ $ this ->registerOptionsPage (
179181 [
180182 'page_title ' => 'CustomGraphqlName ' ,
181- 'menu_title ' => __ ( 'Show in GraphQL False ' ),
183+ 'menu_title ' => __ ( 'Custom GraphQL Name ' ),
182184 'menu_slug ' => 'custom-graphql-name ' ,
183185 'capability ' => 'edit_posts ' ,
186+ 'post_id ' => 'custom-graphql-name ' ,
184187 // options pages will show in the Schema unless set to false
185188 'graphql_type_name ' => 'MyCustomOptionsName ' ,
186189 ]
187190 );
188191
189- $ expected_value = uniqid ( 'test ' , true ) ;
192+ $ expected_value = 'test value ' ;
190193
191194 // Save a value to the ACF Option Field
192195 // see: https://www.advancedcustomfields.com/resources/update_field/#update-a-value-from-different-objects
193- if ( function_exists ( 'update_field ' ) ) {
194- update_field ( 'text ' , $ expected_value , 'option ' );
195- }
196+ update_field ( 'text ' , $ expected_value , 'custom-graphql-name ' );
197+ $ get_field = get_field ( 'text ' , 'custom-graphql-name ' );
198+
199+ codecept_debug ( [
200+ '$get_field ' => $ get_field ,
201+ '$options_pages ' => acf_get_options_pages (),
202+ ]);
203+
204+ $ this ->assertSame ( $ expected_value , $ get_field );
205+
206+ $ this ->registerOptionsPage (
207+ [
208+ 'page_title ' => 'CustomGraphqlName ' ,
209+ 'menu_title ' => __ ( 'Custom GraphQL Name ' ),
210+ 'menu_slug ' => 'custom-graphql-name ' ,
211+ 'capability ' => 'edit_posts ' ,
212+ 'post_id ' => 'custom-graphql-name ' ,
213+ // options pages will show in the Schema unless set to false
214+ 'graphql_type_name ' => 'MyCustomOptionsName ' ,
215+ ]
216+ );
196217
197218 $ this ->register_acf_field ( [], [
198219 'graphql_field_name ' => 'OptionsFields ' ,
@@ -221,6 +242,10 @@ public function testOptionsPageRespectsGraphqlFieldName() {
221242 'query ' => $ query ,
222243 ]);
223244
245+ codecept_debug ( [
246+ '$get_field ' => $ get_field ,
247+ ]);
248+
224249 self ::assertQuerySuccessful ( $ actual , [
225250 // the instructions should be used for the description
226251 $ this ->expectedField ( 'myCustomOptionsName.optionsFields.text ' , $ expected_value ),
@@ -248,7 +273,7 @@ public function testOptionsPageRespectsGraphqlFieldName() {
248273
249274 public function testQueryOptionsPageAsNode () {
250275
251- acf_add_options_page (
276+ $ this -> registerOptionsPage (
252277 [
253278 'page_title ' => 'OptionsPageNode ' ,
254279 'menu_title ' => __ ( 'Options Page Node ' ),
0 commit comments