simple_multistep-8.x-1.x-dev/tests/src/Unit/MultistepControllerTest.php

tests/src/Unit/MultistepControllerTest.php
<?php

namespace Drupal\Tests\simple_multistep\Unit;

use Drupal\Core\Form\FormStateInterface;
use Drupal\simple_multistep\MultistepController;
use PHPUnit\Framework\TestCase;

/**
 * Cover multistep controller functional.
 */
class MultistepControllerTest extends TestCase {

  /**
   * Test form rebuild.
   */
  public function testRebuildForm(): void {
    $formState = $this->createStub(FormStateInterface::class);

    $form = $this->dummyForm();

    $multistepController = new MultistepController($form, $formState);
    $multistepController->rebuildForm($form);

    $this->assertNotFalse($form['title']['#access'] ?? TRUE);
    $this->assertFalse($form['body']['#access'] ?? TRUE);
    $this->assertFalse($form['field_image']['#access'] ?? TRUE);
    $this->assertEquals('hidden', $form['#fieldgroups']['group_image_details']->format_type);
  }

  /**
   * Return dummy form for testing.
   */
  protected function dummyForm(): array {
    $form = [];

    $form['#fieldgroups']['group_title'] = (object) [
      'children' => [
        'title',
      ],
      'label' => 'Title',
      'region' => 'content',
      'parent_name' => '',
      'weight' => 20,
      'format_type' => 'form_step',
      'format_settings' =>
        [
          'classes' => '',
          'show_empty_fields' => FALSE,
          'id' => '',
          'label_as_html' => FALSE,
          'show_step_title' => TRUE,
          'step_description' => '',
          'back_button_show' => FALSE,
          'back_button_text' => 'Back',
          'next_button_text' => 'Next',
          'required_fields' => TRUE,
          'step_help' => '',
        ],
      'group_name' => 'group_title',
      'entity_type' => 'node',
      'bundle' => 'article',
      'context' => 'form',
      'mode' => 'default',
    ];

    $form['#fieldgroups']['group_other'] = (object) [
      'children' => [
        'group_image_details',
        'body',
      ],
      'label' => 'Other',
      'region' => 'content',
      'parent_name' => '',
      'weight' => 20,
      'format_type' => 'form_step',
      'format_settings' => [
        'classes' => '',
        'show_empty_fields' => FALSE,
        'id' => '',
        'label_as_html' => FALSE,
        'show_step_title' => TRUE,
        'step_description' => '',
        'back_button_show' => TRUE,
        'back_button_text' => 'Back',
        'next_button_text' => 'Submit',
        'step_help' => '',
      ],
      'group_name' => 'group_other',
      'entity_type' => 'node',
      'bundle' => 'article',
      'context' => 'form',
      'mode' => 'default',
    ];
    $form['#fieldgroups']['group_image_details'] = (object) [
      'children' => [
        'field_image',
      ],
      'label' => 'Image details',
      'region' => 'content',
      'parent_name' => 'group_other',
      'weight' => 2,
      'format_type' => 'details',
      'format_settings' => [
        'classes' => '',
        'show_empty_fields' => FALSE,
        'id' => '',
        'label_as_html' => FALSE,
        'open' => FALSE,
        'description' => '',
        'required_fields' => TRUE,
      ],
      'group_name' => 'group_image_details',
      'entity_type' => 'node',
      'bundle' => 'article',
      'context' => 'form',
      'mode' => 'default',
    ];

    $form['title'] = [
      '#type' => 'container',
      '#widget' => [],
      '#weight' => 0,
    ];

    $form['body'] = [
      '#type' => 'container',
      'widget' => [],
      '#weight' => 3,
    ];

    $form['field_image'] = [
      '#type' => 'container',
      'widget' => [],
      '#weight' => 2,
    ];

    return $form;
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc