StockTest.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Bundle\Model\ResourceModel\Indexer;
  7. class StockTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /**
  10. * @var \Magento\CatalogInventory\Model\Indexer\Stock\Processor
  11. */
  12. protected $processor;
  13. protected function setUp()
  14. {
  15. $this->processor = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
  16. \Magento\CatalogInventory\Model\Indexer\Stock\Processor::class
  17. );
  18. }
  19. /**
  20. * @magentoDbIsolation disabled
  21. * @magentoAppIsolation enabled
  22. * @magentoDataFixture Magento/Bundle/_files/product_in_category.php
  23. */
  24. public function testReindexAll()
  25. {
  26. $this->processor->reindexAll();
  27. $categoryFactory = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
  28. \Magento\Catalog\Model\CategoryFactory::class
  29. );
  30. /** @var \Magento\Catalog\Block\Product\ListProduct $listProduct */
  31. $listProduct = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
  32. \Magento\Catalog\Block\Product\ListProduct::class
  33. );
  34. $category = $categoryFactory->create()->load(2);
  35. $layer = $listProduct->getLayer();
  36. $layer->setCurrentCategory($category);
  37. $productCollection = $layer->getProductCollection();
  38. $productCollection->joinField(
  39. 'qty',
  40. 'cataloginventory_stock_status',
  41. 'qty',
  42. 'product_id=entity_id',
  43. '{{table}}.stock_id=1',
  44. 'left'
  45. );
  46. $this->assertCount(3, $productCollection);
  47. $expectedResult = [
  48. 'Simple Product' => 22,
  49. 'Custom Design Simple Product' => 24,
  50. 'Bundle Product' => 0
  51. ];
  52. /** @var $product \Magento\Catalog\Model\Product */
  53. foreach ($productCollection as $product) {
  54. $this->assertEquals($expectedResult[$product->getName()], $product->getQty());
  55. }
  56. }
  57. }