function CommerceRecurringTestCase::testCreateRecurringProduct in Commerce Recurring Framework 7.2
Test creating a recurring product.
File
- tests/
commerce_recurring.test, line 131 - Unit tests for the commerce recurring module.
Class
- CommerceRecurringTestCase
- @file Unit tests for the commerce recurring module.
Code
function testCreateRecurringProduct() {
$store_admin = $this
->createStoreAdmin();
$this
->drupalLogin($store_admin);
$this
->drupalGet('admin/commerce/products/add/recurring');
foreach (array(
'commerce_recurring_ini_period',
'commerce_recurring_rec_period',
'commerce_recurring_end_period',
) as $field_name) {
$instance = field_info_instance('commerce_product', $field_name, 'recurring');
$period[] = array_rand($instance['settings']['allowed_periods'], 1);
}
// Create the recurring product.
$edit = array(
'sku' => 'PROD-01',
'title' => $this
->randomName(10),
'commerce_price[und][0][amount]' => commerce_currency_amount_to_decimal(rand(200, 50000), 'USD'),
'commerce_recurring_ini_price[und][0][amount]' => commerce_currency_amount_to_decimal(rand(200, 50000), 'USD'),
'commerce_recurring_rec_price[und][0][amount]' => commerce_currency_amount_to_decimal(rand(200, 50000), 'USD'),
'commerce_recurring_ini_period[und][0][interval]' => rand(2, 10),
'commerce_recurring_ini_period[und][0][period]' => $period[0],
'commerce_recurring_rec_period[und][0][interval]' => rand(2, 10),
'commerce_recurring_rec_period[und][0][period]' => $period[1],
'commerce_recurring_end_period[und][0][interval]' => rand(2, 10),
'commerce_recurring_end_period[und][0][period]' => $period[2],
'status' => 1,
);
$this
->drupalPost(NULL, $edit, t('Save product'));
$this
->assertText(t('Product saved.'), t('%message message is present', array(
'%message' => t('Product saved'),
)));
$this
->assertText(t('Recurring product'), t('Recurring product type name found after creating a product of that type'));
// Check the product in database.
$product = commerce_product_load_by_sku($edit['sku']);
$product_wrapper = entity_metadata_wrapper('commerce_product', $product);
$this
->pass(t('Test the product edit in database:'));
$this
->assertTrue($product_wrapper->sku
->value() == $edit['sku'], t('SKU stored in database correctly set'));
$this
->assertTrue($product_wrapper->title
->value() == $edit['title'], t('Title stored in database correctly set'));
$this
->assertTrue(commerce_currency_amount_to_decimal($product_wrapper->commerce_price->amount
->value(), $product_wrapper->commerce_price->currency_code
->value()) == $edit['commerce_price[und][0][amount]'], t('Amount stored in database correctly set'));
$this
->assertTrue($product->status == $edit['status'], t('Status stored in database correctly set'));
$this
->assertTrue(commerce_currency_amount_to_decimal($product_wrapper->commerce_recurring_ini_price->amount
->value(), $product_wrapper->commerce_recurring_ini_price->currency_code
->value()) == $edit['commerce_recurring_ini_price[und][0][amount]'], t('Initial amount stored in database correctly set'));
$this
->assertTrue(commerce_currency_amount_to_decimal($product_wrapper->commerce_recurring_rec_price->amount
->value(), $product_wrapper->commerce_recurring_rec_price->currency_code
->value()) == $edit['commerce_recurring_rec_price[und][0][amount]'], t('Recurring amount stored in database correctly set'));
$this
->assertTrue($product_wrapper->commerce_recurring_ini_period->interval
->value() == $edit['commerce_recurring_ini_period[und][0][interval]'], t('Initial period stored in database correctly set'));
$this
->assertTrue($product_wrapper->commerce_recurring_ini_period->period
->value() == $edit['commerce_recurring_ini_period[und][0][period]'], t('Initial interval stored in database correctly set'));
$this
->assertTrue($product_wrapper->commerce_recurring_rec_period->interval
->value() == $edit['commerce_recurring_rec_period[und][0][interval]'], t('Initial period stored in database correctly set'));
$this
->assertTrue($product_wrapper->commerce_recurring_rec_period->period
->value() == $edit['commerce_recurring_rec_period[und][0][period]'], t('Initial interval stored in database correctly set'));
$this
->assertTrue($product_wrapper->commerce_recurring_end_period->interval
->value() == $edit['commerce_recurring_end_period[und][0][interval]'], t('Initial period stored in database correctly set'));
$this
->assertTrue($product_wrapper->commerce_recurring_end_period->period
->value() == $edit['commerce_recurring_end_period[und][0][period]'], t('Initial interval stored in database correctly set'));
}