/**
  * Get configurable product options
  *
  * @param FixtureInterface|null $product [optional]
  * @return array
  * @throws \Exception
  */
 public function getOptions(FixtureInterface $product)
 {
     if ($product instanceof InjectableFixture) {
         /** @var ConfigurableProductInjectable $product */
         $attributesData = $product->hasData('configurable_attributes_data') ? $product->getConfigurableAttributesData()['attributes_data'] : [];
     } else {
         /** @var ConfigurableProduct $product */
         $attributesData = $product->getConfigurableAttributes();
         foreach ($attributesData as $key => $attributeData) {
             $attributeData['label'] = $attributeData['label']['value'];
             $attributeData['frontend_input'] = 'dropdown';
             $attributesData[$key] = $attributeData;
         }
     }
     $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];
         $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';
         $result[$title] = $optionData;
     }
     return $result;
 }
示例#2
0
文件: Curl.php 项目: aiesh/magento2
 /**
  * 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;
 }
示例#3
0
文件: Curl.php 项目: aiesh/magento2
 /**
  * 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 ($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]];
 }
示例#4
0
文件: Curl.php 项目: aiesh/magento2
 /**
  * Post request for creating customer in frontend
  *
  * @param FixtureInterface|null $customer
  * @return array
  * @throws \Exception
  */
 public function persist(FixtureInterface $customer = null)
 {
     $address = [];
     $result = [];
     /** @var CustomerInjectable $customer */
     $url = $_ENV['app_frontend_url'] . 'customer/account/createpost/?nocookie=true';
     $data = $customer->getData();
     if ($customer->hasData('address')) {
         $address = $customer->getAddress();
         unset($data['address']);
     }
     $curl = new CurlTransport();
     $curl->write(CurlInterface::POST, $url, '1.0', [], $data);
     $response = $curl->read();
     $curl->close();
     if (!strpos($response, 'data-ui-id="global-messages-message-success"')) {
         throw new \Exception("Customer entity creating  by curl handler was not successful! Response: {$response}");
     }
     $result['id'] = $this->getCustomerId($customer->getEmail());
     $data['customer_id'] = $result['id'];
     if (!empty($address)) {
         $data['address'] = $address;
         $this->addAddress($data);
     }
     return $result;
 }
示例#5
0
 /**
  * Get data of Customer information, addresses on tabs.
  *
  * @param FixtureInterface $customer
  * @param FixtureInterface|FixtureInterface[]|null $address
  * @return array
  */
 public function getDataCustomer(FixtureInterface $customer, $address = null)
 {
     $data = ['customer' => $customer->hasData() ? parent::getData($customer) : parent::getData()];
     if (null !== $address) {
         $this->openTab('addresses');
         $data['addresses'] = $this->getTabElement('addresses')->getDataAddresses($address);
     }
     return $data;
 }
