public function EntityViewModeFunctionalTest::testEntityViewModes in Entity view modes 7
File
- ./
entity_view_mode.test, line 78 - Test integration for the entity_view_mode module.
Class
Code
public function testEntityViewModes() {
$this
->drupalLogin($this->admin_user);
$this
->drupalGet('admin/config/system/entity-view-modes');
$this
->assertLinkByHref('admin/config/system/entity-view-modes/add/node');
$this
->drupalGet('admin/config/system/entity-view-modes/add/node');
// @todo Set some 'default' settings under a field instance display and
// view mode settings to test that the default settings are applied to
// custom view modes.
//$settings = field_bundle_settings('node', 'article');
//$settings['extra_fields']['display']['test']['default']['testing'] = TRUE;
//field_bundle_settings('node', 'article', $settings);
//$settings = field_bundle_settings('node', 'page');
//$settings['extra_fields']['display']['test']['default']['testing'] = TRUE;
//field_bundle_settings('node', 'page', $settings);
// Attempt to create a view mode that already is provided by core.
$edit = array(
'label' => 'Custom teaser',
'machine_name' => 'teaser',
);
$this
->drupalPost(NULL, $edit, 'Save');
$this
->assertText('The machine-readable name is already in use. It must be unique.');
// Save a new view mode for real.
$edit['label'] = 'Custom 1';
$edit['machine_name'] = 'custom_1';
$edit['enabled_bundles[article]'] = TRUE;
$edit['enabled_bundles[page]'] = FALSE;
$this
->drupalPost(NULL, $edit, 'Save');
$this
->assertViewModeExists('node', 'custom_1');
$this
->assertViewModeCustomDisplay('node', 'article', 'custom_1');
$this
->assertViewModeDefaultDisplay('node', 'page', 'custom_1');
// Switch the view mode from articles to pages.
$edit = array(
'enabled_bundles[article]' => FALSE,
'enabled_bundles[page]' => TRUE,
);
$this
->drupalPost('admin/config/system/entity-view-modes/edit/node/custom_1', $edit, 'Save');
$this
->assertText('Saved the Custom 1 node view mode.');
$this
->assertViewModeExists('node', 'custom_1');
$this
->assertViewModeDefaultDisplay('node', 'article', 'custom_1');
$this
->assertViewModeCustomDisplay('node', 'page', 'custom_1');
// Save a custom value into the view mode settings to check that when a
// view mode's machine name is changed, that the display settings are
// changed as well.
//$settings = field_bundle_settings('node', 'page');
//$settings['view_modes']['custom_1']['testing'] = TRUE;
//$settings['extra_fields']['display']['testing']['custom_1']['custom_1']['testing'] = TRUE;
//field_bundle_settings('node', 'page', $settings);
// Rename the view mode's label and machine name.
$edit = array(
'label' => 'Custom 2',
'machine_name' => 'custom_2',
);
$this
->drupalPost('admin/config/system/entity-view-modes/edit/node/custom_1', $edit, 'Save');
$this
->assertText('Saved the Custom 2 node view mode.');
$this
->assertNoViewModeExists('node', 'custom_1');
$this
->assertViewModeDefaultDisplay('node', 'article', 'custom_1');
$this
->assertViewModeDefaultDisplay('node', 'page', 'custom_1');
$this
->assertViewModeExists('node', 'custom_2');
$this
->assertViewModeDefaultDisplay('node', 'article', 'custom_2');
$this
->assertViewModeCustomDisplay('node', 'page', 'custom_2');
// Check that our custom value was transferred to the new view mode
// settings.
//$settings = field_bundle_settings('node', 'page');
//$this->assertTrue(!isset($settings['view_modes']['custom_1']) && !isset($settings['extra_fields']['display']['custom_1']));
//$this->assertTrue(!empty($settings['view_modes']['custom_2']['testing']) && !empty($settings['extra_fields']['display']['custom_2']['testing']));
// Delete the view mode.
$this
->drupalPost('admin/config/system/entity-view-modes/delete/node/custom_2', array(), 'Delete');
$this
->assertText('Deleted the Custom 2 node view mode.');
$this
->assertNoViewModeExists('node', 'custom_2');
$this
->assertViewModeDefaultDisplay('node', 'article', 'custom_2');
$this
->assertViewModeDefaultDisplay('node', 'page', 'custom_2');
}