Skip to content

Commit 0c0dc6d

Browse files
committed
MC-20624: Automate MC-11459
1 parent f7cc155 commit 0c0dc6d

File tree

2 files changed

+61
-12
lines changed

2 files changed

+61
-12
lines changed

dev/tests/integration/testsuite/Magento/Customer/_files/import_export/customers_rollback.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,4 @@
3434
}
3535
$registry->unregister('isSecureArea');
3636
$registry->register('isSecureArea', false);
37+
$registry->unregister('_fixture/Magento_ImportExport_Customer_Collection');

dev/tests/integration/testsuite/Magento/CustomerImportExport/Model/Export/CustomerTest.php

Lines changed: 60 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,40 +46,76 @@ class CustomerTest extends \PHPUnit\Framework\TestCase
4646
*/
4747
private $attributeTypes;
4848

49+
/**
50+
* @var Collection
51+
*/
52+
private $attributeCollection;
53+
4954
/**
5055
* @inheritdoc
5156
*/
5257
protected function setUp()
5358
{
5459
$this->objectManager = Bootstrap::getObjectManager();
5560
$this->_model = $this->objectManager->create(Customer::class);
61+
$this->attributeCollection = $this->objectManager->create(Collection::class);
5662
}
5763

5864
/**
5965
* Export "Customer Main File".
6066
*
6167
* @magentoDataFixture Magento/Customer/_files/import_export/customers.php
68+
* @return void
6269
*/
6370
public function testExport()
6471
{
65-
/** @var Collection $collection */
66-
$collection = $this->objectManager->create(Collection::class);
67-
$this->initAttributeValues($collection);
68-
$this->initAttributeTypes($collection);
72+
$this->processCustomerAttribute();
73+
$expectedAttributes = $this->getExpectedAttributes();
74+
$lines = $this->export($expectedAttributes);
75+
$this->checkExportData($lines, $expectedAttributes);
76+
}
6977

78+
/**
79+
* Return attributes which should be exported.
80+
*
81+
* @return array
82+
*/
83+
private function getExpectedAttributes(): array
84+
{
7085
$expectedAttributes = [];
7186
/** @var Attribute $attribute */
72-
foreach ($collection as $attribute) {
87+
foreach ($this->attributeCollection as $attribute) {
7388
$expectedAttributes[] = $attribute->getAttributeCode();
7489
}
75-
$expectedAttributes = array_diff($expectedAttributes, $this->_model->getDisabledAttributes());
7690

77-
$this->_model->setWriter($this->objectManager->get(Csv::class));
91+
return array_diff($expectedAttributes, $this->_model->getDisabledAttributes());
92+
}
93+
94+
/**
95+
* Prepare Customer attribute.
96+
*
97+
* @return void
98+
*/
99+
private function processCustomerAttribute(): void
100+
{
101+
$this->initAttributeValues($this->attributeCollection);
102+
$this->initAttributeTypes($this->attributeCollection);
103+
}
104+
105+
/**
106+
* Export customer.
107+
*
108+
* @param array $expectedAttributes
109+
* @return array
110+
*/
111+
private function export(array $expectedAttributes): array
112+
{
113+
$this->_model->setWriter($this->objectManager->create(Csv::class));
78114
$data = $this->_model->export();
115+
79116
$this->assertNotEmpty($data);
80117

81118
$lines = $this->_csvToArray($data, 'email');
82-
83119
$this->assertEquals(
84120
count($expectedAttributes),
85121
count(array_intersect($expectedAttributes, $lines['header'])),
@@ -88,8 +124,20 @@ public function testExport()
88124

89125
$this->assertNotEmpty($lines['data'], 'No data was exported.');
90126

127+
return $lines;
128+
}
129+
130+
/**
131+
* Check that exported data is correct.
132+
*
133+
* @param array $lines
134+
* @param array $expectedAttributes
135+
* @return void
136+
*/
137+
private function checkExportData(array $lines, array $expectedAttributes): void
138+
{
91139
/** @var CustomerModel[] $customers */
92-
$customers = $this->objectManager->create(CustomerCollection::class)->getItems();
140+
$customers = $this->objectManager->create(CustomerCollection::class);
93141
foreach ($customers as $customer) {
94142
$data = $this->processCustomerData($customer, $expectedAttributes);
95143
$exportData = $lines['data'][$data['email']];
@@ -111,7 +159,7 @@ function (&$value) {
111159
* Initialize attribute option values.
112160
*
113161
* @param Collection $attributeCollection
114-
* @return $this
162+
* @return CustomerTest
115163
*/
116164
private function initAttributeValues(Collection $attributeCollection): CustomerTest
117165
{
@@ -127,7 +175,7 @@ private function initAttributeValues(Collection $attributeCollection): CustomerT
127175
* Initialize attribute types.
128176
*
129177
* @param \Magento\Customer\Model\ResourceModel\Attribute\Collection $attributeCollection
130-
* @return $this
178+
* @return CustomerTest
131179
*/
132180
private function initAttributeTypes(Collection $attributeCollection): CustomerTest
133181
{
@@ -184,7 +232,7 @@ private function isMultiselect(string $attributeCode): bool
184232
*
185233
* @param string $attributeCode
186234
* @param int|string $valueId
187-
* @return mixed
235+
* @return int|string|array
188236
*/
189237
private function getAttributeValueById(string $attributeCode, $valueId)
190238
{

0 commit comments

Comments
 (0)