示例#6
0
文件: IdPath.php 项目: aiesh/magento2
 /**
  * @param FixtureFactory $fixtureFactory
  * @param array $params
  * @param array $data [optional]
  */
 public function __construct(FixtureFactory $fixtureFactory, array $params, array $data = [])
 {
     $this->params = $params;
     if (!isset($data['entity']) || $data['entity'] === '-') {
         $this->data = array_shift($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']);
     }
 }
示例#7
0
文件: Curl.php 项目: aiesh/magento2
 /**
  * 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];
 }
示例#8
0
 /**
  * @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'] = isset($cartItem['options']) ? $cartItem['options'] + $checkoutCustomOptions : $checkoutCustomOptions;
     $this->data = $cartItem;
 }
 /**
  * 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);
 }
 /**
  * Assert that product is visible in the assigned category
  *
  * @param CatalogCategoryView $catalogCategoryView
  * @param CmsIndex $cmsIndex
  * @param FixtureInterface $product
  * @param CatalogCategory|null $category
  * @return void
  *
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function processAssert(CatalogCategoryView $catalogCategoryView, CmsIndex $cmsIndex, FixtureInterface $product, CatalogCategory $category = null)
 {
     $categoryName = $product->hasData('category_ids') ? $product->getCategoryIds()[0] : $category->getName();
     $cmsIndex->open();
     $cmsIndex->getTopmenu()->selectCategoryByName($categoryName);
     $isProductVisible = $catalogCategoryView->getListProductBlock()->isProductVisible($product->getName());
     while (!$isProductVisible && $catalogCategoryView->getBottomToolbar()->nextPage()) {
         $isProductVisible = $catalogCategoryView->getListProductBlock()->isProductVisible($product->getName());
     }
     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);
 }
 /**
  * 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()->isProductVisible($product->getName());
     while (!$isVisible && $catalogSearchResult->getBottomToolbar()->nextPage()) {
         $isVisible = $catalogSearchResult->getListProductBlock()->isProductVisible($product->getName());
     }
     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);
 }
示例#12
0
 /**
  * Checking the product in the page of its price
  *
  * @param CatalogCategoryView $catalogCategoryView
  * @param CmsIndex $cmsIndex
  * @param FixtureInterface $product
  * @param CatalogCategory $category
  * @return void
  */
 public function processAssert(CatalogCategoryView $catalogCategoryView, CmsIndex $cmsIndex, FixtureInterface $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()->selectCategoryByName($categoryName);
     $isProductVisible = $catalogCategoryView->getListProductBlock()->isProductVisible($product->getName());
     while (!$isProductVisible && $catalogCategoryView->getToolbar()->nextPage()) {
         $isProductVisible = $catalogCategoryView->getListProductBlock()->isProductVisible($product->getName());
     }
     \PHPUnit_Framework_Assert::assertTrue($isProductVisible, 'Product is absent on category page.');
     //Process price asserts
     $this->assertPrice($product, $catalogCategoryView);
 }
 /**
  * Preparation options before comparing
  *
  * @param array $options
  * @return array
  */
 protected function prepareOptionArray(array $options)
 {
     $result = [];
     $productPrice = $this->product->hasData('group_price') ? $this->product->getGroupPrice()[0]['price'] : $this->product->getPrice();
     $placeholder = ['Yes' => true, 'No' => false];
     foreach ($options as $option) {
         $result[$option['title']]['is_require'] = $placeholder[$option['is_require']];
         $result[$option['title']]['title'] = $option['title'];
         $result[$option['title']]['price'] = [];
         foreach ($option['options'] as $optionValue) {
             if ($optionValue['price_type'] === 'Percent') {
                 $optionValue['price'] = $productPrice / 100 * $optionValue['price'];
             }
             $result[$option['title']]['price'][] = number_format($optionValue['price'], 2);
         }
     }
     return $result;
 }
示例#14
0
文件: Curl.php 项目: aiesh/magento2
 /**
  * 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());
     }
     $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 . '/';
     $curl = new BackendDecorator(new CurlTransport(), new Config());
     $curl->write(CurlInterface::POST, $url, '1.0', array(), $data);
     $response = $curl->read();
     $curl->close();
     preg_match('#http://.+/id/(\\d+).+store/#m', $response, $matches);
     $id = isset($matches[1]) ? (int) $matches[1] : null;
     return ['id' => $id];
 }
示例#15
0
文件: Curl.php 项目: aiesh/magento2
 /**
  * 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();
     }
     $url = $_ENV['app_backend_url'] . 'admin/user/save/active_tab/main_section/';
     $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("Admin user entity creating by curl handler was not successful! Response: {$response}");
     }
     $url = 'admin/user/roleGrid/sort/user_id/dir/desc';
     $regExpPattern = '/class=\\"\\scol\\-id col\\-user_id\\W*>\\W+(\\d+)\\W+<\\/td>\\W+<td[\\w\\s\\"=\\-]*?>\\W+?' . $data['username'] . '/siu';
     $extractor = new Extractor($url, $regExpPattern);
     return ['user_id' => $extractor->getData()[1]];
 }
示例#16
0
 /**
  * Post request for creating Product Attribute
  *
  * @param FixtureInterface|null $fixture [optional]
  * @return array
  * @throws \Exception
  */
 public function persist(FixtureInterface $fixture = null)
 {
     $data = $this->replaceMappingData($fixture->getData());
     $data['frontend_label'] = [0 => $data['frontend_label']];
     if (isset($data['options'])) {
         foreach ($data['options'] as $key => $values) {
             if ($values['is_default'] == 'Yes') {
                 $data['default'][] = $values['view'];
             }
             $index = 'option_' . $key;
             $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(), new Config());
     $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("Product Attribute creating by curl handler was not successful!");
     }
     $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 ($matches[1] as $key => $optionId) {
             $optionsData[$key]['id'] = $optionId;
         }
         $resultData['options'] = $optionsData;
     }
     return $resultData;
 }
