Skip to content

Commit 631282e

Browse files
committed
- added api-functional test for product fragment
1 parent 2b5720c commit 631282e

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\GraphQl\Catalog;
9+
10+
use Magento\TestFramework\TestCase\GraphQlAbstract;
11+
12+
/**
13+
* Test for simple product fragment.
14+
*/
15+
class ProductFragmentTest extends GraphQlAbstract
16+
{
17+
/**
18+
* @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
19+
*/
20+
public function testSimpleProductFragment()
21+
{
22+
$sku = 'simple';
23+
$name = 'Simple Product';
24+
$price = 10;
25+
26+
$query = <<<QUERY
27+
query GetProduct {
28+
products(filter: { sku: { eq: "$sku" } }) {
29+
items {
30+
sku
31+
...BasicProductInformation
32+
}
33+
}
34+
}
35+
36+
fragment BasicProductInformation on ProductInterface {
37+
sku
38+
name
39+
price {
40+
regularPrice {
41+
amount {
42+
value
43+
}
44+
}
45+
}
46+
}
47+
QUERY;
48+
$result = $this->graphQlQuery($query);
49+
$actualProductData = $result['products']['items'][0];
50+
$this->assertNotEmpty($actualProductData);
51+
$this->assertEquals($name, $actualProductData['name']);
52+
$this->assertEquals($price, $actualProductData['price']['regularPrice']['amount']['value']);
53+
}
54+
}

0 commit comments

Comments
 (0)