示例#1
0
文件: Curl.php 项目: aiesh/magento2
 /**
  * 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';
     return $data;
 }
 /**
  * Prepare filter for assert
  *
  * @param FixtureInterface $product
  * @param ReviewInjectable $review
  * @param string $gridStatus
  * @return array
  */
 public function prepareFilter(FixtureInterface $product, ReviewInjectable $review, $gridStatus)
 {
     $filter = [];
     foreach ($this->filter as $key => $item) {
         list($type, $param) = [$key, $item];
         if (is_numeric($key)) {
             $type = $param = $item;
         }
         switch ($param) {
             case 'name':
             case 'sku':
                 $value = $product->getData($param);
                 break;
             case 'select_stores':
                 $value = $review->getData($param)[0];
                 break;
             case 'status_id':
                 $value = $gridStatus != '' ? $gridStatus : $review->getData($param);
                 break;
             default:
                 $value = $review->getData($param);
                 break;
         }
         if ($value !== null) {
             $filter += [$type => $value];
         }
     }
     return $filter;
 }
示例#3
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;
 }
示例#4
0
 /**
  * Post request for creating Subcategory
  *
  * @param FixtureInterface $fixture [optional]
  * @return mixed|string
  */
 public function persist(FixtureInterface $fixture = null)
 {
     $data['general'] = $fixture->getData();
     foreach ($data['general'] as $key => $value) {
         if ($value == 'Yes') {
             $data['general'][$key] = 1;
         }
         if ($value == 'No') {
             $data['general'][$key] = 0;
         }
     }
     $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]) ? $matches[1] : null;
     return ['id' => $id];
 }
示例#5
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]];
 }
示例#6
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;
 }
 /**
  * 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->getData('sku')];
     $productGrid->open()->getProductGrid()->searchAndOpen($filter);
     $fields = $this->convertDownloadableArray($this->prepareFixtureData($product));
     $fieldsForm = $productPage->getForm()->getData($product);
     \PHPUnit_Framework_Assert::assertEquals($fields, $fieldsForm, 'Form data not equals fixture data.');
 }
 /**
  * Verify product special price on product view page
  *
  * @param CatalogProductView $catalogProductView
  * @param FixtureInterface $product
  * @param string $block [optional]
  * @return void
  */
 public function assertPrice(FixtureInterface $product, CatalogProductView $catalogProductView, $block = '')
 {
     $fields = $product->getData();
     $specialPrice = $catalogProductView->getViewBlock()->getPriceBlock()->getSpecialPrice();
     if (isset($fields['special_price'])) {
         \PHPUnit_Framework_Assert::assertEquals(number_format($fields['special_price'], 2), $specialPrice, $this->errorMessage);
     }
 }
示例#9
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;
 }
示例#10
0
文件: Curl.php 项目: aiesh/magento2
 /**
  * Post request for creating tax class
  *
  * @param FixtureInterface $fixture [optional]
  * @return mixed|string
  */
 public function persist(FixtureInterface $fixture = null)
 {
     $data = $fixture->getData();
     $url = $_ENV['app_backend_url'] . 'tax/tax/ajaxSAve/?isAjax=true';
     $curl = new BackendDecorator(new CurlTransport(), new Config());
     $curl->write(CurlInterface::POST, $url, '1.0', array(), $data);
     $response = $curl->read();
     $curl->close();
     $id = $this->getClassId($response);
     return ['id' => $id];
 }
 /**
  * Fill popup form
  *
  * @param FixtureInterface $product
  * @param Element|null $element [optional]
  * @return $this
  */
 public function fill(FixtureInterface $product, Element $element = null)
 {
     $affectedAttributeSet = $product->getData('affected_attribute_set');
     if ($affectedAttributeSet) {
         $fields = ['new_attribute_set_name' => $affectedAttributeSet];
         $mapping = $this->dataMapping($fields);
         $this->_rootElement->find($this->affectedAttributeSetNew)->click();
         $this->_fill($mapping, $element);
     }
     return $this;
 }
示例#12
0
 /**
  * Fill popup form
  *
  * @param FixtureInterface $product
  * @param Element|null $element
  * @return $this
  */
 public function fill(FixtureInterface $product, Element $element = null)
 {
     $data = $product->getData('affect_configurable_product_attributes');
     if (!empty($data)) {
         $this->_rootElement->find($this->affectedAttributeSetNew)->click();
         $fields = ['new_attribute_set_name' => strval($data)];
         $mapping = $this->dataMapping($fields);
         $this->_fill($mapping, $element);
     }
     return $this;
 }
