function PaymentTestEntityCrudWebTestCase::testPaymentCRUD in Payment 7
Test payment CRUD functionality.
File
- tests/
payment_test/ tests/ PaymentTestEntityCrudWebTestCase.test, line 95 - Contains class PaymentTestEntityCrudWebTestCase.
Class
- PaymentTestEntityCrudWebTestCase
- Tests entity CRUD functionality.
Code
function testPaymentCRUD() {
$schema = drupal_get_schema('payment');
$payment_method = $this
->paymentMethodCreate(1, payment_method_controller_load('PaymentMethodControllerUnavailable'));
entity_save('payment_method', $payment_method);
// Test inserting a payment.
$payment = new Payment(array(
'currency_code' => 'foo',
'description' => 'bar',
'finish_callback' => 'payment_test_finish_callback',
'method' => $payment_method,
));
entity_save('payment', $payment);
$query = db_select('payment');
foreach ($schema['fields'] as $name => $definition) {
if (property_exists($payment, $name)) {
if (!empty($definition['serialize'])) {
$query
->condition($name, serialize($payment->{$name}));
}
else {
$query
->condition($name, $payment->{$name});
}
}
}
$count = $query
->countQuery()
->execute()
->fetchField();
$this
->assertTrue($count, 'A new payment is correctly inserted.');
// Test loading a payment.
$payment_loaded = entity_load_single('payment', $payment->pid);
$this
->assertTrue($payment_loaded instanceof Payment);
// Test updating a payment.
$payment->currency_code = 'bar';
$payment->description = 'foo';
entity_save('payment', $payment);
$query = db_select('payment');
foreach ($schema['fields'] as $name => $definition) {
if (property_exists($payment, $name)) {
if (!empty($definition['serialize'])) {
$query
->condition($name, serialize($payment->{$name}));
}
else {
$query
->condition($name, $payment->{$name});
}
}
}
$count = $query
->countQuery()
->execute()
->fetchField();
$this
->assertTrue($count, 'A payment is correctly updated.');
// Test deleting a payment.
entity_delete('payment', $payment->pid);
$count = db_select('payment')
->condition('pid', $payment->pid)
->countQuery()
->execute()
->fetchField();
$this
->assertFalse($count, 'A payment is correctly deleted.');
}