Postponed
Project:
High contrast
Version:
8.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Reporter:
Created:
20 Feb 2020 at 21:52 UTC
Updated:
28 Mar 2020 at 20:34 UTC
Jump to comment: Most recent, Most recent file
I think adding some automated tests might help to solve some issues. I am not aiming for full test coverage, but on the short term these might be useful:
(Can be based on https://git.drupalcode.org/project/whitelabel/blob/8.x-2.x/tests/src/Ker...)
This can also be used to trigger deprecation notices and to prevent WSODs during installation..
| Comment | File | Size | Author |
|---|---|---|---|
| #16 | high_contrast-add-tests-3114980-16.patch | 5.34 KB | neograph734 |
| #3 | high_contrast_tests_3.patch | 5.95 KB | neograph734 |
Comments
Comment #2
neograph734Having a look at this next week.
Comment #3
neograph734I need some more time for the block test, but I think this should already be a nice start. (I think caching is included in the stylesheet test)
Comment #4
neograph734Argh, a typo in the namespace; high_contast...
Retrying
Comment #6
hkirsman commentedAutomated testing is quite new to me but I'm starting to love it. It's a struggle though to set it up in the first place. I actually wrote 2 functional tests yesterday and thought I'd use the same environment and voila Error: Class 'org\bovigo\vfs\vfsStream' not found :D
composer require mikey179/vfsstream --devfixes that but there's something else going on. I think you're running them somehow differently because I'm getting the same errors as is the results of #5.Basically what I run is this:
./vendor/bin/phpunit web/modules/contrib/high_contrast/tests/src/FunctionalJavascript/HighContrastStyleSheetTest.phpor
You should have 7.5 if you're running on Drupal 8.8:
But to the tests
1.
Drupal\Tests\high_contrast\FunctionalJavascript\HighContrastStyleSheetTest::testStyleSheetGenerated
Error: Call to undefined function file_save_data()
This one was strange. You can basically disable everything in the test and you still got the error. Seems though what is triggering it adding 'high_contrast' to $modules :S
In the mean time I had to also install selenium
lando composer require behat/mink-selenium2-driver --devOk, so file_save_data() is used in high_contrast_install() and that breaks it. So file is not test dependency, but module dependency.
What's odd for me is that I can't remove the file dependendy from test. Maybe it's KernelTestBase peculiarity
I also added - drupal:block as dependency as I know the module adds block.
2.
I see this patch will conflict with https://www.drupal.org/project/high_contrast/issues/3114528 There I did changes like:
Could we merge that and then do updates here?
3.
Drupal\Tests\high_contrast\Kernel\HighContrastConfigOverrideTest::testConfigurationOverrides
Drupal\Component\Plugin\Exception\PluginNotFoundException: The "user" entity type does not exist.
In this case it seems that $this->installEntitySchema() needs user. I searched in core and there are about 5 tests where it's used and all have user as dependency. The error is gone.
4.
New errors now, yay! :D
Drupal\Tests\high_contrast\FunctionalJavascript\HighContrastStyleSheetTest::testStyleSheetGenerated
Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException: Circular reference detected for service "theme_handler", path: "theme_handler -> config.factory -> high_contrast.overrider -> theme.manager -> theme.negotiator -> access_check.theme".
Ok, so I searched for "{ name: config.factory.override }" in core and none of them had any arguments, which was suspicious. Then I came across https://www.drupal.org/docs/8/api/configuration-api/configuration-overri... . One sentence there cought my eye:
But as the error is about theme, I removed '@theme.manager' from arguments and instead used \Drupal::theme(). No more errors
But now I'm at point where it says
OK, but incomplete, skipped, or risky tests!
Tests: 2, Assertions: 2, Skipped: 2.
Comment #7
neograph7341.
Yes I figured that out too. It should have been a dependency ever since that install hook :(.
Functional tests install modules with all dependencies resolved; Kernel tests do not enable any of the depending modules, so they have to be enabled manually.
The module adds a block, but I'd say it is a soft dependency. Theoretically the module can function without block being enabled (though there is currently no option to enable the high contrast mode), toggling high contrast could also be done with Core's action module for example. IMO it does not need to be in the .info.yml file.
2.
#3114528: Use Short syntax of array. is committed.
3.
Thanks for figuring that out. It didn't really make sense to me as there are no users created during the tests.
4.
I initially didn't understand this one, because the ConfigOverrideTest for whitelabel does not have an issue. https://git.drupalcode.org/project/whitelabel/blob/8.x-2.x/tests/src/Ker...But then I realised that testStyleSheetGenerated is totally out of place here.The stylesheet is only saved in the submit callback of HighContrastConfigurationForm. So in ConfigOverrideTest we should remove testStyleSheetGenerated. It should be moved into a new functional test in which we could also assert that the values entered in the form are properly saved to the database.UPDATE This was no longer about the ConfigOverrideTest,
but still we cannot assert the stylesheet generation without form submission, so the point above remains valid.UPDATE2 with #3115713: Move stylesheet generation to an event subscriber the test can remain as it is as it would remove the need to save the form.
Comment #8
hkirsman commented1.2
Tx about info on kernel tests!
1.3
About the block dependency. I think it should be there until the module can be used theoretically without block :) Main way how to enable/disable Drupal 7 High Contrast is to use tab key. Maybe now it also has block in D7, but that was the original idea. It's used here for example https://www.valitsus.ee/en - press tab 3 times and you'll see 'Toggle high contrast' link, then press enter. So if that feature would be in Drupal 8, then I would treat block as soft dependency. I propose new task for this feature. What do you think?
2. Cool, tx! I'll re-add the patch against latest changes.
4. Still have to wrap around my head on this change. Haven't had time but will get back to this tomorrow.
Adding patch against latest changes in repo. Interdiff is a bit confusing. Maybe I was too tired but should be ok. There is not trace of enable_high_contrast left in the new patch.
Comment #9
neograph734Retesting now that #3115713: Move stylesheet generation to an event subscriber is in.
Comment #10
neograph734Lets keep it small. I believe this test one test did pass. For the rest we need to decide on a strategy first.
Comment #12
neograph734Reverting the theme manager injection for HighContrastConfigOverride to prevent circular injections.
Comment #14
neograph734Forgot te remove it from the services file.
Comment #16
neograph734How did that other test get back..
Last attempt.
Comment #17
neograph734Finally. Committed. Now lets continue after #2853420: Check if works properly with Boost or Varnish.
Comment #19
hkirsman commentedNice, tx!