function CommerceBpcSettingsTest::testSettingAndRetrievingSettings in Commerce Bulk Product Creation 7
Tests saving and retrieval of settings.
File
- ./
commerce_bpc.test, line 213 - Tests for Commerce bulk product creation
Class
- CommerceBpcSettingsTest
- Unit tests for settings.
Code
function testSettingAndRetrievingSettings() {
$group = $this
->randomName();
$varname = $this
->randomName();
$product_type = drupal_strtolower($this
->randomName());
$global_value = $this
->randomName();
commerce_bpc_setting_set($group, $varname, $global_value);
$this
->assertEqual($global_value, commerce_bpc_setting($group, $varname), "Global setting retrieved as set.");
$this
->assertEqual($global_value, commerce_bpc_setting($group, $varname, $product_type), "Global setting retrieved for product type if no override specified and no type-specific value is set.");
$specific_value = $this
->randomName();
commerce_bpc_setting_set($group, $varname, $specific_value, $product_type);
$this
->assertEqual($global_value, commerce_bpc_setting($group, $varname), "Retrieval of global setting is not impaired by existence of type-specific value.");
$this
->assertEqual($global_value, commerce_bpc_setting($group, $varname, $product_type), "Global setting retrieved for product type if no override is specified, even if specific value is set.");
commerce_bpc_setting_set($group, 'override', TRUE, $product_type);
$this
->assertEqual($global_value, commerce_bpc_setting($group, $varname), "Retrieval of global value not impaired by existence of override and specific value.");
$this
->assertEqual($specific_value, commerce_bpc_setting($group, $varname, $product_type), "When override exists and a a specific value exists, the specific value is returned.");
commerce_bpc_setting_set($group, $varname, NULL, $product_type);
$this
->assertEqual($global_value, commerce_bpc_setting($group, $varname), "Retrieval of global value not impaired if override exists but no specific value.");
$this
->assertEqual($global_value, commerce_bpc_setting($group, $varname, $product_type), "If override exists, but no specific value, retrieve global value.");
commerce_bpc_setting_set($group, $varname, $specific_value, $product_type);
$second_varname = $this
->randomName();
$second_global_value = $this
->randomName();
$second_local_value = $this
->randomName();
commerce_bpc_setting_set($group, $second_varname, $second_global_value);
commerce_bpc_setting_set($group, $second_varname, $second_local_value, $product_type);
$this
->assertEqual($second_global_value, commerce_bpc_setting($group, $second_varname), "Second global value can be saved and retrieved works.");
$this
->assertEqual($second_local_value, commerce_bpc_setting($group, $second_varname, $product_type), "Second type-specific value can be retrieved and saved.");
$this
->assertEqual($global_value, commerce_bpc_setting($group, $varname), "Saving a second value does not impair retrieval of first value (global).");
$this
->assertEqual($specific_value, commerce_bpc_setting($group, $varname, $product_type), "Saving a second value does not impair retrieval of first value (type-specific).");
$group2 = $this
->randomName();
commerce_bpc_setting_set($group2, $varname, $second_global_value);
commerce_bpc_setting_set($group2, $varname, $second_local_value, $product_type);
$this
->assertEqual($second_global_value, commerce_bpc_setting($group2, $varname), "Value with same name can be saved in different group");
$this
->assertEqual($global_value, commerce_bpc_setting($group, $varname), "Saving value with same name in different group does not impact original value.");
$this
->assertEqual($second_global_value, commerce_bpc_setting($group2, $varname, $product_type), "Existence of override in one group does not influence override behavior in another.");
}