From 99a73bbaa3f8415e407a79247f028589e9e89f5e Mon Sep 17 00:00:00 2001 From: Vitalii Zabaznov Date: Fri, 26 Jun 2020 10:54:59 -0500 Subject: [PATCH] [90] [17] Read API :: Web-Api tests :: Magento\GraphQl\Catalog\MediaGalleryTest::testProductSmallImageUrlPlaceholder #90 --- .../wishlist_with_disabled_simple_product.php | 42 +++++++++++-------- 1 file changed, 24 insertions(+), 18 deletions(-) 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 index 3c829a40f0d91..80f5875303044 100644 --- 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 @@ -4,24 +4,30 @@ * See COPYING.txt for license details. */ -use Magento\Catalog\Api\ProductRepositoryInterface; -use Magento\Customer\Model\CustomerRegistry; -use Magento\Framework\DataObject; -use Magento\TestFramework\Helper\Bootstrap; +use Magento\Catalog\Model\Product\Attribute\Source\Status as ProductStatus; use Magento\TestFramework\Workaround\Override\Fixture\Resolver; -use Magento\Wishlist\Model\Wishlist; -Resolver::getInstance()->requireDataFixture('Magento/Customer/_files/customer.php'); -Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple_disabled.php'); +Resolver::getInstance()->requireDataFixture('Magento/Wishlist/_files/wishlist.php'); + +$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); +$productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class); + +$productSku = 'simple'; +$product = $productRepository->get($productSku); +$product->setStatus(ProductStatus::STATUS_DISABLED); +$productRepository->save($product); + +/** + * 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 = \Magento\TestFramework\Helper\Bootstrap + ::getObjectManager()->create(\Magento\Indexer\Model\Indexer::class); +$indexer->load('catalog_product_price'); +$indexer->reindexList([$product->getId()]); -$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();