Exemple #1
0
 /**
  * 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]];
 }
Exemple #2
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];
 }
Exemple #3
0
 /**
  * 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];
 }
Exemple #4
0
 /**
  * Get customer id by email
  *
  * @param string $email
  * @return int|null
  */
 protected function getCustomerId($email)
 {
     $filter = ['email' => $email];
     $url = $_ENV['app_backend_url'] . 'customer/index/grid/filter/' . $this->encodeFilter($filter);
     $curl = new BackendDecorator(new CurlTransport(), new Config());
     $curl->write(CurlInterface::GET, $url, '1.0');
     $response = $curl->read();
     $curl->close();
     preg_match('/data-column="entity_id"[^>]*>\\s*([0-9]+)\\s*</', $response, $match);
     return empty($match[1]) ? null : $match[1];
 }
 /**
  * Post request for creating customer in backend
  *
  * @param FixtureInterface $fixture [optional]
  * @return mixed|string
  */
 public function persist(FixtureInterface $fixture = null)
 {
     $params = $this->_prepareData($fixture);
     $url = $_ENV['app_backend_url'] . 'customer/index/save/active_tab/account';
     $curl = new BackendDecorator(new CurlTransport(), new Config());
     $curl->addOption(CURLOPT_HEADER, 1);
     $curl->write(CurlInterface::POST, $url, '1.0', array(), $params);
     $response = $curl->read();
     $curl->close();
     return $response;
 }
Exemple #6
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();
 }
Exemple #7
0
 /**
  * Getting search term id
  *
  * @param string $queryText
  * @return int
  * @throws \Exception
  */
 protected function getNewSearchTermId($queryText)
 {
     $filter = base64_encode('search_query=' . $queryText);
     $url = $_ENV['app_backend_url'] . 'catalog/search/index/filter/' . $filter;
     $curl = new BackendDecorator(new CurlTransport(), new Config());
     $curl->write(CurlInterface::GET, $url, '1.0');
     $response = $curl->read();
     $curl->close();
     if (!preg_match('#search/edit/id/(\\d+)/"#', $response, $matches)) {
         throw new \Exception('Search term not found in grid!');
     }
     return (int) $matches[1];
 }
Exemple #8
0
 /**
  * Post request for creating tax rule
  *
  * @param FixtureInterface $fixture
  * @return mixed|null
  */
 public function persist(FixtureInterface $fixture = null)
 {
     $data = $this->prepareData($fixture);
     $url = $_ENV['app_backend_url'] . 'tax/rule/save/?back=1';
     $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();
     preg_match("~Location: [^\\s]*\\/rule\\/(\\d+)~", $response, $matches);
     $id = isset($matches[1]) ? $matches[1] : null;
     return ['id' => $id];
 }
Exemple #9
0
 /**
  * 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)];
 }
Exemple #10
0
 /**
  * Post request for creating product Review in backend
  *
  * @param FixtureInterface|null $review [optional]
  * @return array
  * @throws \Exception
  */
 public function persist(FixtureInterface $review = null)
 {
     /** @var ReviewInjectable $review */
     $url = $_ENV['app_backend_url'] . 'review/product/post/';
     $curl = new BackendDecorator(new CurlTransport(), new Config());
     $data = $this->replaceMappingData($this->getPreparedData($review));
     $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 Review entity creating by curl handler was not successful! Response:' . $response);
     }
     return ['review_id' => $this->getReviewId()];
 }
Exemple #11
0
 /**
  * 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)];
 }
Exemple #12
0
 /**
  * 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];
 }
 /**
  * Execute handler
  *
  * @param FixtureInterface $fixture [optional]
  * @return mixed
  */
 public function persist(FixtureInterface $fixture = null)
 {
     /** @var \Magento\Customer\Test\Fixture\VatGroup $fixture */
     $groups = $fixture->getGroupsIds();
     $curl = new BackendDecorator(new CurlTransport(), new Config());
     $curl->addOption(CURLOPT_HEADER, 1);
     $response = '';
     foreach ($groups as $groupId) {
         $url = sprintf($_ENV['app_backend_url'] . $this->deleteUrl, $groupId);
         $curl->write(CurlInterface::GET, $url, '1.0', []);
         $response = $curl->read();
     }
     $curl->close();
     return $response;
 }
Exemple #14
0
 /**
  * POST request for creating CMS Block
  *
  * @param FixtureInterface|null $fixture [optional]
  * @return array
  * @throws \Exception
  */
 public function persist(FixtureInterface $fixture = null)
 {
     $data = $this->prepareData($fixture);
     $url = $_ENV['app_backend_url'] . $this->saveUrl;
     $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("CMS Block entity creating by curl handler was not successful! Response: {$response}");
     }
     $url = 'cms/block/index/sort/creation_time/dir/desc';
     $regExpPattern = '@^.*block_id\\/(\\d+)\\/.*' . $fixture->getTitle() . '@ms';
     $extractor = new Extractor($url, $regExpPattern);
     return ['block_id' => $extractor->getData()[1]];
 }
