Add test for WeekTableElement in a form (not a widget)

Created on 29 May 2024, 30 days ago

Problem/Motivation

In ✨ Use the office hours field widget as Element (in a settings form) Fixed , the Weektable was separated into a widget and an element.
This calls for a test, that makes sure the functionality is preserved.

Steps to reproduce

Create a for like this:

 /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $form = [];

    $config = \Drupal::configFactory()->get('example.settings');
    $field_settings = OfficeHoursItem::defaultStorageSettings();
    $widget_settings = OfficeHoursWeekWidget::defaultSettings();
    $office_hours = $config->get('office_hours') ?? [];

    $form['office_hours'] = [
      '#type' => 'office_hours_table',
      '#title' => $this->t('Office hours'),
      '#default_value' => $office_hours,

      '#field_settings' => $field_settings,
      '#widget_settings' => $widget_settings,
      '#field_type' => $week_season_id = 0,
    ];

    $form['actions'] = [
      '#type' => 'actions',
      'submit' => [
        '#type' => 'submit',
        '#value' => $this->t('Save'),
      ],
    ];

    return $form;
  }

And test if the submitted values are preserved the next time the form is displayed.

Proposed resolution

As per #23 in above issue, for the ECA module, some form submission tests exist and you can find an example at https://git.drupalcode.org/project/eca/-/blob/2.0.x/modules/form/tests/s...

Remaining tasks

Add task.

User interface changes

API changes

Data model changes

πŸ“Œ Task
Status

Active

Version

1.0

Component

Code - widget

Created by

πŸ‡³πŸ‡±Netherlands johnv

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Production build 0.69.0 2024