summaryrefslogtreecommitdiff
path: root/modules/field_ui
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2010-10-20 00:13:33 +0000
committerDries Buytaert <dries@buytaert.net>2010-10-20 00:13:33 +0000
commitadd6d63dbfa7aee6178320c1c63811e08bd3d08e (patch)
tree3333c0c3b4fc9809f89c3c6082d0f5b29eb075ed /modules/field_ui
parentb04836c85e7c6e62e94c396e03123b79df896518 (diff)
downloadbrdo-add6d63dbfa7aee6178320c1c63811e08bd3d08e.tar.gz
brdo-add6d63dbfa7aee6178320c1c63811e08bd3d08e.tar.bz2
- Patch #940668 by yched: Fixed 'Manage display' : Formatter change not reflected on settings.
Diffstat (limited to 'modules/field_ui')
-rw-r--r--modules/field_ui/field_ui.admin.inc22
-rw-r--r--modules/field_ui/field_ui.test269
2 files changed, 178 insertions, 113 deletions
diff --git a/modules/field_ui/field_ui.admin.inc b/modules/field_ui/field_ui.admin.inc
index 09dad0132..39c5e2716 100644
--- a/modules/field_ui/field_ui.admin.inc
+++ b/modules/field_ui/field_ui.admin.inc
@@ -175,12 +175,10 @@ function field_ui_table_pre_render($elements) {
$elements['#regions'][$region_name]['rows_order'] = array_reduce($trees[$region_name], '_field_ui_reduce_order');
}
- drupal_add_js(array('fieldUIRowsData' => $js_settings), 'setting');
- // @todo : use #attached instead when http://drupal.org/node/561858 is fixed.
-// $elements['#attached']['js'][] = array(
-// 'type' => 'setting',
-// 'data' => array('fieldRowsData' => $js_settings),
-// );
+ $elements['#attached']['js'][] = array(
+ 'type' => 'setting',
+ 'data' => array('fieldUIRowsData' => $js_settings),
+ );
return $elements;
}
@@ -956,7 +954,7 @@ function field_ui_display_overview_form($form, &$form_state, $entity_type, $bund
if ($form_state['formatter_settings_edit'] == $name) {
// We are currently editing this field's formatter settings. Display the
// settings form and submit buttons.
- $table[$name]['settings_edit_form'] = array();
+ $table[$name]['format']['settings_edit_form'] = array();
$settings_form = array();
$function = $formatter['module'] . '_field_formatter_settings_form';
@@ -1111,9 +1109,6 @@ function field_ui_display_overview_form($form, &$form_state, $entity_type, $bund
'#type' => 'submit',
'#value' => t('Refresh'),
'#op' => 'refresh_table',
- // Do not check errors, but make sure we get the values of the
- // 'refresh_rows' input.
- '#limit_validation_errors' => array(array('refresh_rows')),
'#submit' => array('field_ui_display_overview_multistep_submit'),
'#ajax' => array(
'callback' => 'field_ui_display_overview_multistep_js',
@@ -1132,11 +1127,8 @@ function field_ui_display_overview_form($form, &$form_state, $entity_type, $bund
$form['#attached']['css'][] = drupal_get_path('module', 'field_ui') . '/field_ui.css';
// Add tabledrag behavior.
- drupal_add_tabledrag('field-display-overview', 'order', 'sibling', 'field-weight');
- drupal_add_tabledrag('field-display-overview', 'match', 'parent', 'field-parent', 'field-parent', 'field-name');
-// @todo : use #attached instead when http://drupal.org/node/561858 is fixed.
-// $form['#attached']['drupal_add_tabledrag'][] = array('field-display-overview', 'order', 'sibling', 'field-weight');
-// $form['#attached']['drupal_add_tabledrag'][] = array('field-display-overview', 'match', 'parent', 'field-parent', 'field-parent', 'field-name');
+ $form['#attached']['drupal_add_tabledrag'][] = array('field-display-overview', 'order', 'sibling', 'field-weight');
+ $form['#attached']['drupal_add_tabledrag'][] = array('field-display-overview', 'match', 'parent', 'field-parent', 'field-parent', 'field-name');
return $form;
}
diff --git a/modules/field_ui/field_ui.test b/modules/field_ui/field_ui.test
index d009dbed8..43649df28 100644
--- a/modules/field_ui/field_ui.test
+++ b/modules/field_ui/field_ui.test
@@ -7,19 +7,13 @@
*/
/**
- * Field UI tests.
+ * Helper class for Field UI test classes.
*/
class FieldUITestCase extends DrupalWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'Field UI tests',
- 'description' => 'Test the field UI functionality.',
- 'group' => 'Field UI',
- );
- }
- function setUp() {
- parent::setUp('field_test');
+ function setUp($modules = array()) {
+ array_unshift($modules, 'field_test');
+ parent::setUp($modules);
// Create test user.
$admin_user = $this->drupalCreateUser(array('access content', 'administer content types', 'administer taxonomy'));
@@ -31,6 +25,119 @@ class FieldUITestCase extends DrupalWebTestCase {
$this->type = $type->type;
// Store a valid URL name, with hyphens instead of underscores.
$this->hyphen_type = str_replace('_', '-', $this->type);
+ }
+
+ /**
+ * Create a new field through the Field UI.
+ *
+ * @param $bundle_path
+ * Path of the 'Manage fields' page for the bundle.
+ * @param $initial_edit
+ * $edit parameter for drupalPost() on the first step ('Manage fields'
+ * screen).
+ * @param $field_edit
+ * $edit parameter for drupalPost() on the second step ('Field settings'
+ * form).
+ * @param $instance_edit
+ * $edit parameter for drupalPost() on the third step ('Instance settings'
+ * form).
+ */
+ function fieldUIAddNewField($bundle_path, $initial_edit, $field_edit = array(), $instance_edit = array()) {
+ // Use 'test_field' field type by default.
+ $initial_edit += array(
+ 'fields[_add_new_field][type]' => 'test_field',
+ 'fields[_add_new_field][widget_type]' => 'test_field_widget',
+ );
+ $label = $initial_edit['fields[_add_new_field][label]'];
+ $field_name = $initial_edit['fields[_add_new_field][field_name]'];
+
+ // First step : 'Add new field' on the 'Manage fields' page.
+ $this->drupalPost("$bundle_path/fields", $initial_edit, t('Save'));
+ $this->assertRaw(t('These settings apply to the %label field everywhere it is used.', array('%label' => $label)), t('Field settings page was displayed.'));
+
+ // Second step : 'Field settings' form.
+ $this->drupalPost(NULL, $field_edit, t('Save field settings'));
+ $this->assertRaw(t('Updated field %label field settings.', array('%label' => $label)), t('Redirected to instance and widget settings page.'));
+
+ // Third step : 'Instance settings' form.
+ $this->drupalPost(NULL, $instance_edit, t('Save settings'));
+ $this->assertRaw(t('Saved %label configuration.', array('%label' => $label)), t('Redirected to "Manage fields" page.'));
+
+ // Check that the field appears in the overview form.
+ $this->assertFieldByXPath('//table[@id="field-overview"]//td[1]', $label, t('Field was created and appears in the overview page.'));
+ }
+
+ /**
+ * Add an existing field through the Field UI.
+ *
+ * @param $bundle_path
+ * Path of the 'Manage fields' page for the bundle.
+ * @param $initial_edit
+ * $edit parameter for drupalPost() on the first step ('Manage fields'
+ * screen).
+ * @param $instance_edit
+ * $edit parameter for drupalPost() on the second step ('Instance settings'
+ * form).
+ */
+ function fieldUIAddExistingField($bundle_path, $initial_edit, $instance_edit = array()) {
+ // Use 'test_field_widget' by default.
+ $initial_edit += array(
+ 'fields[_add_existing_field][widget_type]' => 'test_field_widget',
+ );
+ $label = $initial_edit['fields[_add_existing_field][label]'];
+ $field_name = $initial_edit['fields[_add_existing_field][field_name]'];
+
+ // First step : 'Add existing field' on the 'Manage fields' page.
+ $this->drupalPost("$bundle_path/fields", $initial_edit, t('Save'));
+
+ // Second step : 'Instance settings' form.
+ $this->drupalPost(NULL, $instance_edit, t('Save settings'));
+ $this->assertRaw(t('Saved %label configuration.', array('%label' => $label)), t('Redirected to "Manage fields" page.'));
+
+ // Check that the field appears in the overview form.
+ $this->assertFieldByXPath('//table[@id="field-overview"]//td[1]', $label, t('Field was created and appears in the overview page.'));
+ }
+
+ /**
+ * Delete a field instance through the Field UI.
+ *
+ * @param $bundle_path
+ * Path of the 'Manage fields' page for the bundle.
+ * @param $field_name
+ * The name of the field.
+ * @param $label
+ * The label of the field.
+ * @param $bundle_label
+ * The label of the bundle.
+ */
+ function fieldUIDeleteField($bundle_path, $field_name, $label, $bundle_label) {
+ // Display confirmation form.
+ $this->drupalGet("$bundle_path/fields/$field_name/delete");
+ $this->assertRaw(t('Are you sure you want to delete the field %label', array('%label' => $label)), t('Delete confirmation was found.'));
+
+ // Submit confirmation form.
+ $this->drupalPost(NULL, array(), t('Delete'));
+ $this->assertRaw(t('The field %label has been deleted from the %type content type.', array('%label' => $label, '%type' => $bundle_label)), t('Delete message was found.'));
+
+ // Check that the field does not appear in the overview form.
+ $this->assertNoFieldByXPath('//table[@id="field-overview"]//span[@class="label-field"]', $label, t('Field does not appear in the overview page.'));
+ }
+}
+
+/**
+ * Field UI tests for the 'Manage fields' screen.
+ */
+class FieldUIManageFieldsTestCase extends FieldUITestCase {
+ public static function getInfo() {
+ return array(
+ 'name' => 'Manage fields',
+ 'description' => 'Test the Field UI "Manage fields" screen.',
+ 'group' => 'Field UI',
+ );
+ }
+
+ function setUp() {
+ parent::setUp();
// Create random field name.
$this->field_label = $this->randomName(8);
@@ -298,103 +405,69 @@ class FieldUITestCase extends DrupalWebTestCase {
$this->drupalGet($bundle_path);
$this->assertFalse($this->xpath('//select[@id="edit-add-existing-field-field-name"]//option[@value=:field_name]', array(':field_name' => $field_name)), t("The 'add existing field' select respects field types 'no_ui' property."));
}
+}
- /**
- * Create a new field through the Field UI.
- *
- * @param $bundle_path
- * Path of the 'Manage fields' page for the bundle.
- * @param $initial_edit
- * $edit parameter for drupalPost() on the first step ('Manage fields'
- * screen).
- * @param $field_edit
- * $edit parameter for drupalPost() on the first step ('Field settings'
- * form).
- * @param $instance_edit
- * $edit parameter for drupalPost() on the second step ('Instance settings'
- * form).
- */
- function fieldUIAddNewField($bundle_path, $initial_edit, $field_edit = array(), $instance_edit = array()) {
- // Use 'test_field' field type by default.
- $initial_edit += array(
- 'fields[_add_new_field][type]' => 'test_field',
- 'fields[_add_new_field][widget_type]' => 'test_field_widget',
+/**
+ * Field UI tests for the 'Manage display' screens.
+ */
+class FieldUIManageDisplayTestCase extends FieldUITestCase {
+ public static function getInfo() {
+ return array(
+ 'name' => 'Manage display',
+ 'description' => 'Test the Field UI "Manage display" screens.',
+ 'group' => 'Field UI',
);
- $label = $initial_edit['fields[_add_new_field][label]'];
- $field_name = $initial_edit['fields[_add_new_field][field_name]'];
-
- // First step : 'Add new field' on the 'Manage fields' page.
- $this->drupalPost("$bundle_path/fields", $initial_edit, t('Save'));
- $this->assertRaw(t('These settings apply to the %label field everywhere it is used.', array('%label' => $label)), t('Field settings page was displayed.'));
-
- // Second step : 'Field settings' form.
- $this->drupalPost(NULL, $field_edit, t('Save field settings'));
- $this->assertRaw(t('Updated field %label field settings.', array('%label' => $label)), t('Redirected to instance and widget settings page.'));
-
- // Assert the field settings are correct.
- $this->assertFieldSettings($this->type, $this->field_name);
-
- // Third step : 'Instance settings' form.
- $this->drupalPost(NULL, $instance_edit, t('Save settings'));
- $this->assertRaw(t('Saved %label configuration.', array('%label' => $label)), t('Redirected to "Manage fields" page.'));
-
- // Check that the field appears in the overview form.
- $this->assertFieldByXPath('//table[@id="field-overview"]//td[1]', $label, t('Field was created and appears in the overview page.'));
}
- /**
- * Add an existing field through the Field UI.
- *
- * @param $bundle_path
- * Path of the 'Manage fields' page for the bundle.
- * @param $initial_edit
- * $edit parameter for drupalPost() on the first step ('Manage fields'
- * screen).
- * @param $instance_edit
- * $edit parameter for drupalPost() on the second step ('Instance settings'
- * form).
- */
- function fieldUIAddExistingField($bundle_path, $initial_edit, $instance_edit = array()) {
- // Use 'test_field_widget' by default.
- $initial_edit += array(
- 'fields[_add_existing_field][widget_type]' => 'test_field_widget',
- );
- $label = $initial_edit['fields[_add_existing_field][label]'];
- $field_name = $initial_edit['fields[_add_existing_field][field_name]'];
-
- // First step : 'Add existing field' on the 'Manage fields' page.
- $this->drupalPost("$bundle_path/fields", $initial_edit, t('Save'));
-
- // Second step : 'Instance settings' form.
- $this->drupalPost(NULL, $instance_edit, t('Save settings'));
- $this->assertRaw(t('Saved %label configuration.', array('%label' => $label)), t('Redirected to "Manage fields" page.'));
-
- // Check that the field appears in the overview form.
- $this->assertFieldByXPath('//table[@id="field-overview"]//td[1]', $label, t('Field was created and appears in the overview page.'));
+ function setUp() {
+ parent::setUp(array('search'));
}
/**
- * Delete a field instance through the Field UI.
- *
- * @param $bundle_path
- * Path of the 'Manage fields' page for the bundle.
- * @param $field_name
- * The name of the field.
- * @param $label
- * The label of the field.
- * @param $bundle_label
- * The label of the bundle.
+ * Test formatter formatter settings.
*/
- function fieldUIDeleteField($bundle_path, $field_name, $label, $bundle_label) {
- // Display confirmation form.
- $this->drupalGet("$bundle_path/fields/$field_name/delete");
- $this->assertRaw(t('Are you sure you want to delete the field %label', array('%label' => $label)), t('Delete confirmation was found.'));
+ function testFormatterUI() {
+ $manage_fields = 'admin/structure/types/manage/' . $this->hyphen_type;
+ $manage_display = $manage_fields . '/display';
- // Submit confirmation form.
- $this->drupalPost(NULL, array(), t('Delete'));
- $this->assertRaw(t('The field %label has been deleted from the %type content type.', array('%label' => $label, '%type' => $bundle_label)), t('Delete message was found.'));
+ // Create a field, and a node with some data for the field.
+ $edit = array(
+ 'fields[_add_new_field][label]' => 'Test field',
+ 'fields[_add_new_field][field_name]' => 'field_test',
+ );
+ $this->fieldUIAddNewField($manage_fields, $edit);
- // Check that the field doesn not appear in the overview form
- $this->assertNoFieldByXPath('//table[@id="field-overview"]//span[@class="label-field"]', $label, t('Field does not appear in the overview page.'));
+ // Clear the test-side cache and get the saved field instance.
+ field_info_cache_clear();
+ $instance = field_info_instance('node', 'field_test', $this->type);
+ $format = $instance['display']['default']['type'];
+ $default_settings = field_info_formatter_settings($format);
+ $setting_name = key($default_settings);
+ $setting_value = $instance['display']['default']['settings'][$setting_name];
+
+ // Display the "Manage display" screen and check that the expected formatter is
+ // selected.
+ $this->drupalGet($manage_display);
+ $this->assertFieldByName('fields[field_test][type]', $format, t('The expected formatter is selected.'));
+ $this->assertText("$setting_name: $setting_value", t('The expected summary is displayed.'));
+
+ // Change the formatter and check that the summary is updated.
+ $edit = array('fields[field_test][type]' => 'field_test_multiple', 'refresh_rows' => 'field_test');
+ $this->drupalPostAJAX(NULL, $edit, array('op' => t('Refresh')));
+ $format = 'field_test_multiple';
+ $default_settings = field_info_formatter_settings($format);
+ $setting_name = key($default_settings);
+ $setting_value = $default_settings[$setting_name];
+ $this->assertFieldByName('fields[field_test][type]', $format, t('The expected formatter is selected.'));
+ $this->assertText("$setting_name: $setting_value", t('The expected summary is displayed.'));
+
+ // Submit the form and check that the instance is updated.
+ $this->drupalPost(NULL, array(), t('Save'));
+ field_info_cache_clear();
+ $instance = field_info_instance('node', 'field_test', $this->type);
+ $current_format = $instance['display']['default']['type'];
+ $current_setting_value = $instance['display']['default']['settings'][$setting_name];
+ $this->assertEqual($current_format, $format, t('The formatter was updated.'));
+ $this->assertEqual($current_setting_value, $setting_value, t('The setting was updated.'));
}
}