When testing, the $theme* globals are not reset. This causes test failures under the following circumstances:
- The site running tests has a different theme.
- Some test depends on specific theming output, which is altered by that theme.

Steps to reproduce:

- Install the corporateclean theme. Set a custom breadcrumb separator on the theme settings page
- If you are running tests through the GUI, make sure it is also the admin theme.
- Run the Blog, Forum or Theme tests.

Solution:

Reset the $theme* globals, so that the theme from the test environment is used.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Stevel created an issue. See original summary.

Stevel’s picture

brad.bulger’s picture

I ran into this problem trying to run the forum module test class ForumTestCase with the run-tests.sh script. It was invoking theme functions from the site's custom theme, causing the output to deviate from the test's expectations. When I ran the same test class from the UI, using the admin theme, I had no failures.

Applying this patch fixed the problem.

MustangGB’s picture

Status: Needs review » Reviewed & tested by the community

I too just encountered this whilst implementing hook_custom_theme() with the Bootstrap theme and running Views tests through the web interface.

My initial proposed fix for Views was very similar:

  abstract class ViewsSqlTest extends ViewsTestCase {
    ...

    public function setUp(array $modules = array()) {
      ...

+     global $theme;
+     $theme = NULL;
+     drupal_theme_rebuild();
    }

    ...
  }

However before submitting an issue I figured that actually other modules would also likely be affected, so better to fix it upstream.

Found this issue, and your code works perfectly.

My only comment is it looks like there is unnecessary whitespace being added here:

+ <<< Why?
+    // Reset the theme globals.

But other than that it looks good to go.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 2: drupal-2871459-reset-theme-globals.patch, failed testing. View results

poker10’s picture

Thanks for the patch. We are not going to introduce new dynamic properties, as these would cause deprecation messages in PHP 8.2.

+    $this->originalTheme = $theme;
+    $this->originalThemeKey = $theme_key;
+    $this->originalThemePath = $theme_path;

There is an issue which corrects this for all existing properties in the DrupalWebTestCase class, see: #3304882: [D7 PHP 8.2] Deprecated function: Creation of dynamic property in DrupalWebTestCase->prepareEnvironment(). This patch needs to be updated to correctly define all new properties, so they do not trigger deprecation messages in PHP 8.2.

Random testbot error switched the status to Needs Work, but let's keep it there until the dynamic properties are resolved.

mcdruid’s picture

MustangGB’s picture

It really didn't like the nearly 300 lines of offset I guess.

poker10’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +RTBM

This looks good, thanks! I have tested it manually (according to the steps outlined in the issue summary) and before the patch, there were multiple failures:

Breadcrumbs were displayed

After the patch is applied, the failures are gone.

  • mcdruid committed fc3079f on 7.x
    Issue #2871459 by mcdruid, Stevel, MustangGB, poker10, brad.bulger:...
mcdruid’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: -RTBM

Thank you!

Status: Fixed » Closed (fixed)

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