Finally getting started with writing SimpleTests, thanks to DrupalCon...

For Forum Access I need to make use of Forum's SimpleTests:

1. The trivial but nonetheless very important test is to run Forum's tests with forum_access (and acl) enabled. Forum should continue to work whether these modules are enabled or not, and if Forum ever changes in a way that causes FA to break Forum, we want to know right away.

2. There are a lot of nice helper functions for exercising forum functionality in forum.test. Copy/pasting these to forum_access.test would be very bad form.

So, the Forum Access tests should be able to inherit from the ForumTestCase class. For that, I'd like to have the following:

Index: modules/forum/forum.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/forum/forum.test,v
retrieving revision 1.61
diff -u -r1.61 forum.test
--- modules/forum/forum.test	9 Aug 2010 01:18:46 -0000	1.61
+++ modules/forum/forum.test	27 Aug 2010 21:32:45 -0000
@@ -22,8 +22,8 @@
   /**
    * Enable modules and create users with specific permissions.
    */
-  function setUp() {
-    parent::setUp('taxonomy', 'comment', 'forum');
+  function setUp($modules = array()) {
+    parent::setUp(array('taxonomy', 'comment', 'forum') + $modules);
     // Create users.
     $this->admin_user = $this->drupalCreateUser(array('administer blocks', 'administer forums', 'administer menu', 'administer taxonomy', 'create forum content')); // 'access administration pages'));
     $this->edit_any_topics_user = $this->drupalCreateUser(array('create forum content', 'edit any forum content', 'delete any forum content', 'access administration pages'));

Passing an array to DrupalWebTestCase::setUp() is already supported, and the setUp() methods of all inheritable classes should also support injecting additional modules, so that they can be reused the OO way:

class ForumAccessTestCase extends ForumTestCase {

  function setUp() {
    parent::setUp(array('acl', 'forum_access'));
  }

The patch above would work, but this should probably be changed in all test classes in core, not just in ForumTestCase, and webchick tells me that it's too late even for Forum.

So, for now, here's a minor refactoring that provides a reasonable work-around: extract all the calls that need to be made after enabling a module from DrupalWebTestCase::setUp() into a separate helper function. This way, we can at least do...

class ForumAccessTestCase extends ForumTestCase {

  function setUp() {
    parent::setUp();
    module_enable(array('acl', 'forum_access'));
    $this->resetAll();
  }

... and don't need to duplicate a critical part of DrupalWebTestCase::setUp().

The attached patch does not change any functionality except for exposing the additional resetAll() method to derived classes.

I'm marking this as major bug because if the contrib tests use module_enable() and not resetAll(), and there's any core change in what needs to be done after enabling a module, then all those contrib tests may start to fail in subtle ways and will need to be debugged and fixed one by one. That would be a terrible waste of time.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

chx’s picture

Status: Active » Needs review

Let's see what the bot has to say

salvis’s picture

er, thanks!

chx’s picture

Status: Needs review » Reviewed & tested by the community

There is absolutely no reason not to do this.

salvis’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
2.5 KB

Thanks! I've added a one-line summary at the top of the doxygen comment of my new method, and I also adjusted the doxygen comment of the method above, from which I took the pattern.

There's no functional change compared to the patch in the OP.

klausi’s picture

Status: Needs review » Reviewed & tested by the community

Nice, will us help to use devel.module for debugging during simpletests
#852194: Debugging during Simpletest

Dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to CVS HEAD. Thanks.

Status: Fixed » Closed (fixed)

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