コード例 #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]];
 }
コード例 #2
0
 /**
  * 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;
 }
コード例 #3
0
ファイル: Curl.php プロジェクト: Atlis/docker-magento2
 /**
  * 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];
 }
コード例 #4
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)];
 }
コード例 #5
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)];
 }
コード例 #6
0
 /**
  * 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;
 }
コード例 #7
0
ファイル: Curl.php プロジェクト: buskamuza/magento2-skeleton
 /**
  * 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];
 }
コード例 #8
0
ファイル: CreateStore.php プロジェクト: Atlis/docker-magento2
 /**
  * Get store id by store name
  *
  * @param string $storeName
  * @return int
  * @throws \UnexpectedValueException
  */
 protected function _getStoreIdByStoreName($storeName)
 {
     //Set pager limit to 2000 in order to find created store view by name
     $url = $_ENV['app_backend_url'] . 'admin/system_store/index/sort/store_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/editStore/store_id/';
     $expectedUrl = preg_quote($expectedUrl);
     $expectedUrl = str_replace('/', '\\/', $expectedUrl);
     preg_match('/' . $expectedUrl . '([0-9]*)\\/(.)*>' . $storeName . '<\\/a>/', $response, $matches);
     if (empty($matches)) {
         throw new \UnexpectedValueException('Cannot find store id');
     }
     return intval($matches[1]);
 }
コード例 #9
0
ファイル: Extractor.php プロジェクト: aiesh/magento2
 /**
  * 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;
 }
コード例 #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
ファイル: CreateUser.php プロジェクト: aiesh/magento2
 /**
  * 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;
 }
コード例 #12
0
ファイル: CreateConfigurable.php プロジェクト: aiesh/magento2
 /**
  * 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;
 }
コード例 #13
0
ファイル: CreateBundle.php プロジェクト: aiesh/magento2
 /**
  * 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;
 }
コード例 #14
0
ファイル: Curl.php プロジェクト: aiesh/magento2
 /**
  * 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;
 }
コード例 #15
0
 /**
  * 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());
 }
コード例 #16
0
 /**
  * POST request for creating downloadable product
  *
  * @param FixtureInterface $fixture [optional]
  * @return int id of created product
  */
 public function persist(FixtureInterface $fixture = null)
 {
     $config = $fixture->getDataConfig();
     $curl = new BackendDecorator(new CurlTransport(), new Config());
     $curl->addOption(CURLOPT_HEADER, 1);
     $curl->write(CurlInterface::POST, $this->getUrl($config), '1.0', [], $this->prepareData($fixture->getData('fields'), isset($config['input_prefix']) ? $config['input_prefix'] : null));
     $response = $curl->read();
     $curl->close();
     preg_match("~Location: [^\\s]*\\/id\\/(\\d+)~", $response, $matches);
     return $matches[1];
 }
コード例 #17
0
ファイル: Curl.php プロジェクト: aiesh/magento2
 /**
  * Create Attribute Set
  *
  * @param CatalogAttributeSet $fixture
  * @return string
  */
 protected function createAttributeSet(CatalogAttributeSet $fixture)
 {
     $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->addOption(CURLOPT_HEADER, 1);
     $curl->write(CurlInterface::POST, $url, '1.0', [], $data);
     $response = $curl->read();
     $curl->close();
     return $response;
 }
コード例 #18
0
ファイル: TaxClass.php プロジェクト: aiesh/magento2
 /**
  * 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];
 }