public function CommerceDiscountTest::testCommerceDiscountImport in Commerce Discount 7
Test the importing of commerce discounts.
File
- tests/
commerce_discount.test, line 27 - Commerce Discounts tests.
Class
- CommerceDiscountTest
- Testing commerce discounts functionality.
Code
public function testCommerceDiscountImport() {
$exported_discount = '{
"name" : "pf",
"label" : "PF",
"type" : "product_discount",
"status" : "1",
"component_title" : "pf",
"sort_order" : "10",
"commerce_discount_offer" : {
"type" : "fixed_amount",
"commerce_fixed_amount" : { "und" : [
{
"amount" : "1200",
"currency_code" : "USD",
"data" : { "components" : [] }
}
]
}
},
"commerce_compatibility_strategy" : { "und" : [ { "value" : "any" } ] },
"commerce_compatibility_selection" : [],
"commerce_discount_date" : [],
"inline_conditions" : [],
"discount_usage_per_person" : [],
"discount_usage_limit" : []
}';
// Import the discount.
$import = entity_import('commerce_discount', $exported_discount);
$this
->assertNotNull($import, 'Entity export JSON imported successfully.');
entity_save('commerce_discount', $import);
// Export the discount to make sure it's identical to the import string.
$discount = entity_load_single('commerce_discount', $import->discount_id);
$export = entity_export('commerce_discount', $discount);
$this
->assertTrue($exported_discount == $export, 'Exported discount is identical to its origin.');
}