function PaymentreferenceTestQueueWebTestCase::testQueueCRUD in Payment 7
File
- modules/
paymentreference/ tests/ paymentreference_test/ tests/ PaymentreferenceTestQueueWebTestCase.test, line 31 - Contains class PaymentreferenceTestQueueWebTestCase.
Class
- PaymentreferenceTestQueueWebTestCase
- Tests the reference queue.
Code
function testQueueCRUD() {
$payment_method = $this
->paymentMethodCreate(1, payment_method_controller_load('PaymentMethodControllerUnavailable'));
$payment = $this
->paymentCreate(2, $payment_method);
$payment
->setStatus(new PaymentStatusItem(PAYMENT_STATUS_SUCCESS));
entity_save('payment', $payment);
$entity_type = 'foo';
$bundle = 'bar';
$field_name = 'baz';
// Test queueing a payment.
paymentreference_insert($entity_type, $bundle, $field_name, $payment->pid);
$count = db_query("SELECT COUNT(1) FROM {paymentreference} WHERE entity_type = :entity_type AND bundle = :bundle AND field_name = :field_name AND pid = :pid", array(
':entity_type' => $entity_type,
':bundle' => $bundle,
':field_name' => $field_name,
':pid' => $payment->pid,
))
->fetchField();
$this
->assertTrue($count, 'A payment is saved to the queue correctly.');
// Test loading a queued payment.
$pid = paymentreference_load($entity_type, $bundle, $field_name, $payment->uid);
$this
->assertTrue((bool) $pid, 'A queued payment is loaded correctly.');
$pid = paymentreference_load('bar', $bundle, $field_name, $payment->uid);
$this
->assertFalse($pid, 'Loading a queued payment using the wrong entity type fails.');
$pid = paymentreference_load($entity_type, 'baz', $field_name, $payment->uid);
$this
->assertFalse($pid, 'Loading a queued payment using the wrong bundle fails.');
$pid = paymentreference_load($entity_type, $bundle, 'foo', $payment->uid);
$this
->assertFalse($pid, 'Loading a queued payment using the wrong field name fails.');
$pid = paymentreference_load($entity_type, $bundle, $field_name, $payment->uid + 1);
$this
->assertFalse($pid, 'Loading a queued payment using the wrong UID fails.');
// Test deleting a payment from the queue.
paymentreference_delete_by_pid($payment->pid);
$count = db_query("SELECT COUNT(1) FROM {paymentreference} WHERE pid = :pid", array(
':pid' => $payment->pid,
))
->fetchField();
$this
->assertFalse($count, 'A payment can be deleted from the queue by PID.');
paymentreference_insert($entity_type, $bundle, $field_name, $payment->pid);
paymentreference_delete_by_field($field_name);
$count = db_query("SELECT COUNT(1) FROM {paymentreference} WHERE field_name = :field_name", array(
':field_name' => $field_name,
))
->fetchField();
$this
->assertFalse($count, 'A payment can be deleted from the queue by field name.');
paymentreference_insert($entity_type, $bundle, $field_name, $payment->pid);
paymentreference_delete_by_field_instance($entity_type, $bundle, $field_name);
$count = db_query("SELECT COUNT(1) FROM {paymentreference} WHERE entity_type = :entity_type AND bundle = :bundle AND field_name = :field_name", array(
':entity_type' => $entity_type,
':bundle' => $bundle,
':field_name' => $field_name,
))
->fetchField();
$this
->assertFalse($count, 'A payment can be deleted from the queue by field instance.');
}