ShipmentModelTest.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <?php
  2. /**
  3. * Refer to LICENSE.txt distributed with the Temando Shipping module for notice of license
  4. */
  5. namespace Temando\Shipping\Model;
  6. use Magento\TestFramework\Helper\Bootstrap;
  7. use Temando\Shipping\Model\Shipment\FulfillmentInterface;
  8. use Temando\Shipping\Model\Shipment\LocationInterface;
  9. /**
  10. * Temando Shipment Model Test
  11. *
  12. * @codingStandardsIgnoreFile
  13. *
  14. * @package Temando\Shipping\Test\Integration
  15. * @author Christoph Aßmann <christoph.assmann@netresearch.de>
  16. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  17. * @link http://www.temando.com/
  18. */
  19. class ShipmentModelTest extends \PHPUnit\Framework\TestCase
  20. {
  21. /**
  22. * @test
  23. */
  24. public function dataIsSetThroughConstructorArgument()
  25. {
  26. $shipmentId = '00000000-5000-0005-0000-000000000000';
  27. $originLocationData = [
  28. 'company' => 'Foo Ltd.',
  29. 'person_first_name' => 'Foo',
  30. 'person_last_name' => 'Bar',
  31. 'email' => 'foo@example.org',
  32. 'phone_number' => '0800',
  33. 'street' => 'Foo Street',
  34. 'city' => 'South Foo',
  35. 'postal_code' => 'F00 84R',
  36. 'region_code' => 'YY',
  37. 'country_code' => 'XXX',
  38. ];
  39. $destinationLocationData = [
  40. 'company' => 'Fox, Inc.',
  41. 'person_first_name' => 'Fox',
  42. 'person_last_name' => 'Baz',
  43. 'email' => 'fox@example.org',
  44. 'phone_number' => '911',
  45. 'street' => 'Fox Street',
  46. 'city' => 'North Fox',
  47. 'postal_code' => 'F0X 842',
  48. 'region_code' => 'AA',
  49. 'country_code' => 'BBB',
  50. ];
  51. $fulfillmentData = [
  52. 'service_name' => 'Faster',
  53. 'tracking_reference' => 'ZZ1234',
  54. ];
  55. $documentationData = [
  56. 'documentation_id' => '1234',
  57. 'description' => 'Package Label',
  58. 'type' => 'packageLabels',
  59. 'size' => 'A6',
  60. 'mime_type' => 'image/png',
  61. 'url' => 'https://example.com/documents/label-1234',
  62. ];
  63. $isPaperless = true;
  64. /** @var Shipment\Location $originLocation */
  65. $originLocation = Bootstrap::getObjectManager()->create(Shipment\Location::class, ['data' => [
  66. LocationInterface::COMPANY => $originLocationData['company'],
  67. LocationInterface::PERSON_FIRST_NAME => $originLocationData['person_first_name'],
  68. LocationInterface::PERSON_LAST_NAME => $originLocationData['person_last_name'],
  69. LocationInterface::EMAIL => $originLocationData['email'],
  70. LocationInterface::PHONE_NUMBER => $originLocationData['phone_number'],
  71. LocationInterface::STREET => $originLocationData['street'],
  72. LocationInterface::CITY => $originLocationData['city'],
  73. LocationInterface::POSTAL_CODE => $originLocationData['postal_code'],
  74. LocationInterface::REGION_CODE => $originLocationData['region_code'],
  75. LocationInterface::COUNTRY_CODE => $originLocationData['country_code'],
  76. ]]);
  77. $destinationLocation = Bootstrap::getObjectManager()->create(Shipment\Location::class, ['data' => [
  78. LocationInterface::COMPANY => $destinationLocationData['company'],
  79. LocationInterface::PERSON_FIRST_NAME => $destinationLocationData['person_first_name'],
  80. LocationInterface::PERSON_LAST_NAME => $destinationLocationData['person_last_name'],
  81. LocationInterface::EMAIL => $destinationLocationData['email'],
  82. LocationInterface::PHONE_NUMBER => $destinationLocationData['phone_number'],
  83. LocationInterface::STREET => $destinationLocationData['street'],
  84. LocationInterface::CITY => $destinationLocationData['city'],
  85. LocationInterface::POSTAL_CODE => $destinationLocationData['postal_code'],
  86. LocationInterface::REGION_CODE => $destinationLocationData['region_code'],
  87. LocationInterface::COUNTRY_CODE => $destinationLocationData['country_code'],
  88. ]]);
  89. $fulfillment = Bootstrap::getObjectManager()->create(Shipment\Fulfillment::class, ['data' => [
  90. FulfillmentInterface::SERVICE_NAME => $fulfillmentData['service_name'],
  91. FulfillmentInterface::TRACKING_REFERENCE => $fulfillmentData['tracking_reference'],
  92. ]]);
  93. /** @var Documentation $documentation */
  94. $documentation = Bootstrap::getObjectManager()->create(Documentation::class, ['data' => [
  95. DocumentationInterface::DOCUMENTATION_ID => $documentationData['documentation_id'],
  96. DocumentationInterface::NAME => $documentationData['description'],
  97. DocumentationInterface::TYPE => $documentationData['type'],
  98. DocumentationInterface::SIZE => $documentationData['size'],
  99. DocumentationInterface::MIME_TYPE => $documentationData['mime_type'],
  100. DocumentationInterface::URL => $documentationData['url'],
  101. ]]);
  102. $documentation = [$documentation];
  103. /** @var Shipment $shipment */
  104. $shipment = Bootstrap::getObjectManager()->create(Shipment::class, ['data' => [
  105. ShipmentInterface::SHIPMENT_ID => $shipmentId,
  106. ShipmentInterface::ORIGIN_LOCATION => $originLocation,
  107. ShipmentInterface::DESTINATION_LOCATION => $destinationLocation,
  108. ShipmentInterface::FULFILLMENT => $fulfillment,
  109. ShipmentInterface::DOCUMENTATION => $documentation,
  110. ShipmentInterface::IS_PAPERLESS => $isPaperless,
  111. ]]);
  112. $this->assertEquals($shipmentId, $shipment->getShipmentId());
  113. $this->assertSame($originLocation, $shipment->getOriginLocation());
  114. $this->assertEquals($originLocationData['company'], $shipment->getOriginLocation()->getCompany());
  115. $this->assertEquals($originLocationData['person_first_name'], $shipment->getOriginLocation()->getPersonFirstName());
  116. $this->assertEquals($originLocationData['person_last_name'], $shipment->getOriginLocation()->getPersonLastName());
  117. $this->assertEquals($originLocationData['email'], $shipment->getOriginLocation()->getEmail());
  118. $this->assertEquals($originLocationData['phone_number'], $shipment->getOriginLocation()->getPhoneNumber());
  119. $this->assertEquals($originLocationData['street'], $shipment->getOriginLocation()->getStreet());
  120. $this->assertEquals($originLocationData['city'], $shipment->getOriginLocation()->getCity());
  121. $this->assertEquals($originLocationData['postal_code'], $shipment->getOriginLocation()->getPostalCode());
  122. $this->assertEquals($originLocationData['region_code'], $shipment->getOriginLocation()->getRegionCode());
  123. $this->assertEquals($originLocationData['country_code'], $shipment->getOriginLocation()->getCountryCode());
  124. $this->assertSame($destinationLocation, $shipment->getDestinationLocation());
  125. $this->assertEquals($destinationLocationData['company'], $shipment->getDestinationLocation()->getCompany());
  126. $this->assertEquals($destinationLocationData['person_first_name'], $shipment->getDestinationLocation()->getPersonFirstName());
  127. $this->assertEquals($destinationLocationData['person_last_name'], $shipment->getDestinationLocation()->getPersonLastName());
  128. $this->assertEquals($destinationLocationData['email'], $shipment->getDestinationLocation()->getEmail());
  129. $this->assertEquals($destinationLocationData['phone_number'], $shipment->getDestinationLocation()->getPhoneNumber());
  130. $this->assertEquals($destinationLocationData['street'], $shipment->getDestinationLocation()->getStreet());
  131. $this->assertEquals($destinationLocationData['city'], $shipment->getDestinationLocation()->getCity());
  132. $this->assertEquals($destinationLocationData['postal_code'], $shipment->getDestinationLocation()->getPostalCode());
  133. $this->assertEquals($destinationLocationData['region_code'], $shipment->getDestinationLocation()->getRegionCode());
  134. $this->assertEquals($destinationLocationData['country_code'], $shipment->getDestinationLocation()->getCountryCode());
  135. $this->assertSame($fulfillment, $shipment->getFulfillment());
  136. $this->assertEquals($fulfillmentData['service_name'], $shipment->getFulfillment()->getServiceName());
  137. $this->assertEquals($fulfillmentData['tracking_reference'], $shipment->getFulfillment()->getTrackingReference());
  138. $this->assertSame($documentation, $shipment->getDocumentation());
  139. $this->assertEquals($isPaperless, $shipment->isPaperless());
  140. }
  141. /**
  142. * @test
  143. */
  144. public function dataIsSetThroughSetters()
  145. {
  146. $shipmentId = '00000000-5000-0005-0000-000000000000';
  147. $orderId = '1234567899876543210';
  148. $originId = '897654321123456789';
  149. /** @var Shipment\Location $originLocation */
  150. $originLocation = Bootstrap::getObjectManager()->create(Shipment\Location::class);
  151. /** @var Shipment\Location $destinationLocation */
  152. $destinationLocation = Bootstrap::getObjectManager()->create(Shipment\Location::class);
  153. $fulfillment = Bootstrap::getObjectManager()->create(FulfillmentInterface::class);
  154. $packages = ['pack'];
  155. $documentation = ['doc'];
  156. $isPaperless = true;
  157. /** @var Shipment $shipment */
  158. $shipment = Bootstrap::getObjectManager()->create(Shipment::class);
  159. $this->assertEmpty($shipment->getShipmentId());
  160. $shipment->setData(Shipment::SHIPMENT_ID, $shipmentId);
  161. $this->assertEquals($shipmentId, $shipment->getShipmentId());
  162. $shipment->setData(Shipment::ORDER_ID, $orderId);
  163. $this->assertEquals($orderId, $shipment->getOrderId());
  164. $shipment->setData(Shipment::ORIGIN_LOCATION, $originLocation);
  165. $this->assertSame($originLocation, $shipment->getOriginLocation());
  166. $shipment->setData(Shipment::DESTINATION_LOCATION, $destinationLocation);
  167. $this->assertSame($destinationLocation, $shipment->getDestinationLocation());
  168. $shipment->setData(Shipment::ORIGIN_ID, $originId);
  169. $this->assertSame($originId, $shipment->getOriginId());
  170. $shipment->setData(Shipment::FULFILLMENT, $fulfillment);
  171. $this->assertEquals($fulfillment, $shipment->getFulfillment());
  172. $shipment->setData(Shipment::PACKAGES, $packages);
  173. $this->assertEquals($packages, $shipment->getPackages());
  174. $shipment->setData(Shipment::DOCUMENTATION, $documentation);
  175. $this->assertEquals($documentation, $shipment->getDocumentation());
  176. $shipment->setData(Shipment::IS_PAPERLESS, $isPaperless);
  177. $this->assertEquals($isPaperless, $shipment->isPaperless());
  178. }
  179. }