9 use Codeception\Module\REST;
100 if (empty($this->config[
'url']) || empty($this->config[
'username']) || empty($this->config[
'password'])) {
106 $this->haveHttpHeader(
'Content-Type',
'application/json');
108 'integration/admin/token',
109 [
'username' => $this->config[
'username'],
'password' => $this->config[
'password']]
111 $token = substr($this->grabResponse(), 1, strlen($this->grabResponse())-2);
112 $this->seeResponseCodeIs(\Codeception\Util\HttpCode::OK);
113 $this->haveHttpHeader(
'Authorization',
'Bearer ' .
$token);
114 self::$adminTokens[$this->config[
'username']] =
$token;
116 $this->getModule(
'\Magento\FunctionalTestingFramework\Module\MagentoSequence')->_initialize();
126 parent::_afterSuite();
127 $this->deleteHeader(
'Authorization');
142 $username = $username !==
null ? $username : $this->config[
'username'];
143 $password = $password !==
null ? $password : $this->config[
'password'];
147 && (isset(self::$adminTokens[$username]) || array_key_exists($username, self::$adminTokens))) {
148 return self::$adminTokens[$username];
150 $this->haveHttpHeader(
'Content-Type',
'application/json');
151 $this->sendPOST(
'integration/admin/token', [
'username' => $username,
'password' => $password]);
152 $token = substr($this->grabResponse(), 1, strlen($this->grabResponse())-2);
153 $this->seeResponseCodeIs(\Codeception\Util\HttpCode::OK);
154 self::$adminTokens[$username] =
$token;
170 $username = $username !==
null ? $username : $this->config[
'username'];
171 $password = $password !==
null ? $password : $this->config[
'password'];
173 $this->haveHttpHeader(
'Content-Type',
'application/json');
174 if ($newToken || !isset(self::$adminTokens[$username])) {
175 $this->sendPOST(
'integration/admin/token', [
'username' => $username,
'password' => $password]);
176 $token = substr($this->grabResponse(), 1, strlen($this->grabResponse()) - 2);
177 $this->seeResponseCodeIs(\Codeception\Util\HttpCode::OK);
178 self::$adminTokens[$username] =
$token;
180 $this->amBearerAuthenticated(self::$adminTokens[$username]);
199 switch ($httpMethod) {
201 $this->sendGET($endpoint,
$params);
204 $this->sendPOST($endpoint,
$params);
207 $this->sendPUT($endpoint,
$params);
210 $this->sendDELETE($endpoint,
$params);
213 throw new \LogicException(
"HTTP method '{$httpMethod}' is not supported.");
215 $this->seeResponseCodeIs(\Codeception\Util\HttpCode::OK);
217 if (!$decode && $grabByJsonPath ===
null) {
218 return $this->grabResponse();
220 return $this->grabDataFromResponseByJsonPath($grabByJsonPath);
222 return \GuzzleHttp\json_decode($this->grabResponse());
236 if (!$categoryData) {
240 self::$categoryEndpoint,
241 self::HTTP_METHOD_POST,
242 [
'category' => $categoryData]
244 return $categoryData;
258 if (!$simpleProductData) {
262 self::$productEndpoint,
263 self::HTTP_METHOD_POST,
264 [
'product' => $simpleProductData]
266 return $simpleProductData;
280 $configurableProductData = $this->
getProductApiData(
'configurable', $categoryId, $configurableProductData);
282 self::$productEndpoint,
283 self::HTTP_METHOD_POST,
284 [
'product' => $configurableProductData]
289 self::$productAttributesEndpoint,
290 self::HTTP_METHOD_POST,
294 sprintf(self::$productAttributesOptionsEndpoint,
$attribute->attribute_code),
295 self::HTTP_METHOD_GET
300 self::$productAttributeSetEndpoint,
301 self::HTTP_METHOD_POST,
307 $simpleProduct1Data[
'custom_attributes'],
309 'attribute_code' =>
$attribute->attribute_code,
314 self::$productEndpoint,
315 self::HTTP_METHOD_POST,
316 [
'product' => $simpleProduct1Data]
321 $simpleProduct2Data[
'custom_attributes'],
323 'attribute_code' =>
$attribute->attribute_code,
328 self::$productEndpoint,
329 self::HTTP_METHOD_POST,
330 [
'product' => $simpleProduct2Data]
347 [$simpleProduct1Id, $simpleProduct2Id],
348 $configurableProductData
352 self::$productEndpoint .
'/' . $configurableProductData[
'sku'],
353 self::HTTP_METHOD_PUT,
354 [
'product' => $configurableProductData]
356 return $configurableProductData;
371 self::$productAttributesEndpoint,
372 self::HTTP_METHOD_POST,
394 self::$customersEndpoint,
395 self::HTTP_METHOD_POST,
411 $faker = \Faker\Factory::create();
413 return array_replace_recursive(
416 'name' =>
'category' . $sq,
418 'include_in_menu' =>
true,
419 'available_sort_by' => [
'position',
'name'],
420 'custom_attributes' => [
421 [
'attribute_code' =>
'url_key',
'value' =>
'category' . $sq],
422 [
'attribute_code' =>
'description',
'value' => $faker->text(20)],
423 [
'attribute_code' =>
'meta_title',
'value' => $faker->text(20)],
424 [
'attribute_code' =>
'meta_keywords',
'value' => $faker->text(20)],
425 [
'attribute_code' =>
'meta_description',
'value' => $faker->text(20)],
426 [
'attribute_code' =>
'display_mode',
'value' =>
'PRODUCTS'],
427 [
'attribute_code' =>
'landing_page',
'value' =>
''],
428 [
'attribute_code' =>
'is_anchor',
'value' =>
'0'],
429 [
'attribute_code' =>
'custom_use_parent_settings',
'value' =>
'0'],
430 [
'attribute_code' =>
'custom_apply_to_products',
'value' =>
'0'],
431 [
'attribute_code' =>
'custom_design',
'value' =>
''],
432 [
'attribute_code' =>
'page_layout',
'value' =>
''],
433 [
'attribute_code' =>
'custom_design_to',
'value' => $faker->date(
$format =
'm/d/Y')],
434 [
'attribute_code' =>
'custom_design_from',
'value' => $faker->date(
$format =
'm/d/Y',
'now')]
453 $faker = \Faker\Factory::create();
455 return array_replace_recursive(
457 'sku' =>
$type .
'_product_sku' . $sq,
458 'name' =>
$type .
'_product' . $sq,
461 'price' => $faker->randomFloat(2, 1),
463 'attribute_set_id' => 4,
464 'extension_attributes' => [
465 'stock_item' => [
'is_in_stock' => 1,
'qty' => $faker->numberBetween(100, 9000)]
467 'custom_attributes' => [
468 [
'attribute_code' =>
'url_key',
'value' =>
$type .
'_product' . $sq],
469 [
'attribute_code' =>
'tax_class_id',
'value' => 2],
470 [
'attribute_code' =>
'category_ids',
'value' => $categoryId],
487 $faker = \Faker\Factory::create();
488 return array_replace_recursive(
490 'firstname' => $faker->firstName,
491 'middlename' => $faker->firstName,
492 'lastname' => $faker->lastName,
493 'email' => $faker->email,
494 'gender' => rand(0, 1),
498 'custom_attributes' => [
500 'attribute_code' =>
'disable_auto_group_change',
533 return array_replace_recursive(
536 'attribute_code' =>
$code . $sq,
537 'frontend_labels' => [
540 'label' =>
$code . $sq
543 'is_required' =>
false,
544 'is_unique' =>
false,
545 'is_visible' =>
true,
547 'default_value' =>
'',
548 'frontend_input' =>
'select',
549 'is_visible_on_front' =>
true,
550 'is_searchable' =>
true,
551 'is_visible_in_advanced_search' =>
true,
552 'is_filterable' =>
true,
553 'is_filterable_in_search' =>
true,
557 'used_in_product_listing' =>
true,
558 'is_used_for_promo_rules' =>
true,
561 'label' =>
'option1',
564 'is_default' =>
true,
577 'label' =>
'option2',
580 'is_default' =>
false,
608 $configurableProductOptions = [];
616 $attributeItem[
'values'][] = [
'value_index' =>
$optionId];
618 $configurableProductOptions [] = $attributeItem;
620 return $configurableProductOptions;
633 array $configurableProductOptions,
634 array $childProductIds,
644 'extension_attributes' => [
645 'configurable_product_options' => $configurableProductOptions,
646 'configurable_product_links' => $childProductIds,
getCategoryApiData($categoryData=[])
getConfigurableProductOptionsApiData($attributes, $optionIds)
$block setTitle( 'CMS Block Title') -> setIdentifier('fixture_block') ->setContent('< h1 >Fixture Block Title</h1 >< a href=" store url</a><p> Config value
static sanitizeWebDriverConfig($config, $params=['url', 'selenium'])
requireProductAttribute($code='attribute')
elseif(isset( $params[ 'redirect_parent']))
sendRestRequest($endpoint, $httpMethod, $params=[], $grabByJsonPath=null, $decode=true)
getCustomerApiData($customerData=[])
getProductApiData($type='simple', $categoryId=0, $productData=[])
getConfigurableProductApiData(array $configurableProductOptions, array $childProductIds, array $configurableProduct=[], int $categoryId=0)
getProductAttributeApiData($code='attribute', $attributeData=[])
getAdminAuthToken($username=null, $password=null, $newToken=false)
_beforeSuite($settings=[])
requireCategory($categoryData=[])
requireSimpleProduct($categoryId=0, $simpleProductData=[])
getAssignAttributeToAttributeSetApiData( $attributeCode, int $attributeSetId=4, int $attributeGroupId=7)
requireCustomer(array $customerData=[], $password='123123qW')
amAdminTokenAuthenticated($username=null, $password=null, $newToken=false)
getCustomerApiDataWithPassword($customerData=[], $password='123123qW')
requireConfigurableProduct($categoryId=0, $configurableProductData=[])
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]