You are here

public function PayPalPaymentIPNControllerTest::testValidate in PayPal for Payment 7

Tests validate().

File

paypal_payment_ipn/tests/PayPalPaymentIPNControllerTest.test, line 99
Contains \PayPalPaymentIPNControllerTest.

Class

PayPalPaymentIPNControllerTest
Tests PayPalPaymentIPNController functionality.

Code

public function testValidate() {
  $payment_method = $this
    ->paymentMethodCreate(2, payment_method_controller_load('PayPalPaymentIPNTestPaymentMethodController'));
  entity_save('payment_method', $payment_method);
  $payment = $this
    ->paymentCreate(2, $payment_method);
  entity_save('payment', $payment);

  // Test valid IPN variables.
  $ipn_variables = $this
    ->mockIPNVariables($payment->pid);
  $this
    ->assertTrue(PayPalPaymentIPNController::validate($ipn_variables));

  // Test an already processed IPN.
  $ipn = new PayPalPaymentIPN($ipn_variables);
  $ipn->pid = PayPalPaymentIPNController::PID($ipn_variables['invoice']);
  PayPalPaymentIPNController::save($ipn);
  $this
    ->assertTrue(PayPalPaymentIPNController::validate($ipn_variables));

  // Test IPN variables for which no Payment exists.
  $ipn_variables = $this
    ->mockIPNVariables(999);
  $this
    ->assertFalse(PayPalPaymentIPNController::validate($ipn_variables));
}