示例#17
0
 /**
  * Fill in the option specified for the product
  *
  * @param FixtureInterface $product
  * @return void
  */
 public function fillOptions(FixtureInterface $product)
 {
     $dataConfig = $product->getDataConfig();
     $typeId = isset($dataConfig['type_id']) ? $dataConfig['type_id'] : null;
     /** @var CatalogProductSimple $product */
     if ($this->hasRender($typeId)) {
         $this->callRender($typeId, 'fillOptions', ['product' => $product]);
     } else {
         $optionsCheckoutData = [];
         if ($product instanceof InjectableFixture) {
             /** @var CatalogProductSimple $product */
             $customOptions = $product->hasData('custom_options') ? $product->getDataFieldConfig('custom_options')['source']->getCustomOptions() : [];
             $checkoutData = $product->getCheckoutData();
             $productCheckoutData = isset($checkoutData['custom_options']) ? $checkoutData['custom_options'] : [];
             $optionsCheckoutData = $this->prepareCheckoutData($customOptions, $productCheckoutData);
         }
         $this->getCustomOptionsBlock()->fillCustomOptions($optionsCheckoutData);
     }
 }
示例#18
0
 /**
  * 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 {
         $isHasData = $fixture instanceof InjectableFixture ? $fixture->hasData() : true;
         $tabsFields = $isHasData ? $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;
 }
示例#19
0
文件: Curl.php 项目: aiesh/magento2
 /**
  * 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());
     // 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['group_price'])) {
         $fields['group_price'] = $this->preparePriceData($fields['group_price']);
     }
     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;
     }
     $fields = $this->prepareStockData($fields);
     $fields = $prefix ? [$prefix => $fields] : $fields;
     if ($isCustomOptions) {
         $fields['affect_product_custom_options'] = 1;
     }
     return $fields;
 }
示例#20
0
 /**
  * Get product options
  *
  * @param FixtureInterface $product
  * @return array
  * @throws \Exception
  */
 public function getOptions(FixtureInterface $product)
 {
     if ($product instanceof InjectableFixture) {
         $dataOptions = $product->hasData('custom_options') ? $product->getDataFieldConfig('custom_options')['source']->getCustomOptions() : [];
     } else {
         // TODO: Removed after refactoring(removed) old product fixture.
         $dataOptions = $product->getData('fields/custom_options/value');
         $dataOptions = $dataOptions ? $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];
         $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->find($this->required, Locator::SELECTOR_XPATH)->isVisible() ? 'Yes' : 'No';
         $result[$title] = $optionData;
     }
     return ['custom_options' => $result];
 }
