@@ -69,6 +69,11 @@ class ProductTest extends \Magento\TestFramework\Indexer\TestCase
69
69
*/
70
70
private $ logger ;
71
71
72
+ /**
73
+ * @var \Magento\Framework\EntityManager\EntityMetadata
74
+ */
75
+ private $ metadata ;
76
+
72
77
protected function setUp ()
73
78
{
74
79
$ this ->objectManager = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ();
@@ -79,6 +84,12 @@ protected function setUp()
79
84
\Magento \CatalogImportExport \Model \Import \Product::class,
80
85
['logger ' => $ this ->logger ]
81
86
);
87
+
88
+ $ metadataPool = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()->create (
89
+ \Magento \Framework \EntityManager \MetadataPool::class
90
+ );
91
+ $ this ->metadata = $ metadataPool ->getMetadata (ProductInterface::class);
92
+
82
93
parent ::setUp ();
83
94
}
84
95
@@ -1278,6 +1289,63 @@ public function testProductPositionInCategory()
1278
1289
}
1279
1290
}
1280
1291
1292
+ /**
1293
+ * @magentoAppArea adminhtml
1294
+ * @magentoDbIsolation enabled
1295
+ * @magentoAppIsolation enabled
1296
+ * @magentoDataFixture Magento/Catalog/_files/category_product.php
1297
+ */
1298
+ public function testNewProductPositionInCategory ()
1299
+ {
1300
+ $ categoryId = 333 ;
1301
+
1302
+ $ filesystem = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()->create (
1303
+ \Magento \Framework \Filesystem::class
1304
+ );
1305
+
1306
+ $ directory = $ filesystem ->getDirectoryWrite (DirectoryList::ROOT );
1307
+ $ source = $ this ->objectManager ->create (
1308
+ \Magento \ImportExport \Model \Import \Source \Csv::class,
1309
+ [
1310
+ 'file ' => __DIR__ . '/_files/product_to_import_with_category.csv ' ,
1311
+ 'directory ' => $ directory
1312
+ ]
1313
+ );
1314
+ $ errors = $ this ->_model ->setSource (
1315
+ $ source
1316
+ )->setParameters (
1317
+ [
1318
+ 'behavior ' => \Magento \ImportExport \Model \Import::BEHAVIOR_APPEND ,
1319
+ 'entity ' => 'catalog_product ' ,
1320
+ ]
1321
+ )->validateData ();
1322
+
1323
+ $ this ->assertTrue ($ errors ->getErrorsCount () == 0 );
1324
+ $ this ->_model ->importData ();
1325
+
1326
+ /** @var \Magento\Framework\App\ResourceConnection $resourceConnection */
1327
+ $ resourceConnection = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()->get (
1328
+ \Magento \Framework \App \ResourceConnection::class
1329
+ );
1330
+ $ linkField = $ this ->metadata ->getLinkField ();
1331
+ $ categoryProductstableName = $ resourceConnection ->getTableName ('catalog_category_product ' );
1332
+ $ productEntitiesTableName = $ resourceConnection ->getTableName ('catalog_product_entity ' );
1333
+ $ select = $ resourceConnection ->getConnection ()
1334
+ ->select ()
1335
+ ->from (['category_products ' => $ categoryProductstableName ])
1336
+ ->join (
1337
+ ['product_entities ' => $ productEntitiesTableName ],
1338
+ 'product_entities. ' . $ linkField . ' = category_products.product_id ' ,
1339
+ ''
1340
+ )
1341
+ ->where ('category_products.category_id = ? ' , $ categoryId )
1342
+ ->where ('product_entities.sku = "simpleImported" ' );
1343
+ $ importedItem = $ resourceConnection ->getConnection ()->fetchRow ($ select );
1344
+ $ this ->assertTrue (is_array ($ importedItem ));
1345
+ $ this ->assertNotEmpty ($ importedItem );
1346
+ $ this ->assertEquals (0 , $ importedItem ['position ' ]);
1347
+ }
1348
+
1281
1349
/**
1282
1350
* @return array
1283
1351
*/
0 commit comments