示例#13
0
 /**
  * Prepare POST data for creating customer request
  *
  * @param FixtureInterface $fixture
  * @return array
  */
 protected function prepareData(FixtureInterface $fixture)
 {
     $data = $fixture->getData('fields');
     foreach ($data as $key => $values) {
         $value = $this->getValue($values);
         if (null === $value) {
             continue;
         }
         $data[$key] = $value;
     }
     return $data;
 }
示例#14
0
 /**
  * Post request for creating url rewrite
  *
  * @param FixtureInterface $fixture
  * @throws \Exception
  * @return mixed|void
  */
 public function persist(FixtureInterface $fixture = null)
 {
     $url = $_ENV['app_backend_url'] . $this->url . $fixture->getIdPath();
     $data = $this->replaceMappingData($fixture->getData());
     $curl = new BackendDecorator(new CurlTransport(), new Config());
     $curl->write(CurlInterface::POST, $url, '1.0', array(), $data);
     $response = $curl->read();
     if (!strpos($response, 'data-ui-id="messages-message-success"')) {
         throw new \Exception("Product creation by curl handler was not successful! Response: {$response}");
     }
     $curl->close();
 }
示例#15
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;
 }
示例#16
0
 /**
  * Post request for creating customer in frontend
  *
  * @param FixtureInterface|null $customer
  * @return array
  * @throws \Exception
  */
 public function persist(FixtureInterface $customer = null)
 {
     /** @var CustomerInjectable $customer */
     $url = $_ENV['app_frontend_url'] . 'customer/account/createpost/?nocookie=true';
     $data = $customer->getData();
     $curl = new CurlTransport();
     $curl->write(CurlInterface::POST, $url, '1.0', array(), $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}");
     }
     return ['id' => $this->getCustomerId($customer->getEmail())];
 }
示例#17
0
文件: Curl.php 项目: aiesh/magento2
 /**
  * Post request for creating sitemap
  *
  * @param FixtureInterface $fixture
  * @return array
  * @throws \Exception
  */
 public function persist(FixtureInterface $fixture = null)
 {
     $url = $_ENV['app_backend_url'] . 'admin/sitemap/save/generate/';
     $data = array_merge($this->defaultAttributeValues, $fixture->getData());
     $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("Sitemap entity creating by curl handler was not successful! Response: {$response}");
     }
     return ['sitemap_id' => $this->getSitemapId($data)];
 }
 /**
  * Assert form data equals duplicate product configurable data
  *
  * @param FixtureInterface $product
  * @param CatalogProductIndex $productGrid
  * @param CatalogProductEdit $productPage
  * @return void
  */
 public function processAssert(FixtureInterface $product, CatalogProductIndex $productGrid, CatalogProductEdit $productPage)
 {
     $duplicateProductSku = $product->getSku() . '-1';
     $filter = ['sku' => $duplicateProductSku];
     $productGrid->open();
     $productGrid->getProductGrid()->searchAndOpen($filter);
     $productData = $product->getData();
     $productData['sku'] = $duplicateProductSku;
     $productData['status'] = 'Product offline';
     $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);
 }
示例#19
0
 /**
  * Prepares and returns data to the fixture, ready for comparison
  *
  * @param FixtureInterface $product
  * @return array
  */
 protected function prepareFixtureData(FixtureInterface $product)
 {
     $compareData = $product->getData();
     $compareData = array_filter($compareData);
     array_walk_recursive($compareData, function (&$item, $key, $formattingOptions) {
         if (isset($formattingOptions[$key])) {
             $item = number_format($item, $formattingOptions[$key]['decimals'], $formattingOptions[$key]['dec_point'], $formattingOptions[$key]['thousands_sep']);
         }
     }, $this->formattingOptions);
     if (isset($compareData['special_price'])) {
         $compareData['special_price'] = ['special_price' => $compareData['special_price']];
     }
     return $compareData;
 }
示例#20
0
 /**
  * Post request for creating customer
  *
  * @param FixtureInterface $fixture [optional]
  * @return mixed|string
  */
 public function persist(FixtureInterface $fixture = null)
 {
     $data = $fixture->getData('fields');
     $fields = array();
     foreach ($data as $key => $field) {
         $fields[$key] = $field['value'];
     }
     $url = $_ENV['app_frontend_url'] . 'customer/account/createpost/?nocookie=true';
     $curl = new CurlTransport();
     $curl->write(CurlInterface::POST, $url, '1.0', array(), $fields);
     $response = $curl->read();
     $curl->close();
     return $response;
 }
