Problem/Motivation
Core registers and auto-loads classes in themes. As it is today, themes do not have their classes registered by PHPUnit, as such, you cannot unit test your theme and any unit tests you write will fail on d.o.
Proposed resolution
We should discuss whether or not we want to do that (themes with unit tests! crazy! on the other hand, maybe theme maintainers want that!). Then do it. Patch could be as few as two lines (See #65 of #2025883: Drupal's PHPUnit bootstrap.php does not register module namespaces out of /core)
Remaining tasks
- Discuss whether or not we should register classes provided by core/contrib themes in the context of PHPUnit.
- Once that discussion has concluded, implement the change or close this issue as "won't fix."
- This will need to go in before/if we implement: #2025883: Drupal's PHPUnit bootstrap.php does not register module namespaces out of /core
User interface changes
None.
API changes
None.
Related Issues
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | 2070559_6.patch | 858 bytes | mile23 |
Comments
Comment #1
webchickIt's worth looking at the existing theme system tests and see how they're done. My guess is they do not put .test files in the themes they're testing, but instead have those owned by a module. If so, I think we can "won't fix" this, personally. If not, that would be a reason to add it.
Comment #2
iamEAP commentedI guess it's not obvious from the description, but this applies to both existing Core and all of contrib going forward. By not doing this, we would effectively be saying, "Sorry themers, no matter what you do, you cannot unit test your themes."
I'm just not familiar enough with D8's theme system to say one way or the other how much unit-testable code could/would go into a theme.
In any event, I'm amazed at how on-top of the queue you are! webchick++
Comment #3
ParisLiakos commentedrelated #2070581: Themes should not register namespaces
why would you put functionality in your theme and unit test it? for theme engines it makes sense but not for themes..if you have php classes in your theme then you are doing it wrong.
Comment #4
mile23@ParisLiakos:
a) Classes in your themes doesn't mean you're doing it wrong. :-)
b) Functions are units, too. You can (and should) test them with PHPUnit.
Comment #4.0
mile23Adding a couple more related issues.
Comment #6
mile23+1 on scanning for themes under PHPUnit.
If you run
run-tests.sh, theme tests will run becauseTestDiscovery::getExtensions()scans for themes as well as other extensions.If you run the
phpunittool, theme tests won't run.Core's phpunit config now uses test suite discovery classes, which calls
drupal_phpunit_contrib_extension_directory_roots()frombootstrap.php.So here's a patch which changes
drupal_phpunit_contrib_extension_directory_roots()to look for themes, which then feeds into theTestSuiteset of classes.It's a simple change, and brings both tool chains into harmony.
Comment #8
dawehnerLooks perfect. We will have a usecase for themes maybe at some point.
Comment #9
davidwbarratt commented+1 for this!
Comment #10
alexpottThis looks like a good idea. Committed 73333c5 and pushed to 8.3.x. Committed 0a08d8e and pushed to 8.2.x. Committed eec19d0 and pushed to 8.1.x. Thanks!