function MediaFileFieldDisplayTestCase::testNodeDisplay in D7 Media 7.4
Same name and namespace in other branches
- 7.2 tests/media.test \MediaFileFieldDisplayTestCase::testNodeDisplay()
- 7.3 tests/media.test \MediaFileFieldDisplayTestCase::testNodeDisplay()
Tests normal formatter display on node display.
File
- tests/
media.test, line 1225 - Tests for media.module.
Class
- MediaFileFieldDisplayTestCase
- Tests that formatters are working properly.
Code
function testNodeDisplay() {
$field_name = strtolower($this
->randomName());
$type_name = 'article';
$field_settings = array(
'display_field' => '1',
'display_default' => '1',
);
$instance_settings = array(
'description_field' => '1',
);
$widget_settings = array();
$this
->createFileField($field_name, $type_name, $field_settings, $instance_settings, $widget_settings);
$field = field_info_field($field_name);
$instance = field_info_instance('node', $field_name, $type_name);
// Create a new node *without* the file field set, and check that the field
// is not shown for each node display.
$node = $this
->drupalCreateNode(array(
'type' => $type_name,
));
$file_formatters = array(
'file_default',
'file_table',
'file_url_plain',
'hidden',
);
foreach ($file_formatters as $formatter) {
$edit = array(
"fields[{$field_name}][type]" => $formatter,
);
$this
->drupalPost("admin/structure/types/manage/{$type_name}/display", $edit, t('Save'));
$this
->drupalGet('node/' . $node->nid);
$this
->assertNoText($field_name, format_string('Field label is hidden when no file attached for formatter %formatter', array(
'%formatter' => $formatter,
)));
}
$test_file = $this
->getTestFile('text');
$test_file->uid = $this->admin_user->uid;
$test_file = file_save($test_file);
// Create a new node with the attached file.
$nid = $this
->attachNodeFile($test_file, $field_name, $type_name);
$this
->drupalGet('node/' . $nid . '/edit');
// Check that the media thumbnail is displaying with the file name.
$node = node_load($nid, NULL, TRUE);
$node_file = (object) $node->{$field_name}[LANGUAGE_NONE][0];
$thumbnail = media_get_thumbnail_preview($node_file);
$default_output = drupal_render($thumbnail);
$this
->assertRaw($default_output, 'Default formatter displaying correctly on full node view.');
// Turn the "display" option off and check that the file is no longer displayed.
$edit = array(
$field_name . '[' . LANGUAGE_NONE . '][0][display]' => FALSE,
);
$this
->drupalPost('node/' . $nid . '/edit', $edit, t('Save'));
$this
->assertNoRaw($default_output, 'Field is hidden when "display" option is unchecked.');
}