You are here

class ShipmentAddressTest in Commerce Shipping 8.2

@coversDefaultClass \Drupal\commerce_shipping\Plugin\Commerce\Condition\ShipmentAddress @group commerce

Hierarchy

Expanded class hierarchy of ShipmentAddressTest

File

tests/src/Unit/Plugin/Commerce/Condition/ShipmentAddressTest.php, line 16

Namespace

Drupal\Tests\commerce_shipping\Unit\Plugin\Commerce\Condition
View source
class ShipmentAddressTest extends UnitTestCase {

  /**
   * ::covers evaluate.
   */
  public function testIncompleteShipment() {
    $condition = new ShipmentAddress([
      'zone' => [
        'territories' => [
          [
            'country_code' => 'US',
            'administrative_area' => 'CA',
          ],
        ],
      ],
    ], 'shipment_address', [
      'entity_type' => 'commerce_shipment',
    ]);
    $shipment = $this
      ->prophesize(ShipmentInterface::class);
    $shipment
      ->getEntityTypeId()
      ->willReturn('commerce_shipment');
    $shipment
      ->getShippingProfile()
      ->willReturn(NULL);
    $shipment = $shipment
      ->reveal();
    $this
      ->assertFalse($condition
      ->evaluate($shipment));
  }

  /**
   * ::covers evaluate.
   */
  public function testIncompleteShippingProfile() {
    $condition = new ShipmentAddress([
      'zone' => [
        'territories' => [
          [
            'country_code' => 'US',
            'administrative_area' => 'CA',
          ],
        ],
      ],
    ], 'shipment_address', [
      'entity_type' => 'commerce_shipment',
    ]);
    $address_list = $this
      ->prophesize(FieldItemListInterface::class);
    $address_list
      ->first()
      ->willReturn(NULL);
    $address_list = $address_list
      ->reveal();
    $shipping_profile = $this
      ->prophesize(ProfileInterface::class);
    $shipping_profile
      ->get('address')
      ->willReturn($address_list);
    $shipping_profile = $shipping_profile
      ->reveal();
    $shipment = $this
      ->prophesize(ShipmentInterface::class);
    $shipment
      ->getEntityTypeId()
      ->willReturn('commerce_shipment');
    $shipment
      ->getShippingProfile()
      ->willReturn($shipping_profile);
    $shipment = $shipment
      ->reveal();
    $this
      ->assertFalse($condition
      ->evaluate($shipment));
  }

  /**
   * ::covers evaluate.
   */
  public function testEvaluate() {
    $address_list = $this
      ->prophesize(FieldItemListInterface::class);
    $address_list
      ->first()
      ->willReturn(new Address('US', 'SC'));
    $address_list = $address_list
      ->reveal();
    $shipping_profile = $this
      ->prophesize(ProfileInterface::class);
    $shipping_profile
      ->get('address')
      ->willReturn($address_list);
    $shipping_profile = $shipping_profile
      ->reveal();
    $shipment = $this
      ->prophesize(ShipmentInterface::class);
    $shipment
      ->getEntityTypeId()
      ->willReturn('commerce_shipment');
    $shipment
      ->getShippingProfile()
      ->willReturn($shipping_profile);
    $shipment = $shipment
      ->reveal();
    $condition = new ShipmentAddress([
      'zone' => [
        'territories' => [
          [
            'country_code' => 'US',
            'administrative_area' => 'CA',
          ],
        ],
      ],
    ], 'shipment_address', [
      'entity_type' => 'commerce_shipment',
    ]);
    $this
      ->assertFalse($condition
      ->evaluate($shipment));
    $condition = new ShipmentAddress([
      'zone' => [
        'territories' => [
          [
            'country_code' => 'US',
            'administrative_area' => 'CA',
          ],
        ],
      ],
      'negate' => TRUE,
    ], 'shipment_address', [
      'entity_type' => 'commerce_shipment',
    ]);
    $this
      ->assertTrue($condition
      ->evaluate($shipment));
    $condition = new ShipmentAddress([
      'zone' => [
        'territories' => [
          [
            'country_code' => 'US',
            'administrative_area' => 'SC',
          ],
        ],
      ],
    ], 'shipment_address', [
      'entity_type' => 'commerce_shipment',
    ]);
    $this
      ->assertTrue($condition
      ->evaluate($shipment));
    $condition = new ShipmentAddress([
      'zone' => [
        'territories' => [
          [
            'country_code' => 'US',
            'administrative_area' => 'SC',
          ],
        ],
      ],
      'negate' => TRUE,
    ], 'shipment_address', [
      'entity_type' => 'commerce_shipment',
    ]);
    $this
      ->assertFalse($condition
      ->evaluate($shipment));
  }

}

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.
ShipmentAddressTest::testEvaluate public function ::covers evaluate.
ShipmentAddressTest::testIncompleteShipment public function ::covers evaluate.
ShipmentAddressTest::testIncompleteShippingProfile public function ::covers evaluate.
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.
UnitTestCase::setUp protected function 340