@@ -146,14 +146,60 @@ public function testFilterByCategoryUrlPath()
146
146
}
147
147
}
148
148
149
+ /**
150
+ * Filter by multiple categories url paths
151
+ *
152
+ * @magentoApiDataFixture Magento/Catalog/_files/categories.php
153
+ * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
154
+ */
155
+ public function testFilterByMultipleCategoriesUrlPaths ()
156
+ {
157
+ $ categoriesPath = ['category-1/category-1-2 ' ,'category-1/category-1-1 ' ];
158
+
159
+ $ query = <<<QUERY
160
+ {
161
+ products(filter:{
162
+ category_url_path : {in:[" {$ categoriesPath [0 ]}"," {$ categoriesPath [1 ]}"]}
163
+ }) {
164
+ total_count
165
+ items {
166
+ name
167
+ sku
168
+ }
169
+ }
170
+ }
171
+ QUERY ;
172
+ $ response = $ this ->graphQlQuery ($ query );
173
+ $ this ->assertEquals (3 , $ response ['products ' ]['total_count ' ]);
174
+ /** @var ProductRepositoryInterface $productRepository */
175
+ $ productRepository = ObjectManager::getInstance ()->get (ProductRepositoryInterface::class);
176
+ $ product1 = $ productRepository ->get ('simple ' );
177
+ $ product2 = $ productRepository ->get ('12345 ' );
178
+ $ product3 = $ productRepository ->get ('simple-4 ' );
179
+ $ filteredProducts = [$ product3 , $ product2 , $ product1 ];
180
+ $ productItemsInResponse = array_map (null , $ response ['products ' ]['items ' ], $ filteredProducts );
181
+ //phpcs:ignore Generic.CodeAnalysis.ForLoopWithTestFunctionCall
182
+ for ($ itemIndex = 0 ; $ itemIndex < count ($ filteredProducts ); $ itemIndex ++) {
183
+ $ this ->assertNotEmpty ($ productItemsInResponse [$ itemIndex ]);
184
+ //validate that correct products are returned
185
+ $ this ->assertResponseFields (
186
+ $ productItemsInResponse [$ itemIndex ][0 ],
187
+ [
188
+ 'name ' => $ filteredProducts [$ itemIndex ]->getName (),
189
+ 'sku ' => $ filteredProducts [$ itemIndex ]->getSku ()
190
+ ]
191
+ );
192
+ }
193
+ }
194
+
149
195
/**
150
196
* Filter by wrong category url path
151
197
*
152
198
* @magentoApiDataFixture Magento/Catalog/_files/categories.php
153
199
*/
154
200
public function testFilterByWrongCategoryUrlPath ()
155
201
{
156
- $ categoryUrlPath = 'test ' ;
202
+ $ categoryUrlPath = 'not-a-category url path ' ;
157
203
$ this ->expectException (\Exception::class);
158
204
$ this ->expectExceptionMessage ('No category with the provided `category_url_path` was found ' );
159
205
0 commit comments