You are here

function PaymentUbercartDeleteOrderWebTestCase::testDeleteOrder in Payment for Ubercart 7.2

Same name and namespace in other branches
  1. 7 tests/PaymentUbercartDeleteOrderWebTestCase.test \PaymentUbercartDeleteOrderWebTestCase::testDeleteOrder()

File

tests/PaymentUbercartDeleteOrderWebTestCase.test, line 18

Class

PaymentUbercartDeleteOrderWebTestCase

Code

function testDeleteOrder() {
  $payment_method = $this
    ->paymentMethodCreate(0, payment_method_controller_load('PaymentMethodBasicController'));
  entity_save('payment_method', $payment_method);

  // Delete an order, but keep its payments.
  $uc_order = uc_order_new();
  $uc_order->payment_method = 'payment_ubercart_' . $payment_method->pmid;
  entity_save('uc_order', $uc_order);
  $payment = new Payment(array(
    'method' => $payment_method,
    'payment_ubercart_uc_order_id' => $uc_order->order_id,
  ));
  entity_save('payment', $payment);
  payment_ubercart_order_id_save($payment);
  uc_order_delete($uc_order->order_id);
  $this
    ->assertTrue((bool) entity_load_unchanged('payment', $payment->pid), 'When deleting an Ubercart order, its payments remain if they are configured to do so.');

  // Delete an order and its payments.
  variable_set('payment_ubercart_uc_order_delete', TRUE);
  $uc_order = uc_order_new();
  $uc_order->payment_method = 'payment_ubercart_' . $payment_method->pmid;
  entity_save('uc_order', $uc_order);
  $payment->payment_ubercart_uc_order_id = $uc_order->order_id;
  payment_ubercart_order_id_save($payment);
  uc_order_delete($uc_order->order_id);
  $this
    ->assertFalse((bool) entity_load_unchanged('payment', $payment->pid), 'When deleting an Ubercart order, its payments are deleted as well if they are configured to do so.');
}