1 field_ui.test | public FieldUIViewModeFunctionalTest::testFieldUIViewModes() |
Tests display mode functionality.
File
- core/
modules/ field_ui/ tests/ field_ui.test, line 945 - Tests for field_ui.module.
Class
- FieldUIViewModeFunctionalTest
- Tests display mode functionality.
Code
public function testFieldUIViewModes() {
$this->backdropLogin($this->admin_user);
$this->backdropGet('admin/structure/types/manage/post/display');
$this->assertLinkByHref('admin/structure/types/manage/post/display/add');
// Set some 'default' settings under a field instance.
$settings = field_bundle_settings('node', 'post');
$settings['extra_fields']['display']['test']['default']['testing'] = TRUE;
field_bundle_settings('node', 'post', $settings);
$settings = field_bundle_settings('node', 'page');
$settings['extra_fields']['display']['test']['default']['testing'] = FALSE;
field_bundle_settings('node', 'page', $settings);
$settings = field_bundle_settings('comment', 'comment_node_post');
$settings['extra_fields']['display']['test']['default']['testing'] = TRUE;
field_bundle_settings('comment', 'comment_node_post', $settings);
// Attempt to create a display mode that already is provided by core.
$edit = array(
'label' => 'Custom 1',
'machine_name' => 'teaser',
);
$this->backdropPost('admin/structure/types/manage/post/display/add', $edit, 'Save');
$this->assertText('The machine-readable name is already in use. It must be unique.');
// Save a valid custom display mode for the Post content type.
$edit['machine_name'] = 'custom_1';
$this->backdropPost('admin/structure/types/manage/post/display/add', $edit, 'Save');
$this->assertViewModeExists('node', 'custom_1');
$this->assertViewModeDefaultDisplay('node', 'page', 'custom_1');
$this->assertViewModeCustomDisplay('node', 'post', 'custom_1');
// Test that the default settings are applied to new custom display modes.
$settings = field_bundle_settings('node', 'post');
$this->assertEqual($settings['extra_fields']['display']['test']['custom_1']['testing'], TRUE, 'The default settings were applied to the new display mode.');
// Reset the view-mode on the post content type.
$this->backdropPost('admin/structure/types/manage/post/display/custom_1/reset', array(), 'Reset');
$this->assertViewModeExists('node', 'custom_1');
$this->assertViewModeDefaultDisplay('node', 'post', 'custom_1');
$this->assertViewModeDefaultDisplay('node', 'page', 'custom_1');
// Enable the view-mode on the page content type.
$this->backdropGet('admin/structure/types/manage/page/display');
list($enable_link) = $this->xpath('//tr[contains(@class, "view-mode--custom-1")]//a');
$enable_href_parts = backdrop_parse_url($enable_link['href']);
$this->backdropGet($enable_href_parts['path'], $enable_href_parts);
$this->assertViewModeExists('node', 'custom_1');
$this->assertViewModeCustomDisplay('node', 'page', 'custom_1');
$this->assertViewModeDefaultDisplay('node', 'post', 'custom_1');
// Test that the default settings are applied to newly enabled display modes.
$settings = field_bundle_settings('node', 'page');
$this->assertEqual($settings['extra_fields']['display']['test']['custom_1']['testing'], FALSE, 'The default settings were applied to the newly enabled display mode.');
// Delete the display mode.
$this->backdropPost('admin/structure/types/manage/page/display/custom_1/delete', array(), 'Delete');
$this->assertText('Deleted the Custom 1 display mode.');
$this->assertNoViewModeExists('node', 'custom_1');
$this->assertViewModeDefaultDisplay('node', 'page', 'custom_1');
$this->assertViewModeDefaultDisplay('node', 'post', 'custom_1');
//Create a comment display mode.
$edit = array(
'label' => 'Comment 1',
'machine_name' => 'com_1',
);
$this->backdropPost('admin/structure/types/manage/post/comment/display/add', $edit, 'Save');
$this->assertViewModeExists('comment', 'com_1');
$this->assertViewModeDefaultDisplay('comment', 'comment_node_page', 'com_1');
$this->assertViewModeCustomDisplay('comment', 'comment_node_post', 'com_1');
// Test that the default comment settings are applied to custom display modes.
$settings = field_bundle_settings('comment', 'comment_node_post');
$this->assertEqual($settings['extra_fields']['display']['test']['com_1']['testing'], TRUE, 'The default settings were applied to the comment display mode.');
}