You are here

function PaymentWebformTestQueueWebTestCase::testQueueWebformImplementation in Payment for Webform 7

File

tests/PaymentWebformTestQueueWebTestCase.test, line 54

Class

PaymentWebformTestQueueWebTestCase

Code

function testQueueWebformImplementation() {

  // Create a webform node.
  $node = $this
    ->drupalCreateNode(array(
    'type' => 'webform',
  ));

  // Create a component.
  $component = array(
    'nid' => $node->nid,
    'pid' => 0,
    'form_key' => 'foo',
    'name' => 'foo',
    'type' => 'payment_webform',
    'extra' => array(),
    'mandatory' => TRUE,
    'weight' => 0,
  );
  $cid = webform_component_insert($component);

  // Create two payments
  $payment_method = $this
    ->paymentMethodCreate(1, payment_method_controller_load('PaymentMethodControllerUnavailable'));
  foreach (range(1, 2) as $pid) {
    $payment = $this
      ->paymentCreate(2, $payment_method);
    $payment
      ->setStatus(new PaymentStatusItem(PAYMENT_STATUS_SUCCESS));
    entity_save('payment', $payment);
    payment_webform_insert($cid, $pid);
  }

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

  // Test response to component deletion.
  webform_component_delete($node, $component);
  $pid = payment_webform_load($cid, 2);
  $this
    ->assertNotEqual($pid, 2, 'When deleting a component, all payments associated with it are removed from the queue.');
}