Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AssertProductQtyDecreased.php
Go to the documentation of this file.
1 <?php
7 
8 use Magento\Catalog\Test\Page\Adminhtml\CatalogProductEdit;
9 use Magento\Catalog\Test\Page\Adminhtml\CatalogProductIndex;
10 use Magento\Mtf\Constraint\AbstractConstraint;
11 use Magento\Mtf\Fixture\FixtureFactory;
12 use Magento\Mtf\Fixture\FixtureInterface;
13 use Magento\Mtf\ObjectManager;
14 use Magento\Mtf\System\Event\EventManagerInterface;
16 
20 class AssertProductQtyDecreased extends AbstractConstraint
21 {
25  protected $fixtureFactory;
26 
32  protected $skipFields = [
33  'attribute_set_id',
34  'website_ids',
35  'checkout_data',
36  'type_id',
37  'price',
38  ];
39 
47  public function __construct(
48  ObjectManager $objectManager,
49  EventManagerInterface $eventManager,
50  FixtureFactory $fixtureFactory
51  ) {
52  $this->fixtureFactory = $fixtureFactory;
53  parent::__construct($objectManager, $eventManager);
54  }
55 
64  public function processAssert(
65  OrderInjectable $order,
66  CatalogProductIndex $productGrid,
67  CatalogProductEdit $productPage
68  ) {
69  $product = $this->getProduct($order);
70  $this->objectManager->get(\Magento\Catalog\Test\Constraint\AssertProductForm::class)->processAssert(
71  $product,
72  $productGrid,
73  $productPage
74  );
75  }
76 
84  protected function getProduct(OrderInjectable $order, $index = 0)
85  {
86  $product = $order->getEntityId()['products'][$index];
87  $productData = $product->getData();
88  $checkoutDataQty = isset($productData['checkout_data']['qty']) ? $productData['checkout_data']['qty'] : 1;
89  $productData['quantity_and_stock_status']['qty'] -= $checkoutDataQty;
90 
91  $productData = array_diff_key($productData, array_flip($this->skipFields));
92 
93  return $this->fixtureFactory->create(get_class($product), ['data' => $productData]);
94  }
95 
101  public function toString()
102  {
103  return 'Product qty was decreased after placing an order.';
104  }
105 }
$objectManager
Definition: bootstrap.php:17
__construct(ObjectManager $objectManager, EventManagerInterface $eventManager, FixtureFactory $fixtureFactory)
processAssert(OrderInjectable $order, CatalogProductIndex $productGrid, CatalogProductEdit $productPage)
$order
Definition: order.php:55
$productData
$index
Definition: list.phtml:44