public function UbercartAttributeTestCase::testAttributeUIAddAttribute in Ubercart 7.3
Same name and namespace in other branches
- 6.2 uc_attribute/uc_attribute.test \UbercartAttributeTestCase::testAttributeUIAddAttribute()
Tests the "add attribute" user interface.
File
- uc_attribute/
tests/ uc_attribute.test, line 311 - Ubercart Attribute Tests.
Class
- UbercartAttributeTestCase
- SimpleTests for the Ubercart Attributes API.
Code
public function testAttributeUIAddAttribute() {
$this
->drupalGet('admin/store/products/attributes/add');
$this
->assertText(t('The name of the attribute used in administrative forms'), t('Attribute add form working.'));
$edit = (array) self::createAttribute(array(), FALSE);
$this
->drupalPost('admin/store/products/attributes/add', $edit, t('Submit'));
if ($edit['display'] != 0) {
// We redirect to add options page ONLY for non-textfield attributes.
$this
->assertText('Options for ' . $edit['name']);
$this
->assertText('No options for this attribute have been added yet.');
}
else {
// For textfield attributes we redirect to attribute list.
}
$this
->drupalGet('admin/store/products/attributes');
$this
->assertRaw('<td class="active">' . $edit['name'] . '</td>', t('Verify name field.'));
$this
->assertRaw('<td>' . $edit['label'] . '</td>', t('Verify label field.'));
$this
->assertRaw('<td>' . ($edit['required'] ? t('Yes') : t('No')) . '</td>', t('Verify required field.'));
$this
->assertRaw('<td>' . $edit['ordering'] . '</td>', t('Verify ordering field.'));
$types = _uc_attribute_display_types();
$this
->assertRaw('<td>' . $types[$edit['display']] . '</td>', t('Verify display field.'));
$aid = db_query("SELECT aid FROM {uc_attributes} WHERE name = :name", array(
':name' => $edit['name'],
))
->fetchField();
$this
->assertTrue($aid, t('Attribute was created.'));
$attribute = uc_attribute_load($aid);
$fields_ok = TRUE;
foreach ($edit as $field => $value) {
if ($attribute->{$field} != $value) {
$this
->showVar($attribute);
$this
->showVar($edit);
$fields_ok = FALSE;
break;
}
}
$this
->assertTrue($fields_ok, t('Attribute created properly.'));
}