/** * Post request for creating widget instance. * * @param FixtureInterface $fixture [optional] * @throws \Exception * @return array */ public function persist(FixtureInterface $fixture = null) { $data = $this->prepareData($fixture); $url = $_ENV['app_backend_url'] . 'widget_instance/save/type/' . $data['type'] . '/package/' . $this->prepareTheme($data['package_theme']); if (isset($data['page_id'])) { $data['parameters']['page_id'] = $data['page_id'][0]; unset($data['page_id']); } if ($fixture->hasData('store_ids')) { $stores = $fixture->getDataFieldConfig('store_ids')['source']->getStores(); foreach ($stores as $store) { $data['store_ids'][] = $store->getStoreId(); } } $data['parameters']['unique_id'] = isset($data['parameters']['unique_id']) ? uniqid() : ''; unset($data['type']); unset($data['package_theme']); $curl = new BackendDecorator(new CurlTransport(), $this->_configuration); $curl->write(CurlInterface::POST, $url, '1.1', [], $data); $response = $curl->read(); $curl->close(); if (!strpos($response, 'class="success-msg"')) { throw new \Exception("Widget instance creation by curl handler was not successful! Response: {$response}"); } $id = $this->getWidgetId($response); return ['id' => $id]; }
/** * Post request for creating sales rule. * * @param FixtureInterface $fixture * @return array * @throws \Exception */ public function persist(FixtureInterface $fixture = null) { $this->mapTypeParams = array_merge($this->mapTypeParams, $this->additionalMapTypeParams); $url = $_ENV['app_backend_url'] . 'sales_rule/promo_quote/save/'; $data = $this->replaceMappingData($fixture->getData()); $data['rule'] = []; if (isset($data['conditions_serialized'])) { $data['rule']['conditions'] = $this->prepareCondition($data['conditions_serialized']); unset($data['conditions_serialized']); } $data['website_ids'] = $this->prepareWebsites($data); $data['customer_group_ids'] = $this->prepareCustomerGroup($data); if (isset($data['actions_serialized'])) { $this->mapTypeParams['Conditions combination']['type'] = 'Magento\\SalesRule\\Model\\Rule\\Condition\\Product\\Combine'; $data['rule']['actions'] = $this->prepareCondition($data['actions_serialized']); unset($data['actions_serialized']); } $curl = new BackendDecorator(new CurlTransport(), $this->_configuration); $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("Sales rule entity creating by curl handler was not successful! Response: {$response}"); } preg_match('`<tr.*title=".*sales_rule\\/promo_quote\\/edit\\/id\\/([\\d]+)`ims', $response, $matches); if (empty($matches)) { throw new \Exception('Cannot find Sales Rule id'); } return ['id' => $matches[1]]; }
/** * 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 ((array) $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]]; }
/** * Post request for creating currency symbol * * @param FixtureInterface $fixture * @return void */ public function persist(FixtureInterface $fixture = null) { $data = $fixture->getData(); $url = $_ENV['app_backend_url'] . 'admin/system_currencysymbol/save'; $curl = new BackendDecorator(new CurlTransport(), $this->_configuration); $curl->write(CurlInterface::POST, $url, '1.0', [], $data); $curl->read(); $curl->close(); // Response verification is absent, because sending a post request returns an index page }
/** * Get Reward exchange rate id. * * @return string|null */ protected function getRateId() { $url = $_ENV['app_backend_url'] . 'reward_rate/index/sort/rate_id/dir/desc/'; $curl = new BackendDecorator(new CurlTransport(), $this->_configuration); $curl->write(CurlInterface::GET, $url, '1.0'); $response = $curl->read(); $curl->close(); preg_match('@rate_id/(\\d+)@', $response, $match); return empty($match[1]) ? null : $match[1]; }
/** * Post request for creating reward points. * * @param FixtureInterface $fixture * @return void * @throws \Exception */ public function persist(FixtureInterface $fixture = null) { $url = $_ENV['app_backend_url'] . 'customer/save/back/edit/tab/customer_info_tabs_customer_edit_tab_reward/'; $curl = new BackendDecorator(new CurlTransport(), $this->_configuration); $curl->write(CurlInterface::POST, $url, '1.1', [], $this->prepareData($fixture)); $response = $curl->read(); $curl->close(); if (!strpos($response, 'class="success-msg"')) { throw new \Exception("Adding reward points by curl handler was not successful! Response: {$response}"); } }
/** * 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(), $this->_configuration); $curl->write($url, $data); $response = $curl->read(); $curl->close(); $id = $this->getClassId($response); return ['id' => $id]; }
/** * Get created user id. * * @return string */ protected function getId() { $url = $_ENV['app_backend_url'] . 'permissions_user/roleGrid/sort/user_id/dir/desc/'; $curl = new BackendDecorator(new CurlTransport(), $this->_configuration); $curl->addOption(CURLOPT_HEADER, 1); $curl->write(CurlInterface::POST, $url, '1.0'); $response = $curl->read(); $curl->close(); preg_match('@edit/user_id/(\\d+)/@siu', $response, $matches); return $matches[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', [], $params); $response = $curl->read(); $curl->close(); return $response; }
/** * Get id after creating Customer Group. * * @param array $data * @return string|null */ public function getCustomerGroupId(array $data) { $regExp = '/.*id\\/(\\d+)\\/.*' . $data['code'] . '/siu'; $url = $_ENV['app_backend_url'] . 'customer_group/index/sort/time/dir/desc/'; $curl = new BackendDecorator(new CurlTransport(), $this->_configuration); $curl->write(CurlInterface::GET, $url, '1.1'); $response = $curl->read(); $curl->close(); preg_match($regExp, $response, $matches); return empty($matches[1]) ? null : $matches[1]; }
/** * Post request for creating Event. * * @param FixtureInterface $fixture * @return array */ public function persist(FixtureInterface $fixture = null) { $data = $this->prepareData($fixture); $url = $_ENV['app_backend_url'] . 'catalog_event/save/category_id/' . $data['categoryId'] . '/category/'; $curl = new BackendDecorator(new CurlTransport(), $this->_configuration); $curl->write(CurlInterface::POST, $url, '1.1', [], $data['data']); $response = $curl->read(); $curl->close(); $id = $this->getCatalogEventId($response); return ['id' => $id]; }
/** * Getting block id by name. * * @param string $landingName * @return int|null */ protected function getBlockId($landingName) { $url = $_ENV['app_backend_url'] . 'catalog/category'; $curl = new BackendDecorator(new CurlTransport(), $this->_configuration); $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; }
/** * Apply config settings via curl * * @param array $data * @param string $section * @throws \Exception */ protected function applyConfigSettings(array $data, $section) { $url = $this->getUrl($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"') === false) { throw new \Exception("Settings are not applied! Response: {$response}"); } }
/** * @param FixtureInterface $fixture [optional] * @throws \Exception * @return mixed|void */ public function persist(FixtureInterface $fixture = null) { $url = $_ENV['app_backend_url'] . $this->url; $data = $this->replaceMappingData($fixture->getData()); $curl = new BackendDecorator(new CurlTransport(), $this->_configuration); $curl->write($url, $data); $response = $curl->read(); if (!strpos($response, 'data-ui-id="messages-message-success"')) { throw new \Exception("Newsletter template creation by curl was not successful! Response: {$response}"); } $curl->close(); }
/** * Post request for creating url rewrite * * @param FixtureInterface $fixture * @throws \Exception * @return void */ public function persist(FixtureInterface $fixture = null) { $url = $_ENV['app_backend_url'] . $this->url . $fixture->getTargetPath(); $data = $this->replaceMappingData($fixture->getData()); $curl = new BackendDecorator(new CurlTransport(), $this->_configuration); $curl->write(CurlInterface::POST, $url, '1.0', [], $data); $response = $curl->read(); if (!strpos($response, 'data-ui-id="messages-message-success"')) { throw new \Exception("URL Rewrite creation by curl handler was not successful! Response: {$response}"); } $curl->close(); }
/** * Post request for setting currency rate. * * @param FixtureInterface $fixture [optional] * @return mixed|string * @throws \Exception */ public function persist(FixtureInterface $fixture = null) { $data = $this->prepareData($fixture); $url = $_ENV['app_backend_url'] . 'admin/system_currency/saveRates/'; $curl = new BackendDecorator(new CurlTransport(), $this->_configuration); $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("Currency rates setting by curl handler was not successful! Response:\n" . $response); } }
/** * 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(), $this->_configuration); $curl->addOption(CURLOPT_HEADER, 1); $curl->write(CurlInterface::POST, $url, '1.0', [], $params); $response = $curl->read(); $curl->close(); return $this->findId($response, $fixture->getGroupName()); }
/** * Curl creation of User Role. * * @param FixtureInterface $fixture [optional] * @return array * @throws \Exception */ public function persist(FixtureInterface $fixture = null) { $data = $this->prepareData($fixture); $url = $_ENV['app_backend_url'] . 'permissions_role/saverole/'; $curl = new BackendDecorator(new CurlTransport(), $this->_configuration); $curl->write(CurlInterface::POST, $url, '1.1', [], $data); $response = $curl->read(); $curl->close(); if (!strpos($response, 'class="success-msg"')) { throw new \Exception("Role entity creating by curl handler was not successful! Response: {$response}"); } return ['role_id' => $this->getRoleId($response)]; }
/** * 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'] . $this->url . 'index/filter/' . $filter; $curl = new BackendDecorator(new CurlTransport(), $this->_configuration); $curl->write($url, [], CurlInterface::GET); $response = $curl->read(); $curl->close(); if (!preg_match('#' . $this->url . 'edit/id/(\\d+)/"#', $response, $matches)) { throw new \Exception('Search term not found in grid!'); } return (int) $matches[1]; }
/** * Post request for creating product Rating in backend. * * @param FixtureInterface|null $rating * @return array * @throws \Exception */ public function persist(FixtureInterface $rating = null) { $url = $_ENV['app_backend_url'] . 'rating/save'; $curl = new BackendDecorator(new CurlTransport(), $this->_configuration); $data = $this->replaceMappingData($this->prepareData($rating->getData())); $curl->write(CurlInterface::POST, $url, '1.1', [], $data); $response = $curl->read(); $curl->close(); if (!strpos($response, 'class="success-msg"')) { throw new \Exception('Product Rating entity creating by curl handler was not successful! Response:' . $response); } return ['rating_id' => $this->getProductRatingId()]; }
/** * 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(), $this->_configuration); $curl->addOption(CURLOPT_HEADER, 1); $curl->write(CurlInterface::POST, $url, '1.0', [], $data); $response = $curl->read(); $curl->close(); preg_match("~Location: [^\\s]*\\/rule\\/(\\d+)~", $response, $matches); $id = isset($matches[1]) ? $matches[1] : null; return ['id' => $id]; }
/** * 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(), $this->_configuration); $curl->addOption(CURLOPT_HEADER, 1); $curl->write($url, $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)]; }
/** * Set tax class id * * @param string $taxClassName * @return void * @throws \Exception */ protected function setTaxClassId($taxClassName) { $url = $_ENV['app_backend_url'] . 'tax/rule/new/'; $curl = new BackendDecorator(new CurlTransport(), new Config()); $curl->addOption(CURLOPT_HEADER, 1); $curl->write(CurlInterface::POST, $url, '1.0', [], []); $response = $curl->read(); $curl->close(); preg_match('~<option value="(\\d+)".*>' . $taxClassName . '</option>~', $response, $matches); if (!isset($matches[1]) || empty($matches[1])) { throw new \Exception('Product tax class id ' . $taxClassName . ' undefined!'); } $this->taxClassId = (int) $matches[1]; }
/** * Post request for creating product Review in backend * * @param FixtureInterface|null $review [optional] * @return array * @throws \Exception */ public function persist(FixtureInterface $review = null) { /** @var Review $review */ $url = $_ENV['app_backend_url'] . 'review/product/post/'; $curl = new BackendDecorator(new CurlTransport(), $this->_configuration); $data = $this->replaceMappingData($this->getPreparedData($review)); $curl->write($url, $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()]; }
/** * Create product via curl. * * @param array $data * @param array $config * @return array * @throws \Exception */ protected function createProduct(array $data, array $config) { $url = $this->getUrl($config); $curl = new BackendDecorator(new CurlTransport(), $this->_configuration); $curl->addOption(CURLOPT_HEADER, 1); $curl->write($url, $data); $response = $curl->read(); $curl->close(); if (!strpos($response, 'data-ui-id="messages-message-success"')) { $this->_eventManager->dispatchEvent(['curl_failed'], [$response]); throw new \Exception('Product creation by curl handler was not successful!'); } return $this->parseResponse($response); }
/** * Post request for creating tax class. * * @param FixtureInterface $fixture [optional] * @return array * @throws \Exception */ public function persist(FixtureInterface $fixture = null) { $data = $fixture->getData(); $url = $_ENV['app_backend_url'] . 'tax_class/save'; $curl = new BackendDecorator(new CurlTransport(), $this->_configuration); $curl->write(CurlInterface::POST, $url, '1.0', [], $data); $response = $curl->read(); $curl->close(); if (!strpos($response, 'id="messages"')) { throw new \Exception('Tax rate creation by curl handler was not successful!'); } $id = $this->getClassId($response); return ['id' => $id]; }
/** * 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(), $this->_configuration); $curl->write($url, $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}"); } preg_match("`block_id\\/(\\d*?)\\/`", $response, $matches); $id = isset($matches[1]) ? $matches[1] : null; return ['block_id' => $id]; }
/** * Post request for creating tax rule. * * @param FixtureInterface $fixture [optional] * @return array * @throws \Exception */ 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(), $this->_configuration); $curl->addOption(CURLOPT_HEADER, 1); $curl->write(CurlInterface::POST, $url, '1.1', [], $data); $response = $curl->read(); $curl->close(); if (!strpos($response, 'success-msg')) { throw new \Exception("Tax rule creation by curl handler was not successful!\nResponse:\n{$response}"); } $id = $this->getTaxRuleId($response); return ['id' => $id]; }
/** * 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(), $this->_configuration); $curl->addOption(CURLOPT_HEADER, 1); $curl->write($url, $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)]; }
/** * Set tax class id. * * @param string $taxClassName * @return void * @throws \Exception */ protected function setTaxClassId($taxClassName) { $url = $_ENV['app_backend_url'] . 'tax/rule/new/'; $config = \Magento\Mtf\ObjectManagerFactory::getObjectManager()->create('Magento\\Mtf\\Config\\DataInterface'); $curl = new BackendDecorator(new CurlTransport(), $config); $curl->addOption(CURLOPT_HEADER, 1); $curl->write($url, [], CurlInterface::GET); $response = $curl->read(); $curl->close(); preg_match('~<option value="(\\d+)".*>' . $taxClassName . '</option>~', $response, $matches); if (!isset($matches[1]) || empty($matches[1])) { throw new \Exception('Product tax class id ' . $taxClassName . ' undefined!'); } $this->taxClassId = (int) $matches[1]; }