Problem/Motivation

Subclasses of StringComparisonBase:

Evaluator:

Proposed resolution

The variables and methods are badly named and inconsistent, that needs to be cleaned up.

Issue fork eca-3271473

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

jurgenhaas created an issue. See original summary.

jurgenhaas’s picture

Assigned: jurgenhaas » Unassigned
Status: Active » Needs review
StatusFileSize
new22.02 KB
new59.27 KB

This is now the corrected version:

mxh’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

We definetly need to cover this with tests so that the mix-up won't happen again.

mxh’s picture

We could also create a separate issue that addresses the tests. However I'd recommend to include tests as early as possible, especially on these fundamental ones.

jurgenhaas’s picture

Assigned: Unassigned » jurgenhaas

Working on tests right here is perfect, I'll get to it now.

jurgenhaas’s picture

Assigned: jurgenhaas » Unassigned
Status: Needs work » Needs review

First few tests are now available. Please have a look and let me know what else we should be testing.

Note that I'm focusing on testing the condition plugin, not tokens, entities, or field functionality.

mxh’s picture

Status: Needs review » Needs work

The test is a good start. Some important parts are missing IMO that need to be covered:

  • Some cases where evaluate would return FALSE (currently only TRUE cases are tested)
  • Test the operators with a numeric value, which is especially interesting for greater-than less-than etc. checks. Currently only a string text is being covered.

I see why you implemented the private evaluate method, but it makes the test harder to read and understand. We should try to write the test as easily readable as possible. It's not a bad thing when instructions are (super) repetitive.

If you need some orientation, a look at the plugin may already give some hints what use cases might occur and should be covered with a test.

jurgenhaas’s picture

@mxh that sounds as if you only noticed the one test class that tests entity field values. The more comprehensive test is in ScalarComparison which also starts with numeric values, tests the negation, and has a different architecture, which should be even more readable.

mxh’s picture

Ah yes, my bad :) definetly very well readable, especially with the data provider methods, this is great!

Suggestions to integerDataProvider():

  • I think we should test for numeric string values, as the configuration stores plugin fields as strings. The plugin should be capable of comparing numerical values also when they are passed along as strings.
  • We could name that method "numericDataProvider". We should at least test with integer values, a decimal / float value would also be interesting.
  • Definetly we need to have more comparison operators covered for numeric comparison.

  • jurgenhaas committed 1980f99 on 1.0.x
    Issue #3271473 by jurgenhaas, mxh: StringComparisonBase doesn’t work...
jurgenhaas’s picture

Merged !MR98 for the upcoming beta release but leave the issue open for test completion work.

jurgenhaas’s picture

Status: Needs work » Needs review

Tests are now implemented for numeric comparisons as expected with all the different combinations. The negate functionality has only been tested once because it is called for either TRUE or FALSE always in the same way, i.e. if it works once, it always works.

The entity field comparison test has been adjusted to also use a data provider.

In addition, there are now also test for more subclasses like original entity field value, form field value and state value.

The remaining sub-class to compare the routing will get its test in #3271667: Condition "Route match" should return the route name.

The idea behind the tests for StringComparisonBase is that the scalar comparison comes with tests for all the different comparison types and arguments. All other plugins get only tested with fewer tests that foxus on the plugin logic, but don't test all the combinations a second time.

jurgenhaas’s picture

MR !114 now also includes the tests for RouteMatch condition and TokenLoadRouteParameter action, brought over from #3271667: Condition "Route match" should return the route name

mxh’s picture

Status: Needs review » Needs work

RouteTest is currently not covering access checks. We should test access checks of that action, to make sure that the current user is only able to access allowed route parameter objects.

jurgenhaas’s picture

Status: Needs work » Needs review

I have addressed the comments, but with the access test, I'm having some issues. The route match interface provides parameters without any access test itself. That's why the action plugin doesn't test that either.

Reason being, that the current route will have been access tested before we even get to this point. A current route by definition is accessible by the current user. If it isn't, the route will never be the current one. The route handler will have switched to a 403 or whatever request, before we can even access the current route. Testing, if that works properly, is more a task for the route handler, not for us who are only reading the result.

What might be an interesting scenario though is to test such a request to an inaccessible route, where the route handler has been performing that access control and where our route would no longer be in current route but in parent or master. But I have no idea, how I could get the route interface to do that in a test environment. Suggestions or commits to the MR welcome.

mxh’s picture

Status: Needs review » Needs work

We are performing an access check on the entity in the "Token: load entity" action and at other places when loading the entity. For consistency, we then also need to perform an access check on the route parameters (I'm not talking about the route object itself). In the MR there is already a test for executing the action for getting a node from the route. The access check of that action should therefore perform an access check on the node that is about to be returned by this action. This may be generalized to check whether the route object to access is an instance of AccessibleInterface.

jurgenhaas’s picture

Is that a request to improve the test or is this about to change the behaviour of the action?

mxh’s picture

In case the action is not yet performing an access check, I'd suggest to adjust the action accordingly, so that the behavior is consistent to the other action implementations of ECA, and cover it within the KernelTest that is already in the MR.

jurgenhaas’s picture

Status: Needs work » Needs review

Agreed, I've now enhanced the access control in the action plugin. I first thought, that's not required because the route handler manages that, but if we access the main route match, then this might be a route where the user doesn't have access.

After that, I also added 2 more tests for this scenario.

mxh’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs tests

Reviewed the code, tests are passing, this looks good :)

  • jurgenhaas committed 402210e on 1.0.x
    Issue #3271473 by jurgenhaas, mxh: StringComparisonBase doesn’t work...
jurgenhaas’s picture

Status: Reviewed & tested by the community » Fixed

:+1:

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.