You are here

private function PaymentTest::assertPaymentEntity in Commerce Migrate 3.1.x

Same name and namespace in other branches
  1. 8.2 modules/commerce/tests/src/Kernel/Migrate/commerce1/PaymentTest.php \Drupal\Tests\commerce_migrate_commerce\Kernel\Migrate\commerce1\PaymentTest::assertPaymentEntity()
  2. 3.0.x modules/commerce/tests/src/Kernel/Migrate/commerce1/PaymentTest.php \Drupal\Tests\commerce_migrate_commerce\Kernel\Migrate\commerce1\PaymentTest::assertPaymentEntity()

Asserts a payment entity.

Parameters

array $payment: An array of payment information.

  • The payment id.
  • The order id for this payment.
  • The payment type.
  • The gateway id.
  • The payment method.
  • The payment amount.
  • The payment currency code.
  • The order balance.
  • The order balance currency code.
  • The refunded amount.
  • The refunded amount currency code.

Overrides CommerceMigrateTestTrait::assertPaymentEntity

1 call to PaymentTest::assertPaymentEntity()
PaymentTest::testPayment in modules/commerce/tests/src/Kernel/Migrate/commerce1/PaymentTest.php
Test line item migration from Drupal 7 to 8.

File

modules/commerce/tests/src/Kernel/Migrate/commerce1/PaymentTest.php, line 68

Class

PaymentTest
Tests payment migration.

Namespace

Drupal\Tests\commerce_migrate_commerce\Kernel\Migrate\commerce1

Code

private function assertPaymentEntity(array $payment) {
  $payment_instance = Payment::load($payment['id']);
  $this
    ->assertInstanceOf(Payment::class, $payment_instance);
  $this
    ->assertSame($payment['order_id'], $payment_instance
    ->getOrderId());
  $this
    ->assertSame($payment['type'], $payment_instance
    ->getType()
    ->getPluginId());
  $this
    ->assertSame($payment['payment_gateway'], $payment_instance
    ->getPaymentGatewayId());
  $this
    ->assertSame($payment['payment_method'], $payment_instance
    ->getPaymentMethodId());
  $formatted_number = $this
    ->formatNumber($payment['amount_number'], $payment_instance
    ->getAmount()
    ->getNumber());
  $this
    ->assertSame($formatted_number['expected'], $formatted_number['actual']);
  $this
    ->assertSame($payment['amount_currency_code'], $payment_instance
    ->getAmount()
    ->getCurrencyCode());
  $formatted_number = $this
    ->formatNumber($payment['balance_number'], $payment_instance
    ->getBalance()
    ->getNumber());
  $this
    ->assertSame($formatted_number['expected'], $formatted_number['actual']);
  $this
    ->assertSame($payment['balance_currency_code'], $payment_instance
    ->getBalance()
    ->getCurrencyCode());
  $formatted_number = $this
    ->formatNumber($payment['refunded_amount_number'], $payment_instance
    ->getRefundedAmount()
    ->getNumber());
  $this
    ->assertSame($formatted_number['expected'], $formatted_number['actual']);
  $this
    ->assertSame($payment['refunded_amount_currency_code'], $payment_instance
    ->getRefundedAmount()
    ->getCurrencyCode());
  $this
    ->assertSame($payment['label_value'], $payment_instance
    ->getState()->value);
  $state_label = $payment_instance
    ->getState()
    ->getLabel();
  $label = NULL;
  if (is_string($state_label)) {
    $label = $state_label;
  }
  elseif ($state_label instanceof TranslatableMarkup) {
    $arguments = $state_label
      ->getArguments();
    $label = isset($arguments['@label']) ? $arguments['@label'] : $state_label
      ->render();
  }
  $this
    ->assertSame($payment['label_rendered'], $label);
}