View source
<?php
namespace Drupal\Tests\form_mode_manager\Functional;
use Drupal\Tests\BrowserTestBase;
abstract class FormModeManagerBase extends BrowserTestBase {
use DisplayFormModeTestTrait;
public static $modules = [
'block',
'entity_test',
'field_ui',
'node',
'user',
'form_mode_manager',
'taxonomy',
];
public static $uiLocalTabsExpected = [
'Settings',
'Local task settings',
];
protected $anonymousUser;
protected $adminUser;
protected $testUser;
protected $nodeTypeFmm1;
protected $nodeFormMode;
protected $userFormMode;
protected $formModeManager;
protected function setUp() {
parent::setUp();
$this
->drupalPlaceBlock('local_actions_block');
$this
->drupalPlaceBlock('local_tasks_block');
$this
->drupalPlaceBlock('page_title_block');
$this->nodeTypeFmm1 = $this
->drupalCreateContentType([
'type' => 'fmm_test',
'name' => 'Form Mode Manager Test 1',
]);
$this->nodeFormMode = $this
->drupalCreateFormMode('node');
$this->userFormMode = $this
->drupalCreateFormMode('user');
$this->container
->get('router.builder')
->rebuildIfNeeded();
$this
->drupalLogin($this->rootUser);
$this
->setUpNodeFormMode();
$this
->setUpUserFormMode();
$this
->setUpUsers();
}
public function setUpUsers() {
$this->anonymousUser = $this
->drupalCreateUser([
'access content',
]);
$this->adminUser = $this
->drupalCreateUser([
'access content',
'access administration pages',
'administer site configuration',
'administer users',
'administer permissions',
'administer content types',
'administer node fields',
'administer node display',
'administer node form display',
'administer nodes',
'administer display modes',
'use node.default form mode',
'use user.default form mode',
'use ' . $this->nodeFormMode
->id() . ' form mode',
'use ' . $this->userFormMode
->id() . ' form mode',
'edit any ' . $this->nodeTypeFmm1
->id() . ' content',
'create ' . $this->nodeTypeFmm1
->id() . ' content',
]);
$this->testUser = $this
->drupalCreateUser([
'access content',
]);
}
public function setUpUserFormMode() {
$this
->setUpFormMode("admin/config/people/accounts/form-display", $this->userFormMode
->id());
}
public function setUpNodeFormMode() {
$this
->setUpFormMode("admin/structure/types/manage/{$this->nodeTypeFmm1->id()}/form-display", $this->nodeFormMode
->id());
}
public function setUpFormMode($path, $form_mode_id) {
$this
->drupalGet($path);
$this->formModeManager = $this->container
->get('form_mode.manager');
$edit = [
"display_modes_custom[{$this->formModeManager->getFormModeMachineName($form_mode_id)}]" => TRUE,
];
$this
->drupalPostForm($path, $edit, t('Save'));
}
public function assertLocalTasks($tabs_expected) {
foreach ($tabs_expected as $link) {
$this
->assertSession()
->linkExists($link);
}
}
}