/**
  * Get data of the tabs.
  *
  * @param InjectableFixture|null $fixture
  * @param Element|null $element
  * @return array
  *
  * @SuppressWarnings(PHPMD.UnusedLocalVariable)
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function getData(InjectableFixture $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;
 }
 /**
  * Get configurable product options.
  *
  * @param InjectableFixture|null $product [optional]
  * @return array
  * @throws \Exception
  */
 public function getOptions(InjectableFixture $product)
 {
     /** @var ConfigurableProduct $product */
     $attributesData = $product->hasData('configurable_options') ? $product->getConfigurableOptions()['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 Element $optionElement */
         $optionElement = $listOptions[$title];
         $type = $option['frontend_input'];
         $option['frontend_input'] = explode('/', $option['frontend_input'])[1];
         $typeMethod = preg_replace('/[^a-zA-Z]/', '', $option['frontend_input']);
         $getTypeData = 'get' . ucfirst(strtolower($typeMethod)) . 'Data';
         $optionData = $this->{$getTypeData}($optionElement);
         $optionData['title'] = $title;
         $optionData['type'] = $type;
         $isRequire = $this->_rootElement->find(sprintf($this->required, $title), Locator::SELECTOR_XPATH)->isVisible();
         $optionData['is_require'] = $isRequire ? 'Yes' : 'No';
         $result[$title] = $optionData;
     }
     return $result;
 }
 /**
  * Preparation of category data.
  *
  * @return void
  */
 protected function prepareCategory()
 {
     if ($this->fixture->hasData('category_ids')) {
         $this->fields['product']['category_ids'] = [];
         foreach ($this->fixture->getDataFieldConfig('category_ids')['source']->getCategories() as $category) {
             $this->fields['product']['category_ids'][] = $category->getId();
         }
     }
 }
 /**
  * Fill default fields.
  *
  * @param InjectableFixture $product
  * @return void
  */
 protected function fillDefaultField(InjectableFixture $product)
 {
     $data = [];
     foreach ($this->defaultFields as $field) {
         if ($product->hasData($field)) {
             $data[$field . '_autogenerate'] = 'No';
         }
     }
     $mapping = $this->dataMapping($data);
     $this->_fill($mapping);
 }
 /**
  * Assert that out of stock product is visible in the assigned category.
  *
  * @param CatalogCategoryView $catalogCategoryView
  * @param CmsIndex $cmsIndex
  * @param InjectableFixture $product
  * @param CatalogCategory|null $category
  * @return void
  */
 public function processAssert(CatalogCategoryView $catalogCategoryView, CmsIndex $cmsIndex, InjectableFixture $product, CatalogCategory $category = null)
 {
     $categoryName = $product->hasData('category_ids') ? $product->getCategoryIds()[0] : $category->getName();
     $cmsIndex->open();
     $cmsIndex->getTopmenu()->selectCategory($categoryName);
     $isProductVisible = $catalogCategoryView->getListProductBlock()->isProductVisible($product);
     while (!$isProductVisible && $catalogCategoryView->getBottomToolbar()->nextPage()) {
         $isProductVisible = $catalogCategoryView->getListProductBlock()->isProductVisible($product);
     }
     \PHPUnit_Framework_Assert::assertTrue($isProductVisible, "Product is absent on category page.");
 }
 /**
  * Add this attribute to Default attribute Template. Create product and Assert that created attribute
  * is displayed on product form (Products > Inventory > Catalog).
  *
  * @param InjectableFixture $product
  * @param CatalogProductIndex $productGrid
  * @param CatalogProductEdit $productEdit
  * @param CatalogProductAttribute $attribute
  * @param CatalogAttributeSet $attributeSet
  * @param CatalogProductAttribute $productAttributeOriginal
  * @throws \Exception
  * @return void
  */
 public function processAssert(InjectableFixture $product, CatalogProductIndex $productGrid, CatalogProductEdit $productEdit, CatalogProductAttribute $attribute, CatalogAttributeSet $attributeSet, CatalogProductAttribute $productAttributeOriginal = null)
 {
     if (!$product->hasData('sku')) {
         $product = $this->createProductWithAttributeSet($productAttributeOriginal, $attributeSet);
     }
     $filterProduct = ['sku' => $product->getSku()];
     $productGrid->open();
     $productGrid->getProductGrid()->searchAndOpen($filterProduct);
     $catalogProductAttribute = $productAttributeOriginal !== null ? array_merge($productAttributeOriginal->getData(), $attribute->getData()) : $attribute->getData();
     \PHPUnit_Framework_Assert::assertTrue($productEdit->getProductForm()->checkAttributeLabel($catalogProductAttribute), "Product Attribute is absent on Product form.");
 }
 /**
  * @constructor
  * @param FixtureFactory $fixtureFactory
  * @param array $params
  * @param array $data
  */
 public function __construct(FixtureFactory $fixtureFactory, array $params, array $data = [])
 {
     $this->params = $params;
     $explodeValue = explode('::', $data['value']);
     if (!empty($explodeValue) && count($explodeValue) > 1) {
         $fixtureCode = $explodeValue[0];
         $dataSet = isset($explodeValue[2]) ? $explodeValue[1] : '';
         $searchValue = isset($explodeValue[2]) ? $explodeValue[2] : $explodeValue[1];
         $this->product = $fixtureFactory->createByCode($fixtureCode, ['dataSet' => $dataSet]);
         if (!$this->product->hasData('id')) {
             $this->product->persist();
         }
         if ($this->product->hasData($searchValue)) {
             $getProperty = 'get' . str_replace(' ', '', ucwords(str_replace('_', ' ', $searchValue)));
             $this->data = $this->product->{$getProperty}();
         } else {
             $this->data = $searchValue;
         }
     } else {
         $this->data = strval($data['value']);
     }
 }
