Skip to content

Commit a6c3cb6

Browse files
committed
ACPT-648: Cover API with Webapi Test
1 parent f38d587 commit a6c3cb6

File tree

5 files changed

+86
-1
lines changed

5 files changed

+86
-1
lines changed

app/code/Magento/ImportExport/Model/Import.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ protected function _getSourceAdapterForApi()
337337
{
338338
return Adapter::findAdapterForData(
339339
// phpcs:ignore Magento2.Functions.DiscouragedFunction
340-
base64_decode($this->getData('csvData')),
340+
trim(base64_decode($this->getData('csvData'))),
341341
$this->getData(self::FIELD_FIELD_SEPARATOR)
342342
);
343343
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
3+
namespace Magento\ImportCsv\Api;
4+
5+
use Magento\TestFramework\TestCase\WebapiAbstract;
6+
7+
class ImportCsvApiTest extends WebapiAbstract
8+
{
9+
const RESOURCE_PATH = '/V1/import/csv';
10+
11+
/**
12+
* Test Rest API Import
13+
*
14+
* @param array $requestData
15+
* @param array $expectedResponse
16+
* @dataProvider getRequestData
17+
*/
18+
public function testImport(array $requestData, array $expectedResponse): void
19+
{
20+
$serviceInfo = [
21+
'rest' => [
22+
'resourcePath' => self::RESOURCE_PATH,
23+
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST,
24+
]
25+
];
26+
$requestData['source']['csvData'] = base64_encode(file_get_contents($requestData['source']['csvData']));
27+
$response = $this->_webApiCall($serviceInfo, $requestData);
28+
$this->assertEquals($expectedResponse, $response);
29+
}
30+
31+
/**
32+
* @return array
33+
*/
34+
public function getRequestData(): array
35+
{
36+
return [
37+
['requestData' => [
38+
'source' => [
39+
'entity' => 'catalog_product',
40+
'behavior' => 'append',
41+
'validationStrategy' => 'validation-stop-on-errors',
42+
'allowedErrorCount' => '10',
43+
'csvData' => __DIR__ . '/_files/products.csv'
44+
]
45+
],
46+
'expectedResponse' => [
47+
0 => 'Entities Processed: 3'
48+
]],
49+
['requestData' => [
50+
'source' => [
51+
'entity' => 'customer',
52+
'behavior' => 'add_update',
53+
'validationStrategy' => 'validation-stop-on-errors',
54+
'allowedErrorCount' => '10',
55+
'csvData' => __DIR__ . '/_files/customers.csv'
56+
]
57+
],
58+
'expectedResponse' => [
59+
0 => 'Entities Processed: 3'
60+
]],
61+
['requestData' => [
62+
'source' => [
63+
'entity' => 'advanced_pricing',
64+
'behavior' => 'append',
65+
'validationStrategy' => 'validation-stop-on-errors',
66+
'allowedErrorCount' => '10',
67+
'csvData' => __DIR__ . '/_files/advanced_pricing.csv'
68+
]
69+
],
70+
'expectedResponse' => [
71+
0 => 'Entities Processed: 1'
72+
]]
73+
];
74+
}
75+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
sku,tier_price_website,tier_price_customer_group,tier_price_qty,tier_price,tier_price_value_type
2+
Simple1,"All Websites [USD]","NOT LOGGED IN",1.0000,250.000000,Fixed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
email,_website,_store,website_id,store_id,created_in,prefix,firstname,middlename,lastname,suffix,group_id,dob,password_hash,rp_token,rp_token_created_at,taxvat,confirmation,created_at,gender,disable_auto_group_change,updated_at,failures_num,first_failure,lock_expires,reward_update_notification,reward_warning_notification,password
2+
[email protected],base,default,1,1,"Default Store View",,C1,,C1L,,1,,,0:3:Odhon9E4VktVZ/Qkb7TlfCvYZaQgCTM+LzSuPP4ox++7j0Ne4s52gQMK35vccWuDBosZxmrA96amJBzt,"2022-06-21 18:44:18",,,"2022-06-21 18:44:18",0,0,"2022-06-21 18:44:18",0,,,0,0,
3+
[email protected],base,default,1,1,"Default Store View",,C2,,C2L,,1,,,0:3:Adc2mk3JhzRppiaWZlSa3NHQ30Nzhz0LtKp/P76nkiz/FAllmygux+1xvHPrnLnpMIbRVX6ti8YGluzO,"2022-06-21 18:44:42",,,"2022-06-21 18:44:42",0,0,"2022-06-21 18:44:42",0,,,0,0,
4+
[email protected],base,default,1,1,"Default Store View",,C3,,C3L,,1,,,0:3:h3x6Qh6DsMuLQiFCZCaQvCR+CNGEqzEqg5g4mjecDElHdQtbUUx5dV+CIssHvah1fwY6THxJkRiqHDCg,"2022-06-21 18:45:08",,,"2022-06-21 18:45:08",0,0,"2022-06-21 18:45:08",0,,,0,0,
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
sku,store_view_code,attribute_set_code,product_type,categories,product_websites,name,description,short_description,weight,product_online,tax_class_name,visibility,price,special_price,special_price_from_date,special_price_to_date,url_key,meta_title,meta_keywords,meta_description,base_image,base_image_label,small_image,small_image_label,thumbnail_image,thumbnail_image_label,swatch_image,swatch_image_label,created_at,updated_at,new_from_date,new_to_date,display_product_options_in,map_price,msrp_price,map_enabled,gift_message_available,custom_design,custom_design_from,custom_design_to,custom_layout_update,page_layout,product_options_container,msrp_display_actual_price_type,country_of_manufacture,additional_attributes,qty,out_of_stock_qty,use_config_min_qty,is_qty_decimal,allow_backorders,use_config_backorders,min_cart_qty,use_config_min_sale_qty,max_cart_qty,use_config_max_sale_qty,is_in_stock,notify_on_stock_below,use_config_notify_stock_qty,manage_stock,use_config_manage_stock,use_config_qty_increments,qty_increments,use_config_enable_qty_inc,enable_qty_increments,is_decimal_divided,website_id,related_skus,related_position,crosssell_skus,crosssell_position,upsell_skus,upsell_position,additional_images,additional_image_labels,hide_from_product_page,custom_options,bundle_price_type,bundle_sku_type,bundle_price_view,bundle_weight_type,bundle_values,bundle_shipment_type,associated_skus,downloadable_links,downloadable_samples,configurable_variations,configurable_variation_labels
2+
Simple1,,Default,simple,"Default Category",base,Simple1,,,1.000000,1,"Taxable Goods","Catalog, Search",10.000000,,,,simple1,Simple1,Simple1,"Simple1 ",,,,,,,,,"6/7/22, 3:15 PM","6/7/22, 3:15 PM",,,"Block after Info Column",,,,"Use config",,,,,,,"Use config","United States",,1000.0000,0.0000,1,0,0,1,1.0000,1,10000.0000,1,1,1.0000,1,1,1,1,1.0000,1,0,0,0,,,,,,,,,,,,,,,,,,,,,
3+
Simple2,,Default,simple,"Default Category",base,Simple2,,,1.000000,1,"Taxable Goods","Catalog, Search",200.000000,,,,simple2,Simple2,Simple2,"Simple2 ",,,,,,,,,"6/7/22, 3:16 PM","6/7/22, 3:16 PM",,,"Block after Info Column",,,,"Use config",,,,,,,"Use config","United States",,1000.0000,0.0000,1,0,0,1,1.0000,1,10000.0000,1,1,1.0000,1,1,1,1,1.0000,1,0,0,0,,,,,,,,,,,,,,,,,,,,,
4+
Simple3,,Default,simple,"Default Category",base,Simple3,,,1.000000,1,"Taxable Goods","Catalog, Search",300.000000,,,,simple3,Simple3,Simple3,"Simple3 ",,,,,,,,,"6/7/22, 3:16 PM","6/7/22, 3:16 PM",,,"Block after Info Column",,,,"Use config",,,,,,,"Use config","United States",,1000.0000,0.0000,1,0,0,1,1.0000,1,10000.0000,1,1,1.0000,1,1,1,1,1.0000,1,0,0,0,,,,,,,,,,,,,,,,,,,,,

0 commit comments

Comments
 (0)