Skip to content

Commit

Permalink
[90] [17] Read API :: Web-Api tests :: Magento\GraphQl\Catalog\MediaG…
Browse files Browse the repository at this point in the history
…alleryTest::testProductSmallImageUrlPlaceholder #90
  • Loading branch information
vzabaznov committed Jun 26, 2020
1 parent de71581 commit 99a73bb
Showing 1 changed file with 24 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();

0 comments on commit 99a73bb

Please sign in to comment.