diff options
author | Dries Buytaert <dries@buytaert.net> | 2010-10-20 00:13:33 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2010-10-20 00:13:33 +0000 |
commit | add6d63dbfa7aee6178320c1c63811e08bd3d08e (patch) | |
tree | 3333c0c3b4fc9809f89c3c6082d0f5b29eb075ed /modules/field_ui/field_ui.test | |
parent | b04836c85e7c6e62e94c396e03123b79df896518 (diff) | |
download | brdo-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/field_ui.test')
-rw-r--r-- | modules/field_ui/field_ui.test | 269 |
1 files changed, 171 insertions, 98 deletions
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.')); } } |