You are here

public function UPSRateRequestTest::testRateRequest in Commerce UPS 8.3

Test rate requests return valid rates.

@covers ::getRates

@dataProvider measurementUnitsDataProvider

Parameters

string $weight_unit: Weight unit.

string $length_unit: Length unit.

bool $send_from_usa: Whether the shipment should be sent from USA.

File

tests/src/Unit/UPSRateRequestTest.php, line 94

Class

UPSRateRequestTest
Class UPSRateRequestTest.

Namespace

Drupal\Tests\commerce_ups\Unit

Code

public function testRateRequest($weight_unit, $length_unit, $send_from_usa) {

  // Invoke the rate request object.
  $shipment = $this
    ->mockShipment($weight_unit, $length_unit, $send_from_usa);
  $shipping_method_plugin = $this
    ->mockShippingMethod();
  $shipping_method_entity = $this
    ->prophesize(ShippingMethodInterface::class);
  $shipping_method_entity
    ->id()
    ->willReturn('123456789');
  $shipping_method_entity
    ->getPlugin()
    ->willReturn($shipping_method_plugin);
  $rates = $this->rateRequest
    ->getRates($shipment, $shipping_method_entity
    ->reveal());

  // Make sure at least one rate was returned.
  $this
    ->assertArrayHasKey(0, $rates);
  foreach ($rates as $rate) {
    assert($rate instanceof ShippingRate);
    $this
      ->assertGreaterThan(0, $rate
      ->getAmount()
      ->getNumber());
    $this
      ->assertGreaterThan(0, $rate
      ->getOriginalAmount()
      ->getNumber());
    $this
      ->assertEquals($rate
      ->getAmount()
      ->getCurrencyCode(), $send_from_usa ? 'USD' : 'EUR');
    $this
      ->assertNotEmpty($rate
      ->getService()
      ->getLabel());
    $this
      ->assertEquals('123456789', $rate
      ->getShippingMethodId());
  }
}