diff --git a/dev/tests/integration/framework/Magento/TestFramework/TestCase/AbstractBackendController.php b/dev/tests/integration/framework/Magento/TestFramework/TestCase/AbstractBackendController.php index bf8ca0dc51b18..e93e07d768fdf 100644 --- a/dev/tests/integration/framework/Magento/TestFramework/TestCase/AbstractBackendController.php +++ b/dev/tests/integration/framework/Magento/TestFramework/TestCase/AbstractBackendController.php @@ -58,7 +58,12 @@ protected function setUp(): void parent::setUp(); $this->_objectManager->get(\Magento\Backend\Model\UrlInterface::class)->turnOffSecretKey(); - + /** + * Authorization can be created on test bootstrap... + * If it will be created on test bootstrap we will have invalid RoleLocator object. + * As tests by default are run not from adminhtml area... + */ + \Magento\TestFramework\ObjectManager::getInstance()->removeSharedInstance(\Magento\Framework\Authorization::class); $this->_auth = $this->_objectManager->get(\Magento\Backend\Model\Auth::class); $this->_session = $this->_auth->getAuthStorage(); $credentials = $this->_getAdminCredentials(); diff --git a/dev/tests/integration/testsuite/Magento/Catalog/_files/product_simple.php b/dev/tests/integration/testsuite/Magento/Catalog/_files/product_simple.php index a7e4f702e5630..f80e3ca6a75d3 100644 --- a/dev/tests/integration/testsuite/Magento/Catalog/_files/product_simple.php +++ b/dev/tests/integration/testsuite/Magento/Catalog/_files/product_simple.php @@ -207,3 +207,16 @@ $product->getSku(), [2] ); + +/** + * We need to remember that automatic reindexation is not working properly in integration tests + * Reindexation is sitting on top of afterCommit callbacks: + * \Magento\Catalog\Model\Product::priceReindexCallback + * + * However, callbacks are applied only when transaction_level = 0 (when transaction is commited), however + * integration tests are not committing transactions, so we need to reindex data manually in order to reuse it in tests + */ +/** @var \Magento\Indexer\Model\Indexer $indexer */ +$indexer = $objectManager->create(\Magento\Indexer\Model\Indexer::class); +$indexer->load('catalog_product_price'); +$indexer->reindexRow($product->getId()); diff --git a/dev/tests/integration/testsuite/Magento/Catalog/_files/product_simple_disabled.php b/dev/tests/integration/testsuite/Magento/Catalog/_files/product_simple_disabled.php new file mode 100644 index 0000000000000..0a37f4b9e921e --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Catalog/_files/product_simple_disabled.php @@ -0,0 +1,222 @@ +reinitialize(); + +/** @var \Magento\TestFramework\ObjectManager $objectManager */ +$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); + +/** @var \Magento\Catalog\Api\CategoryLinkManagementInterface $categoryLinkManagement */ +$categoryLinkManagement = $objectManager->get(\Magento\Catalog\Api\CategoryLinkManagementInterface::class); + +$tierPrices = []; +/** @var \Magento\Catalog\Api\Data\ProductTierPriceInterfaceFactory $tierPriceFactory */ +$tierPriceFactory = $objectManager->get(\Magento\Catalog\Api\Data\ProductTierPriceInterfaceFactory::class); +/** @var $tpExtensionAttributes */ +$tpExtensionAttributesFactory = $objectManager->get(ProductTierPriceExtensionFactory::class); +/** @var $productExtensionAttributes */ +$productExtensionAttributesFactory = $objectManager->get(ProductExtensionInterfaceFactory::class); + +$adminWebsite = $objectManager->get(\Magento\Store\Api\WebsiteRepositoryInterface::class)->get('admin'); +$tierPriceExtensionAttributes1 = $tpExtensionAttributesFactory->create() + ->setWebsiteId($adminWebsite->getId()); +$productExtensionAttributesWebsiteIds = $productExtensionAttributesFactory->create( + ['website_ids' => $adminWebsite->getId()] +); + +$tierPrices[] = $tierPriceFactory->create( + [ + 'data' => [ + 'customer_group_id' => \Magento\Customer\Model\Group::CUST_GROUP_ALL, + 'qty' => 2, + 'value' => 8 + ] + ] +)->setExtensionAttributes($tierPriceExtensionAttributes1); + +$tierPrices[] = $tierPriceFactory->create( + [ + 'data' => [ + 'customer_group_id' => \Magento\Customer\Model\Group::CUST_GROUP_ALL, + 'qty' => 5, + 'value' => 5 + ] + ] +)->setExtensionAttributes($tierPriceExtensionAttributes1); + +$tierPrices[] = $tierPriceFactory->create( + [ + 'data' => [ + 'customer_group_id' => \Magento\Customer\Model\Group::NOT_LOGGED_IN_ID, + 'qty' => 3, + 'value' => 5 + ] + ] +)->setExtensionAttributes($tierPriceExtensionAttributes1); + +$tierPrices[] = $tierPriceFactory->create( + [ + 'data' => [ + 'customer_group_id' => \Magento\Customer\Model\Group::NOT_LOGGED_IN_ID, + 'qty' => 3.2, + 'value' => 6, + ] + ] +)->setExtensionAttributes($tierPriceExtensionAttributes1); + +$tierPriceExtensionAttributes2 = $tpExtensionAttributesFactory->create() + ->setWebsiteId($adminWebsite->getId()) + ->setPercentageValue(50); + +$tierPrices[] = $tierPriceFactory->create( + [ + 'data' => [ + 'customer_group_id' => \Magento\Customer\Model\Group::NOT_LOGGED_IN_ID, + 'qty' => 10 + ] + ] +)->setExtensionAttributes($tierPriceExtensionAttributes2); + +/** @var $product \Magento\Catalog\Model\Product */ +$product = $objectManager->create(\Magento\Catalog\Model\Product::class); +$product->isObjectNew(true); +$product->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE) + ->setId(1) + ->setAttributeSetId(4) + ->setWebsiteIds([1]) + ->setName('Simple Product') + ->setSku('simple') + ->setPrice(10) + ->setWeight(1) + ->setShortDescription("Short description") + ->setTaxClassId(0) + ->setTierPrices($tierPrices) + ->setDescription('Description with html tag') + ->setExtensionAttributes($productExtensionAttributesWebsiteIds) + ->setMetaTitle('meta title') + ->setMetaKeyword('meta keyword') + ->setMetaDescription('meta description') + ->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH) + ->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_DISABLED) + ->setStockData( + [ + 'use_config_manage_stock' => 1, + 'qty' => 100, + 'is_qty_decimal' => 0, + 'is_in_stock' => 1, + ] + )->setCanSaveCustomOptions(true) + ->setHasOptions(true); + +$oldOptions = [ + [ + 'previous_group' => 'text', + 'title' => 'Test Field', + 'type' => 'field', + 'is_require' => 1, + 'sort_order' => 0, + 'price' => 1, + 'price_type' => 'fixed', + 'sku' => '1-text', + 'max_characters' => 100, + ], + [ + 'previous_group' => 'date', + 'title' => 'Test Date and Time', + 'type' => 'date_time', + 'is_require' => 1, + 'sort_order' => 0, + 'price' => 2, + 'price_type' => 'fixed', + 'sku' => '2-date', + ], + [ + 'previous_group' => 'select', + 'title' => 'Test Select', + 'type' => 'drop_down', + 'is_require' => 1, + 'sort_order' => 0, + 'values' => [ + [ + 'option_type_id' => null, + 'title' => 'Option 1', + 'price' => 3, + 'price_type' => 'fixed', + 'sku' => '3-1-select', + ], + [ + 'option_type_id' => null, + 'title' => 'Option 2', + 'price' => 3, + 'price_type' => 'fixed', + 'sku' => '3-2-select', + ], + ] + ], + [ + 'previous_group' => 'select', + 'title' => 'Test Radio', + 'type' => 'radio', + 'is_require' => 1, + 'sort_order' => 0, + 'values' => [ + [ + 'option_type_id' => null, + 'title' => 'Option 1', + 'price' => 3, + 'price_type' => 'fixed', + 'sku' => '4-1-radio', + ], + [ + 'option_type_id' => null, + 'title' => 'Option 2', + 'price' => 3, + 'price_type' => 'fixed', + 'sku' => '4-2-radio', + ], + ] + ] +]; + +$options = []; + +/** @var \Magento\Catalog\Api\Data\ProductCustomOptionInterfaceFactory $customOptionFactory */ +$customOptionFactory = $objectManager->create(\Magento\Catalog\Api\Data\ProductCustomOptionInterfaceFactory::class); + +foreach ($oldOptions as $option) { + /** @var \Magento\Catalog\Api\Data\ProductCustomOptionInterface $option */ + $option = $customOptionFactory->create(['data' => $option]); + $option->setProductSku($product->getSku()); + + $options[] = $option; +} + +$product->setOptions($options); + +/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */ +$productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class); +$productRepository->save($product); + +$categoryLinkManagement->assignProductToCategories( + $product->getSku(), + [2] +); + +/** + * We need to remember that automatic reindexation is not working properly in integration tests + * Reindexation is sitting on top of afterCommit callbacks: + * \Magento\Catalog\Model\Product::priceReindexCallback + * + * However, callbacks are applied only when transaction_level = 0 (when transaction is commited), however + * integration tests are not committing transactions, so we need to reindex data manually in order to reuse it in tests + */ +/** @var \Magento\Indexer\Model\Indexer $indexer */ +$indexer = $objectManager->create(\Magento\Indexer\Model\Indexer::class); +$indexer->load('catalog_product_price'); +$indexer->reindexRow($product->getId()); diff --git a/dev/tests/integration/testsuite/Magento/Catalog/_files/product_simple_xss.php b/dev/tests/integration/testsuite/Magento/Catalog/_files/product_simple_xss.php index cff5671d1bf49..c27a760988818 100644 --- a/dev/tests/integration/testsuite/Magento/Catalog/_files/product_simple_xss.php +++ b/dev/tests/integration/testsuite/Magento/Catalog/_files/product_simple_xss.php @@ -31,3 +31,17 @@ $product->getSku(), [2] ); + + +/** + * We need to remember that automatic reindexation is not working properly in integration tests + * Reindexation is sitting on top of afterCommit callbacks: + * \Magento\Catalog\Model\Product::priceReindexCallback + * + * However, callbacks are applied only when transaction_level = 0 (when transaction is commited), however + * integration tests are not committing transactions, so we need to reindex data manually in order to reuse it in tests + */ +/** @var \Magento\Indexer\Model\Indexer $indexer */ +$indexer = $objectManager->create(\Magento\Indexer\Model\Indexer::class); +$indexer->load('catalog_product_price'); +$indexer->reindexRow($product->getId()); diff --git a/dev/tests/integration/testsuite/Magento/ConfigurableProduct/_files/product_configurable.php b/dev/tests/integration/testsuite/Magento/ConfigurableProduct/_files/product_configurable.php index 9dd43f13a8a64..4a8fc951f48c3 100644 --- a/dev/tests/integration/testsuite/Magento/ConfigurableProduct/_files/product_configurable.php +++ b/dev/tests/integration/testsuite/Magento/ConfigurableProduct/_files/product_configurable.php @@ -36,7 +36,7 @@ $attributeValues = []; $attributeSetId = $installer->getAttributeSetId(Product::ENTITY, 'Default'); $associatedProductIds = []; -$productIds = [10, 20]; +$idsToReindex = $productIds = [10, 20]; array_shift($options); //remove the first option which is empty foreach ($options as $option) { @@ -143,3 +143,17 @@ $product->getSku(), [2] ); + +/** + * We need to remember that automatic reindexation is not working properly in integration tests + * Reindexation is sitting on top of afterCommit callbacks: + * \Magento\Catalog\Model\Product::priceReindexCallback + * + * However, callbacks are applied only when transaction_level = 0 (when transaction is commited), however + * integration tests are not committing transactions, so we need to reindex data manually in order to reuse it in tests + */ +/** @var \Magento\Indexer\Model\Indexer $indexer */ +$indexer = Bootstrap::getObjectManager()->create(\Magento\Indexer\Model\Indexer::class); +$indexer->load('catalog_product_price'); +$indexer->reindexRow($product->getId()); +$indexer->reindexList($idsToReindex); diff --git a/dev/tests/integration/testsuite/Magento/ConfigurableProduct/_files/product_configurable_sku.php b/dev/tests/integration/testsuite/Magento/ConfigurableProduct/_files/product_configurable_sku.php index ca8e1e91e5061..bd9fe806b2b00 100644 --- a/dev/tests/integration/testsuite/Magento/ConfigurableProduct/_files/product_configurable_sku.php +++ b/dev/tests/integration/testsuite/Magento/ConfigurableProduct/_files/product_configurable_sku.php @@ -36,7 +36,7 @@ $attributeValues = []; $attributeSetId = $installer->getAttributeSetId('catalog_product', 'Default'); $associatedProductIds = []; -$productIds = [10, 20]; +$idsToReindex = $productIds = [10, 20]; array_shift($options); //remove the first option which is empty foreach ($options as $option) { @@ -142,3 +142,16 @@ $product->getSku(), [2] ); + +/** + * We need to remember that automatic reindexation is not working properly in integration tests + * Reindexation is sitting on top of afterCommit callbacks: + * \Magento\Catalog\Model\Product::priceReindexCallback + * + * However, callbacks are applied only when transaction_level = 0 (when transaction is commited), however + * integration tests are not committing transactions, so we need to reindex data manually in order to reuse it in tests + */ +/** @var \Magento\Indexer\Model\Indexer $indexer */ +$indexer = Bootstrap::getObjectManager()->create(\Magento\Indexer\Model\Indexer::class); +$indexer->load('catalog_product_price'); +$indexer->reindexList($idsToReindex); diff --git a/dev/tests/integration/testsuite/Magento/Wishlist/Model/WishlistTest.php b/dev/tests/integration/testsuite/Magento/Wishlist/Model/WishlistTest.php index 29dda2bbde581..28edf31ad4afc 100644 --- a/dev/tests/integration/testsuite/Magento/Wishlist/Model/WishlistTest.php +++ b/dev/tests/integration/testsuite/Magento/Wishlist/Model/WishlistTest.php @@ -116,17 +116,13 @@ public function testGetItemCollection(): void } /** - * @magentoDataFixture Magento/Wishlist/_files/wishlist.php + * @magentoDataFixture Magento/Wishlist/_files/wishlist_with_disabled_simple_product.php * * @return void */ public function testGetItemCollectionWithDisabledProduct(): void { - $productSku = 'simple'; $customerId = 1; - $product = $this->productRepository->get($productSku); - $product->setStatus(ProductStatus::STATUS_DISABLED); - $this->productRepository->save($product); $this->assertEmpty($this->getWishlistByCustomerId->execute($customerId)->getItemCollection()->getItems()); } diff --git a/dev/tests/integration/testsuite/Magento/Wishlist/_files/wishlist_with_disabled_simple_product.php b/dev/tests/integration/testsuite/Magento/Wishlist/_files/wishlist_with_disabled_simple_product.php new file mode 100644 index 0000000000000..3c829a40f0d91 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Wishlist/_files/wishlist_with_disabled_simple_product.php @@ -0,0 +1,27 @@ +requireDataFixture('Magento/Customer/_files/customer.php'); +Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple_disabled.php'); + +$objectManager = Bootstrap::getObjectManager(); +/** @var CustomerRegistry $customerRegistry */ +$customerRegistry = Bootstrap::getObjectManager()->create(CustomerRegistry::class); +$customer = $customerRegistry->retrieve(1); +/** @var ProductRepositoryInterface $productRepository */ +$productRepository = $objectManager->create(ProductRepositoryInterface::class); +$product = $productRepository->get('simple'); +$wishlist = Bootstrap::getObjectManager()->create(Wishlist::class); +$wishlist->loadByCustomerId($customer->getId(), true); +$item = $wishlist->addNewItem($product, new DataObject([])); +$wishlist->setSharingCode('fixture_unique_code')->save();