/** * Verify product tier price on product view page * * @param FixtureInterface $product * @param CatalogProductView $catalogProductView * @return void */ protected function assertTierPrice(FixtureInterface $product, CatalogProductView $catalogProductView) { $noError = true; $match = []; $index = 1; $viewBlock = $catalogProductView->getViewBlock(); $tierPrices = $product->getTierPrice(); foreach ($tierPrices as $tierPrice) { $text = $viewBlock->getTierPrices($index++); $noError = (bool) preg_match('#^[^\\d]+(\\d+)[^\\d]+(\\d+(?:(?:,\\d+)*)+(?:.\\d+)*).*#i', $text, $match); if (!$noError) { break; } if (count($match) < 2 && $match[1] != $tierPrice['price_qty'] || $match[2] !== number_format($tierPrice['price'], 2)) { $noError = false; break; } } \PHPUnit_Framework_Assert::assertTrue($noError, 'Product tier price on product page is not correct.'); }
/** * Verify product tier price on product view page * * @param FixtureInterface $product * @param CatalogProductView $catalogProductView * @param string $block [optional] * @return void */ public function assertPrice(FixtureInterface $product, CatalogProductView $catalogProductView, $block = '') { $noError = true; $match = []; $index = 1; /** @var View $viewBlock */ $viewBlock = $catalogProductView->{'get' . $block . 'ViewBlock'}(); $tierPrices = $product->getTierPrice(); foreach ($tierPrices as $tierPrice) { $text = $viewBlock->getTierPrices($index++); $noError = (bool) preg_match('#^[^\\d]+(\\d+)[^\\d]+(\\d+(?:(?:,\\d+)*)+(?:.\\d+)*).*#i', $text, $match); if (!$noError) { break; } if (count($match) < 2 && $match[1] != $tierPrice['price_qty'] || $match[2] !== number_format($tierPrice['price'], $this->priceFormat)) { $noError = false; break; } } \PHPUnit_Framework_Assert::assertTrue($noError, $this->errorMessage); }