|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +declare(strict_types=1); |
| 7 | + |
| 8 | +namespace Magento\Elasticsearch\Model\CatalogSearch; |
| 9 | + |
| 10 | +use Magento\CatalogSearch\Model\Advanced; |
| 11 | +use Magento\Catalog\Model\Product\Visibility; |
| 12 | +use Magento\Catalog\Api\Data\ProductInterface; |
| 13 | +use Magento\TestFramework\Helper\Bootstrap; |
| 14 | +use PHPUnit\Framework\TestCase; |
| 15 | + |
| 16 | +/** |
| 17 | + * Check catalog Advanced Search process with Elasticsearch enabled. |
| 18 | + */ |
| 19 | +class AdvancedTest extends TestCase |
| 20 | +{ |
| 21 | + /** |
| 22 | + * @var Visibility |
| 23 | + */ |
| 24 | + private $productVisibility; |
| 25 | + |
| 26 | + /** |
| 27 | + * @var Advanced |
| 28 | + */ |
| 29 | + private $advancedSearch; |
| 30 | + |
| 31 | + /** |
| 32 | + * @inheritDoc |
| 33 | + */ |
| 34 | + protected function setUp(): void |
| 35 | + { |
| 36 | + parent::setUp(); |
| 37 | + |
| 38 | + $objectManager = Bootstrap::getObjectManager(); |
| 39 | + $this->productVisibility = $objectManager->get(Visibility::class); |
| 40 | + $this->advancedSearch = $objectManager->get(Advanced::class); |
| 41 | + } |
| 42 | + |
| 43 | + /** |
| 44 | + * Check that Advanced Search does NOT return products that do NOT have search visibility. |
| 45 | + * |
| 46 | + * @magentoDbIsolation disabled |
| 47 | + * @magentoConfigFixture default/catalog/search/engine elasticsearch7 |
| 48 | + * @magentoDataFixture Magento/ConfigurableProduct/_files/configurable_product_with_two_child_products.php |
| 49 | + * @return void |
| 50 | + */ |
| 51 | + public function testAddFilters(): void |
| 52 | + { |
| 53 | + $searchName = 'Configurable'; |
| 54 | + |
| 55 | + $this->advancedSearch->addFilters(['name' => $searchName]); |
| 56 | + /** @var ProductInterface[] $itemsResult */ |
| 57 | + $itemsResult = $this->advancedSearch->getProductCollection() |
| 58 | + ->addAttributeToSelect(ProductInterface::VISIBILITY) |
| 59 | + ->getItems(); |
| 60 | + $this->assertCount(1, $itemsResult); |
| 61 | + |
| 62 | + $product = array_shift($itemsResult); |
| 63 | + $this->assertStringContainsString($searchName, $product->getName()); |
| 64 | + $this->assertContains((int)$product->getVisibility(), $this->productVisibility->getVisibleInSearchIds()); |
| 65 | + } |
| 66 | +} |
0 commit comments