You are here

public function FormsStepsTestTrait::formsModesCreation in Forms Steps 8

Creation of the forms modes.

1 call to FormsStepsTestTrait::formsModesCreation()
FormsStepsNavigationTest::setUp in tests/src/Functional/FormsStepsNavigationTest.php
Setup the env for current test using trait methods.

File

tests/src/Traits/FormsStepsTestTrait.php, line 106

Class

FormsStepsTestTrait
Trait FormsStepsTestTrait.

Namespace

Drupal\Tests\forms_steps\Traits

Code

public function formsModesCreation() {

  // Creation of the page node.
  $this
    ->createContentType([
    'type' => 'page',
  ]);

  // Creation of all form display modes.
  foreach ($this->data['form_display_modes'] as $form_display_mode) {

    // Access form mode add page.
    $this
      ->drupalGet(Url::fromRoute('entity.entity_form_mode.add_form', [
      'entity_type_id' => 'node',
    ]));

    // Add a form mode.
    $this
      ->drupalPostForm(NULL, [
      'label' => $form_display_mode['label'],
      'id' => $form_display_mode['id'],
    ], t('Save'));
    Role::load($this->user
      ->getRoles()[1])
      ->grantPermission('use node.' . $form_display_mode['id'] . ' form mode')
      ->save();
  }

  // Create Article content type.
  $this
    ->createContentType([
    'type' => 'article',
  ]);
  Role::load($this->user
    ->getRoles()[1])
    ->grantPermission("administer nodes")
    ->grantPermission("create article content")
    ->grantPermission("create page content")
    ->grantPermission("edit any article content")
    ->grantPermission("edit any page content")
    ->save();

  // Access article's form display page.
  $this
    ->drupalGet(Url::fromRoute('entity.entity_form_display.node.default', [
    'node_type' => 'article',
  ]));

  // Activate Test Form Modes as a custom display mode.
  foreach ($this->data['form_display_modes'] as $form_display_mode) {
    $this
      ->drupalPostForm(NULL, [
      "display_modes_custom[{$form_display_mode['id']}]" => $form_display_mode['id'],
    ], t('Save'));
  }

  // Configure the visible fields.
  $this
    ->drupalGet(Url::fromRoute('entity.entity_form_display.node.form_mode', [
    'node_type' => 'article',
    'form_mode_name' => $form_display_mode['id'],
  ]));
  $this
    ->drupalPostForm(NULL, [
    'fields[title][region]' => 'content',
    'fields[body][region]' => 'hidden',
    'fields[status][region]' => 'hidden',
    'fields[uid][region]' => 'hidden',
    'fields[created][region]' => 'hidden',
    'fields[promote][region]' => 'hidden',
    'fields[sticky][region]' => 'hidden',
  ], t('Save'));

  // Access forms steps add page.
  $this
    ->drupalGet(Url::fromRoute('entity.forms_steps.add_form'));

  // Test the creation of a form step.
  $this
    ->drupalPostForm(NULL, [
    'label' => $this->data['forms_steps']['label'],
    'id' => $this->data['forms_steps']['id'],
    'description' => $this->data['forms_steps']['description'],
  ], t('Save'));

  // Perform steps creation.
  foreach ($this->data['forms_steps']['steps'] as $step) {

    // Access step add page of the form step.
    $this
      ->drupalGet(Url::fromRoute('entity.forms_steps.add_step_form', [
      'forms_steps' => $this->data['forms_steps']['id'],
    ]));

    // Test the creation of an add step.
    $this
      ->drupalPostForm(NULL, [
      'label' => $step['label'],
      'id' => $step['id'],
      'target_form_mode' => $step['target_form_mode'],
      'target_entity_bundle' => $step['target_entity_bundle'],
      'target_entity_type' => $step['target_entity_type'],
      'url' => $step['url'],
    ], t('Save'));
    if (!is_null($step['previous'])) {

      // Update step with previous label.
      $this
        ->drupalPostForm(Url::fromRoute('entity.forms_steps.edit_step_form', [
        'forms_steps' => $this->data['forms_steps']['id'],
        'forms_steps_step' => $step['id'],
      ]), [
        'display_previous' => TRUE,
        'previous_label' => $step['previous'],
      ], t('Save'));
    }
  }
}