@@ -84,6 +84,97 @@ public function testUidAndIdUsageErrorOnProductFilteringCategory()
84
84
$ this ->graphQlQuery ($ query );
85
85
}
86
86
87
+
88
+ /**
89
+ * Verify that filters category url path and uid can't be used at the same time
90
+ */
91
+ public function testUidAndCategoryUrlPathUsageErrorOnProductFilteringCategory ()
92
+ {
93
+ $ this ->expectException (\Exception::class);
94
+ $ this ->expectExceptionMessage ('`category_uid` and `category_url_path` can \'t be used at the same time ' );
95
+ $ query = <<<QUERY
96
+ {
97
+ products(filter: {category_uid: {eq: "OTk5OTk5OTk="}, category_url_path: {eq: "category-1/category-1-2"}}) {
98
+ filters {
99
+ name
100
+ }
101
+ }
102
+ }
103
+ QUERY ;
104
+ $ this ->graphQlQuery ($ query );
105
+ }
106
+
107
+ /**
108
+ * Filter by category url path
109
+ *
110
+ * @magentoApiDataFixture Magento/Catalog/_files/categories.php
111
+ */
112
+ public function testFilterByCategoryUrlPath ()
113
+ {
114
+ $ categoryUrlPath = 'category-1/category-1-2 ' ;
115
+ $ query = <<<QUERY
116
+ {
117
+ products(filter:{
118
+ category_url_path : {eq:" {$ categoryUrlPath }"}
119
+ }) {
120
+ total_count
121
+ items {
122
+ name
123
+ sku
124
+ }
125
+ }
126
+ }
127
+ QUERY ;
128
+ $ response = $ this ->graphQlQuery ($ query );
129
+ $ this ->assertEquals (2 , $ response ['products ' ]['total_count ' ]);
130
+ /** @var ProductRepositoryInterface $productRepository */
131
+ $ productRepository = ObjectManager::getInstance ()->get (ProductRepositoryInterface::class);
132
+ $ product1 = $ productRepository ->get ('simple ' );
133
+ $ product2 = $ productRepository ->get ('simple-4 ' );
134
+ $ filteredProducts = [$ product2 , $ product1 ];
135
+ $ productItemsInResponse = array_map (null , $ response ['products ' ]['items ' ], $ filteredProducts );
136
+ //phpcs:ignore Generic.CodeAnalysis.ForLoopWithTestFunctionCall
137
+ for ($ itemIndex = 0 ; $ itemIndex < count ($ filteredProducts ); $ itemIndex ++) {
138
+ $ this ->assertNotEmpty ($ productItemsInResponse [$ itemIndex ]);
139
+ //validate that correct products are returned
140
+ $ this ->assertResponseFields (
141
+ $ productItemsInResponse [$ itemIndex ][0 ],
142
+ [
143
+ 'name ' => $ filteredProducts [$ itemIndex ]->getName (),
144
+ 'sku ' => $ filteredProducts [$ itemIndex ]->getSku ()
145
+ ]
146
+ );
147
+ }
148
+ }
149
+
150
+ /**
151
+ * Filter by wrong category url path
152
+ *
153
+ * @magentoApiDataFixture Magento/Catalog/_files/categories.php
154
+ */
155
+ public function testFilterByWrongCategoryUrlPath ()
156
+ {
157
+ $ categoryUrlPath = 'test ' ;
158
+
159
+ $ this ->expectException (\Exception::class);
160
+ $ this ->expectExceptionMessage ('No category with the provided `category_url_path` was found ' );
161
+
162
+ $ query = <<<QUERY
163
+ {
164
+ products(filter:{
165
+ category_url_path : {eq:" {$ categoryUrlPath }"}
166
+ }) {
167
+ total_count
168
+ items {
169
+ name
170
+ sku
171
+ }
172
+ }
173
+ }
174
+ QUERY ;
175
+ $ this ->graphQlQuery ($ query );
176
+ }
177
+
87
178
/**
88
179
* Verify that layered navigation filters and aggregations are correct for product query
89
180
*
0 commit comments