11<?php
22/**
3- * Copyright © Magento, Inc. All rights reserved.
4- * See COPYING.txt for license details .
3+ * Copyright 2011 Adobe
4+ * All Rights Reserved .
55 */
6- namespace Magento \Catalog \Controller \Adminhtml \Product \Action ;
6+ declare (strict_types=1 );
7+
8+ namespace Magento \Catalog \Controller \Adminhtml \Product \Action \Attribute ;
79
810use Magento \Backend \Model \Session ;
911use Magento \Catalog \Block \Product \ListProduct ;
1012use Magento \Catalog \Helper \Product \Edit \Action \Attribute ;
1113use Magento \Catalog \Model \CategoryFactory ;
1214use Magento \Catalog \Model \Product \Visibility ;
13- use Magento \Framework \Message \MessageInterface ;
1415use Magento \Catalog \Model \ProductRepository ;
1516use Magento \Framework \App \Request \Http as HttpRequest ;
17+ use Magento \Framework \Message \MessageInterface ;
1618use Magento \Framework \UrlInterface ;
17- use Magento \TestFramework \Helper \Bootstrap ;
1819use Magento \TestFramework \MessageQueue \EnvironmentPreconditionException ;
1920use Magento \TestFramework \MessageQueue \PreconditionFailedException ;
2021use Magento \TestFramework \MessageQueue \PublisherConsumerController ;
2122use Magento \TestFramework \TestCase \AbstractBackendController ;
2223
2324/**
25+ * @covers \Magento\Catalog\Controller\Adminhtml\Product\Action\Attribute\Save::execute
2426 * @magentoAppArea adminhtml
2527 * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2628 */
27- class AttributeTest extends AbstractBackendController
29+ class SaveTest extends AbstractBackendController
2830{
2931 /** @var PublisherConsumerController */
3032 private $ publisherConsumerController ;
33+
3134 /**
3235 * @var string[]
3336 */
@@ -39,22 +42,14 @@ protected function setUp(): void
3942
4043 $ this ->publisherConsumerController = $ this ->_objectManager ->create (
4144 PublisherConsumerController::class,
42- [
43- 'consumers ' => $ this ->consumers ,
44- 'logFilePath ' => TESTS_TEMP_DIR . "/MessageQueueTestLog.txt " ,
45- 'maxMessages ' => null ,
46- 'appInitParams ' => Bootstrap::getInstance ()->getAppInitParams ()
47- ]
45+ ['consumers ' => $ this ->consumers ]
4846 );
49-
5047 try {
5148 $ this ->publisherConsumerController ->startConsumers ();
5249 } catch (EnvironmentPreconditionException $ e ) {
5350 $ this ->markTestSkipped ($ e ->getMessage ());
5451 } catch (PreconditionFailedException $ e ) {
55- $ this ->fail (
56- $ e ->getMessage ()
57- );
52+ $ this ->fail ($ e ->getMessage ());
5853 }
5954 }
6055
@@ -65,12 +60,10 @@ protected function tearDown(): void
6560 }
6661
6762 /**
68- * @covers \Magento\Catalog\Controller\Adminhtml\Product\Action\Attribute\Save::execute
69- *
7063 * @magentoDataFixture Magento/Catalog/_files/product_simple.php
7164 * @magentoDbIsolation disabled
7265 */
73- public function testSaveActionRedirectsSuccessfully ()
66+ public function testSaveActionRedirectsSuccessfully (): void
7467 {
7568 /** @var $session Session */
7669 $ session = $ this ->_objectManager ->get (Session::class);
@@ -100,14 +93,12 @@ public function testSaveActionRedirectsSuccessfully()
10093 }
10194
10295 /**
103- * @covers \Magento\Catalog\Controller\Adminhtml\Product\Action\Attribute\Save::execute
104- *
10596 * @dataProvider saveActionVisibilityAttrDataProvider
10697 * @param array $attributes
10798 * @magentoDataFixture Magento/Catalog/_files/product_simple.php
10899 * @magentoDbIsolation disabled
109100 */
110- public function testSaveActionChangeVisibility ($ attributes )
101+ public function testSaveActionChangeVisibility (array $ attributes ): void
111102 {
112103 /** @var ProductRepository $repository */
113104 $ repository = $ this ->_objectManager ->create (ProductRepository::class);
@@ -129,88 +120,26 @@ public function testSaveActionChangeVisibility($attributes)
129120 /** @var ListProduct $listProduct */
130121 $ listProduct = $ this ->_objectManager ->get (ListProduct::class);
131122
132- sleep (30 ); // timeout to processing queue
133123 $ this ->publisherConsumerController ->waitForAsynchronousResult (
134- function () use ($ repository ) {
135- sleep (10 ); // Should be refactored in the scope of MC-22947
136- return $ repository ->get (
137- 'simple ' ,
138- false ,
139- null ,
140- true
141- )->getVisibility () != Visibility::VISIBILITY_NOT_VISIBLE ;
142- },
143- []
124+ fn () => (int ) $ repository ->get ('simple ' , forceReload: true )->getVisibility ()
125+ !== Visibility::VISIBILITY_NOT_VISIBLE
144126 );
145127
146128 $ category = $ categoryFactory ->create ()->load (2 );
147129 $ layer = $ listProduct ->getLayer ();
148130 $ layer ->setCurrentCategory ($ category );
149131 $ productCollection = $ layer ->getProductCollection ();
150132 $ productItem = $ productCollection ->getFirstItem ();
151- $ this ->assertEquals ($ session ->getProductIds (), [$ productItem ->getId ()]);
152- }
153-
154- /**
155- * @param array $attributes Request parameter.
156- *
157- * @covers \Magento\Catalog\Controller\Adminhtml\Product\Action\Attribute\Validate::execute
158- *
159- * @dataProvider validateActionDataProvider
160- *
161- * @magentoDataFixture Magento/Catalog/_files/product_simple.php
162- * @magentoDataFixture Magento/Catalog/_files/product_simple_duplicated.php
163- * @magentoDbIsolation disabled
164- */
165- public function testValidateActionWithMassUpdate ($ attributes )
166- {
167- /** @var $session Session */
168- $ session = $ this ->_objectManager ->get (Session::class);
169- $ session ->setProductIds ([1 , 2 ]);
170-
171- $ this ->getRequest ()->setParam ('attributes ' , $ attributes );
172-
173- $ this ->dispatch ('backend/catalog/product_action_attribute/validate/store/0 ' );
174-
175- $ this ->assertEquals (200 , $ this ->getResponse ()->getHttpResponseCode ());
176-
177- $ response = $ this ->getResponse ()->getBody ();
178- $ this ->assertJson ($ response );
179- $ data = json_decode ($ response , true );
180- $ this ->assertArrayHasKey ('error ' , $ data );
181- $ this ->assertFalse ($ data ['error ' ]);
182- $ this ->assertCount (1 , $ data );
183- }
184-
185- /**
186- * Data Provider for validation
187- *
188- * @return array
189- */
190- public static function validateActionDataProvider ()
191- {
192- return [
193- [
194- 'attributes ' => [
195- 'name ' => 'Name ' ,
196- 'description ' => 'Description ' ,
197- 'short_description ' => 'Short Description ' ,
198- 'price ' => '512 ' ,
199- 'weight ' => '16 ' ,
200- 'meta_title ' => 'Meta Title ' ,
201- 'meta_keyword ' => 'Meta Keywords ' ,
202- 'meta_description ' => 'Meta Description ' ,
203- ],
204- ]
205- ];
133+ $ this ->assertEquals ([$ product ->getId ()], [$ productItem ->getId ()]);
134+ $ this ->assertEmpty ($ session ->getProductIds ());
206135 }
207136
208137 /**
209138 * Data Provider for save with visibility attribute
210139 *
211140 * @return array
212141 */
213- public static function saveActionVisibilityAttrDataProvider ()
142+ public static function saveActionVisibilityAttrDataProvider (): array
214143 {
215144 return [
216145 ['attributes ' => ['visibility ' => Visibility::VISIBILITY_BOTH ]],
0 commit comments