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

User interface changes

None.

API changes

None.

CommentFileSizeAuthor
#6 2070559_6.patch858 bytesmile23

Comments

webchick’s picture

It'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.

iamEAP’s picture

I 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++

ParisLiakos’s picture

related #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.

mile23’s picture

@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.

mile23’s picture

Issue summary: View changes

Adding a couple more related issues.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

mile23’s picture

Title: PHPUnit should register theme namespaces » Harmonize PHPUnit and run-tests to both scan for themes.
Version: 8.1.x-dev » 8.2.x-dev
Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new858 bytes

+1 on scanning for themes under PHPUnit.

If you run run-tests.sh, theme tests will run because TestDiscovery::getExtensions() scans for themes as well as other extensions.

If you run the phpunit tool, theme tests won't run.

Core's phpunit config now uses test suite discovery classes, which calls drupal_phpunit_contrib_extension_directory_roots() from bootstrap.php.

So here's a patch which changes drupal_phpunit_contrib_extension_directory_roots() to look for themes, which then feeds into the TestSuite set of classes.

It's a simple change, and brings both tool chains into harmony.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Looks perfect. We will have a usecase for themes maybe at some point.

davidwbarratt’s picture

+1 for this!

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

This 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!

  • alexpott committed 73333c5 on 8.3.x
    Issue #2070559 by Mile23: Harmonize PHPUnit and run-tests to both scan...

  • alexpott committed 0a08d8e on 8.2.x
    Issue #2070559 by Mile23: Harmonize PHPUnit and run-tests to both scan...

  • alexpott committed eec19d0 on 8.1.x
    Issue #2070559 by Mile23: Harmonize PHPUnit and run-tests to both scan...

Status: Fixed » Closed (fixed)

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