Exemple #15
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];
 }
Exemple #16
0
 /**
  * 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)];
 }
Exemple #17
0
 /**
  * Get store id by store name
  *
  * @param string $storeName
  * @return int
  * @throws \Exception
  */
 protected function getStoreGroupIdByGroupName($storeName)
 {
     //Set pager limit to 2000 in order to find created store group by name
     $url = $_ENV['app_backend_url'] . 'admin/system_store/index/sort/group_title/dir/asc/limit/2000';
     $curl = new BackendDecorator(new CurlTransport(), new Config());
     $curl->addOption(CURLOPT_HEADER, 1);
     $curl->write(CurlInterface::POST, $url, '1.0');
     $response = $curl->read();
     $expectedUrl = '/admin/system_store/editGroup/group_id/';
     $expectedUrl = preg_quote($expectedUrl);
     $expectedUrl = str_replace('/', '\\/', $expectedUrl);
     preg_match('/' . $expectedUrl . '([0-9]*)\\/(.)*>' . $storeName . '<\\/a>/', $response, $matches);
     if (empty($matches)) {
         throw new \Exception('Cannot find store group id');
     }
     return intval($matches[1]);
 }
 /**
  * Create attribute
  *
  * @param FixtureInterface|\Magento\Catalog\Test\Fixture\ProductAttribute $fixture [optional]
  * @return mixed|string
  */
 public function persist(FixtureInterface $fixture = null)
 {
     $url = $_ENV['app_backend_url'] . 'catalog/product_attribute/save/back/edit/active_tab/main';
     $curl = new BackendDecorator(new CurlTransport(), new Config());
     $curl->write(CurlInterface::POST, $url, '1.0', array(), $this->getPostParams($fixture));
     $response = $curl->read();
     $curl->close();
     $id = null;
     if (preg_match('!catalog/product_attribute/save/attribute_id/(\\d+)/active_tab/main/!', $response, $matches)) {
         $id = $matches[1];
     }
     $optionIds = array();
     if (preg_match_all('!attributeOption\\.add\\({"checked":"(.?)*","intype":"radio","id":"(\\d+)"!', $response, $matches)) {
         $optionIds = $matches[2];
     }
     return array('attributeId' => $id, 'optionIds' => $optionIds);
 }
Exemple #19
0
 /**
  * Retrieves data from cURL response
  *
  * @throws \Exception
  * @return array
  */
 public function getData()
 {
     $url = $_ENV['app_backend_url'] . $this->url;
     $curl = new BackendDecorator(new CurlTransport(), new Config());
     $curl->addOption(CURLOPT_HEADER, 1);
     $curl->write(CurlInterface::POST, $url, '1.0');
     $response = $curl->read();
     $curl->close();
     if ($this->isAll) {
         preg_match_all($this->regExpPattern, $response, $matches);
     } else {
         preg_match($this->regExpPattern, $response, $matches);
     }
     $countMatches = $this->isAll ? count($matches[1]) : count($matches);
     if ($countMatches == 0) {
         throw new \Exception('Matches array can\'t be empty.');
     }
     return $matches;
 }
Exemple #20
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];
 }
Exemple #21
0
 /**
  * Getting block id by name
  *
  * @param string $landingName
  * @return int|null
  */
 public function getBlockId($landingName)
 {
     $url = $_ENV['app_backend_url'] . 'catalog/category';
     $curl = new BackendDecorator(new CurlTransport(), new Config());
     $curl->write(CurlInterface::POST, $url, '1.0', [], []);
     $response = $curl->read();
     $curl->close();
     preg_match('~<option.*value="(\\d+)".*>' . preg_quote($landingName) . '</option>~', $response, $matches);
     $id = isset($matches[1]) ? (int) $matches[1] : null;
     return $id;
 }
Exemple #22
0
 /**
  * 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]];
 }
Exemple #23
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;
 }
Exemple #24
0
 /**
  * Post request for persisting Magento Store View
  *
  * @param FixtureInterface $fixture
  * @return array
  * @throws \UnexpectedValueException
  * @throws \UnderflowException
  */
 public function persist(FixtureInterface $fixture = null)
 {
     $data = $this->_prepareData($fixture->getData());
     $data['store_id'] = '';
     $fields = array('store' => $data, 'store_action' => 'add', 'store_type' => 'store');
     $url = $_ENV['app_backend_url'] . 'admin/system_store/save/';
     $curl = new BackendDecorator(new CurlTransport(), new Config());
     $curl->write(CurlInterface::POST, $url, '1.0', array(), $fields);
     $response = $curl->read();
     $curl->close();
     if (!preg_match('/The store view has been saved/', $response)) {
         throw new \UnderflowException('Store was\'t saved');
     }
     $data['id'] = $this->_getStoreIdByStoreName($fixture->getData('fields/name/value'));
     return $data;
 }
