11<?php
22/**
3- * Copyright © Magento, Inc. All rights reserved.
4- * See COPYING.txt for license details .
3+ * Copyright 2014 Adobe
4+ * All Rights Reserved .
55 */
66declare (strict_types=1 );
77
@@ -98,6 +98,11 @@ class CarrierTest extends TestCase
9898 */
9999 private $ productMetadataMock ;
100100
101+ /**
102+ * @var mixed
103+ */
104+ private mixed $ responseData ;
105+
101106 /**
102107 * @inheritdoc
103108 */
@@ -173,9 +178,12 @@ public function scopeConfigGetValue($path)
173178 'carriers/dhl/intl_shipment_days ' => 'Mon,Tue,Wed,Thu,Fri,Sat ' ,
174179 'carriers/dhl/allowed_methods ' => 'IE ' ,
175180 'carriers/dhl/international_service ' => 'IE ' ,
176- 'carriers/dhl/gateway_url ' => 'https://xmlpi-ea.dhl.com/XMLShippingServlet ' ,
181+ 'carriers/dhl/gateway_xml_url ' => 'https://xmlpi-ea.dhl.com/XMLShippingServlet ' ,
182+ 'carriers/dhl/gateway_rest_url ' => 'https://express.api.dhl.com/mydhlapi ' ,
177183 'carriers/dhl/id ' => 'some ID ' ,
178184 'carriers/dhl/password ' => 'some password ' ,
185+ 'carriers/dhl/api_key ' => 'some key ' ,
186+ 'carriers/dhl/api_secret ' => 'some secret key ' ,
179187 'carriers/dhl/content_type ' => 'N ' ,
180188 'carriers/dhl/nondoc_methods ' => '1,3,4,8,P,Q,E,F,H,J,M,V,Y ' ,
181189 'carriers/dhl/showmethod ' => 1 ,
@@ -453,15 +461,19 @@ public static function buildSoftwareVersionProvider()
453461 *
454462 * @dataProvider getGatewayURLProvider
455463 * @param $sandboxMode
464+ * @param string $type
456465 * @param $expectedURL
457466 * @throws \ReflectionException
458467 */
459- public function testGetGatewayURL ($ sandboxMode , $ expectedURL )
468+ public function testGetGatewayURL ($ sandboxMode , $ type , $ expectedURL )
460469 {
461470 $ scopeConfigValueMap = [
462- ['carriers/dhl/gateway_url ' , 'store ' , null , 'https://xmlpi-ea.dhl.com/XMLShippingServlet ' ],
463- ['carriers/dhl/sandbox_url ' , 'store ' , null , 'https://xmlpitest-ea.dhl.com/XMLShippingServlet ' ],
464- ['carriers/dhl/sandbox_mode ' , 'store ' , null , $ sandboxMode ]
471+ ['carriers/dhl/sandbox_mode ' , 'store ' , null , $ sandboxMode ],
472+ ['carriers/dhl/type ' , 'store ' , null , $ type ],
473+ ['carriers/dhl/sandbox_xml_url ' , 'store ' , null , 'https://xmlpitest-ea.dhl.com/XMLShippingServlet ' ],
474+ ['carriers/dhl/sandbox_rest_url ' , 'store ' , null , 'https://express.api.dhl.com/mydhlapi/test ' ],
475+ ['carriers/dhl/gateway_xml_url ' , 'store ' , null , 'https://xmlpi-ea.dhl.com/XMLShippingServlet ' ],
476+ ['carriers/dhl/gateway_rest_url ' , 'store ' , null , 'https://express.api.dhl.com/mydhlapi ' ]
465477 ];
466478
467479 $ this ->scope ->method ('getValue ' )
@@ -487,8 +499,10 @@ public function testGetGatewayURL($sandboxMode, $expectedURL)
487499 public static function getGatewayURLProvider ()
488500 {
489501 return [
490- 'standard_url ' => [0 , 'https://xmlpi-ea.dhl.com/XMLShippingServlet ' ],
491- 'sandbox_url ' => [1 , 'https://xmlpitest-ea.dhl.com/XMLShippingServlet ' ]
502+ 'standard_xml_url ' => [0 , 'DHL_XML ' , 'https://xmlpi-ea.dhl.com/XMLShippingServlet ' ],
503+ 'sandbox_xml_url ' => [1 , 'DHL_XML ' , 'https://xmlpitest-ea.dhl.com/XMLShippingServlet ' ],
504+ 'standard_rest_url ' => [0 , 'DHL_REST ' , 'https://express.api.dhl.com/mydhlapi ' ],
505+ 'sandbox_rest_url ' => [1 , 'DHL_REST ' , 'https://express.api.dhl.com/mydhlapi/test ' ]
492506 ];
493507 }
494508
@@ -670,4 +684,37 @@ private function getHttpClientFactory(): MockObject
670684
671685 return $ httpClientFactory ;
672686 }
687+
688+ public function testSuccessfulLabelGeneration ()
689+ {
690+ $ this ->responseData = json_decode (file_get_contents (__DIR__ . '/_files/response_shipping_label.json ' ), true );
691+ $ result = new DataObject ();
692+
693+ // Extract label content from response and decode it
694+ $ labelContent = base64_decode ($ this ->responseData ['documents ' ][0 ]['content ' ]);
695+
696+ $ result ->setData ('shipping_label_content ' , $ labelContent );
697+
698+ // Assert that the label was correctly set
699+ $ this ->assertEquals ($ labelContent , $ result ->getData ('shipping_label_content ' ));
700+ }
701+
702+ public function testLabelGenerationException ()
703+ {
704+ $ this ->responseData = json_decode (file_get_contents (__DIR__ . '/_files/response_shipping_label.json ' ), true );
705+ $ this ->expectException (\Exception::class);
706+
707+ $ result = new DataObject ();
708+
709+ // Simulate a failure (e.g., missing document content)
710+ $ invalidResponse = $ this ->responseData ;
711+ unset($ invalidResponse ['documents ' ][0 ]['content ' ]);
712+
713+ if (!isset ($ invalidResponse ['documents ' ][0 ]['content ' ])) {
714+ throw new \Exception ("Shipping label content is missing " );
715+ }
716+
717+ $ labelContent = base64_decode ($ invalidResponse ['documents ' ][0 ]['content ' ]);
718+ $ result ->setData ('shipping_label_content ' , $ labelContent );
719+ }
673720}
0 commit comments