CommerceNoPaymentUpgrade.test in Commerce No Payment 7.2
Contains class CommerceNoPaymentUpgrade.
File
tests/CommerceNoPaymentUpgrade.testView source
<?php
/**
* @file
* Contains class CommerceNoPaymentUpgrade.
*/
/**
* Tests the upgrade path from Commerce no payment 7.x-1.x to 7.x-2.x.
*/
class CommerceNoPaymentUpgrade extends DrupalWebTestCase {
/**
* Implements DrupalTestCase::getInfo().
*/
static function getInfo() {
return array(
'name' => 'Upgrade path',
'group' => 'No Payment',
'dependencies' => array(
'commerce_no_payment',
),
);
}
/**
* Overrides parent::setUp().
*/
function setUp(array $modules = array()) {
$this->profile = 'testing';
parent::setUp($modules + array(
'commerce_no_payment',
));
$sets = round(COMMERCE_NO_PAYMENT_MIGRATE_PER_RUN / 2 + 1);
while ($sets) {
$this
->createTransaction(COMMERCE_PAYMENT_STATUS_PENDING);
$this
->createTransaction(COMMERCE_PAYMENT_STATUS_FAILURE);
$sets--;
}
}
/**
* Tests the upgrade process.
*/
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);
}
/**
* Creates a Commerce Payment transaction.
*
* @param string $transaction_status
*
* @return NULL
*/
function createTransaction($transaction_status) {
$transaction = commerce_payment_transaction_new('commerce_no_payment', 1);
$transaction->instance_id = 'commerce_no_payment|commerce_payment_commerce_no_payment';
$transaction->amount = 999;
$transaction->currency_code = 'EUR';
$transaction->status = $transaction_status;
commerce_payment_transaction_save($transaction);
}
}
Classes
Name | Description |
---|---|
CommerceNoPaymentUpgrade | Tests the upgrade path from Commerce no payment 7.x-1.x to 7.x-2.x. |