Exemple #25
0
 /**
  * Create configurable product
  *
  * @param FixtureInterface $fixture [optional]
  * @return mixed|string
  * @throws \Exception
  */
 public function persist(FixtureInterface $fixture = null)
 {
     $url = $_ENV['app_backend_url'] . 'catalog/product/save/' . $fixture->getUrlParams('create_url_params') . '/popup/1/back/edit';
     $params = $this->_prepareData($fixture);
     $curl = new BackendDecorator(new CurlTransport(), new Config());
     $curl->addOption(CURLOPT_HEADER, 1);
     $curl->write(CurlInterface::POST, $url, '1.0', array(), $params);
     $response = $curl->read();
     $curl->close();
     if (!strpos($response, 'data-ui-id="messages-message-success"')) {
         throw new \Exception("Product creation by curl handler was not successful! Response: {$response}");
     }
     preg_match("~Location: [^\\s]*\\/id\\/(\\d+)~", $response, $matches);
     return isset($matches[1]) ? $matches[1] : null;
 }
Exemple #26
0
 /**
  * Post request for creating bundle product
  *
  * @param FixtureInterface|null $fixture [optional]
  * @return mixed|string
  * @throws \Exception
  */
 public function persist(FixtureInterface $fixture = null)
 {
     $config = $fixture->getDataConfig();
     $prefix = isset($config['input_prefix']) ? $config['input_prefix'] : null;
     $data = $this->_prepareData($fixture->getData('fields'), $prefix);
     if ($fixture->getData('category_id')) {
         $data['product']['category_ids'] = $fixture->getData('category_id');
     }
     $url = $this->_getUrl($config);
     $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("Product creation by curl handler was not successful! Response: {$response}");
     }
     preg_match("~Location: [^\\s]*\\/id\\/(\\d+)~", $response, $matches);
     return isset($matches[1]) ? $matches[1] : null;
 }
Exemple #27
0
 /**
  * Execute handler
  *
  * @param Fixture|null $fixture [optional]
  * @throws \UnexpectedValueException
  * @throws \UnderflowException from findIdWithFilter
  * @throws \Exception from findIdWithFilter
  * @return mixed
  */
 public function persist(FixtureInterface $fixture = null)
 {
     $url = $_ENV['app_backend_url'] . 'admin/user_role/saverole/';
     $data = $this->_preparePostData($fixture->getData('fields'));
     $curl = new BackendDecorator(new CurlTransport(), new Config());
     $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 \UnexpectedValueException('Success confirmation not found');
     }
     $data['id'] = $this->findIdWithFilter($data['rolename'], $response);
     return $data;
 }
Exemple #28
0
 /**
  * Create product via curl
  *
  * @param array $data
  * @param array $config
  * @return int|null
  * @throws \Exception
  */
 protected function createProduct(array $data, array $config)
 {
     $url = $this->getUrl($config);
     $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("Product creation by curl handler was not successful! Response: {$response}");
     }
     preg_match("~Location: [^\\s]*\\/id\\/(\\d+)~", $response, $matches);
     return isset($matches[1]) ? $matches[1] : null;
 }
 /**
  * Execute handler
  *
  * @param FixtureInterface $fixture [optional]
  * @return mixed
  */
 public function persist(FixtureInterface $fixture = null)
 {
     /** @var \Magento\Customer\Test\Fixture\CustomerGroup $fixture*/
     $params = $this->prepareData($fixture);
     $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(), $params);
     $response = $curl->read();
     $curl->close();
     return $this->findId($response, $fixture->getGroupName());
 }
Exemple #30
0
 /**
  * Post request for creating user in backend
  *
  * @param FixtureInterface $fixture
  * @return array|mixed
  * @throws \Exception
  */
 public function persist(FixtureInterface $fixture = null)
 {
     $url = $_ENV['app_backend_url'] . 'admin/user/save';
     $data = $this->_prepareData($fixture->getData('fields'));
     $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("User creation by curl handler was not successful! Response: {$response}");
     }
     //Sort data in grid to define user id if more than 20 items in grid
     $url = $_ENV['app_backend_url'] . 'admin/user/roleGrid/sort/user_id/dir/desc';
     $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();
     $data['id'] = $this->_getUserId($data);
     return $data;
 }