You are here

class UPSShipmentTest in Commerce UPS 8.3

Class UPSShipmentTest.

@coversDefaultClass \Drupal\commerce_ups\UPSShipment @group commerce_ups

Hierarchy

Expanded class hierarchy of UPSShipmentTest

File

tests/src/Unit/UPSShipmentTest.php, line 13

Namespace

Drupal\Tests\commerce_ups\Unit
View source
class UPSShipmentTest extends UPSUnitTestBase {

  /**
   * The UPS shipment object.
   *
   * @var \Drupal\commerce_ups\UPSShipment
   */
  protected $upsShipment;

  /**
   * Set up requirements for test.
   */
  public function setUp() {
    parent::setUp();
    $this->upsShipment = new UPSShipment();
  }

  /**
   * Test ship from address.
   *
   * @covers ::setShipFrom
   */
  public function testShipFrom() {
    $api_shipment = $this->upsShipment
      ->getShipment($this
      ->mockShipment(), $this
      ->mockShippingMethod());
    $ship_from = $api_shipment
      ->getShipFrom()
      ->getAddress();
    $this
      ->assertEquals('1025 Brevard Rd', $ship_from
      ->getAddressLine1());
    $this
      ->assertEquals('Asheville', $ship_from
      ->getCity());
    $this
      ->assertEquals('NC', $ship_from
      ->getStateProvinceCode());
    $this
      ->assertEquals('28806', $ship_from
      ->getPostalCode());
    $this
      ->assertEquals('US', $ship_from
      ->getCountryCode());
  }

  /**
   * Test ship to address.
   *
   * @covers ::setShipTo
   */
  public function testShipTo() {
    $api_shipment = $this->upsShipment
      ->getShipment($this
      ->mockShipment(), $this
      ->mockShippingMethod());
    $ship_to = $api_shipment
      ->getShipTo()
      ->getAddress();
    $this
      ->assertEquals('1025 Brevard Rd', $ship_to
      ->getAddressLine1());
    $this
      ->assertEquals('Asheville', $ship_to
      ->getCity());
    $this
      ->assertEquals('NC', $ship_to
      ->getStateProvinceCode());
    $this
      ->assertEquals('28806', $ship_to
      ->getPostalCode());
    $this
      ->assertEquals('US', $ship_to
      ->getCountryCode());
  }

  /**
   * Test set package.
   *
   * @covers ::setPackage
   * @covers ::setDimensions
   * @covers ::setWeight
   * @covers ::setPackagingType
   */
  public function testPackage() {
    $api_shipment = $this->upsShipment
      ->getShipment($this
      ->mockShipment(), $this
      ->mockShippingMethod());
    $packages = $api_shipment
      ->getPackages();
    $this
      ->assertCount(1, $packages);

    /** @var \Ups\Entity\Package $package */
    $package = reset($packages);
    $this
      ->assertEquals(10, $package
      ->getDimensions()
      ->getLength());
    $this
      ->assertEquals(3, $package
      ->getDimensions()
      ->getWidth());
    $this
      ->assertEquals(10, $package
      ->getDimensions()
      ->getHeight());
    $this
      ->assertEquals(10, $package
      ->getPackageWeight()
      ->getWeight());
    $this
      ->assertEquals('00', $package
      ->getPackagingType()
      ->getCode());
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.
UPSShipmentTest::$upsShipment protected property The UPS shipment object.
UPSShipmentTest::setUp public function Set up requirements for test. Overrides UPSUnitTestBase::setUp
UPSShipmentTest::testPackage public function Test set package.
UPSShipmentTest::testShipFrom public function Test ship from address.
UPSShipmentTest::testShipTo public function Test ship to address.
UPSUnitTestBase::$configuration protected property A shipping method configuration array.
UPSUnitTestBase::mockShipment public function Creates a mock Drupal Commerce shipment entity.
UPSUnitTestBase::mockShippingMethod public function Creates a mock Drupal Commerce shipping method.