You are here

class OrderPaymentGatewayTest in Commerce Core 8.2

@coversDefaultClass \Drupal\commerce_payment\Plugin\Commerce\Condition\OrderPaymentGateway @group commerce

Hierarchy

Expanded class hierarchy of OrderPaymentGatewayTest

File

modules/payment/tests/src/Unit/Plugin/Commerce/Condition/OrderPaymentGatewayTest.php, line 15

Namespace

Drupal\Tests\commerce_payment\Unit\Plugin\Commerce\Condition
View source
class OrderPaymentGatewayTest extends UnitTestCase {

  /**
   * ::covers evaluate.
   */
  public function testIncompleteOrder() {
    $condition = new OrderPaymentGateway([
      'payment_gateways' => [
        'test',
      ],
    ], 'order_payment_gateway', [
      'entity_type' => 'commerce_order',
    ]);
    $order = $this
      ->prophesize(OrderInterface::class);
    $entity_reference_item = $this
      ->prophesize(EntityReferenceItem::class);
    $entity_reference_item
      ->isEmpty()
      ->willReturn(TRUE);
    $entity_reference_item = $entity_reference_item
      ->reveal();
    $order = $this
      ->prophesize(OrderInterface::class);
    $order
      ->getEntityTypeId()
      ->willReturn('commerce_order');
    $order
      ->get('payment_gateway')
      ->willReturn($entity_reference_item);
    $order = $order
      ->reveal();
    $this
      ->assertFalse($condition
      ->evaluate($order));
  }

  /**
   * Covers evaluate.
   */
  public function testOrderPaymentGateway() {
    $entity_reference_item = $this
      ->prophesize(EntityReferenceItem::class);
    $entity_reference_item
      ->getValue()
      ->willReturn([
      'target_id' => 'test_payment',
    ]);
    $entity_reference_item_list = $this
      ->prophesize(EntityReferenceFieldItemList::class);
    $entity_reference_item_list
      ->isEmpty()
      ->willReturn(FALSE);
    $entity_reference_item_list
      ->first()
      ->willReturn($entity_reference_item
      ->reveal());
    $entity_reference_item_list = $entity_reference_item_list
      ->reveal();
    $order = $this
      ->prophesize(OrderInterface::class);
    $order
      ->getEntityTypeId()
      ->willReturn('commerce_order');
    $order
      ->get('payment_gateway')
      ->willReturn($entity_reference_item_list);
    $order = $order
      ->reveal();
    $condition = new OrderPaymentGateway([
      'payment_gateways' => [],
    ], 'order_payment_gateway', [
      'entity_type' => 'commerce_order',
    ]);
    $this
      ->assertFalse($condition
      ->evaluate($order));
    $condition = new OrderPaymentGateway([
      'payment_gateways' => [
        'cash_on_delivery',
        'bank_transfer',
      ],
    ], 'order_payment_gateway', [
      'entity_type' => 'commerce_order',
    ]);
    $this
      ->assertFalse($condition
      ->evaluate($order));
    $condition = new OrderPaymentGateway([
      'payment_gateways' => [
        'cash_on_delivery',
        'test_payment',
      ],
    ], 'order_payment_gateway', [
      'entity_type' => 'commerce_order',
    ]);
    $this
      ->assertTrue($condition
      ->evaluate($order));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
OrderPaymentGatewayTest::testIncompleteOrder public function ::covers evaluate.
OrderPaymentGatewayTest::testOrderPaymentGateway 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