ShippingTest.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Shipping\Model;
  7. use Magento\Framework\DataObject;
  8. use Magento\Framework\ObjectManagerInterface;
  9. use Magento\Quote\Model\Quote\Address\RateResult\Method;
  10. use Magento\Shipping\Model\Rate\Result;
  11. use Magento\TestFramework\Helper\Bootstrap;
  12. /**
  13. * Contains list of tests for Shipping model
  14. */
  15. class ShippingTest extends \PHPUnit\Framework\TestCase
  16. {
  17. /**
  18. * @var Shipping
  19. */
  20. private $model;
  21. /**
  22. * @var ObjectManagerInterface
  23. */
  24. private $objectManager;
  25. /**
  26. * @inheritdoc
  27. */
  28. protected function setUp()
  29. {
  30. $this->objectManager = Bootstrap::getObjectManager();
  31. $this->model = $this->objectManager->get(Shipping::class);
  32. }
  33. /**
  34. * Checks shipping rates processing by address.
  35. * @covers \Magento\Shipping\Model\Shipping::collectRatesByAddress
  36. * @return Result
  37. */
  38. public function testCollectRatesByAddress()
  39. {
  40. $address = $this->objectManager->create(DataObject::class, [
  41. 'data' => [
  42. 'region_id' => 'CA',
  43. 'postcode' => '11111',
  44. 'lastname' => 'John',
  45. 'firstname' => 'Doe',
  46. 'street' => 'Some street',
  47. 'city' => 'Los Angeles',
  48. 'email' => 'john.doe@example.com',
  49. 'telephone' => '11111111',
  50. 'country_id' => 'US',
  51. 'item_qty' => 1
  52. ]
  53. ]);
  54. /** @var Shipping $result */
  55. $result = $this->model->collectRatesByAddress($address, 'flatrate');
  56. static::assertInstanceOf(Shipping::class, $result);
  57. return $result->getResult();
  58. }
  59. /**
  60. * Checks shipping rate details for processed address.
  61. * @covers \Magento\Shipping\Model\Shipping::collectRatesByAddress
  62. * @param Result $result
  63. * @depends testCollectRatesByAddress
  64. * @magentoConfigFixture carriers/flatrate/active 1
  65. * @magentoConfigFixture carriers/flatrate/price 5.00
  66. */
  67. public function testCollectRates(Result $result)
  68. {
  69. $rates = $result->getAllRates();
  70. static::assertNotEmpty($rates);
  71. /** @var Method $rate */
  72. $rate = array_pop($rates);
  73. static::assertInstanceOf(Method::class, $rate);
  74. static::assertEquals('flatrate', $rate->getData('carrier'));
  75. static::assertEquals(5, $rate->getData('price'));
  76. }
  77. }