You are here

public function PayPalPaymentECPaymentMethodCRUD::testCRUD in PayPal for Payment 7

Tests CRUD.

File

paypal_payment_ec/tests/PayPalPaymentECPaymentMethodCRUD.test, line 35
Contains \PayPalPaymentECPaymentMethodCRUD.

Class

PayPalPaymentECPaymentMethodCRUD
Tests PayPalPaymentECPaymentMethodController CRUD.

Code

public function testCRUD() {
  $controller = payment_method_controller_load('PayPalPaymentECPaymentMethodController');
  $payment_method = new PaymentMethod(array(
    'controller' => $controller,
    'controller_data' => array(
      'server' => $controller::NVP_API_SERVER_SANDBOX,
      'capture' => $controller::CAPTURE_MANUAL,
    ),
  ));
  entity_save('payment_method', $payment_method);
  $this
    ->assertTrue($this
    ->paymentMethodControllerDataExists($payment_method, 'paypal_payment_ec_payment_method'));

  // Test loading a payment method.
  $payment_method_loaded = entity_load_single('payment_method', $payment_method->pmid);
  $this
    ->assertEqual($payment_method->controller_data, $payment_method_loaded->controller_data);

  // Test updating a payment method.
  $payment_method->controller_data = $controller->controller_data_defaults;
  entity_save('payment_method', $payment_method);
  $this
    ->assertTrue($this
    ->paymentMethodControllerDataExists($payment_method, 'paypal_payment_ec_payment_method'));

  // Test deleting a payment method.
  entity_delete('payment_method', $payment_method->pmid);
  $count = db_select('paypal_payment_ec_payment_method', 'mpi')
    ->condition('pmid', $payment_method->pmid)
    ->countQuery()
    ->execute()
    ->fetchField();
  $this
    ->assertFalse($count);
}