@@ -559,6 +559,8 @@ public function testSaveChild()
559
559
$ isDefault = true ;
560
560
$ linkProductId = 45 ;
561
561
$ parentProductId = 32 ;
562
+ $ bundleProductSku = 'bundleProductSku ' ;
563
+
562
564
$ productLink = $ this ->getMock ('\Magento\Bundle\Api\Data\LinkInterface ' );
563
565
$ productLink ->expects ($ this ->any ())->method ('getSku ' )->will ($ this ->returnValue ('linked_product_sku ' ));
564
566
$ productLink ->expects ($ this ->any ())->method ('getId ' )->will ($ this ->returnValue ($ id ));
@@ -580,7 +582,12 @@ public function testSaveChild()
580
582
$ linkedProductMock ->expects ($ this ->any ())->method ('getId ' )->will ($ this ->returnValue ($ linkProductId ));
581
583
$ linkedProductMock ->expects ($ this ->once ())->method ('isComposite ' )->will ($ this ->returnValue (false ));
582
584
$ this ->productRepository
583
- ->expects ($ this ->once ())
585
+ ->expects ($ this ->at (0 ))
586
+ ->method ('get ' )
587
+ ->with ($ bundleProductSku )
588
+ ->will ($ this ->returnValue ($ productMock ));
589
+ $ this ->productRepository
590
+ ->expects ($ this ->at (1 ))
584
591
->method ('get ' )
585
592
->with ('linked_product_sku ' )
586
593
->will ($ this ->returnValue ($ linkedProductMock ));
@@ -623,8 +630,7 @@ public function testSaveChild()
623
630
$ selection ->expects ($ this ->once ())->method ('setIsDefault ' )->with ($ isDefault );
624
631
625
632
$ this ->bundleSelectionMock ->expects ($ this ->once ())->method ('create ' )->will ($ this ->returnValue ($ selection ));
626
- $ result = $ this ->model ->saveChild ($ productMock , $ productLink );
627
- $ this ->assertEquals ($ id , $ result );
633
+ $ this ->assertTrue ($ this ->model ->saveChild ($ bundleProductSku , $ productLink ));
628
634
}
629
635
630
636
/**
@@ -638,6 +644,7 @@ public function testSaveChildFailedToSave()
638
644
$ productLink = $ this ->getMock ('\Magento\Bundle\Api\Data\LinkInterface ' );
639
645
$ productLink ->expects ($ this ->any ())->method ('getSku ' )->will ($ this ->returnValue ('linked_product_sku ' ));
640
646
$ productLink ->expects ($ this ->any ())->method ('getId ' )->will ($ this ->returnValue ($ id ));
647
+ $ bundleProductSku = 'bundleProductSku ' ;
641
648
642
649
$ productMock = $ this ->getMock ('\Magento\Catalog\Model\Product ' , [], [], '' , false );
643
650
$ productMock ->expects ($ this ->once ())->method ('getTypeId ' )->will ($ this ->returnValue (
@@ -649,7 +656,12 @@ public function testSaveChildFailedToSave()
649
656
$ linkedProductMock ->expects ($ this ->any ())->method ('getId ' )->will ($ this ->returnValue ($ linkProductId ));
650
657
$ linkedProductMock ->expects ($ this ->once ())->method ('isComposite ' )->will ($ this ->returnValue (false ));
651
658
$ this ->productRepository
652
- ->expects ($ this ->once ())
659
+ ->expects ($ this ->at (0 ))
660
+ ->method ('get ' )
661
+ ->with ($ bundleProductSku )
662
+ ->will ($ this ->returnValue ($ productMock ));
663
+ $ this ->productRepository
664
+ ->expects ($ this ->at (1 ))
653
665
->method ('get ' )
654
666
->with ('linked_product_sku ' )
655
667
->will ($ this ->returnValue ($ linkedProductMock ));
@@ -686,14 +698,15 @@ public function testSaveChildFailedToSave()
686
698
$ selection ->expects ($ this ->once ())->method ('setProductId ' )->with ($ linkProductId );
687
699
688
700
$ this ->bundleSelectionMock ->expects ($ this ->once ())->method ('create ' )->will ($ this ->returnValue ($ selection ));
689
- $ this ->model ->saveChild ($ productMock , $ productLink );
701
+ $ this ->model ->saveChild ($ bundleProductSku , $ productLink );
690
702
}
691
703
692
704
/**
693
705
* @expectedException \Magento\Framework\Exception\InputException
694
706
*/
695
707
public function testSaveChildWithoutId ()
696
708
{
709
+ $ bundleProductSku = "bundleSku " ;
697
710
$ linkedProductSku = 'simple ' ;
698
711
$ productLink = $ this ->getMock ('\Magento\Bundle\Api\Data\LinkInterface ' );
699
712
$ productLink ->expects ($ this ->any ())->method ('getId ' )->will ($ this ->returnValue (null ));
@@ -707,12 +720,17 @@ public function testSaveChildWithoutId()
707
720
$ linkedProductMock = $ this ->getMock ('\Magento\Catalog\Model\Product ' , [], [], '' , false );
708
721
$ linkedProductMock ->expects ($ this ->once ())->method ('isComposite ' )->will ($ this ->returnValue (false ));
709
722
$ this ->productRepository
710
- ->expects ($ this ->once ())
723
+ ->expects ($ this ->at (0 ))
724
+ ->method ('get ' )
725
+ ->with ($ bundleProductSku )
726
+ ->will ($ this ->returnValue ($ productMock ));
727
+ $ this ->productRepository
728
+ ->expects ($ this ->at (1 ))
711
729
->method ('get ' )
712
730
->with ($ linkedProductSku )
713
731
->will ($ this ->returnValue ($ linkedProductMock ));
714
732
715
- $ this ->model ->saveChild ($ productMock , $ productLink );
733
+ $ this ->model ->saveChild ($ bundleProductSku , $ productLink );
716
734
}
717
735
718
736
/**
@@ -723,6 +741,7 @@ public function testSaveChildWithInvalidId()
723
741
{
724
742
$ id = 12345 ;
725
743
$ linkedProductSku = 'simple ' ;
744
+ $ bundleProductSku = "bundleProductSku " ;
726
745
$ productLink = $ this ->getMock ('\Magento\Bundle\Api\Data\LinkInterface ' );
727
746
$ productLink ->expects ($ this ->any ())->method ('getId ' )->will ($ this ->returnValue ($ id ));
728
747
$ productLink ->expects ($ this ->any ())->method ('getSku ' )->will ($ this ->returnValue ($ linkedProductSku ));
@@ -735,7 +754,12 @@ public function testSaveChildWithInvalidId()
735
754
$ linkedProductMock = $ this ->getMock ('\Magento\Catalog\Model\Product ' , [], [], '' , false );
736
755
$ linkedProductMock ->expects ($ this ->once ())->method ('isComposite ' )->will ($ this ->returnValue (false ));
737
756
$ this ->productRepository
738
- ->expects ($ this ->once ())
757
+ ->expects ($ this ->at (0 ))
758
+ ->method ('get ' )
759
+ ->with ($ bundleProductSku )
760
+ ->will ($ this ->returnValue ($ productMock ));
761
+ $ this ->productRepository
762
+ ->expects ($ this ->at (1 ))
739
763
->method ('get ' )
740
764
->with ($ linkedProductSku )
741
765
->will ($ this ->returnValue ($ linkedProductMock ));
@@ -755,14 +779,15 @@ public function testSaveChildWithInvalidId()
755
779
756
780
$ this ->bundleSelectionMock ->expects ($ this ->once ())->method ('create ' )->will ($ this ->returnValue ($ selection ));
757
781
758
- $ this ->model ->saveChild ($ productMock , $ productLink );
782
+ $ this ->model ->saveChild ($ bundleProductSku , $ productLink );
759
783
}
760
784
761
785
/**
762
786
* @expectedException \Magento\Framework\Exception\InputException
763
787
*/
764
788
public function testSaveChildWithCompositeProductLink ()
765
789
{
790
+ $ bundleProductSku = "bundleProductSku " ;
766
791
$ id = 12 ;
767
792
$ linkedProductSku = 'simple ' ;
768
793
$ productLink = $ this ->getMock ('\Magento\Bundle\Api\Data\LinkInterface ' );
@@ -777,12 +802,17 @@ public function testSaveChildWithCompositeProductLink()
777
802
$ linkedProductMock = $ this ->getMock ('\Magento\Catalog\Model\Product ' , [], [], '' , false );
778
803
$ linkedProductMock ->expects ($ this ->once ())->method ('isComposite ' )->will ($ this ->returnValue (true ));
779
804
$ this ->productRepository
780
- ->expects ($ this ->once ())
805
+ ->expects ($ this ->at (0 ))
806
+ ->method ('get ' )
807
+ ->with ($ bundleProductSku )
808
+ ->will ($ this ->returnValue ($ productMock ));
809
+ $ this ->productRepository
810
+ ->expects ($ this ->at (1 ))
781
811
->method ('get ' )
782
812
->with ($ linkedProductSku )
783
813
->will ($ this ->returnValue ($ linkedProductMock ));
784
814
785
- $ this ->model ->saveChild ($ productMock , $ productLink );
815
+ $ this ->model ->saveChild ($ bundleProductSku , $ productLink );
786
816
}
787
817
788
818
/**
@@ -792,6 +822,8 @@ public function testSaveChildWithSimpleProduct()
792
822
{
793
823
$ id = 12 ;
794
824
$ linkedProductSku = 'simple ' ;
825
+ $ bundleProductSku = "bundleProductSku " ;
826
+
795
827
$ productLink = $ this ->getMock ('\Magento\Bundle\Api\Data\LinkInterface ' );
796
828
$ productLink ->expects ($ this ->any ())->method ('getId ' )->will ($ this ->returnValue ($ id ));
797
829
$ productLink ->expects ($ this ->any ())->method ('getSku ' )->will ($ this ->returnValue ($ linkedProductSku ));
@@ -801,7 +833,10 @@ public function testSaveChildWithSimpleProduct()
801
833
\Magento \Catalog \Model \Product \Type::TYPE_SIMPLE
802
834
));
803
835
804
- $ this ->model ->saveChild ($ productMock , $ productLink );
836
+ $ this ->productRepository ->expects ($ this ->once ())->method ('get ' )->with ($ bundleProductSku )
837
+ ->willReturn ($ productMock );
838
+
839
+ $ this ->model ->saveChild ($ bundleProductSku , $ productLink );
805
840
}
806
841
807
842
public function testRemoveChild ()
0 commit comments