7
7
namespace Magento \BundleImportExport \Test \Unit \Model \Import \Product \Type \Bundle ;
8
8
9
9
use Magento \BundleImportExport \Model \Import \Product \Type \Bundle \RelationsDataSaver ;
10
+ use Magento \Catalog \Model \ResourceModel \Product \Relation ;
10
11
use Magento \Framework \App \ResourceConnection ;
11
12
use Magento \Framework \DB \Adapter \AdapterInterface ;
12
13
@@ -30,6 +31,11 @@ class RelationsDataSaverTest extends \PHPUnit\Framework\TestCase
30
31
*/
31
32
private $ connectionMock ;
32
33
34
+ /**
35
+ * @var Relation|\PHPUnit_Framework_MockObject_MockObject
36
+ */
37
+ private $ productRelationMock ;
38
+
33
39
protected function setUp ()
34
40
{
35
41
$ helper = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
@@ -39,12 +45,16 @@ protected function setUp()
39
45
$ this ->connectionMock = $ this ->getMockBuilder (AdapterInterface::class)
40
46
->disableOriginalConstructor ()
41
47
->getMock ();
42
- $ this ->resourceMock ->expects ($ this ->once ())->method ('getConnection ' )->willReturn ($ this ->connectionMock );
48
+
49
+ $ this ->productRelationMock = $ this ->getMockBuilder (Relation::class)
50
+ ->disableOriginalConstructor ()
51
+ ->getMock ();
43
52
44
53
$ this ->relationsDataSaver = $ helper ->getObject (
45
54
RelationsDataSaver::class,
46
55
[
47
- 'resource ' => $ this ->resourceMock
56
+ 'resource ' => $ this ->resourceMock ,
57
+ 'productRelation ' => $ this ->productRelationMock
48
58
]
49
59
);
50
60
}
@@ -53,7 +63,7 @@ public function testSaveOptions()
53
63
{
54
64
$ options = [1 , 2 ];
55
65
$ table_name = 'catalog_product_bundle_option ' ;
56
-
66
+ $ this -> resourceMock -> expects ( $ this -> once ())-> method ( ' getConnection ' )-> willReturn ( $ this -> connectionMock );
57
67
$ this ->resourceMock ->expects ($ this ->once ())
58
68
->method ('getTableName ' )
59
69
->with ('catalog_product_bundle_option ' )
@@ -78,6 +88,7 @@ public function testSaveOptionValues()
78
88
$ optionsValues = [1 , 2 ];
79
89
$ table_name = 'catalog_product_bundle_option_value ' ;
80
90
91
+ $ this ->resourceMock ->expects ($ this ->once ())->method ('getConnection ' )->willReturn ($ this ->connectionMock );
81
92
$ this ->resourceMock ->expects ($ this ->once ())
82
93
->method ('getTableName ' )
83
94
->with ('catalog_product_bundle_option_value ' )
@@ -98,6 +109,7 @@ public function testSaveSelections()
98
109
$ selections = [1 , 2 ];
99
110
$ table_name = 'catalog_product_bundle_selection ' ;
100
111
112
+ $ this ->resourceMock ->expects ($ this ->once ())->method ('getConnection ' )->willReturn ($ this ->connectionMock );
101
113
$ this ->resourceMock ->expects ($ this ->once ())
102
114
->method ('getTableName ' )
103
115
->with ('catalog_product_bundle_selection ' )
@@ -121,4 +133,16 @@ public function testSaveSelections()
121
133
122
134
$ this ->relationsDataSaver ->saveSelections ($ selections );
123
135
}
136
+
137
+ public function testSaveProductRelations ()
138
+ {
139
+ $ parentId = 1 ;
140
+ $ children = [2 , 3 ];
141
+
142
+ $ this ->productRelationMock ->expects ($ this ->once ())
143
+ ->method ('processRelations ' )
144
+ ->with ($ parentId , $ children );
145
+
146
+ $ this ->relationsDataSaver ->saveProductRelations ($ parentId , $ children );
147
+ }
124
148
}
0 commit comments