Beispiel #8
0
 /**
  * Preparation of fpt attribute data.
  *
  * @return void
  */
 protected function prepareFpt()
 {
     if ($this->fixture->hasData('fpt')) {
         $fptLabel = $this->fixture->getDataFieldConfig('attribute_set_id')['source']->getAttributeSet()->getDataFieldConfig('assigned_attributes')['source']->getAttributes()[0]->getFrontendLabel();
         $fptValues = $this->fields['product'][$fptLabel];
         foreach ($fptValues as $key => $item) {
             $item['value'] = $item['price'];
             unset($item['price']);
             $fptValues[$key] = $item;
         }
         $this->fields['product']['custom_attributes'][] = ['attribute_code' => $fptLabel, 'value' => $fptValues];
         unset($this->fields['product'][$fptLabel]);
     }
 }
 /**
  * Assert that product is visible in the assigned category.
  *
  * @param CatalogCategoryView $catalogCategoryView
  * @param CmsIndex $cmsIndex
  * @param InjectableFixture $product
  * @param CatalogCategory|null $category
  * @return void
  *
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function processAssert(CatalogCategoryView $catalogCategoryView, CmsIndex $cmsIndex, InjectableFixture $product, CatalogCategory $category = null)
 {
     $categoryName = $product->hasData('category_ids') ? $product->getCategoryIds()[0] : $category->getName();
     $cmsIndex->open();
     $cmsIndex->getTopmenu()->selectCategory($categoryName);
     $isProductVisible = $catalogCategoryView->getListProductBlock()->isProductVisible($product);
     while (!$isProductVisible && $catalogCategoryView->getBottomToolbar()->nextPage()) {
         $isProductVisible = $catalogCategoryView->getListProductBlock()->isProductVisible($product);
     }
     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);
 }
 /**
  * Verify displayed product price on product page(front-end) equals passed from fixture.
  *
  * @return string|null
  */
 protected function verifyPrice()
 {
     if ($this->product->hasData('price') == false) {
         return null;
     }
     $fixtureProductPrice = number_format($this->product->getPrice(), 2);
     $formProductPrice = $this->productView->getPriceBlock()->getRegularPrice();
     if ($fixtureProductPrice == $formProductPrice) {
         return null;
     }
     $error = "Displayed product price on product page(front-end) not equals passed from fixture. " . "Actual: {$formProductPrice}, expected: {$fixtureProductPrice}.";
     $verifySpecialPriceResult = $this->verifySpecialPrice();
     if ($verifySpecialPriceResult !== null) {
         $error .= $verifySpecialPriceResult;
     }
     return $error;
 }
 /**
  * Add this attribute to Default attribute Template. Create product and Assert that created attribute
  * is displayed on product form (Products > Inventory > Catalog).
  *
  * @param InjectableFixture $product
  * @param FixtureFactory $fixtureFactory
  * @param CatalogProductIndex $catalogProductIndex
  * @param CatalogProductEdit $catalogProductEdit
  * @param CatalogProductAttribute $attribute
  * @param CatalogAttributeSet $attributeSet
  * @param CatalogProductAttribute $productAttributeOriginal
  * @throws \Exception
  * @return void
  */
 public function processAssert(InjectableFixture $product, FixtureFactory $fixtureFactory, CatalogProductIndex $catalogProductIndex, CatalogProductEdit $catalogProductEdit, CatalogProductAttribute $attribute, CatalogAttributeSet $attributeSet, CatalogProductAttribute $productAttributeOriginal = null)
 {
     $this->fixtureFactory = $fixtureFactory;
     $this->catalogProductIndex = $catalogProductIndex;
     $this->catalogProductEdit = $catalogProductEdit;
     if (!$product->hasData('sku')) {
         if (!$productAttributeOriginal) {
             $productAttributeOriginal = $attribute;
         }
         $product = $this->objectManager->create('Magento\\Catalog\\Test\\TestStep\\CreateProductWithAttributeSetStep', ['attribute' => $productAttributeOriginal, 'attributeSet' => $attributeSet])->run();
         $product = $product['product'];
     }
     $filterProduct = ['sku' => $product->getSku()];
     $catalogProductIndex->open();
     $catalogProductIndex->getProductGrid()->searchAndOpen($filterProduct);
     $catalogProductAttribute = $productAttributeOriginal !== null ? array_merge($productAttributeOriginal->getData(), $attribute->getData()) : $attribute->getData();
     \PHPUnit_Framework_Assert::assertTrue($catalogProductEdit->getProductForm()->checkAttributeLabel($catalogProductAttribute), "Product Attribute is absent on Product form.");
 }
 /**
  * Checking the product in the page of its price.
  *
  * @param CatalogCategoryView $catalogCategoryView
  * @param CmsIndex $cmsIndex
  * @param InjectableFixture $product
  * @param CatalogCategory $category
  * @return void
  */
 public function processAssert(CatalogCategoryView $catalogCategoryView, CmsIndex $cmsIndex, InjectableFixture $product, CatalogCategory $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()->selectCategory($categoryName);
     $isProductVisible = $catalogCategoryView->getListProductBlock()->isProductVisible($product);
     while (!$isProductVisible && $catalogCategoryView->getBottomToolbar()->nextPage()) {
         $isProductVisible = $catalogCategoryView->getListProductBlock()->isProductVisible($product);
     }
     \PHPUnit_Framework_Assert::assertTrue($isProductVisible, 'Product is absent on category page.');
     //Process price asserts
     $this->assertPrice($product, $catalogCategoryView);
 }
 /**
  * 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);
 }
Beispiel #14
0
 /**
  * Get product options.
  *
  * @param InjectableFixture $product
  * @return array
  * @throws \Exception
  */
 public function getOptions(InjectableFixture $product)
 {
     $dataOptions = $product->hasData('custom_options') ? $product->getCustomOptions() : [];
     if (empty($dataOptions)) {
         return $dataOptions;
     }
     $listCustomOptions = $this->getListOptions();
     $result = [];
     foreach ($dataOptions as $option) {
         $title = $option['title'];
         if (!isset($listCustomOptions[$title])) {
             throw new \Exception("Can't find option: \"{$title}\"");
         }
         /** @var Element $optionElement */
         $optionElement = $listCustomOptions[$title];
         $option['type'] = explode('/', $option['type'])[1];
         $typeMethod = preg_replace('/[^a-zA-Z]/', '', $option['type']);
         $getTypeData = 'get' . ucfirst(strtolower($typeMethod)) . 'Data';
         $optionData = $this->{$getTypeData}($optionElement);
         $optionData['title'] = $title;
         $optionData['type'] = $option['type'];
         $optionData['is_require'] = $optionElement['title']->find($this->required, Locator::SELECTOR_XPATH)->isVisible() ? 'Yes' : 'No';
         $result[$title] = $optionData;
     }
     return ['custom_options' => $result];
 }
 /**
  * Prepare categories for fill.
  *
  * @param InjectableFixture $product
  * @param CatalogCategory|null $category
  * @return array
  */
 protected function prepareCategories(InjectableFixture $product, CatalogCategory $category = null)
 {
     return $category ? [$category] : ($product->hasData('category_ids') ? $product->getDataFieldConfig('category_ids')['source']->getCategories() : []);
 }
 /**
  * Get product actual price.
  *
  * @param InjectableFixture $product
  * @return int
  */
 protected function getProductActualPrice(InjectableFixture $product)
 {
     return $product->hasData('special_price') ? $product->getSpecialPrice() : $product->getPrice();
 }
