You are here

function PaymentreferenceTestQueueWebTestCase::testQueueFieldImplementation in Payment 7

File

modules/paymentreference/tests/paymentreference_test/tests/PaymentreferenceTestQueueWebTestCase.test, line 84
Contains class PaymentreferenceTestQueueWebTestCase.

Class

PaymentreferenceTestQueueWebTestCase
Tests the reference queue.

Code

function testQueueFieldImplementation() {

  // Create a field, two instances and three payments.
  $entity_type = 'node';
  $bundles = array(
    1 => 'article',
    2 => 'article',
    3 => 'page',
  );
  $field_name = 'baz';
  $field = array(
    'field_name' => $field_name,
    'type' => 'paymentreference',
  );
  field_create_field($field);
  $instance_article = $instance_page = array(
    'entity_type' => $entity_type,
    'field_name' => $field_name,
  );
  $instance_article['bundle'] = $bundles[1];
  $instance_article = field_create_instance($instance_article);
  $instance_page['bundle'] = $bundles[3];
  $instance_page = field_create_instance($instance_page);
  $payment_method = $this
    ->paymentMethodCreate(1, payment_method_controller_load('PaymentMethodControllerUnavailable'));
  foreach (range(1, 3) as $pid) {
    $payment = $this
      ->paymentCreate(2, $payment_method);
    $payment
      ->setStatus(new PaymentStatusItem(PAYMENT_STATUS_SUCCESS));
    entity_save('payment', $payment);
    paymentreference_insert($entity_type, $bundles[$pid], $field_name, $pid);
  }

  // Test response to payment deletion.
  entity_delete('payment', 1);
  $pid = paymentreference_load($entity_type, $bundles[1], $field_name, 2);
  $this
    ->assertNotEqual($pid, 1, 'When deleting a payment, it is removed from the queue as well.');

  // Test response to field instance deletion.
  field_delete_instance($instance_article);
  $pid = paymentreference_load($entity_type, $bundles[2], $field_name, 2);
  $this
    ->assertNotEqual($pid, 2, 'When deleting a field instance, all payments associated with it are removed from the queue.');

  // Test response to field deletion.
  field_delete_field($field_name);
  $pid = paymentreference_load($entity_type, $bundles[3], $field_name, 2);
  $this
    ->assertFalse($pid, 'When deleting a field, all payments associated with it are removed from the queue.');
}