17
17
use Magento \Quote \Model \Quote \Address \RateRequest ;
18
18
use Magento \Quote \Model \Quote \Address \RateResult \Error ;
19
19
use Magento \Shipping \Model \Shipment \Request ;
20
+ use Magento \Shipping \Model \Simplexml \Element as ShippingElement ;
20
21
use Magento \Shipping \Model \Tracking \Result \Status ;
21
22
use Magento \Store \Model \ScopeInterface ;
22
23
use Magento \TestFramework \Helper \Bootstrap ;
23
24
use Magento \TestFramework \HTTP \AsyncClientInterfaceMock ;
24
- use Magento \ Shipping \ Model \ Simplexml \ Element as ShippingElement ;
25
+ use PHPUnit \ Framework \ TestCase ;
25
26
26
27
/**
27
28
* Test for DHL integration.
28
29
*
29
30
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
30
31
*/
31
- class CarrierTest extends \ PHPUnit \ Framework \ TestCase
32
+ class CarrierTest extends TestCase
32
33
{
34
+ private const PRODUCT_NAME_SPECIAL_CHARS = 'Φυστίκι Ψημένο με Αλάτι Συσκευασία ' ;
35
+
33
36
/**
34
37
* @var Carrier
35
38
*/
@@ -254,10 +257,16 @@ private function assertTrackingResult($expectedTrackingData, $trackingResults):
254
257
* @param string $origCountryId
255
258
* @param string $expectedRegionCode
256
259
* @param string $destCountryId
260
+ * @param bool|null $isProductNameContainsSpecialChars
261
+ * @return void
257
262
* @dataProvider requestToShipmentDataProvider
258
263
*/
259
- public function testRequestToShip (string $ origCountryId , string $ expectedRegionCode , string $ destCountryId ): void
260
- {
264
+ public function testRequestToShip (
265
+ string $ origCountryId ,
266
+ string $ expectedRegionCode ,
267
+ string $ destCountryId ,
268
+ bool $ isProductNameContainsSpecialChars = false
269
+ ): void {
261
270
$ this ->config ->setValue (
262
271
'shipping/origin/country_id ' ,
263
272
$ origCountryId ,
@@ -274,6 +283,8 @@ public function testRequestToShip(string $origCountryId, string $expectedRegionC
274
283
)
275
284
]
276
285
);
286
+ $ productName = $ isProductNameContainsSpecialChars ? self ::PRODUCT_NAME_SPECIAL_CHARS : 'item_name ' ;
287
+
277
288
//phpcs:enable Magento2.Functions.DiscouragedFunction
278
289
$ request = new Request (
279
290
[
@@ -291,7 +302,7 @@ public function testRequestToShip(string $origCountryId, string $expectedRegionC
291
302
],
292
303
'items ' => [
293
304
'item1 ' => [
294
- 'name ' => ' item_name ' ,
305
+ 'name ' => $ productName ,
295
306
],
296
307
],
297
308
],
@@ -329,10 +340,15 @@ public function testRequestToShip(string $origCountryId, string $expectedRegionC
329
340
$ requestElement ->Request ->ServiceHeader ->MessageReference = 'MAGE_SHIP_28TO32_Char_CHECKED ' ;
330
341
$ requestElement ->Request ->ServiceHeader ->MessageTime = 'currentTime ' ;
331
342
$ requestElement ->ShipmentDetails ->Date = 'currentTime ' ;
332
- $ this ->assertXmlStringEqualsXmlString (
333
- $ this ->getExpectedLabelRequestXml ($ origCountryId , $ destCountryId , $ expectedRegionCode ),
334
- $ requestElement ->asXML ()
343
+
344
+ $ expectedLabelRequest = $ this ->getExpectedLabelRequestXml (
345
+ $ origCountryId ,
346
+ $ destCountryId ,
347
+ $ expectedRegionCode ,
348
+ $ isProductNameContainsSpecialChars
335
349
);
350
+
351
+ $ this ->assertXmlStringEqualsXmlString ($ expectedLabelRequest , $ requestElement ->asXML ());
336
352
}
337
353
338
354
/**
@@ -351,7 +367,10 @@ public function requestToShipmentDataProvider(): array
351
367
],
352
368
[
353
369
'DE ' , 'EU ' , 'DE '
354
- ]
370
+ ],
371
+ [
372
+ 'GB ' , 'EU ' , 'US ' , true
373
+ ],
355
374
];
356
375
}
357
376
@@ -361,12 +380,14 @@ public function requestToShipmentDataProvider(): array
361
380
* @param string $origCountryId
362
381
* @param string $destCountryId
363
382
* @param string $regionCode
383
+ * @param bool $isProductNameContainsSpecialChars
364
384
* @return string
365
385
*/
366
386
private function getExpectedLabelRequestXml (
367
387
string $ origCountryId ,
368
388
string $ destCountryId ,
369
- string $ regionCode
389
+ string $ regionCode ,
390
+ bool $ isProductNameContainsSpecialChars
370
391
): string {
371
392
$ countryNames = [
372
393
'US ' => 'United States Of America ' ,
@@ -387,6 +408,10 @@ private function getExpectedLabelRequestXml(
387
408
$ expectedRequestElement ->Shipper ->CountryName = $ countryNames [$ origCountryId ];
388
409
$ expectedRequestElement ->RegionCode = $ regionCode ;
389
410
411
+ if ($ isProductNameContainsSpecialChars ) {
412
+ $ expectedRequestElement ->ShipmentDetails ->Pieces ->Piece ->PieceContents = self ::PRODUCT_NAME_SPECIAL_CHARS ;
413
+ }
414
+
390
415
return $ expectedRequestElement ->asXML ();
391
416
}
392
417
0 commit comments