You are here

public function ShipmentAddressTest::testEvaluate in Commerce Shipping 8.2

::covers evaluate.

File

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

Class

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

Namespace

Drupal\Tests\commerce_shipping\Unit\Plugin\Commerce\Condition

Code

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));
}