Skip to content

Commit 234899d

Browse files
committed
MAGETWO-71013: Export missing configurable variations when exporting more than one item
- Clean up formatting, unused variables, and documentation - Add optional dependencies to support running new Import/Replace w/ pagination
1 parent 81b041e commit 234899d

File tree

3 files changed

+46
-33
lines changed

3 files changed

+46
-33
lines changed

dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/AbstractProductExportImportTestCase.php

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
namespace Magento\CatalogImportExport\Model;
77

88
use Magento\Framework\App\Bootstrap;
9-
use Magento\Framework\App\Config;
109
use Magento\Framework\App\Filesystem\DirectoryList;
1110

1211
/**
@@ -16,11 +15,6 @@
1615
*/
1716
abstract class AbstractProductExportImportTestCase extends \PHPUnit\Framework\TestCase
1817
{
19-
/**
20-
* @var \Magento\CatalogImportExport\Model\Export\Product
21-
*/
22-
protected $model;
23-
2418
/**
2519
* @var \Magento\Framework\ObjectManagerInterface
2620
*/
@@ -61,8 +55,6 @@ abstract class AbstractProductExportImportTestCase extends \PHPUnit\Framework\Te
6155

6256
protected function setUp()
6357
{
64-
parent::setUp();
65-
6658
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
6759
$this->fileSystem = $this->objectManager->get(\Magento\Framework\Filesystem::class);
6860
$this->productResource = $this->objectManager->create(
@@ -262,9 +254,33 @@ public function testImportReplace($fixtures, $skus, $skippedAttributes = [])
262254
}
263255

264256
/**
257+
* @magentoAppArea adminhtml
258+
* @magentoDbIsolation enabled
259+
* @magentoAppIsolation enabled
260+
*
261+
* @param array $fixtures
262+
* @param string[] $skus
263+
* @param string[] $skippedAttributes
264+
* @dataProvider importReplaceDataProvider
265+
*/
266+
public function testImportReplaceWithPagination($fixtures, $skus, $skippedAttributes = [])
267+
{
268+
$this->fixtures = $fixtures;
269+
$this->executeFixtures($fixtures, $skus);
270+
$this->modifyData($skus);
271+
$skippedAttributes = array_merge(self::$skippedAttributes, $skippedAttributes);
272+
$this->executeImportReplaceTest($skus, $skippedAttributes, true);
273+
}
274+
275+
/**
276+
* @param string[] $skus
277+
* @param string[] $skippedAttributes
278+
* @param bool $usePagination
279+
*
265280
* @SuppressWarnings(PHPMD.NPathComplexity)
281+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
266282
*/
267-
protected function executeImportReplaceTest($skus, $skippedAttributes)
283+
protected function executeImportReplaceTest($skus, $skippedAttributes, $usePagination = false)
268284
{
269285
$replacedAttributes = [
270286
'row_id',
@@ -285,7 +301,18 @@ protected function executeImportReplaceTest($skus, $skippedAttributes)
285301
$index++;
286302
}
287303

288-
$csvfile = $this->exportProducts();
304+
$exportProduct = $this->objectManager->create(\Magento\CatalogImportExport\Model\Export\Product::class);
305+
if ($usePagination) {
306+
/** @var \ReflectionProperty $itemsPerPageProperty */
307+
$itemsPerPageProperty = $this->objectManager->create(\ReflectionProperty::class, [
308+
'class' => \Magento\CatalogImportExport\Model\Export\Product::class,
309+
'name' => '_itemsPerPage'
310+
]);
311+
$itemsPerPageProperty->setAccessible(true);
312+
$itemsPerPageProperty->setValue($exportProduct, 1);
313+
}
314+
315+
$csvfile = $this->exportProducts($exportProduct);
289316
$this->importProducts($csvfile, \Magento\ImportExport\Model\Import::BEHAVIOR_REPLACE);
290317

291318
while ($index > 0) {
@@ -326,13 +353,16 @@ protected function executeImportReplaceTest($skus, $skippedAttributes)
326353
/**
327354
* Export products in the system
328355
*
356+
* @param \Magento\CatalogImportExport\Model\Export\Product|null $exportProduct
329357
* @return string Return exported file name
330358
*/
331-
private function exportProducts()
359+
private function exportProducts(\Magento\CatalogImportExport\Model\Export\Product $exportProduct = null)
332360
{
333361
$csvfile = uniqid('importexport_') . '.csv';
334362

335-
$exportProduct = $this->objectManager->create(\Magento\CatalogImportExport\Model\Export\Product::class);
363+
$exportProduct = $exportProduct ?: $this->objectManager->create(
364+
\Magento\CatalogImportExport\Model\Export\Product::class
365+
);
336366
$exportProduct->setWriter(
337367
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
338368
\Magento\ImportExport\Model\Export\Adapter\Csv::class,

dev/tests/integration/testsuite/Magento/CatalogImportExport/_files/product_export_data.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,6 @@
7979
\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED
8080
)->setWebsiteIds(
8181
[1]
82-
)->setCateroryIds(
83-
[]
8482
)->setStockData(
8583
['qty' => 100, 'is_in_stock' => 1]
8684
)->setCanSaveCustomOptions(

dev/tests/integration/testsuite/Magento/ConfigurableImportExport/Model/ConfigurableTest.php

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ public function exportImportDataProvider()
3939
*/
4040
protected function assertEqualsSpecificAttributes($expectedProduct, $actualProduct)
4141
{
42-
/** @var \Magento\ConfigurableProduct\Model\Product\Type\Configurable $prooductType */
43-
$prooductType = $expectedProduct->getTypeInstance();
44-
$expectedAssociatedProducts = $prooductType->getUsedProductCollection($expectedProduct);
45-
$actualAssociatedProducts = iterator_to_array($prooductType->getUsedProductCollection($actualProduct));
42+
/** @var \Magento\ConfigurableProduct\Model\Product\Type\Configurable $productType */
43+
$productType = $expectedProduct->getTypeInstance();
44+
$expectedAssociatedProducts = $productType->getUsedProductCollection($expectedProduct);
45+
$actualAssociatedProducts = iterator_to_array($productType->getUsedProductCollection($actualProduct));
4646

4747
$expectedAssociatedProductSkus = [];
4848
$actualAssociatedProductSkus = [];
@@ -103,19 +103,4 @@ public function importReplaceDataProvider()
103103
}
104104
return $data;
105105
}
106-
107-
/**
108-
* @magentoAppArea adminhtml
109-
* @magentoDbIsolation enabled
110-
* @magentoAppIsolation enabled
111-
*
112-
* @param array $fixtures
113-
* @param string[] $skus
114-
* @param string[] $skippedAttributes
115-
* @dataProvider importReplaceDataProvider
116-
*/
117-
public function testImportReplace($fixtures, $skus, $skippedAttributes = [])
118-
{
119-
parent::testImportReplace($fixtures, $skus, $skippedAttributes);
120-
}
121106
}

0 commit comments

Comments
 (0)