示例#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
 /**
  * Get id after creating Customer Group.
  *
  * @param array $data
  * @return int|null
  */
 public function getCustomerGroupId(array $data)
 {
     $url = 'customer/group/index/sort/time/dir/desc';
     $regExp = '/.*id\\/(\\d+)\\/.*' . $data['code'] . '/siu';
     $extractor = new Extractor($url, $regExp);
     $match = $extractor->getData();
     return empty($match[1]) ? null : $match[1];
 }
示例#3
0
 /**
  * Get id after created sitemap
  *
  * @param array $data
  * @return string|null
  */
 protected function getSitemapId(array $data)
 {
     //Sort data in grid to define sitemap id if more than 20 items in grid
     $url = 'admin/sitemap/index/sort/sitemap_id/dir/desc';
     $pattern = '/col\\-sitemap_id[\\s\\W]*(\\d+).*?' . $data['sitemap_filename'] . '/siu';
     $extractor = new Extractor($url, $pattern);
     $match = $extractor->getData();
     return empty($match[1]) ? null : $match[1];
 }
示例#4
0
文件: Curl.php 项目: aiesh/magento2
 /**
  * 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]];
 }
示例#5
0
 /**
  * Curl creation of Admin User Role.
  *
  * @param FixtureInterface $fixture
  * @return array|mixed
  * @throws \Exception
  */
 public function persist(FixtureInterface $fixture = null)
 {
     $data = $this->prepareData($fixture);
     $url = $_ENV['app_backend_url'] . 'admin/user_role/saverole/active_tab/info/';
     $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("Role creating by curl handler was not successful! Response: {$response}");
     }
     $url = 'admin/user_role/roleGrid/sort/role_id/dir/desc/';
     $regExpPattern = '/col\\-role_id[^\\>]+\\>\\s*(\\d+)\\s*<.td>\\s*<[^<>]*?>\\s*' . $data['rolename'] . '/siu';
     $extractor = new Extractor($url, $regExpPattern);
     return ['role_id' => $extractor->getData()[1]];
 }
示例#6
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]];
 }
示例#7
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();
     }
     $data['is_active'] = isset($data['is_active']) && $data['is_active'] === 'Inactive' ? 0 : 1;
     $url = $_ENV['app_backend_url'] . 'admin/user/save/active_tab/main_section/';
     $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("Admin user entity creating by curl handler was not successful! Response: {$response}");
     }
     $url = 'admin/user/roleGrid/sort/user_id/dir/desc';
     $regExpPattern = '/col-user_id[^\\>]+\\>\\s*(\\d+)\\s*<.td>\\s*<[^<>]*?>\\s*' . $data['username'] . '/siu';
     $extractor = new Extractor($url, $regExpPattern);
     return ['user_id' => $extractor->getData()[1]];
 }
示例#8
0
 /**
  * Get rating options
  *
  * @param int $ratingId
  * @return array
  */
 protected function getRatingOptions($ratingId)
 {
     $url = 'review/rating/edit/id/' . $ratingId;
     $regex = '/<input[^>]+name="option_title\\[(\\d+)\\]"[^>]+>/';
     $extractor = new Extractor($url, $regex, true);
     $matches = $extractor->getData();
     if (empty($matches[1])) {
         return [];
     }
     array_unshift($matches[1], null);
     return array_filter($matches[1]);
 }
示例#9
0
 /**
  * Get product Rating id
  *
  * @return int|null
  */
 protected function getReviewId()
 {
     $url = 'review/product/index/sort/review_id/dir/desc/';
     $regex = '/class="[^"]+col-id[^"]+"[^>]*>\\s*([0-9]+)\\s*</';
     $extractor = new Extractor($url, $regex);
     $match = $extractor->getData();
     return empty($match[1]) ? null : $match[1];
 }