Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AssertProductSpecialPriceOnProductPage.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 use Magento\Mtf\Fixture\FixtureInterface;
14 
19 {
25  protected $errorMessage = 'Assert that displayed special price on product page NOT equals to passed from fixture.';
26 
35  public function processAssert(
36  CatalogProductView $catalogProductView,
37  BrowserInterface $browser,
38  FixtureInterface $product
39  ) {
40  $browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html');
41 
42  //Process assertions
43  $this->assertPrice($product, $catalogProductView->getViewBlock());
44  }
45 
52  public function setErrorMessage($errorMessage)
53  {
54  $this->errorMessage = $errorMessage;
55  }
56 
64  public function assertPrice(FixtureInterface $product, View $productViewBlock)
65  {
66  $fields = $product->getData();
67  $specialPrice = $productViewBlock->getPriceBlock($product)->getSpecialPrice();
68  if (isset($fields['special_price'])) {
69  \PHPUnit\Framework\Assert::assertEquals(
70  number_format($fields['special_price'], 2),
71  $specialPrice,
72  $this->errorMessage
73  );
74  }
75  }
76 
82  public function toString()
83  {
84  return "Assert that displayed special price on product page equals passed from fixture.";
85  }
86 }
processAssert(CatalogProductView $catalogProductView, BrowserInterface $browser, FixtureInterface $product)
$fields
Definition: details.phtml:14
getPriceBlock(FixtureInterface $product=null)
Definition: View.php:250