Beispiel #17
0
 /**
  * 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);
 }
 /**
  * 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;
 }
 /**
  * Prepare catalog price rule.
  *
  * @param string $dataSet
  * @return CatalogRule
  */
 protected function prepareCatalogPriceRule($dataSet)
 {
     $rule = $this->fixtureFactory->createByCode('catalogRule', ['dataSet' => $dataSet])->getData('rule');
     if ($this->product->hasData('category_ids')) {
         $pattern = '[Category|is|%d]';
         $category = $this->product->getDataFieldConfig('category_ids')['source']->getProductCategory();
         $rule = sprintf($pattern, $category->getId());
     }
     return $this->fixtureFactory->createByCode('catalogRule', ['dataSet' => $dataSet, 'data' => ['rule' => $rule]]);
 }
Beispiel #20
0
 /**
  * Prepare config data.
  *
  * @param InjectableFixture $product
  * @return array
  */
 protected function prepareConfig(InjectableFixture $product)
 {
     $config = $product->getDataConfig();
     if ($product->hasData('attribute_set_id')) {
         $config['create_url_params']['set'] = $product->getDataFieldConfig('attribute_set_id')['source']->getAttributeSet()->getAttributeSetId();
     }
     return $config;
 }
 /**
  * Get data of the tabs.
  *
  * @param InjectableFixture|null $fixture
  * @param Element|null $element
  * @return array
  *
  * @SuppressWarnings(PHPMD.UnusedLocalVariable)
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function getData(InjectableFixture $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) : [];
         foreach ($tabsFields as $tabName => $fields) {
             $this->openTab($tabName);
             $tabData = $this->getTabElement($tabName)->getDataFormTab($fields, $this->_rootElement);
             $data = array_merge($data, $tabData);
         }
     }
     return $data;
 }