@@ -33,7 +33,7 @@ protected function setUp()
33
33
parent ::setUp ();
34
34
35
35
$ this ->attributeRepositoryMock = $ this ->getMockBuilder (AttributeRepositoryInterface::class)
36
- ->getMockForAbstractClass ();
36
+ ->getMockForAbstractClass ();
37
37
38
38
$ arrayManager = $ this ->objectManager ->getObject (ArrayManager::class);
39
39
@@ -52,35 +52,42 @@ protected function setUp()
52
52
*/
53
53
protected function createModel ()
54
54
{
55
- return $ this ->objectManager ->getObject (General::class, [
55
+ return $ this ->objectManager ->getObject (
56
+ General::class,
57
+ [
56
58
'locator ' => $ this ->locatorMock ,
57
59
'arrayManager ' => $ this ->arrayManagerMock ,
58
- ]);
60
+ ]
61
+ );
59
62
}
60
63
61
64
public function testModifyMeta ()
62
65
{
63
66
$ this ->arrayManagerMock ->expects ($ this ->any ())
64
67
->method ('merge ' )
65
68
->willReturnArgument (2 );
66
- $ this ->assertNotEmpty ($ this ->getModel ()->modifyMeta ([
67
- 'first_panel_code ' => [
69
+ $ this ->assertNotEmpty (
70
+ $ this ->getModel ()->modifyMeta (
71
+ [
72
+ 'first_panel_code ' => [
68
73
'arguments ' => [
69
74
'data ' => [
70
75
'config ' => [
71
76
'label ' => 'Test label ' ,
72
77
]
73
78
],
74
79
]
75
- ]
76
- ]));
80
+ ]
81
+ ]
82
+ )
83
+ );
77
84
}
78
85
79
86
/**
80
- * @param array $data
81
- * @param int $defaultStatusValue
82
- * @param array $expectedResult
83
- * @throws \Magento\Framework\Exception\NoSuchEntityException
87
+ * @param array $data
88
+ * @param int $defaultStatusValue
89
+ * @param array $expectedResult
90
+ * @throws \Magento\Framework\Exception\NoSuchEntityException
84
91
* @dataProvider modifyDataDataProvider
85
92
*/
86
93
public function testModifyDataNewProduct (array $ data , int $ defaultStatusValue , array $ expectedResult )
@@ -100,6 +107,97 @@ public function testModifyDataNewProduct(array $data, int $defaultStatusValue, a
100
107
$ this ->assertSame ($ expectedResult , $ this ->generalModifier ->modifyData ($ data ));
101
108
}
102
109
110
+ /**
111
+ * Verify the product attribute status set owhen editing existing product
112
+ *
113
+ * @param array $data
114
+ * @param string $modelId
115
+ * @param int $defaultStatus
116
+ * @param int $statusAttributeValue
117
+ * @param array $expectedResult
118
+ * @throws \Magento\Framework\Exception\NoSuchEntityException
119
+ * @dataProvider modifyDataOfExistingProductDataProvider
120
+ */
121
+ public function testModifyDataOfExistingProduct (
122
+ array $ data ,
123
+ string $ modelId ,
124
+ int $ defaultStatus ,
125
+ int $ statusAttributeValue ,
126
+ array $ expectedResult
127
+ ) {
128
+ $ attributeMock = $ this ->getMockForAbstractClass (AttributeInterface::class);
129
+ $ attributeMock ->expects ($ this ->any ())
130
+ ->method ('getDefaultValue ' )
131
+ ->willReturn ($ defaultStatus );
132
+ $ this ->attributeRepositoryMock ->expects ($ this ->any ())
133
+ ->method ('get ' )
134
+ ->with (
135
+ ProductAttributeInterface::ENTITY_TYPE_CODE ,
136
+ ProductAttributeInterface::CODE_STATUS
137
+ )
138
+ ->willReturn ($ attributeMock );
139
+ $ this ->productMock ->expects ($ this ->any ())
140
+ ->method ('getId ' )
141
+ ->willReturn ($ modelId );
142
+ $ this ->productMock ->expects ($ this ->any ())
143
+ ->method ('getStatus ' )
144
+ ->willReturn ($ statusAttributeValue );
145
+ $ this ->assertSame ($ expectedResult , current ($ this ->generalModifier ->modifyData ($ data )));
146
+ }
147
+
148
+ /**
149
+ * @return array
150
+ */
151
+ public function modifyDataOfExistingProductDataProvider (): array
152
+ {
153
+ return [
154
+ 'With enable status value ' => [
155
+ 'data ' => [],
156
+ 'modelId ' => '1 ' ,
157
+ 'defaultStatus ' => 1 ,
158
+ 'statusAttributeValue ' => 1 ,
159
+ 'expectedResult ' => [
160
+ General::DATA_SOURCE_DEFAULT => [
161
+ ProductAttributeInterface::CODE_STATUS => 1 ,
162
+ ],
163
+ ],
164
+ ],
165
+ 'Without disable status value ' => [
166
+ 'data ' => [],
167
+ 'modelId ' => '1 ' ,
168
+ 'defaultStatus ' => 1 ,
169
+ 'statusAttributeValue ' => 2 ,
170
+ 'expectedResult ' => [
171
+ General::DATA_SOURCE_DEFAULT => [
172
+ ProductAttributeInterface::CODE_STATUS => 2 ,
173
+ ],
174
+ ],
175
+ ],
176
+ 'With enable status value with empty modelId ' => [
177
+ 'data ' => [],
178
+ 'modelId ' => '' ,
179
+ 'defaultStatus ' => 1 ,
180
+ 'statusAttributeValue ' => 1 ,
181
+ 'expectedResult ' => [
182
+ General::DATA_SOURCE_DEFAULT => [
183
+ ProductAttributeInterface::CODE_STATUS => 1 ,
184
+ ],
185
+ ],
186
+ ],
187
+ 'Without disable status value with empty modelId ' => [
188
+ 'data ' => [],
189
+ 'modelId ' => '' ,
190
+ 'defaultStatus ' => 2 ,
191
+ 'statusAttributeValue ' => 2 ,
192
+ 'expectedResult ' => [
193
+ General::DATA_SOURCE_DEFAULT => [
194
+ ProductAttributeInterface::CODE_STATUS => 2 ,
195
+ ],
196
+ ],
197
+ ],
198
+ ];
199
+ }
200
+
103
201
/**
104
202
* @return array
105
203
*/
0 commit comments