10
10
use Magento \Catalog \Api \CategoryRepositoryInterface ;
11
11
use Magento \Catalog \Api \Data \ProductInterface ;
12
12
use Magento \Catalog \Api \ProductRepositoryInterface ;
13
- use Magento \Catalog \Model \AbstractModel ;
14
13
use Magento \CatalogUrlRewrite \Model \CategoryUrlPathGenerator ;
15
14
use Magento \Framework \App \Config \ScopeConfigInterface ;
16
15
use Magento \Framework \Registry ;
@@ -71,7 +70,7 @@ protected function setUp()
71
70
public function testProductUrlRewrite (): void
72
71
{
73
72
$ product = $ this ->productRepository ->get ('simple2 ' );
74
- $ url = $ this ->prepareUrl ($ product );
73
+ $ url = $ this ->prepareUrl ($ product-> getUrlKey () );
75
74
$ this ->dispatch ($ url );
76
75
77
76
$ this ->assertProductIsVisible ($ product );
@@ -85,7 +84,7 @@ public function testCategoryProductUrlRewrite(): void
85
84
{
86
85
$ category = $ this ->categoryRepository ->get (333 );
87
86
$ product = $ this ->productRepository ->get ('simple333 ' );
88
- $ url = $ this ->prepareUrl ($ category , false ) . $ this ->prepareUrl ($ product );
87
+ $ url = $ this ->prepareUrl ($ category-> getUrlKey () , false ) . $ this ->prepareUrl ($ product-> getUrlKey () );
89
88
$ this ->dispatch ($ url );
90
89
91
90
$ this ->assertProductIsVisible ($ product );
@@ -98,35 +97,36 @@ public function testCategoryProductUrlRewrite(): void
98
97
public function testProductRedirect (): void
99
98
{
100
99
$ product = $ this ->productRepository ->get ('simple2 ' );
101
- $ oldUrl = $ this ->prepareUrl ($ product );
100
+ $ oldUrl = $ this ->prepareUrl ($ product-> getUrlKey () );
102
101
$ data = [
103
102
'url_key ' => 'new-url-key ' ,
104
103
'url_key_create_redirect ' => $ product ->getUrlKey (),
105
104
'save_rewrites_history ' => true ,
106
105
];
107
- $ this ->updateProduct ($ product , $ data );
106
+ $ this ->saveProductWithAdditionalData ($ product , $ data );
108
107
$ this ->dispatch ($ oldUrl );
109
108
110
109
$ this ->assertRedirect ($ this ->stringContains ('new-url-key ' . $ this ->urlSuffix ));
111
110
}
112
111
113
112
/**
114
113
* @magentoDbIsolation disabled
115
- * @magentoDataFixture Magento/Catalog/_files/product_with_two_stores.php
114
+ * @magentoDataFixture Magento/Store/_files/core_fixturestore.php
115
+ * @magentoDataFixture Magento/Catalog/_files/second_product_simple.php
116
116
* @return void
117
117
*/
118
118
public function testMultistoreProductUrlRewrite (): void
119
119
{
120
120
$ currentStore = $ this ->storeManager ->getStore ();
121
121
$ product = $ this ->productRepository ->get ('simple2 ' );
122
- $ firstStoreUrl = $ this ->prepareUrl ($ product );
122
+ $ firstStoreUrl = $ this ->prepareUrl ($ product-> getUrlKey () );
123
123
$ secondStoreId = $ this ->storeManager ->getStore ('fixturestore ' )->getId ();
124
124
$ this ->storeManager ->setCurrentStore ($ secondStoreId );
125
125
126
126
try {
127
- $ product = $ this ->updateProduct ($ product , ['url_key ' => 'second-store-url-key ' ]);
127
+ $ product = $ this ->saveProductWithAdditionalData ($ product , ['url_key ' => 'second-store-url-key ' ]);
128
128
$ this ->assertEquals ('second-store-url-key ' , $ product ->getUrlKey ());
129
- $ secondStoreUrl = $ this ->prepareUrl ($ product );
129
+ $ secondStoreUrl = $ this ->prepareUrl ($ product-> getUrlKey () );
130
130
131
131
$ this ->dispatch ($ secondStoreUrl );
132
132
$ this ->assertProductIsVisible ($ product );
@@ -146,15 +146,15 @@ public function testMultistoreProductUrlRewrite(): void
146
146
* @param array $data
147
147
* @return ProductInterface
148
148
*/
149
- private function updateProduct (ProductInterface $ product , array $ data ): ProductInterface
149
+ private function saveProductWithAdditionalData (ProductInterface $ product , array $ data ): ProductInterface
150
150
{
151
151
$ product ->addData ($ data );
152
152
153
153
return $ this ->productRepository ->save ($ product );
154
154
}
155
155
156
156
/**
157
- * Clear request object.
157
+ * Clean up cached objects
158
158
*
159
159
* @return void
160
160
*/
@@ -171,13 +171,13 @@ private function cleanUpCachedObjects(): void
171
171
/**
172
172
* Prepare url to dispatch
173
173
*
174
- * @param AbstractModel $object
174
+ * @param string $urlKey
175
175
* @param bool $addSuffix
176
176
* @return string
177
177
*/
178
- private function prepareUrl (AbstractModel $ object , bool $ addSuffix = true ): string
178
+ private function prepareUrl (string $ urlKey , bool $ addSuffix = true ): string
179
179
{
180
- $ url = $ addSuffix ? '/ ' . $ object -> getUrlKey () . $ this ->urlSuffix : '/ ' . $ object -> getUrlKey () ;
180
+ $ url = $ addSuffix ? '/ ' . $ urlKey . $ this ->urlSuffix : '/ ' . $ urlKey ;
181
181
182
182
return $ url ;
183
183
}
0 commit comments