示例#21
0
文件: Curl.php 项目: aiesh/magento2
 /**
  * Post request for creating tax rate
  *
  * @param FixtureInterface $fixture [optional]
  * @return mixed|string
  */
 public function persist(FixtureInterface $fixture = null)
 {
     $data = $fixture->getData();
     $data['tax_country_id'] = array_search($data['tax_country_id'], $this->countryId);
     if (isset($data['tax_region_id'])) {
         $data['tax_region_id'] = array_search($data['tax_region_id'], $this->regionId);
     }
     $url = $_ENV['app_backend_url'] . 'tax/rate/ajaxSave/?isAjax=true';
     $curl = new BackendDecorator(new CurlTransport(), new Config());
     $curl->write(CurlInterface::POST, $url, '1.0', array(), $data);
     $response = $curl->read();
     $curl->close();
     $id = $this->getTaxRateId($response);
     return ['id' => $id];
 }
示例#22
0
 /**
  * Fill specified option for the product
  *
  * @param FixtureInterface $product
  * @return void
  */
 public function fillOptions(FixtureInterface $product)
 {
     /** @var DownloadableProductInjectable $product */
     $productData = $product->getData();
     $downloadableLinks = isset($productData['downloadable_links']['downloadable']['link']) ? $productData['downloadable_links']['downloadable']['link'] : [];
     $data = $product->getCheckoutData()['options'];
     // Replace link key to label
     foreach ($data['links'] as $key => $linkData) {
         $linkKey = str_replace('link_', '', $linkData['label']);
         $linkData['label'] = isset($downloadableLinks[$linkKey]['title']) ? $downloadableLinks[$linkKey]['title'] : $linkData['label'];
         $data['links'][$key] = $linkData;
     }
     $this->getDownloadableLinksBlock()->fill($data['links']);
     parent::fillOptions($product);
 }
 /**
  * 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);
 }
示例#24
0
 /**
  * Post request for creating a cms page
  *
  * @param FixtureInterface $fixture
  * @return array
  * @throws \Exception
  */
 public function persist(FixtureInterface $fixture = null)
 {
     $url = $_ENV['app_backend_url'] . $this->url;
     $data = $this->prepareData($this->replaceMappingData($fixture->getData()));
     $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("Cms page entity creating by curl handler was not successful! Response: {$response}");
     }
     preg_match("~page_id\\/(\\d*?)\\/~", $response, $matches);
     $id = isset($matches[1]) ? $matches[1] : null;
     return ['page_id' => $id];
 }
示例#25
0
文件: Curl.php 项目: aiesh/magento2
 /**
  * Post request for creating product Rating in backend
  *
  * @param FixtureInterface|null $rating [optional]
  * @return array
  * @throws \Exception
  */
 public function persist(FixtureInterface $rating = null)
 {
     $url = $_ENV['app_backend_url'] . 'review/rating/save/';
     $curl = new BackendDecorator(new CurlTransport(), new Config());
     $data = $this->replaceMappingData($this->prepareData($rating->getData()));
     $data['stores'] = is_array($data['stores']) ? $data['stores'] : [$data['stores']];
     $data += $this->getAdditionalData();
     $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 Rating entity creating by curl handler was not successful! Response:' . $response);
     }
     $ratingId = $this->getProductRatingId();
     return ['rating_id' => $ratingId, 'options' => $this->getRatingOptions($ratingId)];
 }
示例#26
0
 /**
  * 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;
     }
     // Prepare assigned attribute
     if (isset($fields['attributes'])) {
         $fields += $fields['attributes'];
         unset($fields['attributes']);
     }
     $fields = $this->prepareStockData($fields);
     $fields = $prefix ? [$prefix => $fields] : $fields;
     if ($isCustomOptions) {
         $fields['affect_product_custom_options'] = 1;
     }
     return $fields;
 }
示例#27
0
 /**
  * Fill options for the product
  *
  * @param FixtureInterface $product
  * @return void
  */
 public function fillOptions(FixtureInterface $product)
 {
     $productOptions = $product->getCheckoutData();
     if (!empty($productOptions['configurable_options'])) {
         $configurableAttributesData = $product->getData('fields/configurable_attributes_data/value');
         $checkoutData = [];
         foreach ($productOptions['configurable_options'] as $optionData) {
             $titleKey = $optionData['title'];
             $valueKey = $optionData['value'];
             $checkoutData[] = ['title' => $configurableAttributesData[$titleKey]['label']['value'], 'value' => $configurableAttributesData[$titleKey][$valueKey]['option_label']['value']];
         }
         foreach ($checkoutData as $option) {
             $select = $this->_rootElement->find('//div[@class="product-options"]//label[text()="' . $option['title'] . '"]//following-sibling::*//select', Locator::SELECTOR_XPATH, 'select');
             $select->setValue($option['value']);
         }
         $this->_rootElement->find('.ui-dialog-buttonset button:nth-of-type(2)')->click();
     }
 }
示例#28
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;
 }
示例#29
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];
 }
示例#30
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];
 }