/** * Get element for item block. * * @param InjectableFixture $address * @param int $itemIndex * @return ElementInterface */ protected function getItemBlockElement(InjectableFixture $address, $itemIndex) { $conditions = []; foreach ($this->addressFields as $field) { $conditions[] = "contains(., '{$address->getData($field)}')"; } $itemBlockSelector = sprintf($this->itemBlock, implode(' and ', $conditions)); return $this->_rootElement->find($itemBlockSelector, Locator::SELECTOR_XPATH); }
/** * Assert form data equals fixture data. * * @param InjectableFixture $product * @param CatalogProduct $productGrid * @param CatalogProductEdit $productPage * @return void */ public function processAssert(InjectableFixture $product, CatalogProduct $productGrid, CatalogProductEdit $productPage) { $this->catalogProductEdit = $productPage; $filter = ['sku' => $product->getSku()]; $productGrid->open(); $productGrid->getProductGrid()->searchAndOpen($filter); $productData = $product->getData(); $fixtureData = $this->prepareFixtureData($productData, $this->sortFields); $formData = $this->prepareFormData($productPage->getProductForm()->getData($product), $this->sortFields); $error = $this->verifyData($fixtureData, $formData); \PHPUnit_Framework_Assert::assertTrue(empty($error), $error); }
/** * Prepare filter for assert * * @param InjectableFixture $product * @param array $review * @param string $gridStatus [optional] * @return array */ public function prepareFilter(InjectableFixture $product, array $review, $gridStatus = '') { $filter = []; foreach ($this->filter as $field) { switch ($field) { case 'name': case 'sku': $value = $product->getData($field); break; case 'status_id': $value = $gridStatus !== '' ? $gridStatus : (isset($review[$field]) ? $review[$field] : null); break; default: $value = isset($review[$field]) ? $review[$field] : null; break; } if ($value !== null) { $filter += [$field => $value]; } } return $filter; }
/** * Prepare attribute data. * * @param InjectableFixture $product * @param int $key * @return array */ protected function prepareAttributeData(InjectableFixture $product, $key) { $data = []; foreach ($this->attributeProduct as $attributeKey => $attribute) { $value = $attribute; $attribute = is_numeric($attributeKey) ? $attribute : $attributeKey; $attributeValue = $attribute != 'price' ? $product->hasData($attribute) ? $product->getData($attribute) : 'N/A' : ($product->getDataFieldConfig('price')['source']->getPreset() !== null ? $product->getDataFieldConfig('price')['source']->getPreset() : number_format($product->getPrice(), 2)); $data['attributeValues'][$attribute] = !is_array($attributeValue) ? strtolower($attributeValue) : $attributeValue; $attributeName = $value === 'name' || $value === 'price' ? 'Info' : 'MetaData'; $data['attributeValuesFromPage'][$attribute] = $this->comparePage->getCompareProductsBlock()->{'getProduct' . $attributeName}($key + 1, $value); } return $data; }
/** * Process assert search result. * * @param CatalogsearchResult $catalogSearchResult * @param CmsIndex $cmsIndex * @param InjectableFixture $product * @param string $param * @throws \Exception * @return void * * @SuppressWarnings(PHPMD.NPathComplexity) */ protected function verifySearchResult(CatalogsearchResult $catalogSearchResult, CmsIndex $cmsIndex, InjectableFixture $product, $param) { $cmsIndex->open(); $searchValue = $product->hasData($param) !== false ? $product->getData($param) : null; if ($searchValue === null) { throw new \Exception("Product '{$product->getName}()' doesn't have '{$param}' parameter."); } $param = strtoupper($param); $this->errorMessage = sprintf($this->formatForErrorMessage, $param); $this->successfulMessage = sprintf($this->formatForSuccessfulMessage, $param); $cmsIndex->getSearchBlock()->search($searchValue); $quantityAndStockStatus = $product->getStockData(); $stockStatus = isset($quantityAndStockStatus['is_in_stock']) ? $quantityAndStockStatus['is_in_stock'] : null; $isVisible = $catalogSearchResult->getListProductBlock()->isProductVisible($product); while (!$isVisible && $catalogSearchResult->getBottomToolbar()->nextPage()) { $isVisible = $catalogSearchResult->getListProductBlock()->isProductVisible($product); } if ($product->getVisibility() === 'Catalog' || $stockStatus === 'Out of Stock') { $isVisible = !$isVisible; list($this->errorMessage, $this->successfulMessage) = [$this->successfulMessage, $this->errorMessage]; } \PHPUnit_Framework_Assert::assertTrue($isVisible, $this->errorMessage); }
/** * Create data array for filling containers. * * Returns data in format * [[abstract_container_name => [field_name => [attribute_name => attribute_value, ..], ..], ..] * where container name should be set to 'null' if a field is not present on the form. * * @param InjectableFixture $fixture * @return array */ protected function getFixtureFieldsByContainers(InjectableFixture $fixture) { $dataByContainer = []; $data = $fixture->getData(); foreach ($data as $field => $value) { $attributes = $fixture->getDataFieldConfig($field); $attributes['value'] = $value; if (array_key_exists('group', $attributes) && $attributes['group'] != 'null') { $dataByContainer[$attributes['group']][$field] = $attributes; } elseif (!array_key_exists('group', $attributes)) { $this->unassignedFields[$field] = $attributes; } } return $dataByContainer; }
/** * Get grouped price with fixture product and product page. * * @param View $view * @param InjectableFixture $product * @return array */ protected function getGroupedPrice(View $view, InjectableFixture $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 data of the root form * * @param InjectableFixture|null $fixture * @param Element|null $element * @return array */ public function getData(InjectableFixture $fixture = null, Element $element = null) { if (null === $fixture) { $fields = null; } else { $data = $fixture->hasData() ? $fixture->getData() : []; $fields = isset($data['fields']) ? $data['fields'] : $data; } $mapping = $this->dataMapping($fields); return $this->_getData($mapping, $element); }