class ShipmentAddressTest in Commerce Shipping 8.2
@coversDefaultClass \Drupal\commerce_shipping\Plugin\Commerce\Condition\ShipmentAddress @group commerce
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\commerce_shipping\Unit\Plugin\Commerce\Condition\ShipmentAddressTest
Expanded class hierarchy of ShipmentAddressTest
File
- tests/
src/ Unit/ Plugin/ Commerce/ Condition/ ShipmentAddressTest.php, line 16
Namespace
Drupal\Tests\commerce_shipping\Unit\Plugin\Commerce\ConditionView 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
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
ShipmentAddressTest:: |
public | function | ::covers evaluate. | |
ShipmentAddressTest:: |
public | function | ::covers evaluate. | |
ShipmentAddressTest:: |
public | function | ::covers evaluate. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. | |
UnitTestCase:: |
protected | function | 340 |