66
77namespace Magento \DownloadableImportExport \Test \Unit \Model \Import \Product \Type ;
88
9+ use Magento \Downloadable \Model \Url \DomainValidator ;
910use 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 /**
@@ -550,6 +564,8 @@ public function isRowValidData()
550564 . 'title=Title 2, price=10, downloads=unlimited, url=media/file2.mp4,sortorder=0 ' ,
551565 ],
552566 0 ,
567+ true ,
568+ true ,
553569 true
554570 ],
555571 [
@@ -564,15 +580,8 @@ public function isRowValidData()
564580 . ' title=Title 2, price=10, downloads=unlimited, url=media/file2.mp4,sortorder=0 ' ,
565581 ],
566582 1 ,
567- true
568- ],
569- [
570- [
571- 'sku ' => 'downloadablesku12 ' ,
572- 'product_type ' => 'downloadable ' ,
573- 'name ' => 'Downloadable Product 2 ' ,
574- ],
575- 2 ,
583+ true ,
584+ true ,
576585 true
577586 ],
578587 [
@@ -587,20 +596,24 @@ public function isRowValidData()
587596 . ' url=media/file2.mp4,sortorder=0 ' ,
588597 ],
589598 3 ,
599+ true ,
600+ true ,
590601 true
591602 ],
592603 [
593604 [
594605 'sku ' => 'downloadablesku12 ' ,
595606 'product_type ' => 'downloadable ' ,
596607 'name ' => 'Downloadable Product 2 ' ,
597- 'downloadable_samples ' => 'file=media/file.mp4,sortorder=1|group_title=Group Title, '
598- . ' 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 ' ,
599610 'downloadable_links ' => 'title=Title 1, price=10, downloads=unlimited, file=media/file.mp4, '
600611 . 'sortorder=1|group_title=Group Title, title=Title 2, price=10, downloads=unlimited, '
601612 . ' url=media/file2.mp4,sortorder=0 ' ,
602613 ],
603614 4 ,
615+ true ,
616+ true ,
604617 true
605618 ],
606619 [ //empty group title samples
@@ -615,6 +628,8 @@ public function isRowValidData()
615628 . ' title=Title 2, price=10, downloads=unlimited, url=media/file2.mp4,sortorder=0 ' ,
616629 ],
617630 5 ,
631+ true ,
632+ true ,
618633 true
619634 ],
620635 [ //empty group title links
@@ -629,6 +644,19 @@ public function isRowValidData()
629644 . 'downloads=unlimited, url=media/file2.mp4,sortorder=0 ' ,
630645 ],
631646 6 ,
647+ true ,
648+ true ,
649+ true
650+ ],
651+ [
652+ [
653+ 'sku ' => 'downloadablesku12 ' ,
654+ 'product_type ' => 'downloadable ' ,
655+ 'name ' => 'Downloadable Product 2 ' ,
656+ ],
657+ 2 ,
658+ false ,
659+ true ,
632660 true
633661 ],
634662 [
@@ -640,7 +668,9 @@ public function isRowValidData()
640668 'downloadable_links ' => '' ,
641669 ],
642670 7 ,
643- true
671+ true ,
672+ true ,
673+ false
644674 ],
645675 ];
646676 }
0 commit comments