function UCRestrictQtyFunctionalTest::testAdminProductSettings in Ubercart Restrict Qty 7
Same name and namespace in other branches
- 6.2 tests/uc_restrict_qty.test \UCRestrictQtyFunctionalTest::testAdminProductSettings()
File
- tests/
uc_restrict_qty.test, line 101 - UC Restrict Qty auto-tests.
Class
- UCRestrictQtyFunctionalTest
- @file UC Restrict Qty auto-tests.
Code
function testAdminProductSettings() {
$admin = $this
->drupalCreateUser(array(
'administer product features',
));
$this
->drupalLogin($admin);
// Test settings' validators
$settings = array(
'uc_restrict_qty_global' => 'test',
'uc_restrict_qty_default_qty' => 1,
'uc_restrict_qty_default_lifetime' => 1,
);
$this
->drupalPost('admin/store/settings/products/edit/features', $settings, t('Save configuration'));
$this
->assertText(t('You must enter 0 or a positive number value.'), 'Settings validation [Global limit]');
$settings = array(
'uc_restrict_qty_global' => 1,
'uc_restrict_qty_default_qty' => 'test',
'uc_restrict_qty_default_lifetime' => 1,
);
$this
->drupalPost('admin/store/settings/products/edit/features', $settings, t('Save configuration'));
$this
->assertText(t('You must enter 0 or a positive number value.'), 'Settings validation [Default maximum limit for a product]');
// Submit real data
$settings = array(
'uc_restrict_qty_global' => 5,
'uc_restrict_qty_default_qty' => 2,
'uc_restrict_qty_default_lifetime' => 1,
);
$this
->drupalPost('admin/store/settings/products/edit/features', $settings, t('Save configuration'));
$this
->assertText(t('The configuration options have been saved.'), 'Settings saved');
$product = $this
->drupalCreateProduct();
// Check if feature available
$this
->drupalGet('node/' . $product->nid . '/edit/features');
$this
->assertRaw('<option value="restrict_qty">' . t('Restrict Qty') . '</option>', 'Check if feature ready to be added');
// Test feature form default values
$test = array(
'feature' => 'restrict_qty',
);
$this
->drupalPost('node/' . $product->nid . '/edit/features', $test, t('Add'));
$this
->assertRaw('<input type="text" maxlength="5" name="quantity" id="edit-quantity" size="5" value="' . $settings['uc_restrict_qty_default_qty'] . '" class="form-text" />', 'Check if defaults prefilled [qty]');
$this
->assertRaw('<input type="checkbox" name="lifetime" id="edit-lifetime" value="1" checked="checked" class="form-checkbox" />', 'Check if defaults prefilled [lifetime]');
// Test feature form submision
$product_settings = array(
'model' => $product->model,
'quantity' => 'test',
'lifetime' => 1,
);
$this
->drupalPost('node/' . $product->nid . '/edit/features/restrict_qty/add', $product_settings, t('Save feature'));
$this
->assertText(t('You must enter 0 or a positive integer value.'), 'New product feature [validation]');
// Save proper data
$product_settings['quantity'] = 1;
$this
->drupalPost('node/' . $product->nid . '/edit/features/restrict_qty/add', $product_settings, t('Save feature'));
$this
->assertText(t('The product feature has been added.'), 'New product feature [save|success message]');
$this
->assertRaw('<td nowrap="nowrap">Restrict Qty</td>', 'New product feature [save|appeared in the table]');
// Double SKU submit check
$this
->drupalPost('node/' . $product->nid . '/edit/features/restrict_qty/add', $product_settings, t('Save feature'));
$this
->assertText(t('A quantity restriction has already been set up for this SKU'), 'New product feature [validation SKU]');
$this
->drupalGet('node/' . $product->nid . '/edit/features');
if (preg_match('|node/[0-9]*/edit/features/restrict_qty/[0-9]*|', $this->content, $matches)) {
$edit_url = $matches[0];
$this
->drupalGet($edit_url);
$this
->assertRaw('<input type="text" maxlength="5" name="quantity" id="edit-quantity" size="5" value="' . $product_settings['quantity'] . '" class="form-text" />', 'Check if new data saved [qty]');
$this
->assertRaw('<input type="checkbox" name="lifetime" id="edit-lifetime" value="1" checked="checked" class="form-checkbox" />', 'Check if new data saved [lifetime]');
// Test feature form updation
$product_settings = array(
'model' => $product->model,
'quantity' => 55,
'lifetime' => FALSE,
);
$this
->drupalPost($edit_url, $product_settings, t('Save feature'));
$this
->assertText(t('The product feature has been updated.'), 'Feature updated');
$this
->drupalGet($edit_url);
$this
->assertRaw('<input type="text" maxlength="5" name="quantity" id="edit-quantity" size="5" value="' . $product_settings['quantity'] . '" class="form-text" />', 'Check if updated data saved [qty]');
$this
->assertRaw('<input type="checkbox" name="lifetime" id="edit-lifetime" value="1" class="form-checkbox" />', 'Check if updated data saved [lifetime]');
}
else {
$this
->fail('Feature edit link not found');
}
}