12
12
use Magento \Catalog \Model \Product \Type ;
13
13
use Magento \Catalog \Model \Product \Visibility ;
14
14
use Magento \Catalog \Model \ProductFactory ;
15
- use Magento \Catalog \Model \ResourceModel \ProductFactory as ProductResourceFactory ;
15
+ use Magento \Catalog \Model \ResourceModel \Product as ProductResource ;
16
16
use Magento \CatalogUrlRewrite \Model \Map \DataProductUrlRewriteDatabaseMap ;
17
17
use Magento \Store \Model \ScopeInterface ;
18
18
use Magento \UrlRewrite \Model \Exception \UrlAlreadyExistsException ;
@@ -32,8 +32,8 @@ class ProductUrlRewriteTest extends AbstractUrlRewriteTest
32
32
/** @var string */
33
33
private $ suffix ;
34
34
35
- /** @var ProductResourceFactory */
36
- private $ productResourceFactory ;
35
+ /** @var ProductResource */
36
+ private $ productResource ;
37
37
38
38
/** @var ProductRepositoryInterface */
39
39
private $ productRepository ;
@@ -45,7 +45,7 @@ protected function setUp()
45
45
{
46
46
parent ::setUp ();
47
47
48
- $ this ->productResourceFactory = $ this ->objectManager ->create (ProductResourceFactory ::class);
48
+ $ this ->productResource = $ this ->objectManager ->create (ProductResource ::class);
49
49
$ this ->productFactory = $ this ->objectManager ->get (ProductFactory::class);
50
50
$ this ->productRepository = $ this ->objectManager ->create (ProductRepositoryInterface::class);
51
51
$ this ->suffix = $ this ->config ->getValue (
@@ -61,7 +61,7 @@ protected function setUp()
61
61
*/
62
62
public function testUrlRewriteOnProductSave (array $ data ): void
63
63
{
64
- $ product = $ this ->resourceSaveProductWithData ($ data ['data ' ]);
64
+ $ product = $ this ->saveProduct ($ data ['data ' ]);
65
65
$ this ->assertNotNull ($ product ->getId (), 'The product was not created ' );
66
66
$ productUrlRewriteCollection = $ this ->getEntityRewriteCollection ($ product ->getId ());
67
67
$ this ->assertRewrites (
@@ -144,7 +144,7 @@ public function testUrlRewriteOnProductEdit(array $expectedData): void
144
144
'url_key_create_redirect ' => $ product ->getUrlKey (),
145
145
'save_rewrites_history ' => true ,
146
146
];
147
- $ product = $ this ->resourceSaveProductWithData ($ data , $ product );
147
+ $ product = $ this ->saveProduct ($ data , $ product );
148
148
$ productRewriteCollection = $ this ->getEntityRewriteCollection ($ product ->getId ());
149
149
$ this ->assertRewrites (
150
150
$ productRewriteCollection ,
@@ -184,7 +184,7 @@ public function testUrlRewriteOnProductSaveWithExistingUrlKey(array $data): void
184
184
{
185
185
$ this ->expectException (UrlAlreadyExistsException::class);
186
186
$ this ->expectExceptionMessage ((string )__ ('URL key for specified store already exists. ' ));
187
- $ this ->resourceSaveProductWithData ($ data );
187
+ $ this ->saveProduct ($ data );
188
188
}
189
189
190
190
/**
@@ -255,7 +255,7 @@ public function testProductUrlRewritePerStoreViews(): void
255
255
$ secondStoreId = $ this ->storeRepository ->get ('fixture_second_store ' )->getId ();
256
256
$ product = $ this ->productRepository ->get ('simple2 ' );
257
257
$ urlKeyFirstStore = $ product ->getUrlKey ();
258
- $ product = $ this ->resourceSaveProductWithData (
258
+ $ product = $ this ->saveProduct (
259
259
['store_id ' => $ secondStoreId , 'url_key ' => $ urlKeySecondStore ],
260
260
$ product
261
261
);
@@ -275,12 +275,11 @@ public function testProductUrlRewritePerStoreViews(): void
275
275
* @param ProductInterface|null $product
276
276
* @return ProductInterface
277
277
*/
278
- protected function resourceSaveProductWithData (array $ data , $ product = null ): ProductInterface
278
+ protected function saveProduct (array $ data , $ product = null ): ProductInterface
279
279
{
280
280
$ product = $ product ?: $ this ->productFactory ->create ();
281
281
$ product ->addData ($ data );
282
- $ productResource = $ this ->productResourceFactory ->create ();
283
- $ productResource ->save ($ product );
282
+ $ this ->productResource ->save ($ product );
284
283
285
284
return $ product ;
286
285
}
0 commit comments