#333060: Parent theme pattern clobbering is the perfect example of an issue that affects tweaky logic that only 2-3 people really understand and *really* needs to have regression tests to make sure it continues to work as intended. In fact, I would argue that 90% of the D6 theme system falls under this umbrella. ;)

It's challenging though because AFAIK we can't (currently) test the theme system in SimpleTest. It might be that the only problem is that we need hidden = TRUE recognized in .info files of themes? Or am I on crack and this is totally testable right now?

neclimdul has a nearly-complete test for this issue at http://drupal.org/node/333060#comment-1141774. Would love for the result of this issue to prove that this .zip file can be turned into a test that SimpleTest can run.

Comments

boombatower’s picture

This was discussed about a year ago (never officially) and kinda fell by the wayside.

I think the best way to test the theme layer is to create a "SimpleTest Theme" which seems like the track you're on with hidden = TRUE. Then implementing all possible override combinations and such and testing them by viewing the appropriate pages.

It would be nice to have a $this->setTheme(); method so the setUp() for a theme test could look like

function setUp() {
  parent::setupUp();
  $this->setTheme('SimpleTest');
}

The SimpleTest theme should be very "computer friendly". Each template can simply place a wrapper div around content with an id value representing the template. Or if we don't care about HTML we can go XML route and just make the tag the template id.

webchick’s picture

Category: task » bug

Another really useful set of test themes that are catching all sorts of fun bugs: http://drupal.org/node/489762#comment-1711762

I'm escalating this to a critical bug report. It's something we really do need to figure out.

boombatower’s picture

So what do we need? The tests can goto the theme page and change the active theme.

Please provide more details. The issue linked to has all passing tests?

webchick’s picture

I'm not sure, but it's possible that all we basically need is for themes to respect the hidden = TRUE property in .info files and a way to programmatically enable hidden themes from within a test like we do modules. And maybe add another search path for themes (or maybe not if themes/tests/[theme-name] works). Most of these tests involve enabling themes that have particularly tricky bits in their .info files or preprocess functions and checking to ensure that things worked properly.

boombatower’s picture

Assigned: Unassigned » boombatower

I am for supporting hidden = TRUE in themes. I'll work on a patch shortyl.

johnalbin’s picture

Assigned: boombatower » Unassigned
Status: Active » Needs review
StatusFileSize
new842 bytes

Here's the patch. :-)

I was surprised how easy this was to implement, but it was super easy to copy the necessary code from system_modules().

I think themes/tests/THEMENAME works. And we can't have just one simpletest theme because we need to test inheritance of base/sub themes.

dww’s picture

StatusFileSize
new2.09 KB

Rerolled to fix a few code comments up Update status now that themes can be hidden, too (_update_process_info_list() is already ignoring them, but the comments assumed those where for hidden modules). I'm going to try writing a test for #456088: Sub-themes not notified of security updates for base themes that depends on this patch, and if that all works nicely, I'll mark this RTBC.

dww’s picture

StatusFileSize
new2.59 KB

New patch that also adds a themes/tests/README.txt file. If you use this, you'll need:

cvs add themes/tests
cvs add themes/tests/README.txt
dww’s picture

It'd still be nice to have an easy way to enable these themes via test cases. For now, I'm just doing the following, which isn't ideal:

  db_update('system')
    ->fields(array('status' => 1))
    ->condition('type', 'theme')
    ->condition('name', 'update_test_subtheme')
    ->execute();

Otherwise, this is definitely working. I can add test themes under themes/tests/*, they don't show up at the "Appearance" page, but when I alter the .info files inside update status tests, it all works as expected. I'm tempted to mark this RTBC at this point, since we can always add the $this->setTheme('theme_name') function later, or other support mechanisms to make this easier. But, without the basic plumbing of hidden themes and a themes/tests directory in core, we simply cannot write tests that involve themes...

dave reid’s picture

Looks like a good start. I say we followup here or in separate issues for DWTC->setTheme() and maybe a function that can be re-used by both module and theme listings to 'hide' required or testing projects.

dave reid’s picture

Status: Needs review » Reviewed & tested by the community
robloach’s picture

function theme_dww_and_johnalbin() {
  return 'Awesome'; // Untranslatable, because they are too awesome.
}
johnalbin’s picture

StatusFileSize
new2.6 KB

Very minor text formatting change in themes/tests/README.txt to make it match the format of other README files in sites/all/. Otherwise identical, so still RTBC.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Oooh! Spiffy!! :D

Committed to HEAD! Can't wait for the follow-ups. :)

dww’s picture

Sweet, thanks webchick!

First follow-up: #456088-30: Sub-themes not notified of security updates for base themes. Should be RTBC, although it's my patch so I didn't say so. ;)

dww’s picture

BTW, once #456088 lands (or any patch that adds some hidden test themes like this), we could add a test in theme.test to ensure that the hidden themes aren't showing up on the Appearance page. ;)

Anonymous’s picture

Here's the setTheme method that's working for me:


     public function setTheme($new_theme) {
         db_update('system')->fields(array('status' => 1))
                            ->condition('type', 'theme')
                            ->condition('name', $new_theme)
                            ->execute(); 
         variable_set('theme_default', $new_theme);
         unset($GLOBALS['theme']);
         drupal_theme_initialize();
     }

Status: Fixed » Closed (fixed)

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

rfay’s picture

Version: 7.x-dev » 6.x-dev
Status: Closed (fixed) » Patch (to be ported)

Marking for backport to D6. This is important stuff!

proppy’s picture

The following code allow to set a new theme in simpletest D6 testcases:

  protected function setTheme($new_theme) {
    $this->assertTrue(db_query("update {system} set status=1 where type = 'theme' and name = '%s'", $new_theme), "Theme: $new_theme set as default");
    variable_set('theme_default', $new_theme);
    unset($GLOBALS['theme']);
    init_theme();
  }
boombatower’s picture

Status: Patch (to be ported) » Closed (won't fix)

Seems like this is long since dead.