You are here

function CommerceNoPaymentUpgrade::testUpgrade in Commerce No Payment 7.2

Tests the upgrade process.

File

tests/CommerceNoPaymentUpgrade.test, line 41
Contains class CommerceNoPaymentUpgrade.

Class

CommerceNoPaymentUpgrade
Tests the upgrade path from Commerce no payment 7.x-1.x to 7.x-2.x.

Code

function testUpgrade() {
  $rules_configs_before = entity_load('rules_config');
  $sandbox = array();

  // Test configuration migration.
  commerce_no_payment_update_7200($sandbox);
  $this
    ->assertIdentical(count(array_diff_key(entity_load('rules_config'), $rules_configs_before)), 1);
  $this
    ->assertTrue(count(entity_load('payment_method')), 1);

  // Test content creation in two runs to verify that the batch works.
  $sandbox = array();
  commerce_no_payment_update_7201($sandbox);
  $this
    ->assertIdentical(count(entity_load('payment')), COMMERCE_NO_PAYMENT_MIGRATE_PER_RUN);
  commerce_no_payment_update_7201($sandbox);
  $payments = entity_load('payment');
  $this
    ->assertIdentical(count($payments), COMMERCE_NO_PAYMENT_MIGRATE_PER_RUN + 2);
  $count = array(
    PAYMENT_STATUS_PENDING => 0,
    PAYMENT_STATUS_FAILED => 0,
  );
  foreach ($payments as $payment) {
    $count[$payment
      ->getStatus()->status]++;
  }
  $this
    ->assertEqual($count[PAYMENT_STATUS_PENDING], COMMERCE_NO_PAYMENT_MIGRATE_PER_RUN / 2 + 1);
  $this
    ->assertEqual($count[PAYMENT_STATUS_FAILED], COMMERCE_NO_PAYMENT_MIGRATE_PER_RUN / 2 + 1);

  // Test content migration.
  $sandbox = array();
  commerce_no_payment_update_7202($sandbox);
  $this
    ->assertFalse(commerce_no_payment_commerce_payment_transaction_count('commerce_no_payment'), 0);
  $pmid = variable_get('commerce_no_payment_2_migration_pmid');
  $this
    ->assertEqual(commerce_no_payment_commerce_payment_transaction_count('payment_commerce_' . $pmid), COMMERCE_NO_PAYMENT_MIGRATE_PER_RUN + 2);
}