Skip to content

Commit e83a7bf

Browse files
Merge branch 'MTP-123-m2' into 'PR-5'
Mtp 123 m2 See merge request !222
2 parents d4f822d + 3714b7f commit e83a7bf

File tree

13 files changed

+485
-15
lines changed

13 files changed

+485
-15
lines changed

dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ImportDataTest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<item name="import_multiple_value_separator" xsi:type="string">,</item>
1919
<item name="import_file" xsi:type="array">
2020
<item name="entities" xsi:type="array">
21-
<item name="0" xsi:type="string">catalogProductSimple::default</item>
21+
<item name="0" xsi:type="string">catalogProductSimple::johndoe_with_addresses</item>
2222
</item>
2323
<item name="template" xsi:type="array">
2424
<item name="filename" xsi:type="string">Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_1</item>

dev/tests/functional/tests/app/Magento/Customer/Test/Block/Adminhtml/Edit/Tab/Addresses.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class Addresses extends Tab
5959
*
6060
* @var string
6161
*/
62-
protected $customerAddress = '//*[contains(@class, "address-list-item")][%d]';
62+
protected $customerAddress = '//*[contains(@class, "address-list-item")][%d + 1]';
6363

6464
/**
6565
* Magento loader.
@@ -164,10 +164,10 @@ public function updateAddresses($address)
164164
public function getDataAddresses($address = null)
165165
{
166166
$data = [];
167-
$addresses = is_array($address) ? $address : [1 => $address];
167+
$addresses = is_array($address) ? $address : [0 => $address];
168168

169169
foreach ($addresses as $addressNumber => $address) {
170-
$isHasData = (null === $address) || $address->hasData();
170+
$isHasData = (null !== $address) && $address->hasData();
171171
$isVisibleCustomerAddress = $this->isVisibleCustomerAddress($addressNumber);
172172

173173
if ($isHasData && !$isVisibleCustomerAddress) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\CustomerImportExport\Test\Constraint;
8+
9+
use Magento\Mtf\Constraint\AbstractConstraint;
10+
use Magento\ImportExport\Test\Fixture\ImportData;
11+
use Magento\Mtf\Fixture\FixtureFactory;
12+
use Magento\Customer\Test\Page\Adminhtml\CustomerIndexEdit;
13+
14+
/**
15+
* Assert addresses from csv import file and page are match.
16+
*/
17+
class AssertImportCustomerAddresses extends AbstractConstraint
18+
{
19+
/**
20+
* Array keys mapping for csv file.
21+
*
22+
* @var array
23+
*/
24+
private $mappingKeys = [
25+
'firstname' => 'firstname',
26+
'lastname' => 'lastname',
27+
'postcode' => 'postcode',
28+
'region' => 'region_id',
29+
'city' => 'city',
30+
'company' => 'company',
31+
'country_id' => 'country_id',
32+
'street' => 'street',
33+
'telephone' => 'telephone',
34+
];
35+
36+
/**
37+
* Array keys mapping for countries ids.
38+
*
39+
* @param array
40+
*/
41+
private $mappingCountries = [
42+
'US' => 'United States'
43+
];
44+
45+
/**
46+
* Customer edit page on backend.
47+
*
48+
* @var CustomerIndexEdit
49+
*/
50+
private $customerIndexEdit;
51+
52+
/**
53+
* Fixture factory.
54+
*
55+
* @var FixtureFactory
56+
*/
57+
private $fixtureFactory;
58+
59+
/**
60+
* Import fixture.
61+
*
62+
* @var ImportData
63+
*/
64+
private $import;
65+
66+
/**
67+
* Assert imported customer addresses are correct.
68+
*
69+
* @param CustomerIndexEdit $customerIndexEdit
70+
* @param FixtureFactory $fixtureFactory
71+
* @param ImportData $import
72+
* @return void
73+
*/
74+
public function processAssert(
75+
CustomerIndexEdit $customerIndexEdit,
76+
FixtureFactory $fixtureFactory,
77+
ImportData $import
78+
) {
79+
$this->customerIndexEdit = $customerIndexEdit;
80+
$this->fixtureFactory = $fixtureFactory;
81+
$this->import = $import;
82+
83+
$resultArrays = $this->getPrepareAddresses();
84+
85+
\PHPUnit_Framework_Assert::assertEquals(
86+
$resultArrays['pageData'],
87+
$resultArrays['csvData'],
88+
'Addresses from page and csv are not match.'
89+
);
90+
}
91+
92+
/**
93+
* Prepare arrays for compare.
94+
*
95+
* @return array
96+
*/
97+
private function getPrepareAddresses()
98+
{
99+
$addressTemplate = ($this->import->getBehavior() !== 'Delete Entities')
100+
? $this->fixtureFactory->createByCode('address', ['dataset' => 'US_address_1_without_email'])
101+
: null;
102+
$customers = $this->import->getDataFieldConfig('import_file')['source']->getEntities();
103+
$customerForm = $this->customerIndexEdit->getCustomerForm();
104+
105+
// Prepare customer address data from page form.
106+
$resultAddressesArray = [];
107+
foreach ($customers as $customer) {
108+
$this->customerIndexEdit->open(['id' => $customer->getId()]);
109+
$customerForm->openTab('addresses');
110+
$address = $customerForm->getTab('addresses')->getDataAddresses($addressTemplate)[0];
111+
if (!empty($address)) {
112+
$resultAddressesArray[] = $address;
113+
}
114+
}
115+
116+
// Prepare customer address data from csv file.
117+
$resultCsvArray = [];
118+
if ($this->import->getBehavior() !== 'Delete Entities') {
119+
$resultCsvArray = $this->getResultCsv();
120+
}
121+
return ['pageData' => $resultAddressesArray, 'csvData' => $resultCsvArray];
122+
}
123+
124+
/**
125+
* Prepare array from csv file.
126+
*
127+
* @return array
128+
*/
129+
private function getResultCsv()
130+
{
131+
$csvData = $this->import->getDataFieldConfig('import_file')['source']->getCsv();
132+
133+
$csvKeys = [];
134+
foreach (array_shift($csvData) as $csvKey) {
135+
$csvKeys[] = isset($this->mappingKeys[$csvKey]) ? $this->mappingKeys[$csvKey] : $csvKey;
136+
}
137+
138+
$resultCsvData = [];
139+
foreach ($csvData as $csvRowData) {
140+
$csvRowData = array_combine($csvKeys, $csvRowData);
141+
$csvRowData = $this->deleteWasteData($csvRowData);
142+
if (isset($this->mappingCountries[$csvRowData['country_id']])) {
143+
$csvRowData['country_id'] = $this->mappingCountries[$csvRowData['country_id']];
144+
};
145+
$resultCsvData[] = $csvRowData;
146+
}
147+
return $resultCsvData;
148+
}
149+
150+
/**
151+
* Delete waste data from array.
152+
*
153+
* @param array $csvData
154+
* @return array
155+
*/
156+
private function deleteWasteData(array $csvData)
157+
{
158+
$necessaryData = array_flip($this->mappingKeys);
159+
$wasteKeys = array_keys(array_diff_key($csvData, $necessaryData));
160+
foreach ($wasteKeys as $key) {
161+
unset($csvData[$key]);
162+
};
163+
return $csvData;
164+
}
165+
166+
/**
167+
* Return string representation of object.
168+
*
169+
* @return string
170+
*/
171+
public function toString()
172+
{
173+
return 'Imported advanced prices are correct.';
174+
}
175+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\CustomerImportExport\Test\TestCase;
7+
8+
use Magento\Mtf\TestCase\Scenario;
9+
10+
/**
11+
* Preconditions:
12+
* 1. Create customer.
13+
*
14+
* Steps:
15+
* 1. Login as admin.
16+
* 2. Open import index page.
17+
* 3. Fill import form.
18+
* 4. Click "Check Data" button.
19+
* 5. Perform assertions.
20+
*
21+
* @group ImportExport
22+
* @ZephyrId MAGETWO-46175, MAGETWO-46176
23+
*/
24+
class ImportCustomerAddressTest extends Scenario
25+
{
26+
/**
27+
* Run import data test.
28+
*
29+
* @return void
30+
*/
31+
public function test()
32+
{
33+
$this->executeScenario();
34+
}
35+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
/**
4+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/variations.xsd">
9+
<testCase name="Magento\CustomerImportExport\Test\TestCase\ImportCustomerAddressTest" summary="Import customer address">
10+
<variation name="ImportCustomerAddressesVariation1" ticketId="MAGETWO-46175" summary="Delete Customer Address">
11+
<data name="import/data" xsi:type="array">
12+
<item name="entity" xsi:type="string">Customer Addresses</item>
13+
<item name="behavior" xsi:type="string">Delete Entities</item>
14+
<item name="validation_strategy" xsi:type="string">Stop on Error</item>
15+
<item name="allowed_error_count" xsi:type="string">10</item>
16+
<item name="import_field_separator" xsi:type="string">,</item>
17+
<item name="import_multiple_value_separator" xsi:type="string">,</item>
18+
<item name="import_file" xsi:type="array">
19+
<item name="entities" xsi:type="array">
20+
<item name="0" xsi:type="string">customer::johndoe_with_addresses</item>
21+
</item>
22+
<item name="template" xsi:type="array">
23+
<item name="filename"
24+
xsi:type="string">Magento/CustomerImportExport/Test/_files/template/pricing/customer_addresses_variation_1</item>
25+
<item name="count" xsi:type="number">1</item>
26+
</item>
27+
</item>
28+
</data>
29+
<constraint name="Magento\ImportExport\Test\Constraint\AssertImportSuccessMessage" />
30+
<constraint name="Magento\CustomerImportExport\Test\Constraint\AssertImportCustomerAddresses" />
31+
</variation>
32+
<variation name="ImportCustomerAddressesVariation2" ticketId="MAGETWO-46176" summary="Add/Update Customer Addresses">
33+
<data name="import/data" xsi:type="array">
34+
<item name="entity" xsi:type="string">Customer Addresses</item>
35+
<item name="behavior" xsi:type="string">Add/Update Complex Data</item>
36+
<item name="validation_strategy" xsi:type="string">Stop on Error</item>
37+
<item name="allowed_error_count" xsi:type="string">10</item>
38+
<item name="import_field_separator" xsi:type="string">,</item>
39+
<item name="import_multiple_value_separator" xsi:type="string">,</item>
40+
<item name="import_file" xsi:type="array">
41+
<item name="entities" xsi:type="array">
42+
<item name="0" xsi:type="string">customer::default</item>
43+
<item name="1" xsi:type="string">customer::default</item>
44+
</item>
45+
<item name="template" xsi:type="array">
46+
<item name="filename"
47+
xsi:type="string">Magento/CustomerImportExport/Test/_files/template/pricing/customer_addresses_variation_2</item>
48+
<item name="count" xsi:type="number">2</item>
49+
</item>
50+
</item>
51+
</data>
52+
<constraint name="Magento\ImportExport\Test\Constraint\AssertImportSuccessMessage" />
53+
<constraint name="Magento\CustomerImportExport\Test\Constraint\AssertImportCustomerAddresses" />
54+
</variation>
55+
</testCase>
56+
</config>
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\CustomerImportExport\Test\TestStep;
7+
8+
use Magento\Mtf\TestStep\TestStepInterface;
9+
use Magento\ImportExport\Test\Fixture\Import\File;
10+
use Magento\ImportExport\Test\Fixture\ImportData;
11+
use Magento\ImportExport\Test\Page\Adminhtml\AdminImportIndex;
12+
13+
/**
14+
* Fill custom import form.
15+
*/
16+
class FillCustomImportFormStep implements TestStepInterface
17+
{
18+
/**
19+
* Import index page.
20+
*
21+
* @var AdminImportIndex
22+
*/
23+
private $adminImportIndex;
24+
25+
/**
26+
* Import fixture.
27+
*
28+
* @var ImportData
29+
*/
30+
private $import;
31+
32+
/**
33+
* @param AdminImportIndex $adminImportIndex
34+
* @param ImportData $import
35+
*/
36+
public function __construct(
37+
AdminImportIndex $adminImportIndex,
38+
ImportData $import
39+
) {
40+
$this->adminImportIndex = $adminImportIndex;
41+
$this->import = $import;
42+
}
43+
44+
/**
45+
* Fill import form.
46+
*
47+
* @return array
48+
*/
49+
public function run()
50+
{
51+
$this->adminImportIndex->getCustomImportForm()->fill($this->import);
52+
53+
/** @var File $file */
54+
$file = $this->import->getDataFieldConfig('import_file')['source'];
55+
56+
return [
57+
'entities' => $file->getEntities(),
58+
'import' => $this->import
59+
];
60+
}
61+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
return [
8+
'entity_0' =>
9+
[
10+
'data_0' =>
11+
[
12+
'_website' => 'base',
13+
'_email' => "%email%",
14+
'_entity_id' => '%id%',
15+
'city' => 'Culver City',
16+
'company' => 'Magento',
17+
'country_id' => 'US',
18+
'firstname' => 'John',
19+
'lastname' => 'Doe',
20+
'postcode' => '90230',
21+
'region' => 'California',
22+
'region_id' => '12',
23+
'street' => '6161 West Centinela Avenue',
24+
'telephone' => '555-55-555-55',
25+
],
26+
],
27+
];

0 commit comments

Comments
 (0)