示例#21
0
 /**
  * Prepare POST data for creating product request
  *
  * @param FixtureInterface $fixture
  * @param string|null $prefix [optional]
  * @return array
  *
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 protected function prepareData(FixtureInterface $fixture, $prefix = null)
 {
     $fields = $this->replaceMappingData($fixture->getData());
     // Getting Tax class id
     if ($fixture->hasData('tax_class_id')) {
         $taxClassId = $fixture->getDataFieldConfig('tax_class_id')['source']->getTaxClass()->getId();
         $fields['tax_class_id'] = $taxClassId === null ? $this->getTaxClassId($fields['tax_class_id']) : $taxClassId;
     }
     if (!empty($fields['category_ids'])) {
         $categoryIds = [];
         foreach ($fields['category_ids'] as $categoryData) {
             $categoryIds[] = $categoryData['id'];
         }
         $fields['category_ids'] = $categoryIds;
     }
     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;
     }
     $fields = $this->prepareStockData($fields);
     return $prefix ? [$prefix => $fields] : $fields;
 }
 /**
  * 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;
 }
 /**
  * Verify product displaying on frontend
  *
  * @param FixtureInterface $product
  * @return array
  */
 protected function isNotDisplayingOnFrontendAssert(FixtureInterface $product)
 {
     $errors = [];
     // Check the product page is not available
     // TODO fix initialization url for frontend page
     $this->browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html');
     $titleBlock = $this->catalogProductView->getTitleBlock();
     if ($titleBlock->getTitle() !== self::NOT_FOUND_MESSAGE) {
         $errors[] = '- the headline on the page does not match, the text should be -> "' . self::NOT_FOUND_MESSAGE . '".';
     }
     $this->cmsIndex->open();
     $this->cmsIndex->getSearchBlock()->search($product->getSku());
     if ($this->catalogSearchResult->getListProductBlock()->isProductVisible($product->getName())) {
         $errors[] = '- successful product search.';
     }
     $categoryName = $product->hasData('category_ids') ? $product->getCategoryIds()[0] : $this->category->getName();
     $this->cmsIndex->open();
     $this->cmsIndex->getTopmenu()->selectCategoryByName($categoryName);
     $isProductVisible = $this->catalogCategoryView->getListProductBlock()->isProductVisible($product->getName());
     while (!$isProductVisible && $this->catalogCategoryView->getBottomToolbar()->nextPage()) {
         $isProductVisible = $this->catalogCategoryView->getListProductBlock()->isProductVisible($product->getName());
     }
     if ($isProductVisible) {
         $errors[] = '- product with name "{$product->getName()}" is found in this category.';
     }
     return $errors;
 }
示例#24
0
文件: Form.php 项目: Mohitsahu123/mtf
 /**
  * Get data of the root form
  *
  * @param FixtureInterface|null $fixture
  * @param Element|null $element
  * @return array
  */
 public function getData(FixtureInterface $fixture = null, Element $element = null)
 {
     if (null === $fixture) {
         $fields = null;
     } else {
         $isHasData = $fixture instanceof InjectableFixture ? $fixture->hasData() : true;
         $data = $isHasData ? $fixture->getData() : [];
         $fields = isset($data['fields']) ? $data['fields'] : $data;
     }
     $mapping = $this->dataMapping($fields);
     return $this->_getData($mapping, $element);
 }
示例#25
0
 /**
  * Prepare custom options for fill
  *
  * @param FixtureInterface $product
  * @param array $customOptions
  * @return array
  */
 protected function prepareCustomOptions(FixtureInterface $product, array $customOptions)
 {
     $options = [];
     $productCustomOptions = $product->hasData('custom_options') ? $product->getDataFieldConfig('custom_options')['source']->getCustomOptions() : null;
     if ($productCustomOptions !== null) {
         foreach ($customOptions as $key => $option) {
             $type = $productCustomOptions[$option['option'] - 1]['type'];
             $title = $productCustomOptions[$option['option'] - 1]['title'];
             $titleOption = [];
             foreach ($option['value'] as $value) {
                 $titleOption[] = is_numeric($value) ? $productCustomOptions[$option['option'] - 1]['options'][$value - 1]['title'] : null;
             }
             $options[$key] = $this->dataMapping([$option, $type, $title, $titleOption]);
         }
     }
     return $options;
 }