|
7 | 7 |
|
8 | 8 | namespace Magento\GraphQl\Catalog;
|
9 | 9 |
|
| 10 | +use Magento\Store\Model\StoreManagerInterface; |
| 11 | +use Magento\TestFramework\Helper\Bootstrap; |
10 | 12 | use Magento\TestFramework\TestCase\GraphQlAbstract;
|
11 | 13 |
|
12 | 14 | /**
|
@@ -239,6 +241,64 @@ public function testNoResultsFound()
|
239 | 241 | $this->assertEquals([], $result['categoryList']);
|
240 | 242 | }
|
241 | 243 |
|
| 244 | + /** |
| 245 | + * When no filters are supplied, the root category is returned |
| 246 | + * |
| 247 | + * @magentoApiDataFixture Magento/Catalog/_files/categories.php |
| 248 | + */ |
| 249 | + public function testEmptyFiltersReturnRootCategory() |
| 250 | + { |
| 251 | + $query = <<<QUERY |
| 252 | +{ |
| 253 | + categoryList{ |
| 254 | + id |
| 255 | + name |
| 256 | + url_key |
| 257 | + url_path |
| 258 | + children_count |
| 259 | + path |
| 260 | + position |
| 261 | + } |
| 262 | +} |
| 263 | +QUERY; |
| 264 | + |
| 265 | + $storeManager = Bootstrap::getObjectManager()->get(StoreManagerInterface::class); |
| 266 | + $storeRootCategoryId = $storeManager->getStore()->getRootCategoryId(); |
| 267 | + |
| 268 | + $result = $this->graphQlQuery($query); |
| 269 | + $this->assertArrayNotHasKey('errors', $result); |
| 270 | + $this->assertArrayHasKey('categoryList', $result); |
| 271 | + $this->assertEquals('Default Category', $result['categoryList'][0]['name']); |
| 272 | + $this->assertEquals($storeRootCategoryId, $result['categoryList'][0]['id']); |
| 273 | + } |
| 274 | + |
| 275 | + /** |
| 276 | + * Filtering with match value less than minimum query should return empty result |
| 277 | + * |
| 278 | + * @magentoApiDataFixture Magento/Catalog/_files/categories.php |
| 279 | + */ |
| 280 | + public function testMinimumMatchQueryLength() |
| 281 | + { |
| 282 | + $query = <<<QUERY |
| 283 | +{ |
| 284 | + categoryList(filters: {name: {match: "mo"}}){ |
| 285 | + id |
| 286 | + name |
| 287 | + url_key |
| 288 | + url_path |
| 289 | + children_count |
| 290 | + path |
| 291 | + position |
| 292 | + } |
| 293 | +} |
| 294 | +QUERY; |
| 295 | + |
| 296 | + $result = $this->graphQlQuery($query); |
| 297 | + $this->assertArrayNotHasKey('errors', $result); |
| 298 | + $this->assertArrayHasKey('categoryList', $result); |
| 299 | + $this->assertEquals([], $result['categoryList']); |
| 300 | + } |
| 301 | + |
242 | 302 | /**
|
243 | 303 | * @return array
|
244 | 304 | */
|
|
0 commit comments