Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AssertProductRegularPriceOnStorefront.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
10 use Magento\Cms\Test\Page\CmsIndex;
11 use Magento\Customer\Test\Page\CustomerAccountIndex;
12 use Magento\Wishlist\Test\Page\WishlistIndex;
13 use Magento\Mtf\Constraint\AbstractConstraint;
14 use Magento\Mtf\Fixture\InjectableFixture;
17 
21 class AssertProductRegularPriceOnStorefront extends AbstractConstraint
22 {
26  private $regularPriceLabel = 'Regular Price';
27 
37  public function processAssert(
38  CmsIndex $cmsIndex,
39  CustomerAccountIndex $customerAccountIndex,
40  WishlistIndex $wishlistIndex,
41  InjectableFixture $product
42  ) {
43  $cmsIndex->open();
44  $cmsIndex->getLinksBlock()->openLink('My Account');
45  $customerAccountIndex->getAccountMenuBlock()->openMenuItem('My Wish List');
46 
47  $productRegularPrice = 0;
48  if ($product instanceof GroupedProduct) {
49  $associatedProducts = $product->getAssociated();
50 
52  foreach ($associatedProducts['products'] as $key => $associatedProduct) {
53  $qty = $associatedProducts['assigned_products'][$key]['qty'];
54  $price = $associatedProduct->getPrice();
55  $productRegularPrice += $qty * $price;
56  }
57  } elseif ($product instanceof BundleProduct) {
58  $bundleSelection = (array)$product->getBundleSelections();
59  foreach ($bundleSelection['products'] as $bundleOption) {
60  $regularBundleProductPrice = 0;
62  foreach ($bundleOption as $bundleProduct) {
63  $checkoutData = $bundleProduct->getCheckoutData();
64  $bundleProductPrice = $checkoutData['qty'] * $checkoutData['cartItem']['price'];
65  if (0 === $regularBundleProductPrice) {
66  $regularBundleProductPrice = $bundleProductPrice;
67  } else {
68  $regularBundleProductPrice = max([$bundleProductPrice, $regularBundleProductPrice]);
69  }
70  }
71  $productRegularPrice += $regularBundleProductPrice;
72  }
73  } else {
74  $productRegularPrice = (float)$product->getPrice();
75  }
76 
77  $productItem = $wishlistIndex->getWishlistBlock()->getProductItemsBlock()->getItemProduct($product);
78  $wishListProductRegularPrice = (float)$productItem->getRegularPrice();
79 
80  \PHPUnit\Framework\Assert::assertEquals(
81  $this->regularPriceLabel,
82  $productItem->getPriceLabel(),
83  'Wrong product regular price is displayed.'
84  );
85 
86  \PHPUnit\Framework\Assert::assertNotEmpty(
87  $wishListProductRegularPrice,
88  'Regular Price for "' . $product->getName() . '" is not correct.'
89  );
90 
91  \PHPUnit\Framework\Assert::assertEquals(
92  $productRegularPrice,
93  $wishListProductRegularPrice,
94  'Wrong product regular price is displayed.'
95  );
96  }
97 
103  public function toString(): string
104  {
105  return 'Product is displayed with correct regular price.';
106  }
107 }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$price
$bundleProduct