From fe91fc52901e4aad5624b77d7acb80ba36adc702 Mon Sep 17 00:00:00 2001 From: Geoff Taylor Date: Mon, 13 Jul 2020 19:17:28 -0400 Subject: [PATCH] Product gallery image test added. --- tests/wpunit/ProductQueriesTest.php | 43 +++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/tests/wpunit/ProductQueriesTest.php b/tests/wpunit/ProductQueriesTest.php index e721ce2b..b2846f56 100644 --- a/tests/wpunit/ProductQueriesTest.php +++ b/tests/wpunit/ProductQueriesTest.php @@ -1261,4 +1261,47 @@ class ProductQueriesTest extends \Codeception\TestCase\WPTestCase { $this->assertEquals( $expected, $actual ); } + + public function testProductGalleryImagesConnection() { + $image_id = $this->factory->post->create( + array( + 'post_type' => 'attachment', + 'post_content' => 'Lorem ipsum dolor...', + ) + ); + $product_id = $this->helper->create_simple( + array( 'gallery_image_ids' => array( $image_id ) ) + ); + + $query = ' + query( $id: ID! ) { + product( id: $id ) { + galleryImages { + nodes { + id + } + } + } + } + '; + + $variables = array( 'id' => $this->helper->to_relay_id( $product_id ) ); + $actual = graphql( array( 'query' => $query, 'variables' => $variables ) ); + $expected = array( + 'data' => array( + 'product' => array ( + 'galleryImages' => array( + 'nodes' => array( + array( 'id' => \GraphQLRelay\Relay::toGlobalId( 'post', $image_id ) ) + ) + ) + ), + ), + ); + + // use --debug flag to view. + codecept_debug( $actual ); + + $this->assertEquals( $expected, $actual ); + } }