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
+ use Magento \Catalog \Test \Fixture \Category as CategoryFixture ;
12
+ use Magento \Catalog \Test \Fixture \Product as ProductFixture ;
13
+ use Magento \Store \Test \Fixture \Group as GroupFixture ;
14
+ use Magento \Store \Test \Fixture \Store as StoreFixture ;
15
+ use Magento \Store \Test \Fixture \Website as WebsiteFixture ;
16
+ use Magento \TestFramework \Fixture \AppArea ;
17
+ use Magento \TestFramework \Fixture \DataFixture ;
18
+ use Magento \TestFramework \Fixture \DataFixtureStorageManager ;
15
19
use Magento \TestFramework \TestCase \GraphQlAbstract ;
16
20
17
21
/**
18
22
* Test for product categories
19
23
*/
20
24
class ProductCategoriesTest extends GraphQlAbstract
21
25
{
22
- /**
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
35
- */
26
+ #[
27
+ AppArea('adminhtml ' ),
28
+ DataFixture(CategoryFixture::class, ['name ' => 'Category 1 ' , 'parent_id ' => '2 ' ], 'c11 ' ),
29
+ DataFixture(CategoryFixture::class, ['name ' => 'Category 2 ' , 'parent_id ' => '1 ' ], 'c2 ' ),
30
+ DataFixture(CategoryFixture::class, ['name ' => 'Category 2.1 ' , 'parent_id ' => '$c2.id$ ' ], 'c21 ' ),
31
+ DataFixture(CategoryFixture::class, ['name ' => 'Category 2.1.1 ' , 'parent_id ' => '$c21.id$ ' ], 'c211 ' ),
32
+ DataFixture(WebsiteFixture::class, as: 'w2 ' ),
33
+ DataFixture(GroupFixture::class, ['website_id ' => '$w2.id$ ' , 'root_category_id ' => '$c2.id$ ' ], 's2 ' ),
34
+ DataFixture(StoreFixture::class, ['store_group_id ' => '$s2.id$ ' ]),
35
+ DataFixture(
36
+ ProductFixture::class,
37
+ [
38
+ 'sku ' => 'in-stock-product ' ,
39
+ 'category_ids ' => ['2 ' , '$c11.id$ ' , '$c2.id$ ' , '$c21.id$ ' , '$c211.id$ ' ],
40
+ 'website_ids ' => ['1 ' , '$w2.id$ ' ]
41
+ ],
42
+ ),
43
+ ]
36
44
public function testProductCategoriesInDefaultStore (): void
37
45
{
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
-
51
46
$ response = $ this ->graphQlQuery (
52
47
$ this ->getQuery ('in-stock-product ' ),
53
48
[],
@@ -64,78 +59,77 @@ public function testProductCategoriesInDefaultStore(): void
64
59
self ::assertNull ($ categories [0 ]['breadcrumbs ' ]);
65
60
}
66
61
67
- /**
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
80
- */
62
+ #[
63
+ AppArea('adminhtml ' ),
64
+ DataFixture(CategoryFixture::class, ['name ' => 'Category 1 ' , 'parent_id ' => '2 ' ], 'c11 ' ),
65
+ DataFixture(CategoryFixture::class, ['name ' => 'Category 2 ' , 'parent_id ' => '1 ' ], 'c2 ' ),
66
+ DataFixture(CategoryFixture::class, ['name ' => 'Category 2.1 ' , 'parent_id ' => '$c2.id$ ' ], 'c21 ' ),
67
+ DataFixture(CategoryFixture::class, ['name ' => 'Category 2.1.1 ' , 'parent_id ' => '$c21.id$ ' ], 'c211 ' ),
68
+ DataFixture(WebsiteFixture::class, as: 'w2 ' ),
69
+ DataFixture(GroupFixture::class, ['website_id ' => '$w2.id$ ' , 'root_category_id ' => '$c2.id$ ' ], 's2 ' ),
70
+ DataFixture(StoreFixture::class, ['store_group_id ' => '$s2.id$ ' ], as: 'store2 ' ),
71
+ DataFixture(
72
+ ProductFixture::class,
73
+ [
74
+ 'sku ' => 'in-stock-product ' ,
75
+ 'category_ids ' => ['2 ' , '$c11.id$ ' , '$c2.id$ ' , '$c21.id$ ' , '$c211.id$ ' ],
76
+ 'website_ids ' => ['1 ' , '$w2.id$ ' ]
77
+ ],
78
+ ),
79
+ ]
81
80
public function testProductCategoriesInNonDefaultStore (): void
82
81
{
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 );
82
+ $ fixtures = DataFixtureStorageManager::getStorage ();
83
+ $ storeCode = $ fixtures ->get ('store2 ' )->getCode ();
95
84
96
85
$ response = $ this ->graphQlQuery (
97
86
$ this ->getQuery ('in-stock-product ' ),
98
87
[],
99
88
'' ,
100
- ['Store ' => ' test_store_1 ' ]
89
+ ['Store ' => $ storeCode ]
101
90
);
102
91
103
92
$ product = current ($ response ['products ' ]['items ' ]);
104
93
$ categories = $ product ['categories ' ];
105
94
106
95
self ::assertCount (2 , $ categories );
107
- self ::assertEquals ('Second Root Subcategory ' , $ categories [0 ]['name ' ]);
108
- self ::assertEquals ('second-root-subcategory ' , $ categories [0 ]['url_path ' ]);
96
+ self ::assertEquals ('Category 2.1 ' , $ categories [0 ]['name ' ]);
97
+ self ::assertEquals ('category-2-1 ' , $ categories [0 ]['url_path ' ]);
109
98
self ::assertNull ($ categories [0 ]['breadcrumbs ' ]);
110
- self ::assertEquals ('Second Root Subsubcategory ' , $ categories [1 ]['name ' ]);
111
- self ::assertEquals ('second-root-subcategory/second-root-subsubcategory ' , $ categories [1 ]['url_path ' ]);
99
+ self ::assertEquals ('Category 2.1.1 ' , $ categories [1 ]['name ' ]);
100
+ self ::assertEquals ('category-2-1/category-2-1-1 ' , $ categories [1 ]['url_path ' ]);
112
101
self ::assertCount (1 , $ categories [1 ]['breadcrumbs ' ]);
113
- self ::assertEquals ('Second Root Subcategory ' , $ categories [1 ]['breadcrumbs ' ][0 ]['category_name ' ]);
102
+ self ::assertEquals ('Category 2.1 ' , $ categories [1 ]['breadcrumbs ' ][0 ]['category_name ' ]);
114
103
self ::assertEquals (2 , $ categories [1 ]['breadcrumbs ' ][0 ]['category_level ' ]);
115
104
}
116
105
117
- /**
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$"}
127
- * @magentoApiDataFixture Magento/Store/_files/second_store.php
128
- * @magentoDbIsolation disabled
129
- * @magentoAppArea adminhtml
130
- * phpcs:enable Generic.Files.LineLength.TooLong
131
- */
106
+ #[
107
+ AppArea('adminhtml ' ),
108
+ DataFixture(CategoryFixture::class, ['name ' => 'Category 1 ' , 'parent_id ' => '2 ' ], 'c11 ' ),
109
+ DataFixture(CategoryFixture::class, ['name ' => 'Category 2 ' , 'parent_id ' => '1 ' ], 'c2 ' ),
110
+ DataFixture(CategoryFixture::class, ['name ' => 'Category 2.1 ' , 'parent_id ' => '$c2.id$ ' ], 'c21 ' ),
111
+ DataFixture(CategoryFixture::class, ['name ' => 'Category 2.1.1 ' , 'parent_id ' => '$c21.id$ ' ], 'c211 ' ),
112
+ DataFixture(WebsiteFixture::class, as: 'w2 ' ),
113
+ DataFixture(GroupFixture::class, ['website_id ' => '$w2.id$ ' , 'root_category_id ' => '$c2.id$ ' ], 's2 ' ),
114
+ DataFixture(StoreFixture::class, ['store_group_id ' => '$s2.id$ ' ], as: 'store2 ' ),
115
+ DataFixture(
116
+ ProductFixture::class,
117
+ [
118
+ 'sku ' => 'in-stock-product ' ,
119
+ 'category_ids ' => ['2 ' , '$c11.id$ ' , '$c2.id$ ' , '$c21.id$ ' , '$c211.id$ ' ]
120
+ ],
121
+ ),
122
+ ]
132
123
public function testProductCategoriesInNotRelevantStore (): void
133
124
{
125
+ $ fixtures = DataFixtureStorageManager::getStorage ();
126
+ $ storeCode = $ fixtures ->get ('store2 ' )->getCode ();
127
+
134
128
$ response = $ this ->graphQlQuery (
135
129
$ this ->getQuery ('in-stock-product ' ),
136
130
[],
137
131
'' ,
138
- ['Store ' => ' fixture_second_store ' ]
132
+ ['Store ' => $ storeCode ]
139
133
);
140
134
141
135
self ::assertEmpty ($ response ['products ' ]['items ' ]);
0 commit comments