You are here

public function FormModeManagerUiTest::testFieldFormFormModeManager in Form mode manager 8.2

Test each entities using form mode works.

@dataProvider entityFormModeTestProvider

Throws

\Behat\Mink\Exception\ExpectationException

File

tests/src/Functional/FormModeManagerUiTest.php, line 152

Class

FormModeManagerUiTest
Tests the Form mode manager user interfaces.

Namespace

Drupal\Tests\form_mode_manager\Functional

Code

public function testFieldFormFormModeManager(array $test_parameters, $add_path, $edit_path, $field_name) {
  $form_mode_machine_name = $this->{$test_parameters[2]}
    ->id();
  $this
    ->setUsersTestPermissions([
    "use {$form_mode_machine_name} form mode",
  ]);
  $add_path = new FormattableMarkup($add_path, [
    '@type' => isset($test_parameters[1]) ? $this->{$test_parameters[1]}
      ->id() : 'people',
  ]);
  $edit_path = new FormattableMarkup($edit_path, [
    '@id' => $this->{$test_parameters[0]}[0]
      ->id(),
  ]);
  $form_mode_name = $this->formModeManager
    ->getFormModeMachineName($form_mode_machine_name);
  $this
    ->drupalGet("{$add_path}/{$form_mode_name}");
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->fieldExists($field_name);
  $this
    ->drupalGet($add_path);
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->fieldNotExists($field_name);
  $this
    ->drupalGet("{$edit_path}/{$form_mode_name}");
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->fieldExists($field_name);
  $this
    ->drupalGet($edit_path);
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->fieldNotExists($field_name);
}