1
1
<?php
2
2
/**
3
- * Copyright © Magento, Inc. All rights reserved.
4
- * See COPYING.txt for license details .
3
+ * Copyright 2011 Adobe
4
+ * All Rights Reserved .
5
5
*/
6
- namespace Magento \Catalog \Controller \Adminhtml \Product \Action ;
6
+ declare (strict_types=1 );
7
+
8
+ namespace Magento \Catalog \Controller \Adminhtml \Product \Action \Attribute ;
7
9
8
10
use Magento \Backend \Model \Session ;
9
11
use Magento \Catalog \Block \Product \ListProduct ;
10
12
use Magento \Catalog \Helper \Product \Edit \Action \Attribute ;
11
13
use Magento \Catalog \Model \CategoryFactory ;
12
14
use Magento \Catalog \Model \Product \Visibility ;
13
- use Magento \Framework \Message \MessageInterface ;
14
15
use Magento \Catalog \Model \ProductRepository ;
15
16
use Magento \Framework \App \Request \Http as HttpRequest ;
17
+ use Magento \Framework \Message \MessageInterface ;
16
18
use Magento \Framework \UrlInterface ;
17
- use Magento \TestFramework \Helper \Bootstrap ;
18
19
use Magento \TestFramework \MessageQueue \EnvironmentPreconditionException ;
19
20
use Magento \TestFramework \MessageQueue \PreconditionFailedException ;
20
21
use Magento \TestFramework \MessageQueue \PublisherConsumerController ;
21
22
use Magento \TestFramework \TestCase \AbstractBackendController ;
22
23
23
24
/**
25
+ * @covers \Magento\Catalog\Controller\Adminhtml\Product\Action\Attribute\Save::execute
24
26
* @magentoAppArea adminhtml
25
27
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
26
28
*/
27
- class AttributeTest extends AbstractBackendController
29
+ class SaveTest extends AbstractBackendController
28
30
{
29
31
/** @var PublisherConsumerController */
30
32
private $ publisherConsumerController ;
33
+
31
34
/**
32
35
* @var string[]
33
36
*/
@@ -39,22 +42,14 @@ protected function setUp(): void
39
42
40
43
$ this ->publisherConsumerController = $ this ->_objectManager ->create (
41
44
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 ]
48
46
);
49
-
50
47
try {
51
48
$ this ->publisherConsumerController ->startConsumers ();
52
49
} catch (EnvironmentPreconditionException $ e ) {
53
50
$ this ->markTestSkipped ($ e ->getMessage ());
54
51
} catch (PreconditionFailedException $ e ) {
55
- $ this ->fail (
56
- $ e ->getMessage ()
57
- );
52
+ $ this ->fail ($ e ->getMessage ());
58
53
}
59
54
}
60
55
@@ -65,12 +60,10 @@ protected function tearDown(): void
65
60
}
66
61
67
62
/**
68
- * @covers \Magento\Catalog\Controller\Adminhtml\Product\Action\Attribute\Save::execute
69
- *
70
63
* @magentoDataFixture Magento/Catalog/_files/product_simple.php
71
64
* @magentoDbIsolation disabled
72
65
*/
73
- public function testSaveActionRedirectsSuccessfully ()
66
+ public function testSaveActionRedirectsSuccessfully (): void
74
67
{
75
68
/** @var $session Session */
76
69
$ session = $ this ->_objectManager ->get (Session::class);
@@ -100,14 +93,12 @@ public function testSaveActionRedirectsSuccessfully()
100
93
}
101
94
102
95
/**
103
- * @covers \Magento\Catalog\Controller\Adminhtml\Product\Action\Attribute\Save::execute
104
- *
105
96
* @dataProvider saveActionVisibilityAttrDataProvider
106
97
* @param array $attributes
107
98
* @magentoDataFixture Magento/Catalog/_files/product_simple.php
108
99
* @magentoDbIsolation disabled
109
100
*/
110
- public function testSaveActionChangeVisibility ($ attributes )
101
+ public function testSaveActionChangeVisibility (array $ attributes ): void
111
102
{
112
103
/** @var ProductRepository $repository */
113
104
$ repository = $ this ->_objectManager ->create (ProductRepository::class);
@@ -129,88 +120,26 @@ public function testSaveActionChangeVisibility($attributes)
129
120
/** @var ListProduct $listProduct */
130
121
$ listProduct = $ this ->_objectManager ->get (ListProduct::class);
131
122
132
- sleep (30 ); // timeout to processing queue
133
123
$ 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
144
126
);
145
127
146
128
$ category = $ categoryFactory ->create ()->load (2 );
147
129
$ layer = $ listProduct ->getLayer ();
148
130
$ layer ->setCurrentCategory ($ category );
149
131
$ productCollection = $ layer ->getProductCollection ();
150
132
$ 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 ());
206
135
}
207
136
208
137
/**
209
138
* Data Provider for save with visibility attribute
210
139
*
211
140
* @return array
212
141
*/
213
- public static function saveActionVisibilityAttrDataProvider ()
142
+ public static function saveActionVisibilityAttrDataProvider (): array
214
143
{
215
144
return [
216
145
['attributes ' => ['visibility ' => Visibility::VISIBILITY_BOTH ]],
0 commit comments