예제 #1
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]];
 }
 /**
  * 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;
 }
예제 #3
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;
 }
예제 #4
0
 /**
  * Prepare data from text to values
  *
  * @param FixtureInterface $fixture
  * @return array
  */
 protected function prepareData(FixtureInterface $fixture)
 {
     $data['store'] = $this->replaceMappingData($fixture->getData());
     $data['store_action'] = isset($data['store_action']) ? $data['store_action'] : 'add';
     $data['store_type'] = isset($data['store_type']) ? $data['store_type'] : 'store';
     $data['store']['group_id'] = $fixture->getDataFieldConfig('group_id')['source']->getStoreGroup()->getGroupId();
     return $data;
 }
 /**
  * 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);
 }
예제 #6
0
파일: Curl.php 프로젝트: aiesh/magento2
 /**
  * POST request for creating Customer Group
  *
  * @param FixtureInterface $fixture
  * @return array|mixed
  * @throws \Exception
  */
 public function persist(FixtureInterface $fixture = null)
 {
     $data['code'] = $fixture->getCustomerGroupCode();
     $data['tax_class'] = $fixture->getDataFieldConfig('tax_class_id')['source']->getTaxClass()->getId();
     $url = $_ENV['app_backend_url'] . $this->saveUrl;
     $curl = new BackendDecorator(new CurlTransport(), new Config());
     $curl->addOption(CURLOPT_HEADER, 1);
     $curl->write(CurlInterface::POST, $url, '1.0', array(), $data);
     $response = $curl->read();
     $curl->close();
     if (!strpos($response, 'data-ui-id="messages-message-success"')) {
         throw new \Exception("Customer Group entity creating by curl handler was not successful! Response: {$response}");
     }
     return ['customer_group_id' => $this->getCustomerGroupId($data, $response)];
 }
예제 #7
0
 /**
  * Prepares fixture data for comparison
  *
  * @param array $data
  * @param FixtureInterface $product
  * @param array $sortFields [optional]
  * @return array
  */
 protected function prepareFixtureData(array $data, FixtureInterface $product, array $sortFields = [])
 {
     if (isset($data['website_ids']) && !is_array($data['website_ids'])) {
         $data['website_ids'] = [$data['website_ids']];
     }
     if (isset($data['custom_options'])) {
         $data['custom_options'] = $product->getDataFieldConfig('custom_options')['source']->getCustomOptions();
     }
     if (!empty($this->specialArray)) {
         $data = $this->prepareSpecialPriceArray($data);
     }
     foreach ($sortFields as $path) {
         $data = $this->sortDataByPath($data, $path);
     }
     return $data;
 }
예제 #8
0
 /**
  * Fill the root form
  *
  * @param FixtureInterface $fixture
  * @param Element|null $element
  * @param array $replace [optional]
  * @return $this
  */
 public function fill(FixtureInterface $fixture, Element $element = null, array $replace = [])
 {
     $data = $fixture->getData();
     if (empty($this->getData()['target_path']) && !isset($data['target_path'])) {
         $entity = $fixture->getDataFieldConfig('id_path')['source']->getEntity();
         $data['target_path'] = $entity->hasData('identifier') ? $entity->getIdentifier() : $entity->getUrlKey() . '.html';
     }
     foreach ($replace as $key => $pairs) {
         if (isset($data[$key])) {
             $data[$key] = str_replace(array_keys($pairs), $pairs, $data[$key]);
         }
     }
     // TODO: delete line after removing old fixture
     $fields = isset($data['fields']) ? $data['fields'] : $data;
     $mapping = $this->dataMapping($fields);
     $this->_fill($mapping, $element);
     return $this;
 }
예제 #9
0
 /**
  * Post request for creating Attribute Set
  *
  * @param FixtureInterface $fixture
  * @return array
  * @throws \Exception
  */
 public function persist(FixtureInterface $fixture = null)
 {
     $data = $fixture->getData();
     if (!isset($data['gotoEdit'])) {
         $data['gotoEdit'] = 1;
     }
     $data['skeleton_set'] = $fixture->getDataFieldConfig('skeleton_set')['source']->getAttributeSet()->getAttributeSetId();
     $url = $_ENV['app_backend_url'] . 'catalog/product_set/save/';
     $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*?)\\/.*?data-ui-id=\\"page-actions-toolbar-delete-button\\".*`', $response, $matches);
     $id = isset($matches[1]) ? $matches[1] : null;
     if (!strpos($response, 'data-ui-id="messages-message-success"')) {
         throw new \Exception("Attribute Set creating by curl handler was not successful!");
     }
     return ['attribute_set_id' => $id];
 }
예제 #10
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]];
 }
예제 #11
0
 /**
  * Returns data for curl POST params
  *
  * @param FixtureInterface $fixture
  * @return mixed
  *
  * @SuppressWarnings(PHPMD.UnusedLocalVariable)
  */
 protected function prepareData($fixture)
 {
     $data = $fixture->getData();
     $fields = ['tax_rate', 'tax_customer_class', 'tax_product_class'];
     foreach ($fields as $field) {
         if (!array_key_exists($field, $data)) {
             $data[$field][] = $this->defaultTaxClasses[$field];
             continue;
         }
         $fieldFixture = $fixture->getDataFieldConfig($field);
         $fieldFixture = $fieldFixture['source']->getFixture();
         foreach ($data[$field] as $key => $value) {
             $id = $fieldFixture[$key]->getId();
             if ($id === null) {
                 $fieldFixture[$key]->persist();
                 $id = $fieldFixture[$key]->getId();
             }
             $data[$field][$key] = $id;
         }
     }
     return $data;
 }
예제 #12
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;
 }
예제 #13
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);
     }
 }
 /**
  * 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;
 }
예제 #15
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;
 }
예제 #16
0
 /**
  * Preparing matrix data
  *
  * @param FixtureInterface $product
  * @return array
  */
 protected function prepareVariationsMatrix(FixtureInterface $product)
 {
     /** @var ConfigurableAttributesData $configurableAttributesData */
     $configurableAttributesData = $product->getDataFieldConfig('configurable_attributes_data')['source'];
     $attributesData = $configurableAttributesData->getAttributesData();
     $matrixData = $product->getConfigurableAttributesData()['matrix'];
     $result = [];
     foreach ($matrixData as $variationKey => $variation) {
         $compositeKeys = explode(' ', $variationKey);
         $keyIds = [];
         $configurableAttribute = [];
         foreach ($compositeKeys as $compositeKey) {
             list($attributeKey, $optionKey) = explode(':', $compositeKey);
             $attribute = $attributesData[$attributeKey];
             $keyIds[] = $attribute['options'][$optionKey]['id'];
             $configurableAttribute[] = sprintf('"%s":"%s"', $attribute['attribute_code'], $attribute['options'][$optionKey]['id']);
         }
         $keyIds = implode('-', $keyIds);
         $variation['configurable_attribute'] = '{' . implode(',', $configurableAttribute) . '}';
         $result[$keyIds] = $variation;
     }
     return $result;
 }
예제 #17
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;
 }
예제 #18
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];
 }
예제 #19
0
파일: Curl.php 프로젝트: aiesh/magento2
 /**
  * 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();
     $data['group']['root_category_id'] = $categoryId;
     $data['group']['website_id'] = $websiteId;
     $data['store_action'] = isset($data['store_action']) ? $data['store_action'] : 'add';
     $data['store_type'] = isset($data['store_type']) ? $data['store_type'] : 'group';
     return $data;
 }