@@ -105,15 +105,22 @@ public function get_expected_block_fragment_response() {
105105 return null ;
106106 }
107107
108- /***
108+ /**
109+ * Test class should override this with the fragment to test with
110+ *
109111 * @return string
110112 */
111113 public function get_query_fragment (): string {
112- return '
113- fragment QueryFragment on AcfTestGroup {
114- testText
115- }
116- ' ;
114+ return 'null ' ;
115+ }
116+
117+ /**
118+ * Test class should override this with the expected value
119+ *
120+ * @return mixed
121+ */
122+ public function get_expected_value () {
123+ return 'null ' ;
117124 }
118125
119126 /**
@@ -971,12 +978,57 @@ public function testFieldWithNoGraphqlFieldNameAndNameThatStartsWithNumberDoesNo
971978 acf_remove_local_field ( $ field_key );
972979 }
973980
981+ public function testQueryFieldOnPostReturnsExpectedValue () {
982+ $ field_key = $ this ->register_acf_field ();
983+
984+ // Save data to the post
985+ update_field ( $ field_key , $ this ->get_data_to_store (), $ this ->published_post ->ID );
986+
987+ $ fragment = $ this ->get_query_fragment ();
988+
989+ if ( 'null ' === $ fragment ) {
990+ $ this ->markTestIncomplete ( 'get_query_fragment() not defined ' );
991+ }
992+
993+ $ expected_value = $ this ->get_expected_value ();
994+
995+ if ( 'null ' === $ expected_value ) {
996+ $ this ->markTestIncomplete ( 'get_expected_value() not defined ' );
997+ }
998+
999+ $ query = '
1000+ query AcfFieldOnPost ($id: ID!) {
1001+ post( id: $id idType: DATABASE_ID) {
1002+ databaseId
1003+ __typename
1004+ ...on WithAcfAcfTestGroup {
1005+ acfTestGroup {
1006+ ...AcfTestGroupFragment
1007+ }
1008+ }
1009+ }
1010+ }
1011+ ' . $ fragment ;
1012+
1013+ $ actual = $ this ->graphql ([
1014+ 'query ' => $ query ,
1015+ 'variables ' => [
1016+ 'id ' => $ this ->published_post ->ID ,
1017+ ]
1018+ ]);
1019+
1020+ self ::assertQuerySuccessful ( $ actual , [
1021+ $ this ->expectedField ( 'post.databaseId ' , $ this ->published_post ->ID ),
1022+ $ this ->expectedField ( 'post.__typename ' , 'Post ' ),
1023+ $ this ->expectedField ( 'post.acfTestGroup. ' . $ this ->get_formatted_field_name (), $ this ->get_expected_value () )
1024+ ]);
9741025
9751026
1027+ }
1028+
9761029 /**
9771030 * @todo: implement the below tests
9781031 */
979- // abstract public function testQueryFieldOnPostReturnsExpectedValue();
9801032// abstract public function testQueryFieldOnPageReturnsExpectedValue();
9811033// abstract public function testQueryFieldOnCommentReturnsExpectedValue();
9821034// abstract public function testQueryFieldOnTagReturnsExpectedValue();
@@ -1088,7 +1140,7 @@ public function get_expected_clone_value() {
10881140 */
10891141 public function testQueryCloneFieldOnPost (): void {
10901142
1091- $ this ->markTestIncomplete ( 'Clone Fields are being refactored... ' );
1143+ // $this->markTestIncomplete( 'Clone Fields are being refactored...' );
10921144
10931145 // if ACF PRO is not active, skip the test
10941146 if ( ! defined ( 'ACF_PRO ' ) ) {
0 commit comments