You are here

class OrderBillingAddressTest in Commerce Core 8.2

@coversDefaultClass \Drupal\commerce_order\Plugin\Commerce\Condition\OrderBillingAddress @group commerce

Hierarchy

Expanded class hierarchy of OrderBillingAddressTest

File

modules/order/tests/src/Unit/Plugin/Commerce/Condition/OrderBillingAddressTest.php, line 16

Namespace

Drupal\Tests\commerce_order\Unit\Plugin\Commerce\Condition
View source
class OrderBillingAddressTest extends UnitTestCase {

  /**
   * ::covers evaluate.
   */
  public function testIncompleteOrder() {
    $condition = new OrderBillingAddress([
      'zone' => [
        'territories' => [
          [
            'country_code' => 'US',
            'administrative_area' => 'CA',
          ],
        ],
      ],
    ], 'order_billing_address', [
      'entity_type' => 'commerce_order',
    ]);
    $order = $this
      ->prophesize(OrderInterface::class);
    $order
      ->getEntityTypeId()
      ->willReturn('commerce_order');
    $order
      ->getBillingProfile()
      ->willReturn(NULL);
    $order = $order
      ->reveal();
    $this
      ->assertFalse($condition
      ->evaluate($order));
  }

  /**
   * ::covers evaluate.
   */
  public function testEvaluate() {
    $address_list = $this
      ->prophesize(FieldItemListInterface::class);
    $address_list
      ->first()
      ->willReturn(new Address('US', 'SC'));
    $address_list = $address_list
      ->reveal();
    $billing_profile = $this
      ->prophesize(ProfileInterface::class);
    $billing_profile
      ->get('address')
      ->willReturn($address_list);
    $billing_profile = $billing_profile
      ->reveal();
    $order = $this
      ->prophesize(OrderInterface::class);
    $order
      ->getEntityTypeId()
      ->willReturn('commerce_order');
    $order
      ->getBillingProfile()
      ->willReturn($billing_profile);
    $order = $order
      ->reveal();
    $condition = new OrderBillingAddress([
      'zone' => [
        'territories' => [
          [
            'country_code' => 'US',
            'administrative_area' => 'CA',
          ],
        ],
      ],
    ], 'order_billing_address', [
      'entity_type' => 'commerce_order',
    ]);
    $this
      ->assertFalse($condition
      ->evaluate($order));
    $condition = new OrderBillingAddress([
      'zone' => [
        'territories' => [
          [
            'country_code' => 'US',
            'administrative_area' => 'SC',
          ],
        ],
      ],
    ], 'order_billing_address', [
      'entity_type' => 'commerce_order',
    ]);
    $this
      ->assertTrue($condition
      ->evaluate($order));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
OrderBillingAddressTest::testEvaluate public function ::covers evaluate.
OrderBillingAddressTest::testIncompleteOrder public function ::covers evaluate.
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.
UnitTestCase::setUp protected function 340