Problem/Motivation

The 1.x branch should get a code style cleanup, schema check (if schema existing for this module) and get basic tests. In the main module as well as in submodules (if existing).

As tests will be the most time-consuming and hardest part, we should start with the most basic tests, which might for example be:

  • Configuration page access respecting the permissions set
  • Configuration page functionality (save)
  • Selected layouts removed from the layouts returned from the API function
  • Advanced: Selected layouts removed from the UI, for example in layout_builder
  • ...?

To be able to implement them in a useful way, first check, which functionalities the module provides and get a demonstration.
Afterwards, we could have a look at similar modules / core, what and how they test.

Tests should be implemented from quick and easy to complicated, as it will take a lot of time to have a good test coverage.

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

Anybody created an issue. See original summary.

anybody’s picture

Assigned: Unassigned » grevil

Grevil made their first commit to this issue’s fork.

grevil’s picture

I fixed the coding style issues, added tests, added schema definitions and fixed the flawed config usage.

grevil’s picture

Status: Active » Needs review

anybody’s picture

Status: Needs review » Needs work

GREAT work @Grevil! You identified a lot of flaws etc. :)

Just one (but important) point left, the change has the potential to break all existing sites, which should never happen. After that's fixed, this is all fine, I think :)

grevil’s picture

@Anybody, I reran the Tests with A version of MySQL >= 5.7.8, the tests should work properly now.

anybody’s picture

@Grevil: Can be changed here, I did that: https://www.drupal.org/node/2982948/qa

anybody’s picture

-  $disabledLayouts = $config->get('layout_disable.settings.disabled_layouts');
+  $disabledLayouts = $config->get('disabled_layouts');

still scares me a bit, so I'll leave this open for RTBC and commit until I have the time to immediately test it in production.

anybody’s picture

Status: Needs work » Needs review
grevil’s picture

@Anybody, why though? Before you were getting the "layout_disable.settings" and then in these settings you were looking for the "layout_disable.settings.disabled_layouts" nested keys. So because there was no manually created schema, Drupal automatically created a schema like this (at least logic wise):

layout_disable.settings
  layout_disable
    settings
      disabled_layouts

Since the get() function for the config, will think you are looking for nested keys, because you are using the "." operator in the get function. See https://www.drupal.org/docs/drupal-apis/configuration-api/simple-configu....

How it is currently implemented is correct.
We have a schema like this:

layout_disable.settings
   disabled_layouts

In code, we are getting the module's config like this:

$config = \Drupal::service('config.factory')
    ->getEditable('layout_disable.settings');

Afterwards, we are looking for the disabled_layouts key in the config like this:
$config->get('disabled_layouts');

(For some reason we are getting editable configs, which is actually unnecessary in this case)

anybody’s picture

Status: Needs review » Needs work

As just discussed, this needs an update hook for the wrong old settings structure.

anybody’s picture

Status: Needs work » Needs review
grevil’s picture

Ok, I just tested the update hook, it works as expected!

anybody’s picture

Status: Needs review » Needs work

Manual review looks good now, but two failing tests.

anybody’s picture

Status: Needs work » Reviewed & tested by the community

Failing tests were due to an upstream PHP 8.1 compatibility issue in core (->drupalGet()). RTBC! :)

anybody’s picture

Status: Reviewed & tested by the community » Fixed

Very well done @Grevil, thanks!

  • Anybody committed 5636a9e on 8.x-1.x
    Issue #3263064 by Grevil, Anybody: Code style cleanup, Schema check,...

Status: Fixed » Closed (fixed)

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