8
8
9
9
namespace Magento \GraphQl \Catalog \Product ;
10
10
11
+ use Magento \Catalog \Api \Data \ProductInterface ;
12
+ use Magento \Catalog \Api \ProductRepositoryInterface ;
13
+ use Magento \Store \Api \WebsiteRepositoryInterface ;
14
+ use Magento \TestFramework \Helper \Bootstrap ;
11
15
use Magento \TestFramework \TestCase \GraphQlAbstract ;
12
16
13
17
/**
16
20
class ProductCategoriesTest extends GraphQlAbstract
17
21
{
18
22
/**
19
- * @magentoApiDataFixture Magento/Catalog/_files/product_in_two_root_categories.php
23
+ * phpcs:disable Generic.Files.LineLength.TooLong
24
+ * @magentoDataFixture Magento/Catalog/_files/category.php
25
+ * @magentoDataFixture Magento\Catalog\Test\Fixture\Category with:{"name":"Second Root Category","parent_id":"1","position":"2"} as:c1
26
+ * @magentoDataFixture Magento\Catalog\Test\Fixture\Category with:{"name":"Second Root Subcategory","parent_id":"$c1.id$","level":"2"} as:c2
27
+ * @magentoDataFixture Magento\Catalog\Test\Fixture\Category with:{"name":"Second Root Subsubcategory","parent_id":"$c2.id$","level":"2"} as:c3
28
+ * @magentoDataFixture Magento\Catalog\Test\Fixture\Product with:{"name":"Simple Product In Stock","sku":"in-stock-product","category_ids":["2","333","$c1.id$","$c2.id$","$c3.id$"]}
29
+ * @magentoDataFixture Magento\Store\Test\Fixture\Website with:{"code":"test","name":"Test Website","default_group_id":"1"} as:w2
30
+ * @magentoDataFixture Magento\Store\Test\Fixture\Group with:{"code":"test_store_group_1","name":"Test Store Group","website_id":"$w2.id$","root_category_id":"$c1.id$"} as:s2
31
+ * @magentoDataFixture Magento\Store\Test\Fixture\Store with:{"code":"test_store_1","name":"Test Store","website_id":"$w2.id$","store_group_id":"$s2.id$"}
32
+ * @magentoDbIsolation disabled
33
+ * @magentoAppArea adminhtml
34
+ * phpcs:enable Generic.Files.LineLength.TooLong
20
35
*/
21
36
public function testProductCategoriesInDefaultStore (): void
22
37
{
38
+ $ objectManager = Bootstrap::getObjectManager ();
39
+ $ websiteRepository = $ objectManager ->get (WebsiteRepositoryInterface::class);
40
+ $ defaultWebsiteId = $ websiteRepository ->get ('base ' )->getId ();
41
+ $ secondWebsiteId = $ websiteRepository ->get ('test ' )->getId ();
42
+
43
+ $ productRepository = $ objectManager ->get (ProductRepositoryInterface::class);
44
+ /** @var $product ProductInterface */
45
+ $ product = $ productRepository ->get ('in-stock-product ' );
46
+ $ product
47
+ ->setUrlKey ('in-stock-product ' )
48
+ ->setWebsiteIds ([$ defaultWebsiteId , $ secondWebsiteId ]);
49
+ $ productRepository ->save ($ product );
50
+
23
51
$ response = $ this ->graphQlQuery (
24
52
$ this ->getQuery ('in-stock-product ' ),
25
53
[],
@@ -33,15 +61,38 @@ public function testProductCategoriesInDefaultStore(): void
33
61
self ::assertCount (1 , $ categories );
34
62
self ::assertEquals ('Category 1 ' , $ categories [0 ]['name ' ]);
35
63
self ::assertEquals ('category-1 ' , $ categories [0 ]['url_path ' ]);
36
- self ::assertEquals ('category-1 ' , $ categories [0 ]['url_path ' ]);
37
64
self ::assertNull ($ categories [0 ]['breadcrumbs ' ]);
38
65
}
39
66
40
67
/**
41
- * @magentoApiDataFixture Magento/Catalog/_files/product_in_two_root_categories.php
68
+ * phpcs:disable Generic.Files.LineLength.TooLong
69
+ * @magentoDataFixture Magento/Catalog/_files/category.php
70
+ * @magentoDataFixture Magento\Catalog\Test\Fixture\Category with:{"name":"Second Root Category","parent_id":"1","position":"2"} as:c1
71
+ * @magentoDataFixture Magento\Catalog\Test\Fixture\Category with:{"name":"Second Root Subcategory","parent_id":"$c1.id$","level":"2"} as:c2
72
+ * @magentoDataFixture Magento\Catalog\Test\Fixture\Category with:{"name":"Second Root Subsubcategory","parent_id":"$c2.id$","level":"2"} as:c3
73
+ * @magentoDataFixture Magento\Catalog\Test\Fixture\Product with:{"name":"Simple Product In Stock","sku":"in-stock-product","category_ids":["2","333","$c1.id$","$c2.id$","$c3.id$"]}
74
+ * @magentoDataFixture Magento\Store\Test\Fixture\Website with:{"code":"test","name":"Test Website","default_group_id":"1"} as:w2
75
+ * @magentoDataFixture Magento\Store\Test\Fixture\Group with:{"code":"test_store_group_1","name":"Test Store Group","website_id":"$w2.id$","root_category_id":"$c1.id$"} as:s2
76
+ * @magentoDataFixture Magento\Store\Test\Fixture\Store with:{"code":"test_store_1","name":"Test Store","website_id":"$w2.id$","store_group_id":"$s2.id$"}
77
+ * @magentoDbIsolation disabled
78
+ * @magentoAppArea adminhtml
79
+ * phpcs:enable Generic.Files.LineLength.TooLong
42
80
*/
43
81
public function testProductCategoriesInNonDefaultStore (): void
44
82
{
83
+ $ objectManager = Bootstrap::getObjectManager ();
84
+ $ websiteRepository = $ objectManager ->get (WebsiteRepositoryInterface::class);
85
+ $ defaultWebsiteId = $ websiteRepository ->get ('base ' )->getId ();
86
+ $ secondWebsiteId = $ websiteRepository ->get ('test ' )->getId ();
87
+
88
+ $ productRepository = $ objectManager ->get (ProductRepositoryInterface::class);
89
+ /** @var $product ProductInterface */
90
+ $ product = $ productRepository ->get ('in-stock-product ' );
91
+ $ product
92
+ ->setUrlKey ('in-stock-product ' )
93
+ ->setWebsiteIds ([$ defaultWebsiteId , $ secondWebsiteId ]);
94
+ $ productRepository ->save ($ product );
95
+
45
96
$ response = $ this ->graphQlQuery (
46
97
$ this ->getQuery ('in-stock-product ' ),
47
98
[],
@@ -64,8 +115,19 @@ public function testProductCategoriesInNonDefaultStore(): void
64
115
}
65
116
66
117
/**
67
- * @magentoApiDataFixture Magento/Catalog/_files/product_in_two_root_categories.php
118
+ * phpcs:disable Generic.Files.LineLength.TooLong
119
+ * @magentoDataFixture Magento/Catalog/_files/category.php
120
+ * @magentoDataFixture Magento\Catalog\Test\Fixture\Category with:{"name":"Second Root Category","parent_id":"1","position":"2"} as:c1
121
+ * @magentoDataFixture Magento\Catalog\Test\Fixture\Category with:{"name":"Second Root Subcategory","parent_id":"$c1.id$","level":"2"} as:c2
122
+ * @magentoDataFixture Magento\Catalog\Test\Fixture\Category with:{"name":"Second Root Subsubcategory","parent_id":"$c2.id$","level":"2"} as:c3
123
+ * @magentoDataFixture Magento\Catalog\Test\Fixture\Product with:{"name":"Simple Product In Stock","sku":"in-stock-product","category_ids":["2","333","$c1.id$","$c2.id$","$c3.id$"]}
124
+ * @magentoDataFixture Magento\Store\Test\Fixture\Website with:{"code":"test","name":"Test Website","default_group_id":"1"} as:w2
125
+ * @magentoDataFixture Magento\Store\Test\Fixture\Group with:{"code":"test_store_group_1","name":"Test Store Group","website_id":"$w2.id$","root_category_id":"$c1.id$"} as:s2
126
+ * @magentoDataFixture Magento\Store\Test\Fixture\Store with:{"code":"test_store_1","name":"Test Store","website_id":"$w2.id$","store_group_id":"$s2.id$"}
68
127
* @magentoApiDataFixture Magento/Store/_files/second_store.php
128
+ * @magentoDbIsolation disabled
129
+ * @magentoAppArea adminhtml
130
+ * phpcs:enable Generic.Files.LineLength.TooLong
69
131
*/
70
132
public function testProductCategoriesInNotRelevantStore (): void
71
133
{
0 commit comments