88
99namespace Magento \GraphQl \Catalog \Product ;
1010
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 ;
1115use Magento \TestFramework \TestCase \GraphQlAbstract ;
1216
1317/**
1620class ProductCategoriesTest extends GraphQlAbstract
1721{
1822 /**
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
2035 */
2136 public function testProductCategoriesInDefaultStore (): void
2237 {
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+
2351 $ response = $ this ->graphQlQuery (
2452 $ this ->getQuery ('in-stock-product ' ),
2553 [],
@@ -33,15 +61,38 @@ public function testProductCategoriesInDefaultStore(): void
3361 self ::assertCount (1 , $ categories );
3462 self ::assertEquals ('Category 1 ' , $ categories [0 ]['name ' ]);
3563 self ::assertEquals ('category-1 ' , $ categories [0 ]['url_path ' ]);
36- self ::assertEquals ('category-1 ' , $ categories [0 ]['url_path ' ]);
3764 self ::assertNull ($ categories [0 ]['breadcrumbs ' ]);
3865 }
3966
4067 /**
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
4280 */
4381 public function testProductCategoriesInNonDefaultStore (): void
4482 {
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+
4596 $ response = $ this ->graphQlQuery (
4697 $ this ->getQuery ('in-stock-product ' ),
4798 [],
@@ -64,8 +115,19 @@ public function testProductCategoriesInNonDefaultStore(): void
64115 }
65116
66117 /**
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$"}
68127 * @magentoApiDataFixture Magento/Store/_files/second_store.php
128+ * @magentoDbIsolation disabled
129+ * @magentoAppArea adminhtml
130+ * phpcs:enable Generic.Files.LineLength.TooLong
69131 */
70132 public function testProductCategoriesInNotRelevantStore (): void
71133 {
0 commit comments