[2.0.0-beta2] Tests Strategy

Created on 13 August 2024, about 1 month ago
Updated 5 September 2024, 11 days ago

Test strategy

To make UI testing / Source testing for the differnt submodules (and following contrib modules) easy I would suggest following testing strategy:

1. Kernel test

This is the simplest and easiest one to validate each source plugin without providing an test.
Based on the fixture, the prefiling and validating through a trait should be easy.
See Example Fixture below:

2. UI testing strategy:

We should split the testing in two parts.

The testing of the form should be a seperate step and should NOT relate to a submodule. So we need an isolated FunctionalJavascriptTest that only validates UI Input to the expected configuration.

To test the submodules easy we should rely only on drupal configuration and an automatic way to validate the rendered output with an expected result.
So a render to validate field formatter output we load a drupal Field UI / Layout Builder etc. as a fixture and run the validation against it.

Example (For layout builder):

public function testRenderUiPatternsLayout(): void {

// Load the drupal config fixture and import it.
$config_import = $this->loadConfigFixture(__DIR__ . '/../fixtures/core.entity_view_display.node.bundle_with_section_field.full.yml');


// Mainpulate the UI Patterns config.
$ui_patterns_config = &$config_import['third_party_settings']['layout_builder']['sections'][0]['layout_settings']['ui_patterns'];


// Define a test mapping configuration.
    $mapping = [
      'props' => [
        'textfield' => [
          $this->getSourceDataTestSet('textfield', 'default'),
        ],
        'token' => [
          $this->getSourceDataTestSet('token', 'node'),
        ],
      ],
    ];

// Manipulate the config
    $ui_patterns_config = $this->buildUiPatternsConfiguration($mapping);

// Import the config
$this->importConfigFixture(
      'core.entity_view_display.node.bundle_with_section_field.full',
      $config_import
    );
// Check the page 
$this->drupalGet('node/1');
// Validate the rendered output
$this->validateRenderedComponent($mapping);

}

First we need a source plugin wich simple print entity:true inside the form as inside the render method,
We use the same strategy with configs import like in the render testing. Beside the rendering we open the form and checking for the entity:true existens.

Example Fixture:

Example:

sources:
  textfield:
    test-sets:
      - name: default
        input:
          - name: textfield
            selector: '.textfield'
            value: 'test input'
        configuration:
          expected:
            id: textfield
            value: 'test input'
        output:
          value: test input
  token:
    test-sets:
      - name: default
        input:
          - name: token
            selector: '.token'
            value: '[node:nid]'
        configuration:
          expected:
            id: token
            value: '[node:nid]'
        output:
          regEx: /[0-9]/
📌 Task
Status

Fixed

Version

2.0

Component

Code

Created by

🇩🇪Germany Christian.wiedemann

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024