Skip to content

Commit 51af573

Browse files
committed
- update WPGraphQLAcfTestCase to create 2 images for use in testing (1 as the published image, 1 as the preview image, for example)
- update ImageFieldTest to test querying the image field on a post and querying the image field on a preview
1 parent a73075d commit 51af573

File tree

2 files changed

+53
-3
lines changed

2 files changed

+53
-3
lines changed

tests/_support/WPUnit/WPGraphQLAcfTestCase.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,22 @@ class WPGraphQLAcfTestCase extends \Tests\WPGraphQL\TestCase\WPGraphQLTestCase {
7878
public $test_image;
7979

8080
/**
81-
* @var \WP_Post
81+
* @var string
82+
*/
83+
public $test_image_2;
84+
85+
/**
86+
* @var int
8287
*/
8388
public $imageId;
8489

8590
/**
86-
* @var \WP_Post
91+
* @var int
92+
*/
93+
public $imageId_2;
94+
95+
/**
96+
* @var int
8797
*/
8898
public $fileId;
8999

@@ -103,6 +113,7 @@ public function setUp(): void {
103113
$this->is_acf_pro = in_array( 'advanced-custom-fields-pro/acf.php', $active_plugins, true );
104114

105115
$this->test_image = dirname( __FILE__, 3 ) . '/_data/images/test.png';
116+
$this->test_image_2 = dirname( __FILE__, 3 ) . '/_data/images/test2.png';
106117

107118
// create users for use within tests
108119
$this->admin = self::factory()->user->create_and_get( [ 'role' => 'administrator' ] );
@@ -165,6 +176,7 @@ public function setUp(): void {
165176
$this->fileId = self::factory()->attachment->create_upload_object( $this->test_image, 0 );
166177

167178
$this->imageId = self::factory()->attachment->create_upload_object( $this->test_image, $this->published_post->ID );
179+
$this->imageId_2 = self::factory()->attachment->create_upload_object( $this->test_image_2, $this->published_post->ID );
168180

169181
$this->menu_location_name = 'test-location';
170182
add_theme_support( 'nav_menus' );

tests/wpunit/FieldTypes/ImageFieldTest.php

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ public function setUp(): void {
99
parent::setUp();
1010
}
1111

12-
1312
/**
1413
* @return void
1514
*/
@@ -29,6 +28,44 @@ public function get_expected_field_resolve_kind(): ?string {
2928
return 'OBJECT';
3029
}
3130

31+
public function get_query_fragment(): string {
32+
return '
33+
fragment AcfTestGroupFragment on AcfTestGroup {
34+
testImage {
35+
node {
36+
__typename
37+
databaseId
38+
}
39+
}
40+
}';
41+
}
42+
43+
public function get_data_to_store() {
44+
return $this->imageId;
45+
}
46+
47+
public function get_expected_value() {
48+
return [
49+
'node' => [
50+
'__typename' => 'MediaItem',
51+
'databaseId' => $this->imageId
52+
]
53+
];
54+
}
55+
56+
public function get_preview_data_to_store() {
57+
return $this->imageId_2;
58+
}
59+
60+
public function get_expected_preview_value() {
61+
return [
62+
'node' => [
63+
'__typename' => 'MediaItem',
64+
'databaseId' => $this->imageId_2
65+
]
66+
];;
67+
}
68+
3269
public function get_block_query_fragment() {
3370
return '
3471
fragment BlockQueryFragment on AcfTestGroup {
@@ -46,6 +83,7 @@ public function get_block_data_to_store() {
4683
return $this->imageId;
4784
}
4885

86+
4987
public function get_expected_block_fragment_response() {
5088
return [
5189
'node' => [

0 commit comments

Comments
 (0)