summaryrefslogtreecommitdiff
path: root/modules/field/field.test
diff options
context:
space:
mode:
Diffstat (limited to 'modules/field/field.test')
-rw-r--r--modules/field/field.test39
1 files changed, 35 insertions, 4 deletions
diff --git a/modules/field/field.test b/modules/field/field.test
index 999c74ffa..86983e35b 100644
--- a/modules/field/field.test
+++ b/modules/field/field.test
@@ -786,18 +786,19 @@ class FieldAttachOtherTestCase extends FieldAttachTestCase {
}
/**
- * Test field_attach_views() and field_attach_preprocess().
+ * Test field_attach_view() and field_atach_prepare_view().
*/
- function testFieldAttachViewAndPreprocess() {
+ function testFieldAttachView() {
$entity_type = 'test_entity';
- $entity = field_test_create_stub_entity(0, 0, $this->instance['bundle']);
+ $entity_init = field_test_create_stub_entity();
$langcode = FIELD_LANGUAGE_NONE;
// Populate values to be displayed.
$values = $this->_generateTestFieldValues($this->field['cardinality']);
- $entity->{$this->field_name}[$langcode] = $values;
+ $entity_init->{$this->field_name}[$langcode] = $values;
// Simple formatter, label displayed.
+ $entity = clone($entity_init);
$formatter_setting = $this->randomName();
$this->instance['display'] = array(
'full' => array(
@@ -809,6 +810,7 @@ class FieldAttachOtherTestCase extends FieldAttachTestCase {
),
);
field_update_instance($this->instance);
+ field_attach_prepare_view($entity_type, array($entity->ftid => $entity));
$entity->content = field_attach_view($entity_type, $entity);
$output = drupal_render($entity->content);
$this->content = $output;
@@ -819,14 +821,17 @@ class FieldAttachOtherTestCase extends FieldAttachTestCase {
}
// Label hidden.
+ $entity = clone($entity_init);
$this->instance['display']['full']['label'] = 'hidden';
field_update_instance($this->instance);
+ field_attach_prepare_view($entity_type, array($entity->ftid => $entity));
$entity->content = field_attach_view($entity_type, $entity);
$output = drupal_render($entity->content);
$this->content = $output;
$this->assertNoRaw($this->instance['label'], "Hidden label: label is not displayed.");
// Field hidden.
+ $entity = clone($entity_init);
$this->instance['display'] = array(
'full' => array(
'label' => 'above',
@@ -834,6 +839,7 @@ class FieldAttachOtherTestCase extends FieldAttachTestCase {
),
);
field_update_instance($this->instance);
+ field_attach_prepare_view($entity_type, array($entity->ftid => $entity));
$entity->content = field_attach_view($entity_type, $entity);
$output = drupal_render($entity->content);
$this->content = $output;
@@ -843,6 +849,7 @@ class FieldAttachOtherTestCase extends FieldAttachTestCase {
}
// Multiple formatter.
+ $entity = clone($entity_init);
$formatter_setting = $this->randomName();
$this->instance['display'] = array(
'full' => array(
@@ -854,6 +861,7 @@ class FieldAttachOtherTestCase extends FieldAttachTestCase {
),
);
field_update_instance($this->instance);
+ field_attach_prepare_view($entity_type, array($entity->ftid => $entity));
$entity->content = field_attach_view($entity_type, $entity);
$output = drupal_render($entity->content);
$display = $formatter_setting;
@@ -863,6 +871,29 @@ class FieldAttachOtherTestCase extends FieldAttachTestCase {
$this->content = $output;
$this->assertRaw($display, "Multiple formatter: all values are displayed, formatter settings are applied.");
+ // Test a formatter that uses hook_field_formatter_prepare_view()..
+ $entity = clone($entity_init);
+ $formatter_setting = $this->randomName();
+ $this->instance['display'] = array(
+ 'full' => array(
+ 'label' => 'above',
+ 'type' => 'field_test_needs_additional_data',
+ 'settings' => array(
+ 'test_formatter_setting_additional' => $formatter_setting,
+ )
+ ),
+ );
+ field_update_instance($this->instance);
+ field_attach_prepare_view($entity_type, array($entity->ftid => $entity));
+ $entity->content = field_attach_view($entity_type, $entity);
+ $output = drupal_render($entity->content);
+ $this->content = $output;
+ foreach ($values as $delta => $value) {
+ $this->content = $output;
+ $expected = $formatter_setting . '|' . $value['value'] . '|' . ($value['value'] + 1);
+ $this->assertRaw($expected, "Value $delta is displayed, formatter settings are applied.");
+ }
+
// TODO:
// - check display order with several fields