summaryrefslogtreecommitdiff
path: root/modules/field_ui/field_ui.test
diff options
context:
space:
mode:
authorAngie Byron <webchick@24967.no-reply.drupal.org>2010-10-23 00:54:39 +0000
committerAngie Byron <webchick@24967.no-reply.drupal.org>2010-10-23 00:54:39 +0000
commit21b41548ccf1c83ca480d216a51f30222d15cd0a (patch)
treebd3880a61175fae12a406cb3364b79563174bd1f /modules/field_ui/field_ui.test
parent85dd04fec51a64b4f7bc9ede93b313b3d5daf8ef (diff)
downloadbrdo-21b41548ccf1c83ca480d216a51f30222d15cd0a.tar.gz
brdo-21b41548ccf1c83ca480d216a51f30222d15cd0a.tar.bz2
#886152 by yched, pwolanin, hefox, chx, rszrama, ksenzee: Fixed All fields are hidden after the administrator newly configures a view mode to not use 'default' display.
Diffstat (limited to 'modules/field_ui/field_ui.test')
-rw-r--r--modules/field_ui/field_ui.test147
1 files changed, 147 insertions, 0 deletions
diff --git a/modules/field_ui/field_ui.test b/modules/field_ui/field_ui.test
index 43649df28..f1102488c 100644
--- a/modules/field_ui/field_ui.test
+++ b/modules/field_ui/field_ui.test
@@ -470,4 +470,151 @@ class FieldUIManageDisplayTestCase extends FieldUITestCase {
$this->assertEqual($current_format, $format, t('The formatter was updated.'));
$this->assertEqual($current_setting_value, $setting_value, t('The setting was updated.'));
}
+
+ /**
+ * Test switching view modes to use custom or 'default' settings'.
+ */
+ function testViewModeCustom() {
+ // 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('admin/structure/types/manage/' . $this->hyphen_type, $edit);
+ $value = rand(1, 100);
+ $settings = array(
+ 'type' => $this->type,
+ 'field_test' => array(LANGUAGE_NONE => array(array('value' => $value))),
+ );
+ $node = $this->drupalCreateNode($settings);
+
+ // Gather expected output values with the various formatters.
+ $formatters = field_info_formatter_types();
+ $output = array(
+ 'field_test_default' => $formatters['field_test_default']['settings']['test_formatter_setting'] . '|' . $value,
+ 'field_test_with_prepare_view' => $formatters['field_test_with_prepare_view']['settings']['test_formatter_setting_additional'] . '|' . $value. '|' . ($value + 1),
+ );
+
+ // Check that the field is displayed with the default formatter in 'rss'
+ // mode (uses 'default'), and hidden in 'teaser' mode (uses custom settings).
+ $this->assertNodeViewText($node, 'rss', $output['field_test_default'], t("The field is displayed as expected in view modes that use 'default' settings."));
+ $this->assertNodeViewNoText($node, 'teaser', $value, t("The field is hidden in view modes that use custom settings."));
+
+ // Change fomatter for 'default' mode, check that the field is displayed
+ // accordingly in 'rss' mode.
+ $edit = array(
+ 'fields[field_test][type]' => 'field_test_with_prepare_view',
+ );
+ $this->drupalPost('admin/structure/types/manage/' . $this->hyphen_type . '/display', $edit, t('Save'));
+ $this->assertNodeViewText($node, 'rss', $output['field_test_with_prepare_view'], t("The field is displayed as expected in view modes that use 'default' settings."));
+
+ // Specialize the 'rss' mode, check that the field is displayed the same.
+ $edit = array(
+ "view_modes_custom[rss]" => TRUE,
+ );
+ $this->drupalPost('admin/structure/types/manage/' . $this->hyphen_type . '/display', $edit, t('Save'));
+ $this->assertNodeViewText($node, 'rss', $output['field_test_with_prepare_view'], t("The field is displayed as expected in newly specialized 'rss' mode."));
+
+ // Set the field to 'hidden' in the view mode, check that the field is
+ // hidden.
+ $edit = array(
+ 'fields[field_test][type]' => 'hidden',
+ );
+ $this->drupalPost('admin/structure/types/manage/' . $this->hyphen_type . '/display/rss', $edit, t('Save'));
+ $this->assertNodeViewNoText($node, 'rss', $value, t("The field is hidden in 'rss' mode."));
+
+ // Set the view mode back to 'default', check that the field is displayed
+ // accordingly.
+ $edit = array(
+ "view_modes_custom[rss]" => FALSE,
+ );
+ $this->drupalPost('admin/structure/types/manage/' . $this->hyphen_type . '/display', $edit, t('Save'));
+ $this->assertNodeViewText($node, 'rss', $output['field_test_with_prepare_view'], t("The field is displayed as expected when 'rss' mode is set back to 'default' settings."));
+
+ // Specialize the view mode again.
+ $edit = array(
+ "view_modes_custom[rss]" => TRUE,
+ );
+ $this->drupalPost('admin/structure/types/manage/' . $this->hyphen_type . '/display', $edit, t('Save'));
+ // Check that the previous settings for the view mode have been kept.
+ $this->assertNodeViewNoText($node, 'rss', $value, t("The previous settings are kept when 'rss' mode is specialized again."));
+ }
+
+ /**
+ * Pass if the text is found in the rendered node in a given view mode.
+ *
+ * @param $node
+ * The node.
+ * @param $view_mode
+ * The view mode in which the node should be displayed.
+ * @param $text
+ * Plain text to look for.
+ * @param $message
+ * Message to display.
+ *
+ * @return
+ * TRUE on pass, FALSE on fail.
+ */
+ function assertNodeViewText($node, $view_mode, $text, $message) {
+ return $this->assertNodeViewTextHelper($node, $view_mode, $text, $message, FALSE);
+ }
+
+ /**
+ * Pass if the text is node found in the rendered node in a given view mode.
+ *
+ * @param $node
+ * The node.
+ * @param $view_mode
+ * The view mode in which the node should be displayed.
+ * @param $text
+ * Plain text to look for.
+ * @param $message
+ * Message to display.
+ * @return
+ * TRUE on pass, FALSE on fail.
+ */
+ function assertNodeViewNoText($node, $view_mode, $text, $message) {
+ return $this->assertNodeViewTextHelper($node, $view_mode, $text, $message, TRUE);
+ }
+
+ /**
+ * Helper for assertNodeViewText and assertNodeViewNoText.
+ *
+ * @param $node
+ * The node.
+ * @param $view_mode
+ * The view mode in which the node should be displayed.
+ * @param $text
+ * Plain text to look for.
+ * @param $message
+ * Message to display.
+ * @param $not_exists
+ * TRUE if this text should not exist, FALSE if it should.
+ *
+ * @return
+ * TRUE on pass, FALSE on fail.
+ */
+ function assertNodeViewTextHelper($node, $view_mode, $text, $message, $not_exists) {
+ // Make sure caches on the tester side are refreshed after changes
+ // submitted on the tested side.
+ field_info_cache_clear();
+
+ // Save current content so that we can restore it when we're done.
+ $old_content = $this->drupalGetContent();
+
+ // Render a cloned node, so that we do not alter the original.
+ $clone = clone $node;
+ $output = drupal_render(node_view($clone, $view_mode));
+ $this->verbose(t('Rendered node - view mode: @view_mode', array('@view_mode' => $view_mode)) . '<hr />'. $output);
+
+ // Assign content so that DrupalWebTestCase functions can be used.
+ $this->drupalSetContent($output);
+ $method = ($not_exists ? 'assertNoText' : 'assertText');
+ $return = $this->{$method}((string) $text, $message);
+
+ // Restore previous content.
+ $this->drupalSetContent($old_content);
+
+ return $return;
+ }
}