Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AssertBundlePriceView.php
Go to the documentation of this file.
1 <?php
8 
10 use Magento\Catalog\Test\Page\Product\CatalogProductView;
11 use Magento\Mtf\Client\BrowserInterface;
12 use Magento\Mtf\Constraint\AbstractConstraint;
13 
17 class AssertBundlePriceView extends AbstractConstraint
18 {
27  public function processAssert(
28  CatalogProductView $catalogProductView,
29  BrowserInterface $browser,
30  BundleProduct $product
31  ) {
32  //Open product view page
33  $browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html');
34 
35  //Process assertions
36  $this->assertPrice($product, $catalogProductView);
37  }
38 
46  protected function assertPrice(BundleProduct $product, CatalogProductView $catalogProductView)
47  {
48  $priceData = $product->getDataFieldConfig('price')['source']->getPriceData();
49  $priceView = $product->getPriceView();
50  $priceBlock = $catalogProductView->getViewBlock()->getPriceBlock();
51 
52  if ($product->hasData('special_price')) {
53  $priceLow = $priceBlock->getPrice();
54  } else {
55  $priceLow = ($priceView == 'Price Range') ? $priceBlock->getPriceFrom() : $priceBlock->getPrice();
56  }
57 
58  \PHPUnit\Framework\Assert::assertEquals(
59  $priceData['price_from'],
60  $priceLow,
61  'Bundle price From on product view page is not correct.'
62  );
63 
64  if ($priceView == 'Price Range') {
65  \PHPUnit\Framework\Assert::assertEquals(
66  $priceData['price_to'],
67  $priceBlock->getPriceTo(),
68  'Bundle price To on product view page is not correct.'
69  );
70  }
71  }
72 
78  public function toString()
79  {
80  return 'Bundle price on product view page is not correct.';
81  }
82 }
processAssert(CatalogProductView $catalogProductView, BrowserInterface $browser, BundleProduct $product)
assertPrice(BundleProduct $product, CatalogProductView $catalogProductView)