Issue Bug Closed

#72136Make Validator Unit Tests behave like they are used from Domain Model

Stephan Großberndt 12/09/15, 21:17 updated 11/23/24, 17:31

Description

There is a big problem with Extbase validator unit tests found in #72047: They don’t work the way the domain model works.

If not all options are given in an extbase domain model the given options are MERGED with the default options from the validator supplied in $supportedOptions.

In the validator unit tests the options are just plainly set and NOT MERGED with the default options.

This can lead to differences in the handling and in case of #72047 lead to completely ignoring the given options and only using the default options from $supportedOptions

Reviews 0

No change resolves or names this issue in its commit message, and no comment links one.

History 4

  1. Susanne Moog commented and changed status New Needs Feedback <span data-processor="relativetime" data-value="2017-11-14T07:35:37+00:00" > 11/14/17, 07:35 </span>

    Two questions / remarks here:

    - Can you add an example to this ticket about what exactly do you mean?
    - If we would add some kind of simulation of the behaviour extbase does internally with merging options before calling methods, wouldn’t we then have functional tests? As far as I can see the unit tests are ok, but what is actually missing are the functionals than test including the merge of options.

  2. Stephan Großberndt commented <span data-processor="relativetime" data-value="2017-11-30T20:08:25+00:00" > 11/30/17, 20:08 </span>

    Phew.. two years later.. if I remember correctly its like this:

    In extbase you have supportedOptions defined in a Validator

    protected $supportedOptions = array(
            'minimum' => array(0, 'The minimum value to accept', 'integer'),
            'maximum' => array(PHP_INT_MAX, 'The maximum value to accept', 'integer'),
            'startRange' => array(0, 'The minimum value to accept', 'integer'),
            'endRange' => array(PHP_INT_MAX, 'The maximum value to accept', 'integer')
        );

    If you do not provide all supportedOptions in your validate annotation like here

    * @validate NumberRange (endRange = 2)

    (minimum, maximum and startRange not provided) all is well in Extbase itself as the supportedOptions will get merged with your given annotation in $this->options –
    *but* in the current tests for this (which are apparently (only?) Unit Tests) $this->options only contains the values from the annotation (so minimum, maximum and startRange would be missing here).

    Whether the correct way to test/solve this is to use functionals instead I can’t say – I bet you can ;-)

    I found this issue when searching for the bug in #72047 and I was wondering why (although this area is covered) the tests did not find the issue of the no longer working startRange/endRange annotation (which was fixed separately in https://review.typo3.org/#/c/45109/)

  3. Torben Hansen commented and changed status New Closed <span data-processor="relativetime" data-value="2024-11-23T17:31:37+00:00" > 11/23/24, 17:31 </span>

    I checked this in the current state of the core. Since #96998, all extbase validator test have been transformed into functional tests. There, we work with real instances of the validators, which behave exactly the same as they do, when used in a domain model (validator is instantiated, setOptions is used to set validator options, which MERGES the given options with the default options of the validator).

    So in my opinion, this ticket is no longer valid and I will therefore close it now.