/** * Prepare and return data of review * * @param FixtureInterface $review * @return array */ protected function getPreparedData(FixtureInterface $review) { $data = $review->getData(); /* Prepare ratings */ if ($review->hasData('ratings')) { $sourceRatings = $review->getDataFieldConfig('ratings')['source']; $ratings = []; foreach ($data['ratings'] as $rating) { $ratings[$rating['title']] = $rating['rating']; } $data['ratings'] = []; foreach ($sourceRatings->getRatings() as $ratingFixture) { /** @var Rating $ratingFixture */ $ratingCode = $ratingFixture->getRatingCode(); if (isset($ratings[$ratingCode])) { $ratingOptions = $ratingFixture->getOptions(); $vote = $ratings[$ratingCode]; $data['ratings'][$ratingFixture->getRatingId()] = $ratingOptions[$vote]; } } } if ($review->hasData('select_stores')) { foreach (array_keys($data['select_stores']) as $key) { if (isset($this->mappingData['select_stores'][$data['select_stores'][$key]])) { $data['select_stores'][$key] = $this->mappingData['select_stores'][$data['select_stores'][$key]]; } } } /* Prepare product id */ $data['product_id'] = $data['entity_id']; unset($data['entity_id']); return $data; }
/** * Prepare filter for product grid. * * @return array */ protected function prepareFilter() { $productStatus = $this->product->getStatus() === null || $this->product->getStatus() === 'Product online' ? 'Enabled' : 'Disabled'; $filter = ['type' => $this->getProductType(), 'sku' => $this->product->getSku(), 'status' => $productStatus]; if ($this->product->hasData('attribute_set_id')) { $filter['set_name'] = $this->product->getAttributeSetId(); } return $filter; }
/** * Prepare data from text to values * * @param FixtureInterface $fixture * @return array */ protected function prepareData(FixtureInterface $fixture) { $categoryId = $fixture->getDataFieldConfig('root_category_id')['source']->getCategory()->getId(); $websiteId = $fixture->getDataFieldConfig('website_id')['source']->getWebsite()->getWebsiteId(); $data = ['group' => ['name' => $fixture->getName(), 'root_category_id' => $categoryId, 'website_id' => $websiteId, 'group_id' => $fixture->hasData('group_id') ? $fixture->getGroupId() : ''], 'store_action' => 'add', 'store_type' => 'group']; return $data; }
/** * Curl creation of Admin User Role * * @param FixtureInterface $fixture * @return array|mixed * @throws \Exception * * @SuppressWarnings(PHPMD.NPathComplexity) */ public function persist(FixtureInterface $fixture = null) { $data = $fixture->getData(); $data['all'] = $data['resource_access'] == 'All' ? 1 : 0; if (isset($data['roles_resources'])) { foreach ((array) $data['roles_resources'] as $resource) { $data['resource'][] = $resource; } } unset($data['roles_resources']); $data['gws_is_all'] = isset($data['gws_is_all']) ? $data['gws_is_all'] : '1'; if ($fixture->hasData('in_role_user')) { $adminUsers = $fixture->getDataFieldConfig('in_role_user')['source']->getAdminUsers(); $userIds = []; foreach ($adminUsers as $adminUser) { $userIds[] = $adminUser->getUserId() . "=true"; } $data['in_role_user'] = implode('&', $userIds); } $url = $_ENV['app_backend_url'] . 'admin/user_role/saverole/active_tab/info/'; $curl = new BackendDecorator(new CurlTransport(), new Config()); $curl->addOption(CURLOPT_HEADER, 1); $curl->write(CurlInterface::POST, $url, '1.0', [], $data); $response = $curl->read(); $curl->close(); if (!strpos($response, 'data-ui-id="messages-message-success"')) { throw new \Exception("Role creating by curl handler was not successful! Response: {$response}"); } $url = 'admin/user_role/roleGrid/sort/role_id/dir/desc/'; $regExpPattern = '/class=\\"\\scol\\-id col\\-role_id\\W*>\\W+(\\d+)\\W+<\\/td>\\W+<td[\\w\\s\\"=\\-]*?>\\W+?' . $data['rolename'] . '/siu'; $extractor = new Extractor($url, $regExpPattern); return ['role_id' => $extractor->getData()[1]]; }
/** * Get data of the tabs. * * @param FixtureInterface|null $fixture * @param Element|null $element * @return array * * @SuppressWarnings(PHPMD.UnusedLocalVariable) * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function getData(FixtureInterface $fixture = null, Element $element = null) { $data = []; if (null === $fixture) { foreach ($this->tabs as $tabName => $tab) { $this->openTab($tabName); $tabData = $this->getTabElement($tabName)->getDataFormTab(); $data = array_merge($data, $tabData); } } else { $tabsFields = $fixture->hasData() ? $this->getFieldsByTabs($fixture) : []; $tabsFields['frontend_properties'] = array_merge_recursive($tabsFields['frontend_properties'], $tabsFields['settings']); unset($tabsFields['settings']); foreach ($tabsFields as $tabName => $fields) { $this->openTab($tabName); if (isset($fields['widgetOptions'])) { unset($fields['widgetOptions']['value']['type_id']); $fields['widgetOptions'] = $fields['widgetOptions']['value']; } elseif (isset($fields['layout'])) { $fields['layout'] = $fields['layout']['value']; } $tabData = $this->getTabElement($tabName)->getDataFormTab($fields, $this->_rootElement); $data = array_merge($data, $tabData); } } $data['type'] = $this->type[$data['type']]; return $data; }
/** * Verify product price on category view page. * * @param FixtureInterface $bundle * @param CatalogCategoryView $catalogCategoryView * @return void */ protected function assertPrice(FixtureInterface $bundle, CatalogCategoryView $catalogCategoryView) { /** @var BundleProduct $bundle */ $priceData = $bundle->getDataFieldConfig('price')['source']->getPreset(); //Price from/to verification $priceBlock = $catalogCategoryView->getListProductBlock()->getProductPriceBlock($bundle->getName()); if ($bundle->hasData('special_price') || $bundle->hasData('group_price')) { $priceLow = $priceBlock->getFinalPrice(); } else { $priceLow = $bundle->getPriceView() == 'Price Range' ? $priceBlock->getPriceFrom() : $priceBlock->getRegularPrice(); } \PHPUnit_Framework_Assert::assertEquals($priceData['price_from'], $priceLow, 'Bundle price From on category page is not correct.'); if ($bundle->getPriceView() == 'Price Range') { \PHPUnit_Framework_Assert::assertEquals($priceData['price_to'], $priceBlock->getPriceTo(), 'Bundle price To on category page is not correct.'); } }
/** * Fill the customer data * * @param FixtureInterface $customer * @param SimpleElement|null $element * @return $this */ public function fill(FixtureInterface $customer, SimpleElement $element = null) { /** @var Customer $customer */ if ($customer->hasData()) { return parent::fill($customer, $element); } }
/** * Fill the root form. * * @param FixtureInterface $fixture * @param SimpleElement|null $element * @return $this */ public function fill(FixtureInterface $fixture, SimpleElement $element = null) { // Prepare price data $data = $fixture->getData(); if (isset($data['price'])) { $data = array_merge($data, $data['price']); unset($data['price']); } // Mapping $mapping = $this->dataMapping($data); $attributeType = $attributeCode = ''; if ($fixture->hasData('custom_attribute')) { /** @var CatalogProductAttribute $attribute */ $attribute = $fixture->getDataFieldConfig('custom_attribute')['source']->getAttribute(); $attributeType = $attribute->getFrontendInput(); $attributeCode = $attribute->getAttributeCode(); } if ($this->hasRender($attributeType)) { $element = $this->_rootElement->find(sprintf($this->customAttributeSelector, $attributeCode)); $arguments = ['fixture' => $fixture, 'element' => $element, 'mapping' => $mapping]; $this->callRender($attributeType, 'fill', $arguments); } else { $this->_fill($mapping, $element); } return $this; }
/** * Get configurable product options * * @param FixtureInterface|null $product [optional] * @return array * @throws \Exception */ public function getOptions(FixtureInterface $product) { /** @var ConfigurableProduct $product */ $attributesData = $product->hasData('configurable_attributes_data') ? $product->getConfigurableAttributesData()['attributes_data'] : []; $listOptions = $this->getListOptions(); $result = []; foreach ($attributesData as $option) { $title = $option['label']; if (!isset($listOptions[$title])) { throw new \Exception("Can't find option: \"{$title}\""); } /** @var SimpleElement $optionElement */ $optionElement = $listOptions[$title]; $typeMethod = preg_replace('/[^a-zA-Z]/', '', $option['frontend_input']); $getTypeData = 'get' . ucfirst(strtolower($typeMethod)) . 'Data'; $optionData = $this->{$getTypeData}($optionElement); $optionData['title'] = $title; $optionData['type'] = $option['frontend_input']; $optionData['is_require'] = $optionElement->find($this->required, Locator::SELECTOR_XPATH)->isVisible() ? 'Yes' : 'No'; foreach ($optionData['options'] as $key => $value) { $optionData['options'][$key]['price'] = $this->getOptionPrice($title, $value['title']); } $result[$title] = $optionData; } return $result; }
/** * Get data of the tabs. * * @param FixtureInterface $fixture * @param SimpleElement $element * @return array * @throws \Exception * * @SuppressWarnings(PHPMD.UnusedLocalVariable) * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function getData(FixtureInterface $fixture = null, SimpleElement $element = null) { $this->waitForElementVisible($this->propertiesTab); $data = []; if (null === $fixture) { foreach ($this->tabs as $tabName => $tab) { if ($this->isTabVisible($tabName)) { $this->openTab($tabName); $this->expandAllToggles(); $tabData = $this->getTabElement($tabName)->getDataFormTab(); $data = array_merge($data, $tabData); } } } else { $isHasData = $fixture instanceof InjectableFixture ? $fixture->hasData() : true; $tabsFields = $isHasData ? $this->getFieldsByTabs($fixture) : []; foreach ($tabsFields as $tabName => $fields) { if ($this->isTabVisible($tabName)) { $this->openTab($tabName); $this->expandAllToggles(); $tabData = $this->getTabElement($tabName)->getDataFormTab($fields, $this->_rootElement); $data = array_merge($data, $tabData); } } } return $data; }
/** * Fill the root form. * * @param FixtureInterface $review * @param SimpleElement|null $element * @return $this */ public function fill(FixtureInterface $review, SimpleElement $element = null) { if ($review->hasData('ratings')) { $this->fillRatings($review); } return parent::fill($review, $element); }
/** * Prepare POST data for creating product request. * * @param FixtureInterface $fixture * @param string|null $prefix [optional] * @return array * * @SuppressWarnings(PHPMD.NPathComplexity) * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ protected function prepareData(FixtureInterface $fixture, $prefix = null) { $fields = $this->replaceMappingData($fixture->getData()); if (!isset($fields['status'])) { // Default product is enabled $fields['status'] = 1; } if (!isset($fields['visibility'])) { // Default product is visible on Catalog, Search $fields['visibility'] = 4; } // Getting Tax class id if ($fixture->hasData('tax_class_id')) { $fields['tax_class_id'] = $fixture->getDataFieldConfig('tax_class_id')['source']->getTaxClassId(); } if (!empty($fields['category_ids'])) { $categoryIds = []; foreach ($fixture->getDataFieldConfig('category_ids')['source']->getCategories() as $category) { $categoryIds[] = $category->getId(); } $fields['category_ids'] = $categoryIds; } if (isset($fields['tier_price'])) { $fields['tier_price'] = $this->preparePriceData($fields['tier_price']); } if (isset($fields['fpt'])) { $attributeLabel = $fixture->getDataFieldConfig('attribute_set_id')['source']->getAttributeSet()->getDataFieldConfig('assigned_attributes')['source']->getAttributes()[0]->getFrontendLabel(); $fields[$attributeLabel] = $this->prepareFptData($fields['fpt']); } if ($isCustomOptions = isset($fields['custom_options'])) { $fields = $this->prepareCustomOptionsData($fields); } if (!empty($fields['website_ids'])) { foreach ($fields['website_ids'] as &$value) { $value = isset($this->mappingData['website_ids'][$value]) ? $this->mappingData['website_ids'][$value] : $value; } } // Getting Attribute Set id if ($fixture->hasData('attribute_set_id')) { $attributeSetId = $fixture->getDataFieldConfig('attribute_set_id')['source']->getAttributeSet()->getAttributeSetId(); $fields['attribute_set_id'] = $attributeSetId; } // Prepare assigned attribute if (isset($fields['attributes'])) { $fields += $fields['attributes']; unset($fields['attributes']); } if (isset($fields['custom_attribute'])) { $fields[$fields['custom_attribute']['code']] = $fields['custom_attribute']['value']; } $fields = $this->prepareStockData($fields); $fields = $prefix ? [$prefix => $fields] : $fields; if ($isCustomOptions) { $fields['affect_product_custom_options'] = 1; } return $fields; }
/** * @param FixtureFactory $fixtureFactory * @param array $params * @param string $data [optional] */ public function __construct(FixtureFactory $fixtureFactory, array $params, $data = '') { $this->params = $params; if (!isset($data['entity']) || $data['entity'] === '-') { $this->data = $data; return; } preg_match('`%(.*?)%`', $data['entity'], $dataSet); $entityConfig = isset($dataSet[1]) ? explode('::', $dataSet[1]) : []; if (count($entityConfig) > 1) { /** @var FixtureInterface $fixture */ $this->entity = $fixtureFactory->createByCode($entityConfig[0], ['dataSet' => $entityConfig[1]]); $this->entity->persist(); $id = $this->entity->hasData('id') ? $this->entity->getId() : $this->entity->getPageId(); $this->data = preg_replace('`(%.*?%)`', $id, $data['entity']); } else { $this->data = strval($data['entity']); } }
/** * Post request for creating Product Attribute * * @param FixtureInterface|null $fixture [optional] * @return array * @throws \Exception */ public function persist(FixtureInterface $fixture = null) { if ($fixture->hasData('attribute_id')) { return ['attribute_id' => $fixture->getData('attribute_id')]; } $data = $this->replaceMappingData($fixture->getData()); $data['frontend_label'] = [0 => $data['frontend_label']]; if (isset($data['options'])) { foreach ($data['options'] as $key => $values) { $index = 'option_' . $key; if ($values['is_default'] == 'Yes') { $data['default'][] = $index; } $data['option']['value'][$index] = [$values['admin'], $values['view']]; $data['option']['order'][$index] = $key; } unset($data['options']); } $url = $_ENV['app_backend_url'] . 'catalog/product_attribute/save/back/edit'; $curl = new BackendDecorator(new CurlTransport(), $this->_configuration); $curl->write($url, $data); $response = $curl->read(); $curl->close(); if (!strpos($response, 'data-ui-id="messages-message-success"')) { throw new \Exception("Product Attribute creating by curl handler was not successful! \n" . $response); } $resultData = []; $matches = []; preg_match('#attribute_id[^>]+value="(\\d+)"#', $response, $matches); $resultData['attribute_id'] = $matches[1]; $matches = []; preg_match_all('#"id":"(\\d+)"#Umi', $response, $matches); if ($fixture->hasData('options')) { $optionsData = $fixture->getData()['options']; foreach (array_unique($matches[1]) as $key => $optionId) { $optionsData[$key]['id'] = $optionId; } $resultData['options'] = $optionsData; } return $resultData; }
/** * Prepare data for create widget. * * @param FixtureInterface $widget * @return array */ protected function prepareData(FixtureInterface $widget) { $data = $this->replaceMappingData($widget->getData()); if ($widget->hasData('store_ids')) { $data['store_ids'][0] = $widget->getDataFieldConfig('store_ids')['source']->getStores()[0]->getStoreId(); } unset($data['code']); unset($data['theme_id']); $data = $this->prepareWidgetInstance($data); $data = $this->prepareParameters($data); return $data; }
/** * Prepare category data for curl. * * @param FixtureInterface $fixture * @return array */ protected function prepareData(FixtureInterface $fixture) { $data['general'] = $this->replaceMappingData($fixture->getData()); $data['is_anchor'] = isset($data['is_anchor']) ? $data['is_anchor'] : 0; if ($fixture->hasData('landing_page')) { $data['general']['landing_page'] = $this->getBlockId($fixture->getLandingPage()); } $diff = array_diff($this->dataUseConfig, array_keys($data['general'])); if (!empty($diff)) { $data['use_config'] = $diff; } return $data; }
/** * Fill form with tabs. * * @param FixtureInterface $fixture * @param SimpleElement|null $element * @return FormSections */ public function fill(FixtureInterface $fixture, SimpleElement $element = null) { if ($fixture->hasData('store_id')) { $store = $fixture->getStoreId(); $storeSwitcherBlock = $this->browser->find($this->storeSwitcherBlock); $storeSwitcherBlock->find($this->dropdownBlock, Locator::SELECTOR_CSS, 'liselectstore')->setValue($store); $modalElement = $this->browser->find($this->confirmModal); /** @var \Magento\Ui\Test\Block\Adminhtml\Modal $modal */ $modal = $this->blockFactory->create('Magento\\Ui\\Test\\Block\\Adminhtml\\Modal', ['element' => $modalElement]); $modal->acceptAlert(); } return parent::fill($fixture, $element); }
/** * Verify displayed product special price on product page(front-end) equals passed from fixture * * @return string|null */ protected function verifySpecialPrice() { if (!$this->product->hasData('special_price')) { return null; } $fixtureProductSpecialPrice = $this->product->getSpecialPrice(); $fixtureProductSpecialPrice = number_format($fixtureProductSpecialPrice, 2); $formProductSpecialPrice = $this->productView->getPriceBlock()->getSpecialPrice(); if ($fixtureProductSpecialPrice == $formProductSpecialPrice) { return null; } return "Displayed product special price on product page(front-end) not equals passed from fixture. " . "Actual: {$formProductSpecialPrice}, expected: {$fixtureProductSpecialPrice}."; }
/** * Post request for creating Attribute Set * * @param FixtureInterface|null $fixture * @return array * * @SuppressWarnings(PHPMD.NPathComplexity) * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function persist(FixtureInterface $fixture = null) { /** @var CatalogAttributeSet $fixture */ $response = $fixture->hasData('attribute_set_id') ? $this->getDefaultAttributeSet($fixture) : $this->createAttributeSet($fixture); $attributeSetId = $fixture->hasData('attribute_set_id') ? $fixture->getAttributeSetId() : $this->getData($this->attributeSetId, $response); $assignedAttributes = $fixture->hasData('assigned_attributes') ? $fixture->getDataFieldConfig('assigned_attributes')['source']->getAttributes() : []; $dataAttribute = $this->getDataAttributes($response); $lastAttribute = array_pop($dataAttribute['attributes']); foreach ($assignedAttributes as $key => $assignedAttribute) { $dataAttribute['attributes'][] = [$assignedAttribute->getAttributeId(), $dataAttribute['groups'][0][0], $lastAttribute[2] + ($key + 1), null]; } $this->updateAttributeSet($attributeSetId, $dataAttribute); return ['attribute_set_id' => $attributeSetId]; }
/** * Post request for creating Subcategory. * * @param FixtureInterface|null $fixture [optional] * @return array */ public function persist(FixtureInterface $fixture = null) { $data['general'] = $this->replaceMappingData($fixture->getData()); if ($fixture->hasData('landing_page')) { $data['general']['landing_page'] = $this->getBlockId($fixture->getLandingPage()); } if ($fixture->hasData('category_products')) { $data['category_products'] = $this->prepareCategoryProducts($fixture); } $diff = array_diff($this->dataUseConfig, array_keys($data['general'])); if (!empty($diff)) { $data['use_config'] = $diff; } $parentCategoryId = $data['general']['parent_id']; $url = $_ENV['app_backend_url'] . 'catalog_category/save/store/0/parent/' . $parentCategoryId . '/?isAjax=true'; $curl = new BackendDecorator(new CurlTransport(), $this->_configuration); $curl->write(CurlInterface::POST, $url, '1.1', [], $data); $response = $curl->read(); $curl->close(); preg_match('~http://.+/id/(\\d+).+?isAjax~', $response, $matches); $id = isset($matches[1]) ? (int) $matches[1] : null; return ['id' => $id]; }
/** * Assert form data equals fixture data * * @param FixtureInterface $product * @param CatalogProductIndex $productGrid * @param CatalogProductEdit $productPage * @return void */ public function processAssert(FixtureInterface $product, CatalogProductIndex $productGrid, CatalogProductEdit $productPage) { $filter = ['sku' => $product->getSku()]; $productGrid->open(); $productGrid->getProductGrid()->searchAndOpen($filter); $productData = $product->getData(); if ($product->hasData('custom_options')) { $customOptionsSource = $product->getDataFieldConfig('custom_options')['source']; $productData['custom_options'] = $customOptionsSource->getCustomOptions(); } $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); }
/** * Fill in the option specified for the product * * @param FixtureInterface $product * @return void * * @SuppressWarnings(PHPMD.NPathComplexity) */ public function fillOptions(FixtureInterface $product) { $dataConfig = $product->getDataConfig(); $typeId = isset($dataConfig['type_id']) ? $dataConfig['type_id'] : null; $checkoutData = null; /** @var CatalogProductSimple $product */ if ($this->hasRender($typeId)) { $this->callRender($typeId, 'fillOptions', ['product' => $product]); } /** @var CatalogProductSimple $product */ $checkoutData = $product->getCheckoutData(); $checkoutCustomOptions = isset($checkoutData['options']['custom_options']) ? $checkoutData['options']['custom_options'] : []; $customOptions = $product->hasData('custom_options') ? $product->getDataFieldConfig('custom_options')['source']->getCustomOptions() : []; $checkoutCustomOptions = $this->prepareCheckoutData($customOptions, $checkoutCustomOptions); $this->getCustomOptionsBlock()->fillCustomOptions($checkoutCustomOptions); }
/** * Assert that product is visible in the assigned category * * @param CatalogCategoryView $catalogCategoryView * @param CmsIndex $cmsIndex * @param FixtureInterface $product * @param Category|null $category * @return void * * @SuppressWarnings(PHPMD.NPathComplexity) */ public function processAssert(CatalogCategoryView $catalogCategoryView, CmsIndex $cmsIndex, FixtureInterface $product, Category $category = null) { $categoryName = $product->hasData('category_ids') ? $product->getCategoryIds()[0] : $category->getName(); $cmsIndex->open(); $cmsIndex->getTopmenu()->selectCategoryByName($categoryName); $isProductVisible = $catalogCategoryView->getListProductBlock()->getProductItem($product)->isVisible(); while (!$isProductVisible && $catalogCategoryView->getBottomToolbar()->nextPage()) { $isProductVisible = $catalogCategoryView->getListProductBlock()->getProductItem($product)->isVisible(); } if ($product->getVisibility() === 'Search' || $this->getStockStatus($product) === 'Out of Stock') { $isProductVisible = !$isProductVisible; $this->errorMessage = 'Product found in this category.'; $this->successfulMessage = 'Asserts that the product could not be found in this category.'; } \PHPUnit_Framework_Assert::assertTrue($isProductVisible, $this->errorMessage); }
/** * @constructor * @param FixtureInterface $product */ public function __construct(FixtureInterface $product) { /** @var CatalogProductSimple $product */ $checkoutData = $product->getCheckoutData(); $cartItem = isset($checkoutData['cartItem']) ? $checkoutData['cartItem'] : []; $customOptions = $product->hasData('custom_options') ? $product->getCustomOptions() : []; $checkoutCustomOptions = isset($checkoutData['options']['custom_options']) ? $checkoutData['options']['custom_options'] : []; foreach ($checkoutCustomOptions as $key => $checkoutCustomOption) { $attribute = str_replace('attribute_key_', '', $checkoutCustomOption['title']); $option = str_replace('option_key_', '', $checkoutCustomOption['value']); $checkoutCustomOptions[$key] = ['title' => isset($customOptions[$attribute]['title']) ? $customOptions[$attribute]['title'] : $attribute, 'value' => isset($customOptions[$attribute]['options'][$option]['title']) ? $customOptions[$attribute]['options'][$option]['title'] : $option]; } $cartItem['options'] = $checkoutCustomOptions; $cartItem['qty'] = isset($checkoutData['qty']) ? $checkoutData['qty'] : 1; $this->data = $cartItem; }
/** * Assert that product can be searched via Quick Search using searchable product attributes (Search by SKU) * * @param CatalogsearchResult $catalogSearchResult * @param CmsIndex $cmsIndex * @param FixtureInterface $product * @return void * * @SuppressWarnings(PHPMD.NPathComplexity) */ public function processAssert(CatalogsearchResult $catalogSearchResult, CmsIndex $cmsIndex, FixtureInterface $product) { $cmsIndex->open(); $sku = $product->hasData('sku') !== false ? $product->getSku() : $product->getName(); $cmsIndex->getSearchBlock()->search($sku); $quantityAndStockStatus = $product->getQuantityAndStockStatus(); $stockStatus = isset($quantityAndStockStatus['is_in_stock']) ? $quantityAndStockStatus['is_in_stock'] : null; $isVisible = $catalogSearchResult->getListProductBlock()->getProductItem($product)->isVisible(); while (!$isVisible && $catalogSearchResult->getBottomToolbar()->nextPage()) { $isVisible = $catalogSearchResult->getListProductBlock()->getProductItem($product)->isVisible(); } 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); }
/** * Get configurable attributes options prices * * @param FixtureInterface $product * @return array */ public function getOptionsPrices(FixtureInterface $product) { /** @var ConfigurableProduct $product */ $attributesData = []; $productVariations = []; if ($product->hasData('configurable_attributes_data')) { $attributesData = $product->getConfigurableAttributesData()['attributes_data']; $productVariations = $product->getConfigurableAttributesData()['matrix']; } $productVariations = array_keys($productVariations); $result = []; foreach ($productVariations as $variation) { $variationOptions = explode(' ', $variation); $result[$variation]['price'] = $this->getOptionPrice($variationOptions, $attributesData); } return $result; }
/** * Checking the product in the page of its price. * * @param CatalogCategoryView $catalogCategoryView * @param CmsIndex $cmsIndex * @param FixtureInterface $product * @param Category $category * @return void */ public function processAssert(CatalogCategoryView $catalogCategoryView, CmsIndex $cmsIndex, FixtureInterface $product, Category $category) { // Open category view page and check visible product $categoryName = $category->getName(); if ($product->hasData('category_ids')) { $categoryIds = $product->getCategoryIds(); $categoryName = is_array($categoryIds) ? reset($categoryIds) : $categoryName; } $cmsIndex->open(); $cmsIndex->getTopmenu()->selectCategoryByName($categoryName); $isProductVisible = $catalogCategoryView->getListProductBlock()->getProductItem($product)->isVisible(); while (!$isProductVisible && $catalogCategoryView->getBottomToolbar()->nextPage()) { $isProductVisible = $catalogCategoryView->getListProductBlock()->getProductItem($product)->isVisible(); } \PHPUnit_Framework_Assert::assertTrue($isProductVisible, 'Product is absent on category page.'); //Process price asserts $this->assertPrice($product, $catalogCategoryView); }
/** * Curl creation of Admin User. * * @param FixtureInterface $fixture * @return array|mixed * @throws \Exception */ public function persist(FixtureInterface $fixture = null) { /** @var \Mage\Admin\Test\Fixture\User $fixture */ $data = $this->replaceMappingData($fixture->getData()); if ($fixture->hasData('role_id')) { $data['roles[]'] = $fixture->getDataFieldConfig('role_id')['source']->getRole()->getRoleId(); } $url = $_ENV['app_backend_url'] . 'permissions_user/save/'; $curl = new BackendDecorator(new CurlTransport(), $this->_configuration); $curl->addOption(CURLOPT_HEADER, 1); $curl->write(CurlInterface::POST, $url, '1.1', [], $data); $response = $curl->read(); $curl->close(); if (!strpos($response, 'class="success-msg"')) { throw new \Exception("Admin user entity creating by curl handler was not successful! Response: {$response}"); } return ['user_id' => $this->getId()]; }
/** * Preparation options before comparing * * @param FixtureInterface $product * @param int|null $actualPrice * @return array * * @SuppressWarnings(PHPMD.NPathComplexity) */ protected function prepareOptions(FixtureInterface $product, $actualPrice = null) { $result = []; $customOptions = $product->hasData('custom_options') ? $product->getDataFieldConfig('custom_options')['source']->getCustomOptions() : null; $actualPrice = $actualPrice ? $actualPrice : $product->getPrice(); foreach ($customOptions as $customOption) { $skippedField = isset($this->skippedFieldOptions[$customOption['type']]) ? $this->skippedFieldOptions[$customOption['type']] : []; foreach ($customOption['options'] as &$option) { // recalculate percent price if ('Percent' == $option['price_type']) { $option['price'] = $actualPrice * $option['price'] / 100; $option['price'] = round($option['price'], 2); } $option = array_diff_key($option, array_flip($skippedField)); } $result[$customOption['title']] = $customOption; } return $result; }
/** * Curl creation of Admin User * * @param FixtureInterface $fixture * @return array|mixed * @throws \Exception */ public function persist(FixtureInterface $fixture = null) { /** @var \Magento\User\Test\Fixture\User $fixture */ $data = $fixture->getData(); if ($fixture->hasData('role_id')) { $data['roles[]'] = $fixture->getDataFieldConfig('role_id')['source']->getRole()->getRoleId(); } $data['is_active'] = isset($data['is_active']) && $data['is_active'] === 'Inactive' ? 0 : 1; $url = $_ENV['app_backend_url'] . 'admin/user/save/active_tab/main_section/'; $curl = new BackendDecorator(new CurlTransport(), $this->_configuration); $curl->addOption(CURLOPT_HEADER, 1); $curl->write($url, $data); $response = $curl->read(); $curl->close(); if (!strpos($response, 'data-ui-id="messages-message-success"')) { throw new \Exception("Admin user entity creating by curl handler was not successful! Response: {$response}"); } $url = 'admin/user/roleGrid/sort/user_id/dir/desc'; $regExpPattern = '/col-user_id[^\\>]+\\>\\s*(\\d+)\\s*<.td>\\s*<[^<>]*?>\\s*' . $data['username'] . '/siu'; $extractor = new Extractor($url, $regExpPattern); return ['user_id' => $extractor->getData()[1]]; }