Skip to content

Commit 5f89b46

Browse files
committed
Merge remote-tracking branch 'origin/MC-32306' into 2.4-develop-pr19
2 parents cf93b9e + b3acc9c commit 5f89b46

File tree

2 files changed

+80
-49
lines changed

2 files changed

+80
-49
lines changed

app/code/Magento/DownloadableImportExport/Model/Import/Product/Type/Downloadable.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*
1818
* phpcs:disable Magento2.Commenting.ConstantsPHPDocFormatting
1919
* @SuppressWarnings(PHPMD.TooManyFields)
20+
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
2021
*/
2122
class Downloadable extends \Magento\CatalogImportExport\Model\Import\Product\Type\AbstractType
2223
{
@@ -332,7 +333,7 @@ public function isRowValid(array $rowData, $rowNum, $isNewProduct = true)
332333
{
333334
$this->rowNum = $rowNum;
334335
$error = false;
335-
if (!$this->downloadableHelper->isRowDownloadableNoValid($rowData)) {
336+
if (!$this->downloadableHelper->isRowDownloadableNoValid($rowData) && $isNewProduct) {
336337
$this->_entityModel->addRowError(self::ERROR_OPTIONS_NOT_FOUND, $this->rowNum);
337338
$error = true;
338339
}
@@ -888,8 +889,8 @@ protected function uploadDownloadableFiles($fileName, $type = 'links', $renameFi
888889
try {
889890
$uploader = $this->uploaderHelper->getUploader($type, $this->parameters);
890891
if (!$this->uploaderHelper->isFileExist($fileName)) {
891-
$uploader->move($fileName, $renameFileOff);
892-
$fileName = $uploader['file'];
892+
$res = $uploader->move($fileName, $renameFileOff);
893+
$fileName = $res['file'];
893894
}
894895
} catch (\Exception $e) {
895896
$this->_entityModel->addRowError(self::ERROR_MOVE_FILE, $this->rowNum);

app/code/Magento/DownloadableImportExport/Test/Unit/Model/Import/Product/Type/DownloadableTest.php

Lines changed: 76 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
namespace Magento\DownloadableImportExport\Test\Unit\Model\Import\Product\Type;
88

9+
use Magento\Downloadable\Model\Url\DomainValidator;
910
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManager;
1011

1112
/**
@@ -39,6 +40,11 @@ class DownloadableTest extends \Magento\ImportExport\Test\Unit\Model\Import\Abst
3940
*/
4041
protected $prodAttrColFacMock;
4142

43+
/**
44+
* @var DomainValidator
45+
*/
46+
private $domainValidator;
47+
4248
/**
4349
* @var \Magento\Catalog\Model\ResourceModel\Product\Attribute\Collection|\PHPUnit_Framework_MockObject_MockObject
4450
*/
@@ -498,7 +504,7 @@ public function dataForSave()
498504
/**
499505
* @dataProvider isRowValidData
500506
*/
501-
public function testIsRowValid(array $rowData, $rowNum, $isNewProduct = true)
507+
public function testIsRowValid(array $rowData, $rowNum, $isNewProduct, $isDomainValid, $expectedResult)
502508
{
503509
$this->connectionMock->expects($this->any())->method('fetchAll')->with(
504510
$this->select
@@ -514,6 +520,13 @@ public function testIsRowValid(array $rowData, $rowNum, $isNewProduct = true)
514520
],
515521
]
516522
);
523+
524+
$this->domainValidator = $this->createMock(DomainValidator::class);
525+
$this->domainValidator
526+
->expects($this->any())->method('isValid')
527+
->withAnyParameters()
528+
->willReturn($isDomainValid);
529+
517530
$this->downloadableModelMock = $this->objectManagerHelper->getObject(
518531
\Magento\DownloadableImportExport\Model\Import\Product\Type\Downloadable::class,
519532
[
@@ -522,11 +535,12 @@ public function testIsRowValid(array $rowData, $rowNum, $isNewProduct = true)
522535
'resource' => $this->resourceMock,
523536
'params' => $this->paramsArray,
524537
'uploaderHelper' => $this->uploaderHelper,
525-
'downloadableHelper' => $this->downloadableHelper
538+
'downloadableHelper' => $this->downloadableHelper,
539+
'domainValidator' => $this->domainValidator
526540
]
527541
);
528542
$result = $this->downloadableModelMock->isRowValid($rowData, $rowNum, $isNewProduct);
529-
$this->assertNotNull($result);
543+
$this->assertEquals($expectedResult, $result);
530544
}
531545

532546
/**
@@ -539,7 +553,7 @@ public function isRowValidData()
539553
{
540554
return [
541555
[
542-
[
556+
'row_data' => [
543557
'sku' => 'downloadablesku1',
544558
'product_type' => 'downloadable',
545559
'name' => 'Downloadable Product 1',
@@ -549,11 +563,13 @@ public function isRowValidData()
549563
. 'downloads=unlimited, file=media/file_link.mp4,sortorder=1|group_title=Group Title, '
550564
. 'title=Title 2, price=10, downloads=unlimited, url=media/file2.mp4,sortorder=0',
551565
],
552-
0,
553-
true
566+
'row_num' => 0,
567+
'is_new_product' => true,
568+
'is_domain_valid' => true,
569+
'expected_result' => true
554570
],
555571
[
556-
[
572+
'row_data' => [
557573
'sku' => 'downloadablesku12',
558574
'product_type' => 'downloadable',
559575
'name' => 'Downloadable Product 2',
@@ -563,84 +579,98 @@ public function isRowValidData()
563579
. ' downloads=unlimited, file=media/file.mp4,sortorder=1|group_title=Group Title,'
564580
. ' title=Title 2, price=10, downloads=unlimited, url=media/file2.mp4,sortorder=0',
565581
],
566-
1,
567-
true
582+
'row_num' => 1,
583+
'is_new_product' => true,
584+
'is_domain_valid' => true,
585+
'expected_result' => true
568586
],
569587
[
570-
[
588+
'row_data' => [
571589
'sku' => 'downloadablesku12',
572590
'product_type' => 'downloadable',
573591
'name' => 'Downloadable Product 2',
592+
'downloadable_samples' => 'group_title=Group Title Samples, title=Title 1, file=media/file.mp4'
593+
.',sortorder=1|group_title=Group Title, title=Title 2, url=media/file2.mp4,sortorder=0',
594+
'downloadable_links' => 'group_title=Group Title Links, title=Title 1, price=10,'
595+
.' downloads=unlimited, file=media/file.mp4,sortorder=1|group_title=Group Title,'
596+
.' title=Title 2, price=10, downloads=unlimited, url=media/file2.mp4,sortorder=0',
574597
],
575-
2,
576-
true
598+
'row_num' => 3,
599+
'is_new_product' => true,
600+
'is_domain_valid' => true,
601+
'expected_result' => true
577602
],
578603
[
579-
[
604+
'row_data' => [
580605
'sku' => 'downloadablesku12',
581606
'product_type' => 'downloadable',
582607
'name' => 'Downloadable Product 2',
583-
'downloadable_samples' => 'title=Title 1, file=media/file.mp4,sortorder=1|title=Title 2,'
584-
. ' url=media/file2.mp4,sortorder=0',
608+
'downloadable_samples' => 'title=Title 1, file=media/file.mp4,sortorder=1|title=Title 2,' .
609+
' group_title=Group Title, url=media/file2.mp4,sortorder=0',
585610
'downloadable_links' => 'title=Title 1, price=10, downloads=unlimited, file=media/file.mp4,'
586611
. 'sortorder=1|group_title=Group Title, title=Title 2, price=10, downloads=unlimited,'
587612
. ' url=media/file2.mp4,sortorder=0',
588613
],
589-
3,
590-
true
614+
'row_num' => 4,
615+
'is_new_product' => true,
616+
'is_domain_valid' => true,
617+
'expected_result' => true
591618
],
592-
[
593-
[
619+
[ //empty group title samples
620+
'row_data' => [
594621
'sku' => 'downloadablesku12',
595622
'product_type' => 'downloadable',
596623
'name' => 'Downloadable Product 2',
597-
'downloadable_samples' => 'file=media/file.mp4,sortorder=1|group_title=Group Title, '
598-
. 'url=media/file2.mp4,sortorder=0',
599-
'downloadable_links' => 'title=Title 1, price=10, downloads=unlimited, file=media/file.mp4,'
600-
. 'sortorder=1|group_title=Group Title, title=Title 2, price=10, downloads=unlimited,'
601-
. ' url=media/file2.mp4,sortorder=0',
624+
'downloadable_samples' => 'group_title=Group Title Samples, title=Title 1, file=media/file.mp4'
625+
.',sortorder=1|group_title=Group Title, title=Title 2, url=media/file2.mp4,sortorder=0',
626+
'downloadable_links' => 'group_title=Group Title Links, title=Title 1, price=10,'
627+
.' downloads=unlimited, file=media/file.mp4,sortorder=1|group_title=Group Title,'
628+
.' title=Title 2, price=10, downloads=unlimited, url=media/file2.mp4,sortorder=0',
602629
],
603-
4,
604-
true
630+
'row_num' => 5,
631+
'is_new_product' => true,
632+
'is_domain_valid' => true,
633+
'expected_result' => true
605634
],
606-
[ //empty group title samples
607-
[
635+
[ //empty group title links
636+
'row_data' => [
608637
'sku' => 'downloadablesku12',
609638
'product_type' => 'downloadable',
610639
'name' => 'Downloadable Product 2',
611-
'downloadable_samples' => 'group_title=, title=Title 1, file=media/file.mp4,sortorder=1'
612-
. '|group_title=, title=Title 2, url=media/file2.mp4,sortorder=0',
640+
'downloadable_samples' => 'group_title=Group Title Samples, title=Title 1, file=media/file.mp4'
641+
.',sortorder=1|group_title=Group Title, title=Title 2, url=media/file2.mp4,sortorder=0',
613642
'downloadable_links' => 'group_title=Group Title Links, title=Title 1, price=10,'
614-
. ' downloads=unlimited, file=media/file_link.mp4,sortorder=1|group_title=Group Title,'
615-
. ' title=Title 2, price=10, downloads=unlimited, url=media/file2.mp4,sortorder=0',
643+
.' downloads=unlimited, file=media/file.mp4,sortorder=1|group_title=Group Title,'
644+
.' title=Title 2, price=10, downloads=unlimited, url=media/file2.mp4,sortorder=0',
616645
],
617-
5,
618-
true
646+
'row_num' => 6,
647+
'is_new_product' => true,
648+
'is_domain_valid' => true,
649+
'expected_result' => true
619650
],
620-
[ //empty group title links
621-
[
651+
[
652+
'row_data' => [
622653
'sku' => 'downloadablesku12',
623654
'product_type' => 'downloadable',
624655
'name' => 'Downloadable Product 2',
625-
'downloadable_samples' => 'group_title=Group Title Samples, title=Title 1, file=media/file.mp4,'
626-
. 'sortorder=1|group_title=Group Title, title=Title 2, url=media/file2.mp4,sortorder=0',
627-
'downloadable_links' => 'group_title=, title=Title 1, price=10, downloads=unlimited, '
628-
. 'file=media/file_link.mp4,sortorder=1|group_title=, title=Title 2, price=10, '
629-
. 'downloads=unlimited, url=media/file2.mp4,sortorder=0',
630656
],
631-
6,
632-
true
657+
'row_num' => 2,
658+
'is_new_product' => false,
659+
'is_domain_valid' => true,
660+
'expected_result' => true
633661
],
634662
[
635-
[
663+
'row_data' => [
636664
'sku' => 'downloadablesku12',
637665
'product_type' => 'downloadable',
638666
'name' => 'Downloadable Product 2',
639667
'downloadable_samples' => '',
640668
'downloadable_links' => '',
641669
],
642-
7,
643-
true
670+
'row_num' => 7,
671+
'is_new_product' => true,
672+
'is_domain_valid' => true,
673+
'expected_result' => false
644674
],
645675
];
646676
}

0 commit comments

Comments
 (0)