View source
<?php
namespace Drupal\field_ui\Tests;
use Drupal\simpletest\WebTestBase;
class EntityDisplayModeTest extends WebTestBase {
public static $modules = [
'block',
'entity_test',
'field_ui',
];
protected function setUp() {
parent::setUp();
$this
->drupalPlaceBlock('local_actions_block');
$this
->drupalPlaceBlock('page_title_block');
}
public function testEntityViewModeUI() {
$this
->drupalGet('admin/structure/display-modes/view');
$this
->assertResponse(403);
$this
->drupalLogin($this
->drupalCreateUser(array(
'administer display modes',
)));
$this
->drupalGet('admin/structure/display-modes/view');
$this
->assertResponse(200);
$this
->assertText(t('Add new view mode'));
$this
->assertLinkByHref('admin/structure/display-modes/view/add');
$this
->assertLinkByHref('admin/structure/display-modes/view/add/entity_test');
$this
->drupalGet('admin/structure/display-modes/view/add/entity_test_mulrev');
$this
->assertResponse(404);
$this
->drupalGet('admin/structure/display-modes/view/add');
$this
->assertNoLink(t('Test entity - revisions and data table'), 'An entity type with no view builder cannot have view modes.');
$this
->clickLink(t('Test entity'));
$edit = array(
'id' => strtolower($this
->randomMachineName()) . '.' . strtolower($this
->randomMachineName()),
'label' => $this
->randomString(),
);
$this
->drupalPostForm(NULL, $edit, t('Save'));
$this
->assertRaw('The machine-readable name must contain only lowercase letters, numbers, and underscores.');
$edit = array(
'id' => strtolower($this
->randomMachineName()),
'label' => $this
->randomString(),
);
$this
->drupalPostForm(NULL, $edit, t('Save'));
$this
->assertRaw(t('Saved the %label view mode.', array(
'%label' => $edit['label'],
)));
$this
->drupalGet('admin/structure/display-modes/view/manage/entity_test.' . $edit['id']);
$this
->clickLink(t('Delete'));
$this
->assertRaw(t('Are you sure you want to delete the view mode %label?', array(
'%label' => $edit['label'],
)));
$this
->drupalPostForm(NULL, NULL, t('Delete'));
$this
->assertRaw(t('The view mode %label has been deleted.', array(
'%label' => $edit['label'],
)));
}
public function testEntityFormModeUI() {
$this
->drupalGet('admin/structure/display-modes/form');
$this
->assertResponse(403);
$this
->drupalLogin($this
->drupalCreateUser(array(
'administer display modes',
)));
$this
->drupalGet('admin/structure/display-modes/form');
$this
->assertResponse(200);
$this
->assertText(t('Add new form mode'));
$this
->assertLinkByHref('admin/structure/display-modes/form/add');
$this
->drupalGet('admin/structure/display-modes/form/add/entity_test_no_label');
$this
->assertResponse(404);
$this
->drupalGet('admin/structure/display-modes/form/add');
$this
->assertNoLink(t('Entity Test without label'), 'An entity type with no form cannot have form modes.');
$this
->clickLink(t('Test entity'));
$edit = array(
'id' => strtolower($this
->randomMachineName()) . '.' . strtolower($this
->randomMachineName()),
'label' => $this
->randomString(),
);
$this
->drupalPostForm(NULL, $edit, t('Save'));
$this
->assertRaw('The machine-readable name must contain only lowercase letters, numbers, and underscores.');
$edit = array(
'id' => strtolower($this
->randomMachineName()),
'label' => $this
->randomString(),
);
$this
->drupalPostForm(NULL, $edit, t('Save'));
$this
->assertRaw(t('Saved the %label form mode.', array(
'%label' => $edit['label'],
)));
$this
->drupalGet('admin/structure/display-modes/form/manage/entity_test.' . $edit['id']);
$this
->clickLink(t('Delete'));
$this
->assertRaw(t('Are you sure you want to delete the form mode %label?', array(
'%label' => $edit['label'],
)));
$this
->drupalPostForm(NULL, NULL, t('Delete'));
$this
->assertRaw(t('The form mode %label has been deleted.', array(
'%label' => $edit['label'],
)));
}
}