@@ -33,7 +33,7 @@ protected function setUp()
3333 parent ::setUp ();
3434
3535 $ this ->attributeRepositoryMock = $ this ->getMockBuilder (AttributeRepositoryInterface::class)
36- ->getMockForAbstractClass ();
36+ ->getMockForAbstractClass ();
3737
3838 $ arrayManager = $ this ->objectManager ->getObject (ArrayManager::class);
3939
@@ -52,35 +52,42 @@ protected function setUp()
5252 */
5353 protected function createModel ()
5454 {
55- return $ this ->objectManager ->getObject (General::class, [
55+ return $ this ->objectManager ->getObject (
56+ General::class,
57+ [
5658 'locator ' => $ this ->locatorMock ,
5759 'arrayManager ' => $ this ->arrayManagerMock ,
58- ]);
60+ ]
61+ );
5962 }
6063
6164 public function testModifyMeta ()
6265 {
6366 $ this ->arrayManagerMock ->expects ($ this ->any ())
6467 ->method ('merge ' )
6568 ->willReturnArgument (2 );
66- $ this ->assertNotEmpty ($ this ->getModel ()->modifyMeta ([
67- 'first_panel_code ' => [
69+ $ this ->assertNotEmpty (
70+ $ this ->getModel ()->modifyMeta (
71+ [
72+ 'first_panel_code ' => [
6873 'arguments ' => [
6974 'data ' => [
7075 'config ' => [
7176 'label ' => 'Test label ' ,
7277 ]
7378 ],
7479 ]
75- ]
76- ]));
80+ ]
81+ ]
82+ )
83+ );
7784 }
7885
7986 /**
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
8491 * @dataProvider modifyDataDataProvider
8592 */
8693 public function testModifyDataNewProduct (array $ data , int $ defaultStatusValue , array $ expectedResult )
@@ -100,6 +107,97 @@ public function testModifyDataNewProduct(array $data, int $defaultStatusValue, a
100107 $ this ->assertSame ($ expectedResult , $ this ->generalModifier ->modifyData ($ data ));
101108 }
102109
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+
103201 /**
104202 * @return array
105203 */
0 commit comments