init
This commit is contained in:
+74
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Elasticsearch\Catalog\Controller\Adminhtml\Product\Attribute;
|
||||
|
||||
use Magento\Catalog\Controller\Adminhtml\Product\Attribute\Save\AbstractSaveAttributeTest;
|
||||
|
||||
/**
|
||||
* Test cases related to creating attribute and search engine.
|
||||
*/
|
||||
class SaveTest extends AbstractSaveAttributeTest
|
||||
{
|
||||
/**
|
||||
* Default POST data for create attribute.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private const DEFAULT_ATTRIBUTE_POST_DATA = [
|
||||
'active_tab' => 'main',
|
||||
'frontend_label' => [
|
||||
'0' => 'Test attribute name',
|
||||
],
|
||||
'frontend_input' => 'select',
|
||||
'is_required' => '0',
|
||||
'attribute_code' => 'filtrable_attribute',
|
||||
'is_global' => '1',
|
||||
'default_value_yesno' => '0',
|
||||
'is_unique' => '0',
|
||||
'is_used_in_grid' => '1',
|
||||
'is_visible_in_grid' => '1',
|
||||
'is_filterable_in_grid' => '1',
|
||||
'is_filterable' => '1',
|
||||
'is_filterable_in_search' => '0',
|
||||
'is_searchable' => '0',
|
||||
'is_comparable' => '0',
|
||||
'is_used_for_promo_rules' => '0',
|
||||
'is_html_allowed_on_front' => '1',
|
||||
'is_visible_on_front' => '0',
|
||||
'used_in_product_listing' => '0',
|
||||
];
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @param string $errorMessage
|
||||
* @dataProvider createAttributeWithErrorDataProvider
|
||||
*/
|
||||
public function testCreateAttributeWithError(array $data, string $errorMessage): void
|
||||
{
|
||||
$this->createAttributeUsingDataWithErrorAndAssert(
|
||||
array_merge(self::DEFAULT_ATTRIBUTE_POST_DATA, $data),
|
||||
$errorMessage
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function createAttributeWithErrorDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'should not create attribute with reserved code "category_name"' => [
|
||||
[
|
||||
'attribute_code' => 'category_name'
|
||||
],
|
||||
'The attribute code 'category_name' is reserved by system. ' .
|
||||
'Please try another attribute code'
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
+149
@@ -0,0 +1,149 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Elasticsearch\Catalog\Model\Indexer\Category\Product\Action;
|
||||
|
||||
use Magento\Catalog\Api\CategoryListInterface;
|
||||
use Magento\Catalog\Api\Data\CategoryInterface;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Catalog\Helper\DefaultCategory;
|
||||
use Magento\Catalog\Model\Indexer\Category\Product\Action\Rows;
|
||||
use Magento\CatalogSearch\Model\ResourceModel\Fulltext\SearchCollectionFactory;
|
||||
use Magento\Framework\Api\SearchCriteriaBuilder;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\ObjectManager;
|
||||
use Magento\TestModuleCatalogSearch\Model\SearchEngineVersionReader;
|
||||
use Magento\Framework\Search\EngineResolverInterface;
|
||||
|
||||
/**
|
||||
* Test for Magento\Catalog\Model\Indexer\Category\Product\Action\Rows class.
|
||||
* This test executable with any configuration of ES and should not be deleted with removal of ES2.
|
||||
*
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDbIsolation enabled
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class RowsTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var ObjectManager
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @var Rows
|
||||
*/
|
||||
private $rowsIndexer;
|
||||
|
||||
/**
|
||||
* @var DefaultCategory
|
||||
*/
|
||||
private $defaultCategoryHelper;
|
||||
|
||||
/**
|
||||
* @var SearchCollectionFactory
|
||||
*/
|
||||
private $fulltextSearchCollectionFactory;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->rowsIndexer = $this->objectManager->get(Rows::class);
|
||||
$this->defaultCategoryHelper = $this->objectManager->get(DefaultCategory::class);
|
||||
$this->fulltextSearchCollectionFactory = $this->objectManager->get(SearchCollectionFactory::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function assertPreConditions(): void
|
||||
{
|
||||
$currentEngine = $this->objectManager->get(EngineResolverInterface::class)->getCurrentSearchEngine();
|
||||
$installedEngine = $this->objectManager->get(SearchEngineVersionReader::class)->getFullVersion();
|
||||
$this->assertEquals(
|
||||
$installedEngine,
|
||||
$currentEngine,
|
||||
sprintf(
|
||||
'Search engine configuration "%s" is not compatible with the installed version',
|
||||
$currentEngine
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Catalog/_files/category_tree_with_products.php
|
||||
* @magentoDataFixture Magento/CatalogSearch/_files/full_reindex.php
|
||||
* @magentoDataFixtureBeforeTransaction Magento/Catalog/_files/enable_reindex_schedule.php
|
||||
* @return void
|
||||
*/
|
||||
public function testLoadWithFilterCatalogView()
|
||||
{
|
||||
$categoryA = $this->getCategory('Category A');
|
||||
$categoryB = $this->getCategory('Category B');
|
||||
$categoryC = $this->getCategory('Category C');
|
||||
|
||||
/** Move $categoryB to $categoryA */
|
||||
$categoryB->move($categoryA->getId(), null);
|
||||
$this->rowsIndexer->execute(
|
||||
[
|
||||
$this->defaultCategoryHelper->getId(),
|
||||
$categoryA->getId(),
|
||||
$categoryB->getId(),
|
||||
$categoryC->getId(),
|
||||
],
|
||||
true
|
||||
);
|
||||
|
||||
$fulltextCollection = $this->fulltextSearchCollectionFactory->create()
|
||||
->addCategoryFilter($categoryA);
|
||||
|
||||
$this->assertProductsArePresentInCollection($fulltextCollection->getAllIds());
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that expected products are present in collection.
|
||||
*
|
||||
* @param array $productIds
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function assertProductsArePresentInCollection(array $productIds): void
|
||||
{
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
|
||||
|
||||
$firstProductId = $productRepository->get('simpleB')->getId();
|
||||
$secondProductId = $productRepository->get('simpleC')->getId();
|
||||
|
||||
$this->assertCount(2, $productIds);
|
||||
$this->assertContains($secondProductId, $productIds);
|
||||
$this->assertContains($firstProductId, $productIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets category by name.
|
||||
*
|
||||
* @param string $name
|
||||
* @return CategoryInterface
|
||||
*/
|
||||
private function getCategory(string $name): CategoryInterface
|
||||
{
|
||||
/** @var SearchCriteriaBuilder $searchCriteriaBuilder */
|
||||
$searchCriteriaBuilder = $this->objectManager->get(SearchCriteriaBuilder::class);
|
||||
$searchCriteria = $searchCriteriaBuilder->addFilter('name', $name)
|
||||
->create();
|
||||
/** @var CategoryListInterface $repository */
|
||||
$repository = $this->objectManager->get(CategoryListInterface::class);
|
||||
$items = $repository->getList($searchCriteria)
|
||||
->getItems();
|
||||
|
||||
return array_pop($items);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user