PaymentCommerceDeleteOrderWebTestCase.test in Payment for Drupal Commerce 7
File
tests/PaymentCommerceDeleteOrderWebTestCase.test
View source
<?php
class PaymentCommerceDeleteOrderWebTestCase extends PaymentWebTestCase {
static function getInfo() {
return array(
'description' => '',
'name' => 'Payment deletion upon order deletion',
'group' => 'Payment for Drupal Commerce',
'dependencies' => array(
'payment_commerce',
),
);
}
function setUp(array $modules = array()) {
$this->profile = 'testing';
parent::setUp($modules + array(
'paymentmethodbasic',
'payment_commerce',
));
}
function testDeleteOrder() {
$pid = $this
->assertCreateAndDeleteOrderAndPayment();
$this
->assertTrue((bool) entity_load('payment', array(
$pid,
), array(), TRUE));
variable_set('payment_commerce_order_delete', TRUE);
$pid = $this
->assertCreateAndDeleteOrderAndPayment();
$this
->assertFalse((bool) entity_load('payment', array(
$pid,
), array(), TRUE));
$order = commerce_order_new();
commerce_order_save($order);
commerce_order_delete($order->order_id);
$this
->assertFalse(commerce_order_load($order->order_id));
}
function assertCreateAndDeleteOrderAndPayment() {
$order = commerce_order_new();
commerce_order_save($order);
$this
->assertTrue($order->order_id > 0);
$payment_method = $this
->paymentMethodCreate(0, payment_method_controller_load('PaymentMethodBasicController'));
$payment = payment_commerce_payment_create($order, $payment_method->pmid);
entity_save('payment', $payment);
$this
->assertTrue($payment->pid > 0);
$transaction = commerce_payment_transaction_new('payment_commerce_' . $payment->method->pmid, $payment->context_data['order_id']);
payment_commerce_transaction_fill($transaction, $payment);
commerce_payment_transaction_save($transaction);
payment_commerce_transaction_save($payment->pid, $transaction->transaction_id);
commerce_order_delete($order->order_id);
$this
->assertFalse(commerce_order_load($order->order_id));
return $payment->pid;
}
}