public function CommerceProductReferenceAdminTest::testCommerceProductReferenceEditField in Commerce Core 7
Test editing the field.
File
- modules/
product_reference/ tests/ commerce_product_reference.test, line 117 - Tests for adding and displaying product reference fields.
Class
- CommerceProductReferenceAdminTest
- Functional tests for the Product Reference module.
Code
public function testCommerceProductReferenceEditField() {
// Navigate to the edit field page.
$this
->drupalGet('admin/structure/types/manage/' . strtr($this->display_type->type, '_', '-') . '/fields/field_product');
// Alter the field to be required and unlimited.
$edit = array(
'instance[required]' => 1,
'field[cardinality]' => -1,
);
$this
->drupalPost(NULL, $edit, t('Save settings'));
// Check the message of configuration saved.
$this
->assertRaw(t('Saved %label configuration.', array(
'%label' => $this->field_instance['label'],
)), t('Message of saved field displayed'));
// Navigate again to the edit field page to check if the values have been
// saved.
$this
->drupalGet('admin/structure/types/manage/' . strtr($this->display_type->type, '_', '-') . '/fields/' . $this->field_name);
$this
->assertFieldChecked('edit-instance-required', t('Required field is checked'));
$this
->assertOptionSelected('edit-field-cardinality', -1, t('Field can have unlimited values'));
$this
->assertFieldByXPath("//select[@id='edit-field-product-und' and @multiple='multiple']", NULL, t('Multiple product selector for default values'));
// Clear field's cache.
field_cache_clear();
// Also the product creation form should have the field required and with
// a multiple select widget.
$this
->drupalGet('node/add');
$this
->drupalGet('node/add/' . strtr($this->display_type->type, '_', '-'));
$this
->assertFieldByXPath("//select[@id='edit-field-product-und' and @multiple='multiple']", NULL, t('Multiple product selector for default values'));
}