|
33 | 33 | use Magento\Framework\App\Filesystem\DirectoryList;
|
34 | 34 | use Magento\Framework\App\ResourceConnection;
|
35 | 35 | use Magento\Framework\DB\Adapter\AdapterInterface;
|
| 36 | +use Magento\Framework\DB\Select; |
36 | 37 | use Magento\Framework\EntityManager\EntityMetadata;
|
37 | 38 | use Magento\Framework\EntityManager\MetadataPool;
|
38 | 39 | use Magento\Framework\Event\ManagerInterface;
|
@@ -211,6 +212,9 @@ class ProductTest extends AbstractImportTestCase
|
211 | 212 | /** @var DriverFile|MockObject */
|
212 | 213 | private $driverFile;
|
213 | 214 |
|
| 215 | + /** @var Select|MockObject */ |
| 216 | + protected $select; |
| 217 | + |
214 | 218 | /**
|
215 | 219 | * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
216 | 220 | */
|
@@ -481,6 +485,13 @@ protected function _parentObjectConstructor()
|
481 | 485 | $this->config->expects($this->any())->method('getEntityType')->with(self::ENTITY_TYPE_CODE)->willReturn($type);
|
482 | 486 |
|
483 | 487 | $this->_connection = $this->getMockForAbstractClass(AdapterInterface::class);
|
| 488 | + $this->select = $this->getMockBuilder(Select::class) |
| 489 | + ->disableOriginalConstructor() |
| 490 | + ->setMethods(['from', 'where']) |
| 491 | + ->getMock(); |
| 492 | + $this->select->expects($this->any())->method('from')->willReturnSelf(); |
| 493 | + //$this->select->expects($this->any())->method('where')->willReturnSelf(); |
| 494 | + $this->_connection->expects($this->any())->method('select')->willReturn($this->select); |
484 | 495 | $this->resource->expects($this->any())->method('getConnection')->willReturn($this->_connection);
|
485 | 496 | return $this;
|
486 | 497 | }
|
@@ -1421,6 +1432,62 @@ function ($name) use ($throwException, $exception) {
|
1421 | 1432 | );
|
1422 | 1433 | }
|
1423 | 1434 |
|
| 1435 | + /** |
| 1436 | + * Check that getProductCategoriesDataSave method will return array with product-category-position relations |
| 1437 | + * where new products positioned before existing |
| 1438 | + * |
| 1439 | + * @param array $categoriesData |
| 1440 | + * @param string $tableName |
| 1441 | + * @param array $result |
| 1442 | + * @dataProvider productCategoriesDataProvider |
| 1443 | + */ |
| 1444 | + public function testGetProductCategoriesDataSave(array $categoriesData, string $tableName, array $result) |
| 1445 | + { |
| 1446 | + $this->_connection->expects($this->at(1))->method('fetchOne')->willReturn('0'); |
| 1447 | + $this->_connection->expects($this->at(3))->method('fetchOne')->willReturn('-2'); |
| 1448 | + $this->skuProcessor->expects($this->at(0))->method('getNewSku')->willReturn(['entity_id' => 2]); |
| 1449 | + $this->skuProcessor->expects($this->at(1))->method('getNewSku')->willReturn(['entity_id' => 5]); |
| 1450 | + $actualResult = $this->invokeMethod( |
| 1451 | + $this->importProduct, |
| 1452 | + 'getProductCategoriesDataSave', |
| 1453 | + [$categoriesData, $tableName] |
| 1454 | + ); |
| 1455 | + $this->assertEquals($result, $actualResult); |
| 1456 | + } |
| 1457 | + |
| 1458 | + /** |
| 1459 | + * Data provider for testGetProductCategoriesDataSave. |
| 1460 | + * |
| 1461 | + * @return array |
| 1462 | + */ |
| 1463 | + public function productCategoriesDataProvider() |
| 1464 | + { |
| 1465 | + return [ |
| 1466 | + [ |
| 1467 | + [ |
| 1468 | + 'simple_2' => [3 => true], |
| 1469 | + 'simple_5' => [5 => true] |
| 1470 | + ], |
| 1471 | + 'catalog_category_product', |
| 1472 | + [ |
| 1473 | + [2, 5], |
| 1474 | + [ |
| 1475 | + [ |
| 1476 | + 'product_id' => 2, |
| 1477 | + 'category_id' => 3, |
| 1478 | + 'position' => -1 |
| 1479 | + ], |
| 1480 | + [ |
| 1481 | + 'product_id' => 5, |
| 1482 | + 'category_id' => 5, |
| 1483 | + 'position' => -3 |
| 1484 | + ] |
| 1485 | + ] |
| 1486 | + ] |
| 1487 | + ] |
| 1488 | + ]; |
| 1489 | + } |
| 1490 | + |
1424 | 1491 | /**
|
1425 | 1492 | * Data provider for testFillUploaderObject.
|
1426 | 1493 | *
|
|
0 commit comments