|
7 | 7 |
|
8 | 8 | namespace Magento\GraphQl\Catalog;
|
9 | 9 |
|
| 10 | +use Magento\Catalog\Test\Fixture\Category as CategoryFixture; |
| 11 | +use Magento\Catalog\Test\Fixture\Product as ProductFixture; |
| 12 | +use Magento\Framework\Exception\LocalizedException; |
| 13 | +use Magento\TestFramework\Fixture\DataFixture; |
| 14 | +use Magento\TestFramework\Fixture\DataFixtureStorageManager; |
10 | 15 | use Magento\TestFramework\TestCase\GraphQlAbstract;
|
11 | 16 |
|
12 | 17 | /**
|
@@ -214,6 +219,79 @@ public function testProductMediaGalleryEntries()
|
214 | 219 | );
|
215 | 220 | }
|
216 | 221 |
|
| 222 | + /** |
| 223 | + * Tests the sorting of media gallery entries by their position attribute for a given product. |
| 224 | + * |
| 225 | + * @return void |
| 226 | + * @throws LocalizedException |
| 227 | + */ |
| 228 | + #[ |
| 229 | + DataFixture(CategoryFixture::class, ['name' => 'Category'], 'category'), |
| 230 | + DataFixture( |
| 231 | + ProductFixture::class, |
| 232 | + [ |
| 233 | + 'name' => 'Product 1', |
| 234 | + 'sku' => 'product-1', |
| 235 | + 'category_ids' => ['$category.id$'], |
| 236 | + 'price' => 10, |
| 237 | + 'media_gallery_entries' => [ |
| 238 | + [ |
| 239 | + 'label' => 'image', |
| 240 | + 'media_type' => 'image', |
| 241 | + 'position' => 0, |
| 242 | + 'disabled' => false, |
| 243 | + 'types' => [ |
| 244 | + 'image', |
| 245 | + 'small_image', |
| 246 | + 'thumbnail' |
| 247 | + ], |
| 248 | + 'file' => '/m/product1.jpg', |
| 249 | + ], |
| 250 | + [ |
| 251 | + 'label' => 'image', |
| 252 | + 'media_type' => 'image', |
| 253 | + 'position' => 2, |
| 254 | + 'disabled' => false, |
| 255 | + 'file' => '/m/product3.jpg', |
| 256 | + ], |
| 257 | + [ |
| 258 | + 'label' => 'image', |
| 259 | + 'media_type' => 'image', |
| 260 | + 'position' => 1, |
| 261 | + 'disabled' => false, |
| 262 | + 'file' => '/m/product2.jpg', |
| 263 | + ], |
| 264 | + ], |
| 265 | + ], |
| 266 | + 'product1' |
| 267 | + ), |
| 268 | + ] |
| 269 | + public function testProductMediaGalleryEntriesPositionSort() |
| 270 | + { |
| 271 | + $product = DataFixtureStorageManager::getStorage()->get('product1'); |
| 272 | + $productSku = $product->getSku(); |
| 273 | + $query = <<<QUERY |
| 274 | +{ |
| 275 | + products(filter: {sku: {eq: "{$productSku}"}}) { |
| 276 | + items { |
| 277 | + name |
| 278 | + sku |
| 279 | + media_gallery_entries { |
| 280 | + id |
| 281 | + position |
| 282 | + file |
| 283 | + } |
| 284 | + } |
| 285 | + } |
| 286 | +} |
| 287 | +QUERY; |
| 288 | + $response = $this->graphQlQuery($query); |
| 289 | + self::assertCount(3, $response['products']['items'][0]['media_gallery_entries']); |
| 290 | + foreach ($response['products']['items'][0]['media_gallery_entries'] as $key => $mediaGalleryEntry) { |
| 291 | + self::assertEquals($key, $mediaGalleryEntry['position']); |
| 292 | + } |
| 293 | + } |
| 294 | + |
217 | 295 | /**
|
218 | 296 | * @param string $url
|
219 | 297 | * @return bool
|
|
0 commit comments