1717use Magento \Quote \Model \Quote \Address \RateRequest ;
1818use Magento \Quote \Model \Quote \Address \RateResult \Error ;
1919use Magento \Shipping \Model \Shipment \Request ;
20+ use Magento \Shipping \Model \Simplexml \Element as ShippingElement ;
2021use Magento \Shipping \Model \Tracking \Result \Status ;
2122use Magento \Store \Model \ScopeInterface ;
2223use Magento \TestFramework \Helper \Bootstrap ;
2324use Magento \TestFramework \HTTP \AsyncClientInterfaceMock ;
24- use Magento \ Shipping \ Model \ Simplexml \ Element as ShippingElement ;
25+ use PHPUnit \ Framework \ TestCase ;
2526
2627/**
2728 * Test for DHL integration.
2829 *
2930 * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
3031 */
31- class CarrierTest extends \ PHPUnit \ Framework \ TestCase
32+ class CarrierTest extends TestCase
3233{
34+ private const PRODUCT_NAME_SPECIAL_CHARS = 'Φυστίκι Ψημένο με Αλάτι Συσκευασία ' ;
35+
3336 /**
3437 * @var Carrier
3538 */
@@ -254,10 +257,16 @@ private function assertTrackingResult($expectedTrackingData, $trackingResults):
254257 * @param string $origCountryId
255258 * @param string $expectedRegionCode
256259 * @param string $destCountryId
260+ * @param bool|null $isProductNameContainsSpecialChars
261+ * @return void
257262 * @dataProvider requestToShipmentDataProvider
258263 */
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 {
261270 $ this ->config ->setValue (
262271 'shipping/origin/country_id ' ,
263272 $ origCountryId ,
@@ -274,6 +283,8 @@ public function testRequestToShip(string $origCountryId, string $expectedRegionC
274283 )
275284 ]
276285 );
286+ $ productName = $ isProductNameContainsSpecialChars ? self ::PRODUCT_NAME_SPECIAL_CHARS : 'item_name ' ;
287+
277288 //phpcs:enable Magento2.Functions.DiscouragedFunction
278289 $ request = new Request (
279290 [
@@ -291,7 +302,7 @@ public function testRequestToShip(string $origCountryId, string $expectedRegionC
291302 ],
292303 'items ' => [
293304 'item1 ' => [
294- 'name ' => ' item_name ' ,
305+ 'name ' => $ productName ,
295306 ],
296307 ],
297308 ],
@@ -329,10 +340,15 @@ public function testRequestToShip(string $origCountryId, string $expectedRegionC
329340 $ requestElement ->Request ->ServiceHeader ->MessageReference = 'MAGE_SHIP_28TO32_Char_CHECKED ' ;
330341 $ requestElement ->Request ->ServiceHeader ->MessageTime = 'currentTime ' ;
331342 $ 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
335349 );
350+
351+ $ this ->assertXmlStringEqualsXmlString ($ expectedLabelRequest , $ requestElement ->asXML ());
336352 }
337353
338354 /**
@@ -351,7 +367,10 @@ public function requestToShipmentDataProvider(): array
351367 ],
352368 [
353369 'DE ' , 'EU ' , 'DE '
354- ]
370+ ],
371+ [
372+ 'GB ' , 'EU ' , 'US ' , true
373+ ],
355374 ];
356375 }
357376
@@ -361,12 +380,14 @@ public function requestToShipmentDataProvider(): array
361380 * @param string $origCountryId
362381 * @param string $destCountryId
363382 * @param string $regionCode
383+ * @param bool $isProductNameContainsSpecialChars
364384 * @return string
365385 */
366386 private function getExpectedLabelRequestXml (
367387 string $ origCountryId ,
368388 string $ destCountryId ,
369- string $ regionCode
389+ string $ regionCode ,
390+ bool $ isProductNameContainsSpecialChars
370391 ): string {
371392 $ countryNames = [
372393 'US ' => 'United States Of America ' ,
@@ -387,6 +408,10 @@ private function getExpectedLabelRequestXml(
387408 $ expectedRequestElement ->Shipper ->CountryName = $ countryNames [$ origCountryId ];
388409 $ expectedRequestElement ->RegionCode = $ regionCode ;
389410
411+ if ($ isProductNameContainsSpecialChars ) {
412+ $ expectedRequestElement ->ShipmentDetails ->Pieces ->Piece ->PieceContents = self ::PRODUCT_NAME_SPECIAL_CHARS ;
413+ }
414+
390415 return $ expectedRequestElement ->asXML ();
391416 }
392417
0 commit comments