public function MultifieldTableTest::testMultifieldTableBasic in Multifield table 7
Performs the basic tests.
File
- ./
multifield_table.test, line 126
Class
Code
public function testMultifieldTableBasic() {
$this->multifield = drupal_strtolower($this
->randomName());
$edit = array(
'label' => $this->multifield,
'machine_name' => $this->multifield,
);
$this
->drupalPost('admin/structure/multifield/add', $edit, t('Save'));
$this->multifield_path = 'admin/structure/multifield/manage/' . str_replace('_', '-', $this->multifield);
// Define fields array.
$fields = array(
'text' => array(
'type' => 'text',
'widget' => 'text_textfield',
'label' => $this
->randomName(),
'name' => drupal_strtolower($this
->randomName()),
'value' => $this
->randomName(),
),
'longtext' => array(
'type' => 'text_long',
'widget' => 'text_textarea',
'label' => $this
->randomName(),
'name' => drupal_strtolower($this
->randomName()),
'value' => $this
->randomName(32),
),
'integer' => array(
'type' => 'number_integer',
'widget' => 'number',
'label' => $this
->randomName(),
'name' => drupal_strtolower($this
->randomName()),
'value' => rand(0, 999),
),
);
// Generate fields.
foreach ($fields as $field) {
$edit = array(
'fields[_add_new_field][type]' => $field['type'],
'fields[_add_new_field][widget_type]' => $field['widget'],
'fields[_add_new_field][label]' => $field['label'],
'fields[_add_new_field][field_name]' => $field['name'],
);
$this
->fieldUIAddNewField($this->multifield_path, $edit);
}
// Create the multifield field.
$bundle_path = 'admin/structure/types/manage/' . $this->hyphen_type;
$edit = array(
'fields[_add_new_field][type]' => $this->multifield,
'fields[_add_new_field][widget_type]' => 'multifield_default',
'fields[_add_new_field][label]' => 'Multifield',
'fields[_add_new_field][field_name]' => 'multifield',
);
$this
->fieldUIAddNewField($bundle_path, $edit);
// Set Multifield table as formatter.
$manage_display = $bundle_path . '/display';
$edit = array(
'fields[field_multifield][type]' => 'multifield_table',
);
$this
->drupalPost($manage_display, $edit, t('Save'));
// Go to node creation page.
$edit = array(
'title' => $this
->randomName(),
);
foreach ($fields as $field) {
$edit["field_multifield[und][0][field_{$field['name']}][und][0][value]"] = $field['value'];
}
$this
->drupalPost('node/add/' . $this->hyphen_type, $edit, t('Save'));
$this->node_url = $this
->getUrl();
// Check table is generated successfully.
$this
->checkMultifieldTable($fields);
// Change multifield fields position.
$shuffled_fields = $this
->shuffleAssoc($fields);
$position = 0;
$edit = array();
foreach ($shuffled_fields as $field) {
$position++;
$edit["fields[field_{$field['name']}][weight]"] = $position;
}
$this
->drupalPost($this->multifield_path . '/display', $edit, t('Save'));
// Check that table items respect multifield display weights.
$this
->drupalGet($this->node_url);
$this
->checkMultifieldTable($shuffled_fields);
}