Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge config cascade at depth 2 #3760

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

sinavir
Copy link

@sinavir sinavir commented Sep 2, 2022

Changes addressing #3759

TODO :

  • Write a unit test
  • Update docs

@Klap-in
Copy link
Collaborator

Klap-in commented Sep 2, 2022

Thanks for your contribution!

Maybe a short walk through the config cascade loading helps already for preparing some unit tests?

At opening of a page in your browser, doku.php calls inc/init.php with:
https://github.com/splitbrain/dokuwiki/blob/ec745ed997392ae13957c863b6f58d0f70c7e664/inc/init.php#L21-L26

https://github.com/splitbrain/dokuwiki/blob/ec745ed997392ae13957c863b6f58d0f70c7e664/inc/init.php#L62-L64

Alternatively, before the unit tests are run, the test environment is prepared with bootstrap.php, which does the same initialization:

https://github.com/splitbrain/dokuwiki/blob/ec745ed997392ae13957c863b6f58d0f70c7e664/_test/bootstrap.php#L116-L117

before each test in a test class, setUp() is called:
https://github.com/splitbrain/dokuwiki/blob/ec745ed997392ae13957c863b6f58d0f70c7e664/_test/core/DokuWikiTest.php#L54-L61

setUp() can be used to set up same extra conditions for each test of a class.

Default the default config cascade is already loaded. So that could be used to test what the default behavior is. In another test you could remove the loaded config cascade, set the preload.php, and load the config cascade, and check again. Of course there are more ways to approach this.

Because the unit test structure makes assumptions about that the config cascade is loaded, it is needed that the tearDown() function of the test class restores everything to the defaults.

General notes about writing unit tests:
https://www.dokuwiki.org/devel:unittesting#writing_tests

@Klap-in
Copy link
Collaborator

Klap-in commented Sep 2, 2022

Here an (probably not really up to date) example of how it is used for farmer configs (just as background)
https://www.dokuwiki.org/tips:redirect_farm#step_4let_the_farmer_redirect

or https://www.dokuwiki.org/devel:preload

These are so far all examples of replacing everything at once.
If this change is merged, we can update the preload wiki page with an example.

@Chris--S
Copy link
Collaborator

Chris--S commented Sep 2, 2022

I think your array_merge is the wrong way around. You have it set so $defaults will overwrite $config_cascade.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants