/** * Get grouped price with fixture product and product page * * @param View $view * @param FixtureInterface $product * @return array */ protected function getGroupedPrice(View $view, FixtureInterface $product) { $fields = $product->getData(); $groupPrice['onPage'] = $view->getPriceBlock()->getSpecialPrice(); $groupPrice['fixture'] = number_format($fields['group_price'][array_search($this->customerGroup, $fields['group_price'])]['price'], 2); return $groupPrice; }
/** * Get grouped price with fixture product and product page * * @param View $view * @param FixtureInterface $product * @return array */ protected function getGroupedPrice(View $view, FixtureInterface $product) { $groupPrice['onPage'] = $view->getProductPrice(); $groupPrice['onPage'] = isset($groupPrice['onPage']['price_regular_price']) ? str_replace('As low as $', '', $groupPrice['onPage']['price_regular_price']) : str_replace('$', '', $groupPrice['onPage']['price_from']); $groupPrice['fixture'] = $product->getDataFieldConfig('price')['source']->getPreset()['price_from']; return $groupPrice; }
/** * Verify product special price on product view page * * @param FixtureInterface $product * @param View $productViewBlock * @return void */ public function assertPrice(FixtureInterface $product, View $productViewBlock) { $fields = $product->getData(); $specialPrice = $productViewBlock->getPriceBlock()->getSpecialPrice(); if (isset($fields['special_price'])) { \PHPUnit_Framework_Assert::assertEquals(number_format($fields['special_price'], 2), $specialPrice, $this->errorMessage); } }
/** * Return product options. * * @param FixtureInterface $product [optional] * @return array */ public function getOptions(FixtureInterface $product = null) { $options = []; $this->clickCustomize(); $options['bundle_options'] = $this->getBundleBlock()->getOptions($product); $options += parent::getOptions($product); return $options; }
/** * Verify displayed product short description on product page(front-end) equals passed from fixture * * @return string|null */ protected function verifyShortDescription() { $fixtureShortDescription = $this->product->getShortDescription(); $formProductShortDescription = $this->productView->getProductShortDescription(); if ($fixtureShortDescription === null || $fixtureShortDescription == $formProductShortDescription) { return null; } return "Displayed product short description on product page(front-end) not equals passed from fixture. " . "Actual: {$formProductShortDescription}, expected: {$fixtureShortDescription}."; }
/** * Verify product tier price on product view page * * @param FixtureInterface $product * @param View $productViewBlock * @return void */ public function assertPrice(FixtureInterface $product, View $productViewBlock) { $noError = true; $match = []; $index = 1; $tierPrices = $product->getTierPrice(); foreach ($tierPrices as $tierPrice) { $text = $productViewBlock->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); }
/** * Return product options * * @param FixtureInterface $product * @return array */ public function getOptions(FixtureInterface $product) { $downloadableOptions = []; if ($this->_rootElement->find($this->blockDownloadableLinks, Locator::SELECTOR_XPATH)->isVisible()) { $downloadableOptions['downloadable_links'] = ['title' => $this->getDownloadableLinksBlock()->getTitle(), 'downloadable' => ['link' => $this->getDownloadableLinksBlock()->getLinks()]]; } if ($this->_rootElement->find($this->blockDownloadableSamples)->isVisible()) { $downloadableOptions['downloadable_sample'] = ['title' => $this->getDownloadableSamplesBlock()->getTitle(), 'downloadable' => ['sample' => $this->getDownloadableSamplesBlock()->getLinks()]]; } return ['downloadable_options' => $downloadableOptions] + parent::getOptions($product); }
/** * Verify full image on product page(front-end) is displayed correctly * * @return string|null */ protected function verifyFullImage() { // click base image to see full image $this->productView->clickBaseImage(); if (!$this->productView->isFullImageVisible()) { return 'Full image for product ' . $this->product->getName() . ' should be visible after click on base one'; } if (!$this->isImageLoaded($this->productView->getFullImageSource())) { return 'Full image file is corrupted or does not exist for product ' . $this->product->getName(); } $this->productView->closeFullImage(); return null; }
/** * Return product options * * @param FixtureInterface $product [optional] * @return array */ public function getOptions(FixtureInterface $product = null) { $options = ['configurable_options' => $this->getConfigurableOptionsBlock()->getOptions($product)]; $options += parent::getOptions($product); return $options; }
/** * Return product options * * @param FixtureInterface $product * @return array */ public function getOptions(FixtureInterface $product) { $groupedOptions = $this->getGroupedProductBlock()->getOptions($product); return ['grouped_options' => $groupedOptions] + parent::getOptions($product); }
/** * Fill in the option specified for the product * * @param FixtureInterface $product * @return void */ public function fillOptions(FixtureInterface $product) { if ($product instanceof InjectableFixture) { /** @var \Magento\Bundle\Test\Fixture\CatalogProductBundle $product */ $checkoutData = $product->getCheckoutData(); $bundleCheckoutData = isset($checkoutData['bundle_options']) ? $checkoutData['bundle_options'] : []; } else { // TODO: Removed after refactoring(removed) old product fixture. /** @var \Magento\Bundle\Test\Fixture\BundleFixed $product */ $bundleCheckoutData = $product->getSelectionData(); } $this->_rootElement->find($this->customizeButton)->click(); $this->getBundleBlock()->fillBundleOptions($bundleCheckoutData); parent::fillOptions($product); }
/** * Fill specified option for the product * * @param FixtureInterface $product * @return void */ public function fillOptions(FixtureInterface $product) { $this->getGroupedProductBlock()->fill($product); parent::fillOptions($product); }
/** * Get grouped price with fixture product and product page * * @param View $view * @param FixtureInterface $product * @return array */ protected function getGroupedPrice(View $view, FixtureInterface $product) { $groupPrice = ['onPage' => ['price_regular_price' => $view->getPriceBlock()->getPrice(), 'price_from' => $view->getPriceBlock()->getPriceFrom()], 'fixture' => $product->getDataFieldConfig('price')['source']->getPriceData()['price_from']]; $groupPrice['onPage'] = isset($groupPrice['onPage']['price_regular_price']) ? str_replace('As low as $', '', $groupPrice['onPage']['price_regular_price']) : str_replace('$', '', $groupPrice['onPage']['price_from']); return $groupPrice; }